diff options
author | Stephen Hines <srhines@google.com> | 2016-11-08 05:50:14 +0000 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2016-11-08 05:50:14 +0000 |
commit | f092121b2d390e791dc2dd87e4cd73d4fe582073 (patch) | |
tree | e00836123e9cd4c0ccd191e2b41769f610cb57ff /tools/clang-format | |
parent | d4a11674c514835fa7c9d75506b9886a5d891c41 (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286212 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format')
-rwxr-xr-x | tools/clang-format/git-clang-format | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/tools/clang-format/git-clang-format b/tools/clang-format/git-clang-format index ffa14368b6..74fd451a84 100755 --- a/tools/clang-format/git-clang-format +++ b/tools/clang-format/git-clang-format @@ -346,7 +346,16 @@ def run_clang_format_and_save_to_tree(changed_lines, revision=None, 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, |