- Commit:
-
b514985cd6f766cde96bb5f23a761e7a048c910f45e97eb0a1c33524969ca95df0409082fe661e3d
- Diff:
-
Revision 2 (+92)
Add extra context for added and deleted empty files.
Review Request #5802 — Created May 12, 2014 and submitted
Review Board could not handle added or deleted empty files in SVN, Mercurial,
and Perforce diffs since the diff output fromsvn diff
/hg diff
did not
provide enough context on empty files. This change adds extra processing in
RBTools to generate a diff with extra information on any added or deleted empty
files, if the Review Board server has theempty_files
capability for the
SCM tool in question.The original SVN diff output of an added/deleted empty file was:
Index: foo ===================================================================
After this change, the SVN diff of an added empty file becomes:
Index: foo\t(added) =================================================================== --- foo\t(<base_revision>) +++ foo\t(<tip_revision>)
For Mercurial, the diff of an added empty file is now:
diff -r <base_revision> -r <tip_revision> foo --- /dev/null\tThu Jan 01 00:00:00 1970 +0000 +++ b/foo\t<date>
For Perforce, the diff of an added empty file is:
==== //depot/foo#0 ==A== //depot/foo ====
Ran
rbt post
on a RB server with theempty_files
capabilities with different
SVN, Mercurial, and Perforce diffs, and verified that the modified diffs were
as expected:
- Diff with 1 added empty file
- Diff with 1 added empty file, 1 added non-empty file
- Diff with 1 deleted empty file
- Diff with 1 deleted empty file, 1 deleted non-empty file
- Diff with 1 added empty file, 1 deleted empty file
- Diff with 1 added empty file, 1 added non-empty file, 1 deleted empty file,
1 deleted non-empty file, 1 modified fileRan
rbt post
on a RB server without theempty_files
capabilities, and
verified that the generated diffs did not include any extra information on
added/deleted empty files. These added/deleted empty files were not included in
the review requests.Ran unit tests. More testing was done in /r/5785 as well.
Description | From | Last Updated |
---|---|---|
It would be nice to use re.compile() outside the for loop, so it won't recompile the regex each iteration. |
david | |
It would be nice to use re.compile() outside the for loop, so it won't recompile the regex each iteration. |
david | |
'files' will always be a list, so you can just use the list comprehension version and skip the if/else. If … |
david | |
Should this be _handle_empty_files? |
david | |
Put spaces around the +s |
david | |
This could be if dl == [] and not is_move and changetype_short not in ('A', 'D'): |
david | |
Col: 5 E129 visually indented line with same indent as next logical line |
reviewbot | |
I dare say that parsing diffs should never be the answer. When you emailed me, I neglected to tell you … |
IN indygreg | |
I would use hg locate to obtain the set of all files in each changeset. Take the set difference to … |
IN indygreg | |
You should be using :: instead of : for the revision set. : is revision order (order changesets were added … |
IN indygreg | |
I would return a set from _get_files_in_changeset() and use the overloaded operators on set. e.g. added_empty_files = tip_empty_files - base_files |
IN indygreg | |
This logic is kind of confusing. How about this: is_empty_and_changed = (self._supports_empty_files() and changetype_short in ('A', 'D')) if dl == … |
david |
- Change Summary:
-
Add support for Mercurial.
- Summary:
-
Add extra context for added and deleted empty files in SVN diffs.Add extra context for added and deleted empty files in SVN and Mercurial diffs.
- Description:
-
~ Review Board could not handle added or deleted empty files in SVN diffs since
~ the diff output from svn diff
did not provide enough context on empty files.~ This change adds extra processing in RBTools to generate a diff with extra ~ information on any added or deleted empty files. ~ Review Board could not handle added or deleted empty files in SVN and Mercurial
~ diffs since the diff output from svn diff
/hg diff
did not provide enough~ context on empty files. This change adds extra processing in RBTools to ~ generate a diff with extra information on any added or deleted empty files. The original SVN diff output of an added/deleted empty file was:
~ Index: foo\n
~ ===================================================================\n
~ Index: foo
~ ===================================================================
After this change, the SVN diff of an added empty file becomes:
~ Index: foo\t(added)\n
~ ===================================================================\n
~ --- foo\t(<base_revision>)\n
~ +++ foo\t(<tip_revision>)\n
~ Index: foo\t(added)
~ ===================================================================
~ --- foo\t(<base_revision>)
~ +++ foo\t(<tip_revision>)
~ Similarly, the SVN diff of a deleted empty file becomes:
~ For Mercurial, the diff of an added empty file is now:
~ Index: foo\t(deleted)\n
~ ===================================================================\n
~ --- foo\t(<base_revision>)\n
~ diff -r <base_revision> -r <tip_revision> foo
~ --- /dev/null\tThu Jan 01 00:00:00 1970 +0000
~ +++ b/foo\t<date>
- +++ foo\t(<tip_revision>)\n
- Testing Done:
-
~ Ran
rbt post
with different SVN diffs, and verified that the modified diffs~ were as expected: ~ Ran
rbt post
with different SVN and Mercurial diffs, and verified that the~ modified diffs were as expected: - Diff with 1 added empty file - Diff with 1 deleted empty file - Diff with 1 added empty file, 1 deleted empty file - Diff with 1 added empty file, 1 added non-empty file, 1 deleted empty file, 1 deleted non-empty file, 1 modified file ~ More testing was done in /r/5785 as well.
~ Ran unit tests. More testing was done in /r/5785 as well.
- Commit:
-
45e97eb0a1c33524969ca95df0409082fe661e3d533a9f997321bf39b5bcb4d5f39ac8c931798173
-
-
It would be nice to use
re.compile()
outside the for loop, so it won't recompile the regex each iteration. -
It would be nice to use
re.compile()
outside the for loop, so it won't recompile the regex each iteration. -
'files' will always be a list, so you can just use the list comprehension version and skip the if/else. If files is empty, it's the same as returning
[]
-
-
- Change Summary:
-
Fix review issues, and add support for Perforce.
- Summary:
-
Add extra context for added and deleted empty files in SVN and Mercurial diffs.Add extra context for added and deleted empty files.
- Description:
-
~ Review Board could not handle added or deleted empty files in SVN and Mercurial
~ diffs since the diff output from svn diff
/hg diff
did not provide enough~ context on empty files. This change adds extra processing in RBTools to ~ generate a diff with extra information on any added or deleted empty files. ~ Review Board could not handle added or deleted empty files in SVN, Mercurial,
~ and Perforce diffs since the diff output from svn diff
/hg diff
did not~ provide enough context on empty files. This change adds extra processing in ~ RBTools to generate a diff with extra information on any added or deleted empty + files. The original SVN diff output of an added/deleted empty file was:
Index: foo
===================================================================
After this change, the SVN diff of an added empty file becomes:
Index: foo\t(added)
===================================================================
--- foo\t(<base_revision>)
+++ foo\t(<tip_revision>)
For Mercurial, the diff of an added empty file is now:
diff -r <base_revision> -r <tip_revision> foo
--- /dev/null\tThu Jan 01 00:00:00 1970 +0000
+++ b/foo\t<date>
+ + + + For Perforce, the diff of an added empty file is:
+ + ==== //depot/foo#0 ==A== //depot/foo ====
+ - Testing Done:
-
~ Ran
rbt post
with different SVN and Mercurial diffs, and verified that the~ modified diffs were as expected: ~ Ran
rbt post
with different SVN, Mercurial, and Perforce diffs, and verified~ that the modified diffs were as expected: - Diff with 1 added empty file - Diff with 1 deleted empty file - Diff with 1 added empty file, 1 deleted empty file - Diff with 1 added empty file, 1 added non-empty file, 1 deleted empty file, 1 deleted non-empty file, 1 modified file Ran unit tests. More testing was done in /r/5785 as well.
- Commit:
-
533a9f997321bf39b5bcb4d5f39ac8c9317981735345f75f72b150c934f45b499d2d03e13c318bdb
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
I only looked at the Mercurial changes.
I would rewrite things in terms of
hg locate
. I believe the implementation will be much cleaner.I apologize for not informing you of the existence of filesets via email. It simply slipped my mind. I didn't intend to make you look bad. If another problem I was trying to solve hadn't required me to look at the help page for filesets and see it offers a size() query, I likely wouldn't have remembered at all!
-
For performance reasons, it's unfortunate we have to invoke
hg
more than once to obtain this data.That being said, this will only be an issue on very large repositories (like Firefox's). We already have enough performance problems with rbt on large repositories. I wouldn't worry too much about it.
-
I dare say that parsing diffs should never be the answer.
When you emailed me, I neglected to tell you about a Mercurial feature called filesets. (See http://www.selenic.com/hg/help/filesets). Essentially, any command that takes file arguments can take these fileset queries to dynamically query Mercurial.
In the case of file adds, we can look for 0-size files in an arbitrary changeset:
$ hg locate -r <rev> 'set:size(0)'
So, you can take the output of
hg log --template '{join(file_adds, "\n")}' -r A::B
and intersect that set with the output ofhg locate
from above to find added empty files. This should perform much better than generating a diff (which is relatively slow for Mercurial). Alternatively, you can take the output ofhg locate
for the base and tip revisions and find added entries manually. This may be better than parsinghg log
output. -
I would use
hg locate
to obtain the set of all files in each changeset. Take the set difference to obtain deleted files. Limit the query of the base revision with 'set:size(0)' to only show files that were empty initially. -
You should be using :: instead of : for the revision set. : is revision order (order changesets were added to Mercurial). :: is DAG order. : may include changesets from unrelated branches/heads.
- Change Summary:
-
Handle empty files in Mercurial using
hg locate
instead. - Commit:
-
f11ca36bfb9d53dc8774b72f5bdd3f2d2bdb7fa492cca749637a2ef5b906a33d8c9d87ddfa1e8325
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
- Change Summary:
-
Return a set in
_get_files_in_changeset()
instead. - Commit:
-
92cca749637a2ef5b906a33d8c9d87ddfa1e8325270d86707dbe554d19a1c1a038ac7384117fd4aa
- Testing Done:
-
Ran
rbt post
with different SVN, Mercurial, and Perforce diffs, and verifiedthat the modified diffs were as expected: - Diff with 1 added empty file + - Diff with 1 added empty file, 1 added non-empty file - Diff with 1 deleted empty file + - Diff with 1 deleted empty file, 1 deleted non-empty file - Diff with 1 added empty file, 1 deleted empty file - Diff with 1 added empty file, 1 added non-empty file, 1 deleted empty file, 1 deleted non-empty file, 1 modified file Ran unit tests. More testing was done in /r/5785 as well.
-
What happens if you use rbt post with this code on a review board server that doesn't have /r/5785? Does it still parse the diffs OK?
- Change Summary:
-
Check if the RB server has the empty_files capability before handling added/deleted empty files.
- Description:
-
Review Board could not handle added or deleted empty files in SVN, Mercurial,
and Perforce diffs since the diff output from svn diff
/hg diff
did notprovide enough context on empty files. This change adds extra processing in RBTools to generate a diff with extra information on any added or deleted empty ~ files. ~ files, if the Review Board server has the empty_files
capability for the+ SCM tool in question. The original SVN diff output of an added/deleted empty file was:
Index: foo
===================================================================
After this change, the SVN diff of an added empty file becomes:
Index: foo\t(added)
===================================================================
--- foo\t(<base_revision>)
+++ foo\t(<tip_revision>)
For Mercurial, the diff of an added empty file is now:
diff -r <base_revision> -r <tip_revision> foo
--- /dev/null\tThu Jan 01 00:00:00 1970 +0000
+++ b/foo\t<date>
For Perforce, the diff of an added empty file is:
==== //depot/foo#0 ==A== //depot/foo ====
- Testing Done:
-
~ Ran
rbt post
with different SVN, Mercurial, and Perforce diffs, and verified~ that the modified diffs were as expected: ~ Ran
rbt post
on a RB server with theempty_files
capabilities with different~ SVN, Mercurial, and Perforce diffs, and verified that the modified diffs were + as expected: - Diff with 1 added empty file - Diff with 1 added empty file, 1 added non-empty file - Diff with 1 deleted empty file - Diff with 1 deleted empty file, 1 deleted non-empty file - Diff with 1 added empty file, 1 deleted empty file - Diff with 1 added empty file, 1 added non-empty file, 1 deleted empty file, 1 deleted non-empty file, 1 modified file + Ran
rbt post
on a RB server without theempty_files
capabilities, and+ verified that the generated diffs did not include any extra information on + added/deleted empty files. These added/deleted empty files were not included in + the review requests. + Ran unit tests. More testing was done in /r/5785 as well.
- Commit:
-
92cca749637a2ef5b906a33d8c9d87ddfa1e832547bd0b867408b32e16b8633d59fa5c16bc531a72
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
-
This logic is kind of confusing. How about this:
is_empty_and_changed = (self._supports_empty_files() and changetype_short in ('A', 'D')) if dl == [] and (is_move or is_empty_and_changed): dl.insert(0, '==== %s#%s ==%s== %s ====\n' % (depot_file, base_revision, changetype_short, new_local_path)) dl.append('\n') else: if ignore_unmodified: return [] else: print 'Warning: %s in your changeset is unmodified' % \ local_path
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files:
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: rbtools/clients/svn.py rbtools/clients/mercurial.py rbtools/clients/perforce.py Ignored Files: