Mercurial > hg
changeset 9328:648d6a1a1cf2
patch: create file even if source is not /dev/null
as long as the first hunk is -0,0 and the source and destination have the
same name. Matt found a patch like this, and /usr/bin/patch accepts it.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Fri, 07 Aug 2009 19:27:54 -0700 |
parents | 9a69ab6d7cf7 |
children | 567648eab1dd |
files | mercurial/patch.py tests/test-import tests/test-import.out |
diffstat | 3 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Thu Aug 06 21:35:58 2009 -0700 +++ b/mercurial/patch.py Fri Aug 07 19:27:54 2009 -0700 @@ -793,6 +793,17 @@ if reverse: createfunc = hunk.rmfile missing = not goodb and not gooda and not createfunc() + + # some diff programs apparently produce create patches where the + # afile is not /dev/null, but rather the same name as the bfile + if missing and afile == bfile: + # this isn't very pretty + hunk.create = True + if createfunc(): + missing = False + else: + hunk.create = False + # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the # diff is between a file and its backup. In this case, the original # file should be patched (see original mpatch code).
--- a/tests/test-import Thu Aug 06 21:35:58 2009 -0700 +++ b/tests/test-import Fri Aug 07 19:27:54 2009 -0700 @@ -332,3 +332,16 @@ EOF hg import --no-commit a.patch cd .. + +echo '% create file when source is not /dev/null' +cat > create.patch <<EOF +diff -Naur proj-orig/foo proj-new/foo +--- proj-orig/foo 1969-12-31 16:00:00.000000000 -0800 ++++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700 +@@ -0,0 +1,1 @@ ++a +EOF +hg init oddcreate +cd oddcreate +hg import --no-commit ../create.patch +cat foo