[PATCH] D79054: [NFC] Improve documentation for -i and update example git one liner

Christopher Tetreault via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 28 16:45:49 PDT 2020


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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79054.260795.patch
Type: text/x-patch
Size: 1282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200428/398b48f4/attachment.bin>


More information about the cfe-commits mailing list