[PATCH] patch: improve handling of filenames containing spaces on import (issue3723)

Matt Mackall mpm at selenic.com
Thu Dec 6 15:44:47 CST 2012


On Thu, 2012-12-06 at 21:00 +0000, Alastair Houghton wrote:
> On 6 Dec 2012, at 18:55, Matt Mackall <mpm at selenic.com> wrote:
> 
> > Between your bug report and this description, there's lots of confusion
> > about whether you're talking about git diffs, standard diffs, or diffs
> > in general. I've been assuming the latter up to now.
> 
> Well, it is a general problem, but I certainly hadn't intended to try
> to fix it for the general case because there isn't a good general
> solution.

Have you actually tested it with standard diffs or does someone actually
need to do that? Ok, I just did:

 hg init a
 cd a
 mkdir 'foo b'
 echo b > 'foo b/foo'
 hg ci -Am0
 hg up null
 hg export --git tip > p
 cat p
 hg import p --no-commit
 hg st

Works as expected. Also, the hg-generated patch is accepted correctly by
patch(1). As previously demonstrated, diff(1) generates patches that
work with patch(1) and hg import as well. All is good in standard diff
land.

So the entirety of this discussion can be restricted to git diffs. In
the above test, if we add --git to the export, it breaks as described.

For a baseline, if I try to import the git-diff generated by hg into an
empty git repo with git-apply:

diff --git a/foo b/foo b/foo b/foo
new file mode 100644
--- /dev/null
+++ b/foo b/foo	
@@ -0,0 +1,1 @@
+b

..it almost works. By almost, I mean it creates 'foo\ b/foo' (literal
backslash out of thin air) rather than 'foo b/foo'. LOLWUT. This also
breaks in the same way with the known-to-agree-with-diff-and-patch
standard diff that Mercurial produces.

Conclusions:

a) Git is wacky
b) we should probably handle the above patch without complaint, but
without emulating Git's wackiness
c) we should accept escaping on the input, at least on git patches
d) we should eventually do some escaping for --git diffs

We should probably not do (d) until well after (c) is released to
minimize cross-version compatibility issues between hg clients.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list