Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 6295:bace1990ab12
patch: fix corner case with update + copy patch handling (issue 937)
The self patching of files when diffed with a backup is a bit peculiar to me.
It makes sense in mpatch, that's less clear in mercurial patching code. Let's
document and preserve it for now.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Mon, 17 Mar 2008 23:36:45 +0100 |
parents | 9db24a36d182 |
children | 65029a3aafc2 |
comparison
equal
deleted
inserted
replaced
6294:9cd6292abfdf | 6295:bace1990ab12 |
---|---|
798 i += 1 | 798 i += 1 |
799 # consume '//' in the path | 799 # consume '//' in the path |
800 while i < pathlen - 1 and path[i] == '/': | 800 while i < pathlen - 1 and path[i] == '/': |
801 i += 1 | 801 i += 1 |
802 count -= 1 | 802 count -= 1 |
803 return path[i:].rstrip() | 803 return path[:i].lstrip(), path[i:].rstrip() |
804 | 804 |
805 nulla = afile_orig == "/dev/null" | 805 nulla = afile_orig == "/dev/null" |
806 nullb = bfile_orig == "/dev/null" | 806 nullb = bfile_orig == "/dev/null" |
807 afile = pathstrip(afile_orig, strip) | 807 abase, afile = pathstrip(afile_orig, strip) |
808 gooda = not nulla and os.path.exists(afile) | 808 gooda = not nulla and os.path.exists(afile) |
809 bfile = pathstrip(bfile_orig, strip) | 809 bbase, bfile = pathstrip(bfile_orig, strip) |
810 if afile == bfile: | 810 if afile == bfile: |
811 goodb = gooda | 811 goodb = gooda |
812 else: | 812 else: |
813 goodb = not nullb and os.path.exists(bfile) | 813 goodb = not nullb and os.path.exists(bfile) |
814 createfunc = hunk.createfile | 814 createfunc = hunk.createfile |
815 if reverse: | 815 if reverse: |
816 createfunc = hunk.rmfile | 816 createfunc = hunk.rmfile |
817 missing = not goodb and not gooda and not createfunc() | 817 missing = not goodb and not gooda and not createfunc() |
818 # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the | |
819 # diff is between a file and its backup. In this case, the original | |
820 # file should be patched (see original mpatch code). | |
821 isbackup = (abase == bbase and bfile.startswith(afile)) | |
818 fname = None | 822 fname = None |
819 if not missing: | 823 if not missing: |
820 if gooda and goodb: | 824 if gooda and goodb: |
821 fname = (afile in bfile) and afile or bfile | 825 fname = isbackup and afile or bfile |
822 elif gooda: | 826 elif gooda: |
823 fname = afile | 827 fname = afile |
824 | 828 |
825 if not fname: | 829 if not fname: |
826 if not nullb: | 830 if not nullb: |
827 fname = (afile in bfile) and afile or bfile | 831 fname = isbackup and afile or bfile |
828 elif not nulla: | 832 elif not nulla: |
829 fname = afile | 833 fname = afile |
830 else: | 834 else: |
831 raise PatchError(_("undefined source and destination files")) | 835 raise PatchError(_("undefined source and destination files")) |
832 | 836 |