This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Improve doc string to mention that paths in diff are used as-is
ClosedPublic

Authored by ctetreau on Apr 28 2020, 4:26 PM.

Details

Summary

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.

Add note to doc string to warn users about the fact that filenames
embedded in the diff are used as-is with no attempts to "do what they
mean, not what they say"

Diff Detail

Event Timeline

ctetreau created this revision.Apr 28 2020, 4:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2020, 4:26 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

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.

We should probably encourage people to use git-clang-format with git repositories. It naturally doesn't have this sort of fragility because it integrates with the repository more tightly.

clang/tools/clang-format/clang-format-diff.py
45

That isn't specific to -i. If you look more carefully at what the command is doing, it always goes back to the original source file.

ctetreau updated this revision to Diff 262433.May 6 2020, 11:41 AM

address code review issues

ctetreau retitled this revision from [NFC] Improve documentation for -i and update example git one liner to [NFC] Improve doc string to mention that paths in diff are used as-is.May 6 2020, 11:42 AM
ctetreau edited the summary of this revision. (Show Details)

We should probably encourage people to use git-clang-format with git repositories. It naturally doesn't have this sort of fragility because it integrates with the repository more tightly.

That may be a better choice for me personally, but other version control systems exist, and this is a tool with broader appeal.

efriedma accepted this revision.May 6 2020, 2:31 PM

LGTM

This revision is now accepted and ready to land.May 6 2020, 2:31 PM
This revision was automatically updated to reflect the committed changes.