[clang] 0fd0a01 - [git-clang-format] Do not apply clang-format to symlinks
Pirama Arumuga Nainar via cfe-commits
cfe-commits at lists.llvm.org
Tue May 11 10:35:00 PDT 2021
Author: Pirama Arumuga Nainar
Date: 2021-05-11T10:34:40-07:00
New Revision: 0fd0a010a1ed2ce761d20bfc6378e5bbaa75c8de
URL: https://github.com/llvm/llvm-project/commit/0fd0a010a1ed2ce761d20bfc6378e5bbaa75c8de
DIFF: https://github.com/llvm/llvm-project/commit/0fd0a010a1ed2ce761d20bfc6378e5bbaa75c8de.diff
LOG: [git-clang-format] Do not apply clang-format to symlinks
This fixes PR46992.
Git stores symlinks as text files and we should not format them even if
they have one of the requested extensions.
(Move the call to `cd_to_toplevel()` up a few lines so we can also print
the skipped symlinks during verbose output.)
Differential Revision: https://reviews.llvm.org/D101878
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/tools/clang-format/git-clang-format
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bb8a28ed236ba..17351278974df 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -244,6 +244,9 @@ clang-format
accepts ``AllIfsAndElse`` value that allows to put "else if" and "else" short
statements on a single line. (Fixes https://llvm.org/PR50019.)
+- ``git-clang-format`` no longer formats changes to symbolic links. (Fixes
+ https://llvm.org/PR46992.)
+
libclang
--------
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index ccd2f50fa4ad2..3646b4ff41d7f 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -137,10 +137,15 @@ def main():
if opts.verbose >= 1:
ignored_files = set(changed_lines)
filter_by_extension(changed_lines, opts.extensions.lower().split(','))
+ # The computed
diff outputs absolute paths, so we must cd before accessing
+ # those files.
+ cd_to_toplevel()
+ filter_symlinks(changed_lines)
if opts.verbose >= 1:
ignored_files.
diff erence_update(changed_lines)
if ignored_files:
- print('Ignoring changes in the following files (wrong extension):')
+ print(
+ 'Ignoring changes in the following files (wrong extension or symlink):')
for filename in ignored_files:
print(' %s' % filename)
if changed_lines:
@@ -151,9 +156,6 @@ def main():
if opts.verbose >= 0:
print('no modified files to format')
return
- # The computed
diff outputs absolute paths, so we must cd before accessing
- # those files.
- cd_to_toplevel()
if len(commits) > 1:
old_tree = commits[1]
new_tree = run_clang_format_and_save_to_tree(changed_lines,
@@ -337,6 +339,13 @@ def filter_by_extension(dictionary, allowed_extensions):
del dictionary[filename]
+def filter_symlinks(dictionary):
+ """Delete every key in `dictionary` that is a symlink."""
+ for filename in list(dictionary.keys()):
+ if os.path.islink(filename):
+ del dictionary[filename]
+
+
def cd_to_toplevel():
"""Change to the top level of the git repository."""
toplevel = run('git', 'rev-parse', '--show-toplevel')
More information about the cfe-commits
mailing list