You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2011/11/05 18:54:32 UTC

svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Author: stsp
Date: Sat Nov  5 17:54:31 2011
New Revision: 1197998

URL: http://svn.apache.org/viewvc?rev=1197998&view=rev
Log:
Make 'svn patch' ignore "/dev/null" patch target paths to improve
compatibility with patches generated by git. Git uses "/dev/null" as the
old name for newly added targets, and as the new name for deleted targets.

Reported by: Konstantin Kolinko
http://svn.haxx.se/users/archive-2011-11/0126.shtml

* subversion/libsvn_client/patch.c
  (choose_target_filename): If one of the filenames is "/dev/null",
   use the other filename.

* subversion/tests/cmdline/patch_tests.py
  (patch_dev_null, test_list): New test.

Modified:
    subversion/trunk/subversion/libsvn_client/patch.c
    subversion/trunk/subversion/tests/cmdline/patch_tests.py

Modified: subversion/trunk/subversion/libsvn_client/patch.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/patch.c?rev=1197998&r1=1197997&r2=1197998&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Sat Nov  5 17:54:31 2011
@@ -811,13 +811,20 @@ write_file(void *baton, const char *buf,
  * with the fewest path components, the shortest basename, and the shortest
  * total file name length (in that order). In case of a tie, return the new
  * filename. This heuristic is also used by Larry Wall's UNIX patch (except
- * that it prompts for a filename in case of a tie). */
+ * that it prompts for a filename in case of a tie).
+ * Additionally, for compatibility with git, if one of the filenames
+ * is "/dev/null", use the other filename. */
 static const char *
 choose_target_filename(const svn_patch_t *patch)
 {
   apr_size_t old;
   apr_size_t new;
 
+  if (strcmp(patch->old_filename, "/dev/null") == 0)
+    return patch->new_filename;
+  if (strcmp(patch->new_filename, "/dev/null") == 0)
+    return patch->old_filename;
+
   old = svn_path_component_count(patch->old_filename);
   new = svn_path_component_count(patch->new_filename);
 

Modified: subversion/trunk/subversion/tests/cmdline/patch_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/patch_tests.py?rev=1197998&r1=1197997&r2=1197998&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/patch_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/patch_tests.py Sat Nov  5 17:54:31 2011
@@ -3858,6 +3858,61 @@ def patch_reversed_add_with_props2(sbox)
                                        1, # dry-run
                                        '--reverse-diff') 
 
+def patch_dev_null(sbox):
+  "patch with /dev/null filenames"
+
+  sbox.build()
+  wc_dir = sbox.wc_dir
+
+  patch_file_path = make_patch_path(sbox)
+
+  # Git (and maybe other tools) use '/dev/null' as the old path for
+  # newly added files, and as the new path for deleted files.
+  # The path selection algorithm in 'svn patch' must detect this and
+  # avoid using '/dev/null' as a patch target.
+  unidiff_patch = [
+    "Index: new\n",
+    "===================================================================\n",
+    "--- /dev/null\n",
+    "+++ new	(revision 0)\n",
+    "@@ -0,0 +1 @@\n",
+    "+new\n",
+    "\n",
+    "Index: A/B/E/beta\n",
+    "===================================================================\n",
+    "--- A/B/E/beta	(revision 1)\n",
+    "+++ /dev/null\n",
+    "@@ -1 +0,0 @@\n",
+    "-This is the file 'beta'.\n",
+  ]
+
+  svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
+
+  new_contents = "new\n"
+  expected_output = [
+    'A         %s\n' % os.path.join(wc_dir, 'new'),
+    'D         %s\n' % os.path.join(wc_dir, 'A', 'B', 'E', 'beta'),
+  ]
+
+  expected_disk = svntest.main.greek_state.copy()
+  expected_disk.add({'new' : Item(contents=new_contents)})
+  expected_disk.remove('A/B/E/beta')
+
+  expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
+  expected_status.add({'new' : Item(status='A ', wc_rev=0)})
+  expected_status.tweak('A/B/E/beta', status='D ')
+
+  expected_skip = wc.State('', { })
+
+  svntest.actions.run_and_verify_patch(wc_dir, os.path.abspath(patch_file_path),
+                                       expected_output,
+                                       expected_disk,
+                                       expected_status,
+                                       expected_skip,
+                                       None, # expected err
+                                       1, # check-props
+                                       1) # dry-run
+
 ########################################################################
 #Run the tests
 
@@ -3898,6 +3953,7 @@ test_list = [ None,
               patch_deletes_prop,
               patch_reversed_add_with_props,
               patch_reversed_add_with_props2,
+              patch_dev_null,
             ]
 
 if __name__ == '__main__':



Re: svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
On Sunday, November 06, 2011 11:55 AM, "Stefan Sperling" <st...@elego.de> wrote:
> On Sun, Nov 06, 2011 at 03:28:06AM +0400, Konstantin Kolinko wrote:
> > - paths start with "a/" and not "a/trunk"
> >
> > Thus it is to be applied with "--strip 1".
> 
> This is something where git and Subversion have to differ.
> Subversion has to express paths relative to the repository root.
> Otherwise, copyfrom would be ambiguous. This is documented in the 1.7
> release notes.
> 

FWIW, this point particularly annoys me.  "a/" prefixes mean gf in vim
doesn't work, and when I try to disable them locally (via some dotfile
option that I've misplaced) people complain that the Standard Method for
applying patches (in Git projects) breaks.

Re: svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Posted by Stefan Sperling <st...@elego.de>.
On Sun, Nov 06, 2011 at 07:09:25PM +0400, Konstantin Kolinko wrote:
> Having tests in parse-diff-test.c does not preclude you from adding
> high-level tests to patch_tests.py
> 
> As an end-user I do not care about how patch parsing is done, or what
> paths are returned where and what else goes on under the hood.
> 
> I do care whether I can apply particular real-live patch. I do care
> whether patches generated from the official git mirrors at
> http://git.apache.org/ can be contributed back to the project.
> 
> Adding more real-live test cases does improve the test suite.

Fair eoung, that makes sense. If this is important to you, please
submit a proper patch against the python test suite that makes it
use a real-life diff.
 
> I need to apply the patch using --strip option. How --strip option
> interoperate with "/dev/null" path is not clear without knowing the
> internals. The tests that I propose to add will cover that.

So we should document somewhere that "/dev/null" is treated specially?
I doubt anyone will get the idea that 'svn patch' would apply the strip
count to "/dev/null", if they haven't run into the same problem as you.
I don't really think it's worth documenting. Once the fix is in 1.7.2,
nobody will notice a problem. Things will "just work".

Re: svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/11/6 Stefan Sperling <st...@elego.de>:
> On Sun, Nov 06, 2011 at 03:28:06AM +0400, Konstantin Kolinko wrote:
>> Second, regarding the test case in this commit:
>>
>> The sample patch in the test case is not fair that it does not match
>> to what "svn diff --git" or Git generates.
>
> That doesn't matter.
> The filename "/dev/null" is returned from the diff parser to
> the patch code. The patch code decides what to do with "/dev/null".
> Your suggestions don't make a difference to what's being tested.
>
>> Another test I would like to see is to use the patch format as generated by Git.
>>
>> Note that
>> - headers are a bit different
>> - additional "index..." line
>> - file modes are "100644" instead of "10644"; no revision numbers
>
> All unrelated to the "/dev/null" problem.
>
> If you want to add tests to the git-diff parser, extend the following
> file, not the high-level patch tests:
> https://svn.apache.org/repos/asf/subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c
>

Having tests in parse-diff-test.c does not preclude you from adding
high-level tests to patch_tests.py

As an end-user I do not care about how patch parsing is done, or what
paths are returned where and what else goes on under the hood.

I do care whether I can apply particular real-live patch. I do care
whether patches generated from the official git mirrors at
http://git.apache.org/ can be contributed back to the project.

Adding more real-live test cases does improve the test suite.

I need to apply the patch using --strip option. How --strip option
interoperate with "/dev/null" path is not clear without knowing the
internals. The tests that I propose to add will cover that.


>> - paths start with "a/" and not "a/trunk"
>>
>> Thus it is to be applied with "--strip 1".
>
> This is something where git and Subversion have to differ.
> Subversion has to express paths relative to the repository root.
> Otherwise, copyfrom would be ambiguous. This is documented in the 1.7
> release notes.
>
> If you need to apply patches generated with 'svn diff --git' to a git
> tree, you may need to edit the patch to make the number of path components
> match up (e.g. change "a/branches/mybranch/..." to "a/mybranch...").
> I don't like this but so far we found no good solution to this problem.
> Ideas and patches welcome :)
>
> Another problem is that copyfrom headers in the diff output currently
> don't show the copyfrom revision.
>
> In general, 'svn diff --git' is still work in progress and not as useful
> yet as we'd like it to be. We've postponed further work on it to a future
> release.
>

Thank you. I missed that point in release notes.

Best regards,
Konstantin Kolinko

Re: svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Posted by Stefan Sperling <st...@elego.de>.
On Sun, Nov 06, 2011 at 03:28:06AM +0400, Konstantin Kolinko wrote:
> Second, regarding the test case in this commit:
> 
> The sample patch in the test case is not fair that it does not match
> to what "svn diff --git" or Git generates.

That doesn't matter.
The filename "/dev/null" is returned from the diff parser to
the patch code. The patch code decides what to do with "/dev/null".
Your suggestions don't make a difference to what's being tested.

> Another test I would like to see is to use the patch format as generated by Git.
> 
> Note that
> - headers are a bit different
> - additional "index..." line
> - file modes are "100644" instead of "10644"; no revision numbers

All unrelated to the "/dev/null" problem.

If you want to add tests to the git-diff parser, extend the following
file, not the high-level patch tests:
https://svn.apache.org/repos/asf/subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c

> - paths start with "a/" and not "a/trunk"
>
> Thus it is to be applied with "--strip 1".

This is something where git and Subversion have to differ.
Subversion has to express paths relative to the repository root.
Otherwise, copyfrom would be ambiguous. This is documented in the 1.7
release notes.

If you need to apply patches generated with 'svn diff --git' to a git
tree, you may need to edit the patch to make the number of path components
match up (e.g. change "a/branches/mybranch/..." to "a/mybranch...").
I don't like this but so far we found no good solution to this problem.
Ideas and patches welcome :)

Another problem is that copyfrom headers in the diff output currently
don't show the copyfrom revision.

In general, 'svn diff --git' is still work in progress and not as useful
yet as we'd like it to be. We've postponed further work on it to a future
release.

Re: svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/11/6 Daniel Shahaf <d....@daniel.shahaf.name>:
>
>
> On Saturday, November 05, 2011 5:54 PM, stsp@apache.org wrote:
>> Author: stsp
>> Date: Sat Nov  5 17:54:31 2011
>> New Revision: 1197998
>>
>> URL: http://svn.apache.org/viewvc?rev=1197998&view=rev
>> Log:
>> Make 'svn patch' ignore "/dev/null" patch target paths to improve
>> compatibility with patches generated by git. Git uses "/dev/null" as the
>> old name for newly added targets, and as the new name for deleted targets.
>>
>> Reported by: Konstantin Kolinko
>> http://svn.haxx.se/users/archive-2011-11/0126.shtml
>>
>> * subversion/libsvn_client/patch.c
>>   (choose_target_filename): If one of the filenames is "/dev/null",
>>    use the other filename.
>>
>> * subversion/tests/cmdline/patch_tests.py
>>   (patch_dev_null, test_list): New test.
>
> Does anything (git, svn, etc) generate "NUL" instead of "/dev/null" when on windows?


First, regarding "NUL":  Git and Subversion both use /dev/null -- see below.

Git:
===
The patch that I used to report the issue (see mail thread link above)
was generated by Git on Windows. I am not its author, but I know from
previous discussions and from CRLF line ends in the new file added in
that patch.

It uses /dev/null

Svn:
===
Using svn 1.7.1, on Windows. From the root of Greek tree:
[[[
echo "foo">new
svn add new
svn diff --git
]]]
generates:

[[[
Index: new
===================================================================
diff --git a/trunk/new b/trunk/new
new file mode 10644
--- /dev/null   (revision 0)
+++ b/trunk/new (working copy)
@@ -0,0 +1 @@
+foo
]]]


Second, regarding the test case in this commit:

The sample patch in the test case is not fair that it does not match
to what "svn diff --git" or Git generates.

I do not mind keeping this as is, but it needs an additional test or
two -- see below.

Actual patch generated with svn diff --git on Greek tree:
[[[
Index: A/B/E/alpha
===================================================================
diff --git a/trunk/A/B/E/alpha b/trunk/A/B/E/alpha
--- a/trunk/A/B/E/alpha	(revision 1)
+++ b/trunk/A/B/E/alpha	(working copy)
@@ -1 +1 @@
-This is the file 'A/B/E/alpha'.
+Modified file 'A/B/E/alpha'.
Index: A/B/E/beta
===================================================================
diff --git a/trunk/A/B/E/beta b/trunk/A/B/E/beta
deleted file mode 10644
--- a/trunk/A/B/E/beta	(revision 1)
+++ /dev/null	(working copy)
@@ -1 +0,0 @@
-This is the file 'A/B/E/beta'.
Index: new
===================================================================
diff --git a/trunk/new b/trunk/new
new file mode 10644
--- /dev/null	(revision 0)
+++ b/trunk/new	(working copy)
@@ -0,0 +1 @@
+new
]]]


In testcase format that would be:

[[[
  unidiff_patch = [
    "Index: A/B/E/alpha\n",
    "===================================================================\n",
    "diff --git a/trunk/A/B/E/alpha b/trunk/A/B/E/alpha\n",
    "--- a/trunk/A/B/E/alpha\t(revision 1)\n",
    "+++ b/trunk/A/B/E/alpha\t(working copy)\n",
    "@@ -1 +1 @@\n",
    "-This is the file 'A/B/E/alpha'.\n",
    "+Modified file 'A/B/E/alpha'.\n",
    "Index: A/B/E/beta\n",
    "===================================================================\n",
    "diff --git a/trunk/A/B/E/beta b/trunk/A/B/E/beta\n",
    "deleted file mode 10644\n",
    "--- a/trunk/A/B/E/beta\t(revision 1)\n",
    "+++ /dev/null\t(working copy)\n",
    "@@ -1 +0,0 @@\n",
    "-This is the file 'A/B/E/beta'.\n",
    "Index: new\n",
    "===================================================================\n",
    "diff --git a/trunk/new b/trunk/new\n",
    "new file mode 10644\n",
    "--- /dev/null\t(revision 0)\n",
    "+++ b/trunk/new\t(working copy)\n",
    "@@ -0,0 +1 @@\n",
    "+new\n",
  ]

  svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))

  alpha_contents = "Modified file 'A/B/E/alpha'.\n"
  new_contents = "new\n"
  expected_output = [
    'M         %s\n' % os.path.join(wc_dir, 'A', 'B', 'E', 'alpha'),
    'D         %s\n' % os.path.join(wc_dir, 'A', 'B', 'E', 'beta'),
    'A         %s\n' % os.path.join(wc_dir, 'new'),
  ]

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.tweak('A/B/E/alpha', contents=alpha_contents)
  expected_disk.remove('A/B/E/beta')
  expected_disk.add({'new' : Item(contents=new_contents)})

  expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
  expected_status.tweak('A/B/E/alpha', status='M ')
  expected_status.tweak('A/B/E/beta', status='D ')
  expected_status.add({'new' : Item(status='A ', wc_rev=0)})

  expected_skip = wc.State('', { })

# The above to be applied with "--strip 2".
]]]


Another test I would like to see is to use the patch format as generated by Git.
Compare the above with
http://people.apache.org/~markt/patches/2011-11-03-redeploy-trunk-v2.patch
or patches at Github

E.g. for this commit
https://github.com/apache/subversion/commit/49f2818c5d6f856243f029f1dca574ef8ba8a073

its Git patch is shown by adding ".diff" to the above URL:
https://github.com/apache/subversion/commit/49f2818c5d6f856243f029f1dca574ef8ba8a073.diff


I think that Git-inspired variation of the above test will look like
[[[
  unidiff_patch = [
    "diff --git a/A/B/E/alpha b/A/B/E/alpha\n",
    "index 745bf95..d9d94af 100644\n",
    "--- a/A/B/E/alpha\n",
    "+++ b/A/B/E/alpha\n",
    "@@ -1,1 +1,1 @@\n",
    "-This is the file 'A/B/E/alpha'.\n",
    "+Modified file 'A/B/E/alpha'.\n",
    "diff --git a/A/B/E/beta b/A/B/E/beta\n",
    "deleted file mode 100644\n",
    "index c7fc018..0000000\n",
    "--- a/A/B/E/beta\n",
    "+++ /dev/null\n",
    "@@ -1,1 +0,0 @@\n",
    "-This is the file 'A/B/E/beta'.\n",
    "diff --git a/new b/new\n",
    "new file mode 100644\n",
    "index 0000000..63f6544\n",
    "--- /dev/null\n",
    "+++ b/new\n",
    "@@ -0,0 +1,1 @@\n",
    "+new\n",
  ]

  svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))

  alpha_contents = "Modified file 'A/B/E/alpha'.\n"
  new_contents = "new\n"
  expected_output = [
    'M         %s\n' % os.path.join(wc_dir, 'A', 'B', 'E', 'alpha'),
    'D         %s\n' % os.path.join(wc_dir, 'A', 'B', 'E', 'beta'),
    'A         %s\n' % os.path.join(wc_dir, 'new'),
  ]

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.tweak('A/B/E/alpha', contents=alpha_contents)
  expected_disk.remove('A/B/E/beta')
  expected_disk.add({'new' : Item(contents=new_contents)})

  expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
  expected_status.tweak('A/B/E/alpha', status='M ')
  expected_status.tweak('A/B/E/beta', status='D ')
  expected_status.add({'new' : Item(status='A ', wc_rev=0)})

  expected_skip = wc.State('', { })

# The above to be applied with "--strip 1"
]]]

Note that
- headers are a bit different
- additional "index..." line
- file modes are "100644" instead of "10644"; no revision numbers
- paths start with "a/" and not "a/trunk"

Thus it is to be applied with "--strip 1".

I cannot run tests, so there might be some glitches above.


Best regards,
Konstantin Kolinko

Re: svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.

On Saturday, November 05, 2011 5:54 PM, stsp@apache.org wrote:
> Author: stsp
> Date: Sat Nov  5 17:54:31 2011
> New Revision: 1197998
> 
> URL: http://svn.apache.org/viewvc?rev=1197998&view=rev
> Log:
> Make 'svn patch' ignore "/dev/null" patch target paths to improve
> compatibility with patches generated by git. Git uses "/dev/null" as the
> old name for newly added targets, and as the new name for deleted targets.
> 
> Reported by: Konstantin Kolinko
> http://svn.haxx.se/users/archive-2011-11/0126.shtml
> 
> * subversion/libsvn_client/patch.c
>   (choose_target_filename): If one of the filenames is "/dev/null",
>    use the other filename.
> 
> * subversion/tests/cmdline/patch_tests.py
>   (patch_dev_null, test_list): New test.

Does anything (git, svn, etc) generate "NUL" instead of "/dev/null" when on windows?

Re: svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
On Saturday, November 05, 2011 5:54 PM, stsp@apache.org wrote:
> +++ subversion/trunk/subversion/tests/cmdline/patch_tests.py Sat Nov  5 17:54:31 2011
> @@ -3858,6 +3858,61 @@ def patch_reversed_add_with_props2(sbox)
>                                         1, # dry-run
>                                         '--reverse-diff') 
>  
> +def patch_dev_null(sbox):
> +  "patch with /dev/null filenames"
> +
> +  sbox.build()

read_only=True ?

Re: svn commit: r1197998 - in /subversion/trunk/subversion: libsvn_client/patch.c tests/cmdline/patch_tests.py

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.

On Saturday, November 05, 2011 5:54 PM, stsp@apache.org wrote:
> Author: stsp
> Date: Sat Nov  5 17:54:31 2011
> New Revision: 1197998
> 
> URL: http://svn.apache.org/viewvc?rev=1197998&view=rev
> Log:
> Make 'svn patch' ignore "/dev/null" patch target paths to improve
> compatibility with patches generated by git. Git uses "/dev/null" as the
> old name for newly added targets, and as the new name for deleted targets.
> 
> Reported by: Konstantin Kolinko
> http://svn.haxx.se/users/archive-2011-11/0126.shtml
> 
> * subversion/libsvn_client/patch.c
>   (choose_target_filename): If one of the filenames is "/dev/null",
>    use the other filename.
> 
> * subversion/tests/cmdline/patch_tests.py
>   (patch_dev_null, test_list): New test.

Does anything (git, svn, etc) generate "NUL" instead of "/dev/null" when on windows?