[PATCH] D84375: [git-clang-format] Add --diffstat parameter

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 15 01:57:07 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG191a395343b9: [git-clang-format] Add --diffstat parameter (authored by roligugus, committed by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84375/new/

https://reviews.llvm.org/D84375

Files:
  clang/tools/clang-format/git-clang-format


Index: clang/tools/clang-format/git-clang-format
===================================================================
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -99,6 +99,8 @@
                  help='default commit to use if none is specified'),
   p.add_argument('--diff', action='store_true',
                  help='print a diff instead of applying the changes')
+  p.add_argument('--diffstat', action='store_true',
+                 help='print a diffstat instead of applying the changes')
   p.add_argument('--extensions',
                  default=config.get('clangformat.extensions',
                                     default_extensions),
@@ -176,6 +178,8 @@
       print('clang-format did not modify any files')
   elif opts.diff:
     print_diff(old_tree, new_tree)
+  elif opts.diffstat:
+    print_diffstat(old_tree, new_tree)
   else:
     changed_files = apply_changes(old_tree, new_tree, force=opts.force,
                                   patch_mode=opts.patch)
@@ -506,6 +510,17 @@
   subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree,
                          '--'])
 
+def print_diffstat(old_tree, new_tree):
+  """Print the diffstat between the two trees to stdout."""
+  # We use the porcelain 'diff' and not plumbing 'diff-tree' because the output
+  # is expected to be viewed by the user, and only the former does nice things
+  # like color and pagination.
+  #
+  # We also only print modified files since `new_tree` only contains the files
+  # that were modified, so unmodified files would show as deleted without the
+  # filter.
+  subprocess.check_call(['git', 'diff', '--diff-filter=M', '--stat', old_tree, new_tree,
+                         '--'])
 
 def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
   """Apply the changes in `new_tree` to the working directory.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84375.379938.patch
Type: text/x-patch
Size: 1900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211015/b1cd2896/attachment.bin>


More information about the cfe-commits mailing list