This is an archive of the discontinued LLVM Phabricator instance.

[git-clang-format] Add --diffstat parameter
ClosedPublic

Authored by roligugus on Jul 22 2020, 5:31 PM.

Details

Summary

[git-clang-format][PR46815] Add diffstat functionality

Adding a --diffstat parameter to git-clang-format that essentially uses git diff --stat, i.e. lists the files needing
formatting. This is useful for CI integration or manual usage where one wants to list the files not properly formatted.

I use it for the Suricata project's github action (CI) integration that verifies proper formatting of a pull request
according to project guidelines where it's very helpful to say which files are not properly formatted. I find the list
of files much more useful than e.g. showing the diff in this case using git-clang-format --diff.

An alternative would be to take an additional parameter to diff, e.g. git-clang-format --diff --stat

The goal is not to provide the whole git diff --stat=... parameter functionality, just plain git diff --stat.

Diff Detail

Event Timeline

roligugus created this revision.Jul 22 2020, 5:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2020, 5:31 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
roligugus added a project: Restricted Project.Jul 22 2020, 5:56 PM
roligugus marked an inline comment as done.
roligugus added inline comments.
clang/tools/clang-format/git-clang-format
102

As mentioned in the description, an alternative would be to add a --stat parameter and hand that to print_diff(). E.g. user would call it then with git-clang-format --diff --stat.

Would result in less code duplication of print_diff() vs print_diffstat().

This looks fine to me, but I haven't worked on this part of code myself, so probably others who have can provide better review.

aheejin resigned from this revision.Aug 8 2020, 2:28 AM
JakeMerdichAMD added a subscriber: JakeMerdichAMD.

Reviving this since it looks perfectly fine to me (from my limited commit history in git-clang-format :P), is useful, and there's no good reason for it to be stalled.

I'll wait a day or two to see if there's any objections, then accept it.

JakeMerdichAMD accepted this revision.Aug 23 2020, 3:40 PM
This revision is now accepted and ready to land.Aug 23 2020, 3:40 PM
roligugus requested review of this revision.Apr 29 2021, 7:28 PM

@JakeMerdichAMD, @MyDeveloperDay
Sorry to bother with a re-review. Did not know how to ask this.

Jake accepted this patch last August and it has been sitting in "ready to land" since then. I was assuming that it'll automatically make it into the main line after the acceptance. My bad, I should have read the policy and practices better.

Do you mind re-accepting and then committing this? I don't have any commit rights.

Sorry, I should have followed up way earlier. I was finally getting around to this and wanted to take our local patch out and was assuming this was in the latest clang, but it isn't.

@roligugus I can land this for you, please rebase the review then please add your name and email here so we can ensure you get the credit.

https://llvm.org/docs/DeveloperPolicy.html#commit-messages

MyDeveloperDay accepted this revision.Oct 14 2021, 12:46 AM
This revision is now accepted and ready to land.Oct 14 2021, 12:46 AM
roligugus updated this revision to Diff 379892.Oct 14 2021, 5:21 PM

[git-clang-format] Rebase D84375 on latest main

@MyDeveloperDay Thanks for the follow-up! I've rebased on latest main.

Out of curiosity, as I am trying to wrap my head around the llvm workflow: Could I arc land ... myself once you sign off with "ready to land" even if I don't have llvm commit rights? If so, please let me know and I'll do that.

Otherwise, I've set the author on my commit, but if you need to set it: git commit --amend --author="Roland Fischer <roli@gugus.ca>"

Thanks a lot!

@MyDeveloperDay Thanks for the follow-up! I've rebased on latest main.

Out of curiosity, as I am trying to wrap my head around the llvm workflow: Could I arc land ... myself once you sign off with "ready to land" even if I don't have llvm commit rights? If so, please let me know and I'll do that.

Otherwise, I've set the author on my commit, but if you need to set it: git commit --amend --author="Roland Fischer <roli@gugus.ca>"

Thanks a lot!

I personally don't use arc so I can't answer that, you DO need commit rights though, and you are free to apply for those. (normally I think you need to do some small issues first), but its worth applying if you plan to continue to contribute

I can land this for you for now.

I just tested this an it seems to work

$ git clang-format --diffstat
 clang/lib/Format/Format.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
This revision was automatically updated to reflect the committed changes.