r286212 - clang-format: Use git-ls-tree to get file mode in diff mode
    Stephen Hines via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Mon Nov  7 21:50:14 PST 2016
    
    
  
Author: srhines
Date: Mon Nov  7 23:50:14 2016
New Revision: 286212
URL: http://llvm.org/viewvc/llvm-project?rev=286212&view=rev
Log:
clang-format: Use git-ls-tree to get file mode in diff mode
Summary:
If a file has been renamed/deleted from the filesystem and --diff mode
with two commits is active, attempting to get the file's mode will fail.
This change uses git-ls-tree instead to get the correct permissions for
the given revision.
Patch by Luis Hector Chavez!
Reviewers: djasper, lodato
Subscribers: srhines, cfe-commits
Differential Revision: https://reviews.llvm.org/D26287
Modified:
    cfe/trunk/tools/clang-format/git-clang-format
Modified: cfe/trunk/tools/clang-format/git-clang-format
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/git-clang-format?rev=286212&r1=286211&r2=286212&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/git-clang-format (original)
+++ cfe/trunk/tools/clang-format/git-clang-format Mon Nov  7 23:50:14 2016
@@ -346,7 +346,16 @@ def run_clang_format_and_save_to_tree(ch
   Returns the object ID (SHA-1) of the created tree."""
   def index_info_generator():
     for filename, line_ranges in changed_lines.iteritems():
-      mode = oct(os.stat(filename).st_mode)
+      if revision:
+        git_metadata_cmd = ['git', 'ls-tree',
+                            '%s:%s' % (revision, os.path.dirname(filename)),
+                            os.path.basename(filename)]
+        git_metadata = subprocess.Popen(git_metadata_cmd, stdin=subprocess.PIPE,
+                                        stdout=subprocess.PIPE)
+        stdout = git_metadata.communicate()[0]
+        mode = oct(int(stdout.split()[0], 8))
+      else:
+        mode = oct(os.stat(filename).st_mode)
       blob_id = clang_format_to_blob(filename, line_ranges,
                                      revision=revision,
                                      binary=binary,
    
    
More information about the cfe-commits
mailing list