ctetreau created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ctetreau added reviewers: djasper, alexfh.
ctetreau added a comment.

I considered trying to find a way to work around the issue. Something like "if 
the file is not found, and the current directory is `/foo/bar/`, and the 
computed filename is `bar/baz.c`, then use `/foo/bar/baz.c`". But I don't think 
there's any way we can reliably know that such a computed file is correct, and 
I think it's better to error out than to silently do the wrong thing.

I think the behavior of taking the filename from the diff as-is is reasonable 
as long as it's documented.


- Improve the documentation of -i to mention that the path contained in

the diff is used as-is as the file to update.

- Add --relative to the suggested git-diff one liner. If the user does not

pass this argument, then git will produce a diff with the path relative
to the repository root. If the user's working directory is not the
repository root, then clang-format will complain that the file is not
found. The --relative argument makes git produce a diff with the files
relative to the working directory.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79054

Files:
  clang/tools/clang-format/clang-format-diff.py


Index: clang/tools/clang-format/clang-format-diff.py
===================================================================
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -13,7 +13,7 @@
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git diff -U0 --no-color HEAD^ | clang-format-diff.py -p1 -i
+  git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i
   svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
 
 """
@@ -36,7 +36,9 @@
                                    formatter_class=
                                            
argparse.RawDescriptionHelpFormatter)
   parser.add_argument('-i', action='store_true', default=False,
-                      help='apply edits to files instead of displaying a diff')
+                      help='apply edits to files instead of displaying a diff.'
+                      ' The filename contained in the diff is used unmodified'
+                      ' to determine the source file to update')
   parser.add_argument('-p', metavar='NUM', default=0,
                       help='strip the smallest prefix containing P slashes')
   parser.add_argument('-regex', metavar='PATTERN', default=None,


Index: clang/tools/clang-format/clang-format-diff.py
===================================================================
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -13,7 +13,7 @@
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git diff -U0 --no-color HEAD^ | clang-format-diff.py -p1 -i
+  git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i
   svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
 
 """
@@ -36,7 +36,9 @@
                                    formatter_class=
                                            argparse.RawDescriptionHelpFormatter)
   parser.add_argument('-i', action='store_true', default=False,
-                      help='apply edits to files instead of displaying a diff')
+                      help='apply edits to files instead of displaying a diff.'
+                      ' The filename contained in the diff is used unmodified'
+                      ' to determine the source file to update')
   parser.add_argument('-p', metavar='NUM', default=0,
                       help='strip the smallest prefix containing P slashes')
   parser.add_argument('-regex', metavar='PATTERN', default=None,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to