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)
Developer Infrastructure
Source Code Analysis
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`
Assignee | ||
Comment 1•7 years ago
|
||
Hey Sylvestre, I would like to work on this. 'git diff .. --*.[some_extension]*' works for excluding files based on extensions.
Reporter | ||
Comment 2•7 years ago
|
||
Sure, please go ahead and propose a patch!
Assignee | ||
Comment 3•7 years ago
|
||
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 hidden (mozreview-request) |
Reporter | ||
Comment 5•7 years ago
|
||
mozreview-review |
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?
Assignee | ||
Comment 6•7 years ago
|
||
mozreview-review-reply |
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
Assignee | ||
Comment 7•7 years ago
|
||
mozreview-review-reply |
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
Reporter | ||
Comment 8•7 years ago
|
||
mozreview-review |
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 hidden (mozreview-request) |
Reporter | ||
Comment 10•7 years ago
|
||
mozreview-review |
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)
Assignee | ||
Updated•7 years ago
|
Attachment #8894768 -
Attachment is obsolete: true
Assignee | ||
Updated•7 years ago
|
Attachment #8894777 -
Attachment is obsolete: true
Attachment #8894777 -
Flags: review?(sledru)
Reporter | ||
Updated•7 years ago
|
Assignee: nobody → prithviraj10pawar
Comment hidden (mozreview-request) |
Reporter | ||
Comment 12•7 years ago
|
||
mozreview-review |
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)
Reporter | ||
Updated•7 years ago
|
Attachment #8894891 -
Flags: review?(sledru) → review?(gps)
Reporter | ||
Comment 13•7 years ago
|
||
I transferred the review to gps because I am not owner of this code.
Comment hidden (mozreview-request) |
Assignee | ||
Comment 15•7 years ago
|
||
mozreview-review |
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
Reporter | ||
Comment 16•7 years ago
|
||
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
Reporter | ||
Updated•7 years ago
|
Attachment #8894891 -
Flags: review?(sledru)
Attachment #8894891 -
Flags: review?(gps)
Reporter | ||
Comment 17•7 years ago
|
||
mozreview-review |
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-
Assignee | ||
Comment 18•7 years ago
|
||
(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?
Reporter | ||
Comment 19•7 years ago
|
||
"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)
Assignee | ||
Comment 20•7 years ago
|
||
Yeah I got it. You can use $ git diff --no-color -U0 HEAD -- *.cpp
It shows only the local changes
Reporter | ||
Comment 21•7 years ago
|
||
Good, please update your patch then :)
Assignee | ||
Comment 22•7 years ago
|
||
yeah !!
Assignee | ||
Updated•7 years ago
|
Attachment #8894891 -
Attachment is obsolete: true
Comment hidden (mozreview-request) |
Reporter | ||
Comment 24•7 years ago
|
||
If I understood correctly, the git part never worked as planned, right?
Assignee | ||
Comment 25•7 years ago
|
||
$git diff HEAD ....will show all the changes since the previous commit in local repo...also $filterdiff is avoided...
Assignee | ||
Comment 26•7 years ago
|
||
mozreview-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/#review173120
Attachment #8896626 -
Flags: review+
Assignee | ||
Comment 27•7 years ago
|
||
mozreview-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)
Reporter | ||
Comment 28•7 years ago
|
||
mozreview-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
::: 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
Reporter | ||
Comment 29•7 years ago
|
||
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 hidden (mozreview-request) |
Assignee | ||
Comment 31•7 years ago
|
||
mozreview-review-reply |
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.
Reporter | ||
Comment 32•7 years ago
|
||
mozreview-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
Bravo. There are some room for improvements, are you interested?
Attachment #8896626 -
Flags: review?(sledru) → review+
Comment 33•7 years ago
|
||
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
Assignee | ||
Comment 34•7 years ago
|
||
mozreview-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/#review173150
Attachment #8896626 -
Flags: review+
Assignee | ||
Comment 35•7 years ago
|
||
mozreview-review-reply |
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.
Reporter | ||
Comment 36•7 years ago
|
||
This is bug 1389956
Comment 37•7 years ago
|
||
bugherder |
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Updated•7 years ago
|
Attachment #8896626 -
Flags: review?(gps)
Updated•7 years ago
|
Product: Core → Firefox Build System
Comment 38•6 years ago
|
||
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)
Reporter | ||
Comment 39•6 years ago
|
||
nope, we want the same experience with git & hg.
Could you please open a new bug about that?
thanks
Flags: needinfo?(sledru)
Comment 40•4 years ago
|
||
I filed bug 1674281
Updated•2 years ago
|
Product: Firefox Build System → Developer Infrastructure
You need to log in
before you can comment on or make changes to this bug.
Description
•