Closed Bug 1387036 Opened 7 years ago Closed 7 years ago

./mach clang-format - improve the git filter

Categories

(Developer Infrastructure :: Source Code Analysis, enhancement)

enhancement
Not set
normal

Tracking

(firefox57 fixed)

RESOLVED FIXED
mozilla57
Tracking Status
firefox57 --- fixed

People

(Reporter: Sylvestre, Assigned: prithviraj10pawar, Mentored)

References

Details

(Keywords: good-first-bug, Whiteboard: [good first bug][lang=python])

Attachments

(1 file, 3 obsolete files)

gps: Alternatively, you can first run `git diff --name-only` to print a list of files in the diff. Then you can invoke `git diff .. -- <paths>` on only the files you care about. Also, I'm kinda surprised git doesn't have a built-in command to filter diffs. ---- glandium: Not sure about excluding files, but you can do `git diff ... -- *.cpp *.c *.h`
Hey Sylvestre, I would like to work on this. 'git diff .. --*.[some_extension]*' works for excluding files based on extensions.
Sure, please go ahead and propose a patch!
I think there is a patch to be done in tools/mach_commands.py. Please confirm this Sylvestre. Is there any other file associated with this bug?
Comment on attachment 8894768 [details] Bug 1387036 - Improved the ./mach clang-format git filter. https://reviewboard.mozilla.org/r/165936/#review171052 ::: tools/mach_commands.py:270 (Diff revision 1) > diff_process = Popen(["hg", "diff", "-U0", "-r", ".^", > "--include", "glob:**.c", "--include", "glob:**.cpp", > "--include", "glob:**.h", > "--exclude", "listfile:.clang-format-ignore"], stdout=PIPE) > else: > - git_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD^"], stdout=PIPE) > + git_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD^","--","*.cpp","*.c","*.h","':!.clang-format-ignore'"], stdout=PIPE) Why do you have to explicitly list .clang-format-ignore? Because it is formatted otherwise?
Comment on attachment 8894768 [details] Bug 1387036 - Improved the ./mach clang-format git filter. https://reviewboard.mozilla.org/r/165936/#review171052 previously filterdiff had an --exclude flag for it. i thought it needs to be excluded here as well
Comment on attachment 8894768 [details] Bug 1387036 - Improved the ./mach clang-format git filter. https://reviewboard.mozilla.org/r/165936/#review171052 > Why do you have to explicitly list .clang-format-ignore? > Because it is formatted otherwise? previously filterdiff had an --exclude flag for it. i thought it needs to be excluded here as well
Comment on attachment 8894768 [details] Bug 1387036 - Improved the ./mach clang-format git filter. https://reviewboard.mozilla.org/r/165936/#review171058 ::: tools/mach_commands.py:270 (Diff revision 1) > diff_process = Popen(["hg", "diff", "-U0", "-r", ".^", > "--include", "glob:**.c", "--include", "glob:**.cpp", > "--include", "glob:**.h", > "--exclude", "listfile:.clang-format-ignore"], stdout=PIPE) > else: > - git_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD^"], stdout=PIPE) > + git_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD^","--","*.cpp","*.c","*.h","':!.clang-format-ignore'"], stdout=PIPE) I don't think it is necessary with this change! Thanks
Comment on attachment 8894777 [details] Bug 1387036 ./mach clang-format - improve the git filter https://reviewboard.mozilla.org/r/165944/#review171062 ::: tools/mach_commands.py:270 (Diff revision 1) > diff_process = Popen(["hg", "diff", "-U0", "-r", ".^", > "--include", "glob:**.c", "--include", "glob:**.cpp", > "--include", "glob:**.h", > "--exclude", "listfile:.clang-format-ignore"], stdout=PIPE) > else: > - git_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD^","--","*.cpp","*.c","*.h","':!.clang-format-ignore'"], stdout=PIPE) > + git_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD^","--","*.cpp","*.c","*.h"], stdout=PIPE) You create a new commit, you should amend the other (sorry)
Attachment #8894768 - Attachment is obsolete: true
Attachment #8894777 - Attachment is obsolete: true
Attachment #8894777 - Flags: review?(sledru)
Assignee: nobody → prithviraj10pawar
Comment on attachment 8894891 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/166044/#review171200 ::: commit-message-a921b:1 (Diff revision 1) > +Bug 1387036 : Improved git filter ./mach clang-format Please explain a bit more what you did (improved is too generic)
Attachment #8894891 - Flags: review?(sledru) → review?(gps)
I transferred the review to gps because I am not owner of this code.
Comment on attachment 8894891 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/166044/#review171322
Several things: * please test your change. Seems that you didn't as it is failing with: UnboundLocalError: local variable 'diff_process' referenced before assignment * git diff --no-color -U0 HEAD^ -- *.cpp shows the list of every diff in *.cpp from the previous commit, not the local changes. For example, with hg, we are doing $ hg diff -U0 -r .^ dom/ which will show only the local changes in dom/ * you can probably simplify the code by having one Popen() declaration and using the if else: just to declare the command
Attachment #8894891 - Flags: review?(sledru)
Attachment #8894891 - Flags: review?(gps)
Comment on attachment 8894891 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/166044/#review171354
Attachment #8894891 - Flags: review-
(In reply to Sylvestre Ledru [:sylvestre] from comment #16) > Several things: > * please test your change. Seems that you didn't as it is failing with: > UnboundLocalError: local variable 'diff_process' referenced before assignment > > * git diff --no-color -U0 HEAD^ -- *.cpp > shows the list of every diff in *.cpp from the previous commit, not the > local changes. > > For example, with hg, we are doing > $ hg diff -U0 -r .^ dom/ > which will show only the local changes in dom/ > > * you can probably simplify the code by having one Popen() declaration and > using the > if > else: > just to declare the command HEAD^ shows all the changes before and after commit . If we use HEAD then it shows only the changes after the latest commit. Please verfiy?
"hg clang-format" should be applied only on the local changes (not committed) For example: $ git diff dom/presentation/AvailabilityCollection.cpp diff --git a/dom/presentation/AvailabilityCollection.cpp b/dom/presentation/AvailabilityCollection.cpp index 73752c750524..3282efbd6baf 100644 --- a/dom/presentation/AvailabilityCollection.cpp +++ b/dom/presentation/AvailabilityCollection.cpp @@ -10,7 +10,7 @@ #include "PresentationAvailability.h" namespace mozilla { -namespace dom { + namespace dom { /* static */ StaticAutoPtr<AvailabilityCollection> $ git diff --no-color -U0 HEAD^ -- *.cpp diff --git a/dom/presentation/AvailabilityCollection.cpp b/dom/presentation/AvailabilityCollection.cpp index 73752c750524..3282efbd6baf 100644 --- a/dom/presentation/AvailabilityCollection.cpp +++ b/dom/presentation/AvailabilityCollection.cpp @@ -13 +13 @@ namespace mozilla { -namespace dom { + namespace dom { diff --git a/image/ImageFactory.cpp b/image/ImageFactory.cpp index 11e2703a4a24..8c62a23ac8f9 100644 --- a/image/ImageFactory.cpp +++ b/image/ImageFactory.cpp @@ -99 +99,2 @@ ImageFactory::CreateImage(nsIRequest* aRequest, - if (NS_WARN_IF(obs)) { + NS_WARNING_ASSERTION(obs, "Can't get an observer service handle"); + if (obs) { diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index 3586f322639f..a74204bb30e8 100644 --- a/image/RasterImage.cpp [...] I should get only the first file, the other are from another previous commit (4346bdf652efd32d614191d50215d3b553589c51 here)
Yeah I got it. You can use $ git diff --no-color -U0 HEAD -- *.cpp It shows only the local changes
Good, please update your patch then :)
yeah !!
Attachment #8894891 - Attachment is obsolete: true
If I understood correctly, the git part never worked as planned, right?
$git diff HEAD ....will show all the changes since the previous commit in local repo...also $filterdiff is avoided...
Comment on attachment 8896626 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/167912/#review173120
Attachment #8896626 - Flags: review+
Comment on attachment 8896626 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/167912/#review173132
Attachment #8896626 - Flags: review+ → review?(prithviraj10pawar)
Comment on attachment 8896626 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/167912/#review173140 ::: tools/mach_commands.py:270 (Diff revision 1) > diff_process = Popen(["hg", "diff", "-U0", "-r", ".^", > "--include", "glob:**.c", "--include", "glob:**.cpp", > "--include", "glob:**.h", > "--exclude", "listfile:.clang-format-ignore"], stdout=PIPE) > else: > - git_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD^"], stdout=PIPE) > + diff_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD","--","*.c","*.cpp","*.h"], stdout=PIPE) please remove the trailing whitespace
Comment on attachment 8896626 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. Besides that, works great!
Attachment #8896626 - Flags: review?(sledru)
Attachment #8896626 - Flags: review?(prithviraj10pawar)
Attachment #8896626 - Flags: review+
Comment on attachment 8896626 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/167912/#review173140 > please remove the trailing whitespace sure.
Comment on attachment 8896626 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/167912/#review173146 Bravo. There are some room for improvements, are you interested?
Attachment #8896626 - Flags: review?(sledru) → review+
Pushed by sledru@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b941b5a3550d /mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. r=sylvestre
Comment on attachment 8896626 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/167912/#review173150
Attachment #8896626 - Flags: review+
Comment on attachment 8896626 [details] Bug 1387036 : ./mach clang-format , removed filterdiff and added "git diff -- *" for restricting diff to a given set of file extensions. https://reviewboard.mozilla.org/r/167912/#review173146 Thanks!! Yeah. I am interested.
Depends on: 1389956
This is bug 1389956
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Attachment #8896626 - Flags: review?(gps)
Product: Core → Firefox Build System
This change seems to created a behaviour difference between the 'hg' and 'git' versions. hg diff .^ includes the changes from the current commit git diff HEAD does not include those changes. Is this behaviour difference intentional?
Flags: needinfo?(sledru)
nope, we want the same experience with git & hg. Could you please open a new bug about that? thanks
Flags: needinfo?(sledru)
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: