Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 7505:fe0e02f952b0
When applying a git diff, ensure that the target dir exists for new files
author | Stefan Rusek <stefan@rusek.org> |
---|---|
date | Tue, 09 Dec 2008 14:27:47 +0100 |
parents | bffdab64dfbb |
children | 8e76e9f67cb3 |
comparison
equal
deleted
inserted
replaced
7500:ab3fb222b345 | 7505:fe0e02f952b0 |
---|---|
20 class NoHunks(PatchError): | 20 class NoHunks(PatchError): |
21 pass | 21 pass |
22 | 22 |
23 # helper functions | 23 # helper functions |
24 | 24 |
25 def copyfile(src, dst, basedir=None): | 25 def copyfile(src, dst, basedir): |
26 if not basedir: | 26 abssrc, absdst = [util.canonpath(basedir, basedir, x) for x in [src, dst]] |
27 basedir = os.getcwd() | |
28 | |
29 abssrc, absdst = [os.path.join(basedir, n) for n in (src, dst)] | |
30 if os.path.exists(absdst): | 27 if os.path.exists(absdst): |
31 raise util.Abort(_("cannot create %s: destination already exists") % | 28 raise util.Abort(_("cannot create %s: destination already exists") % |
32 dst) | 29 dst) |
33 | 30 |
34 if not os.path.isdir(basedir): | 31 dstdir = os.path.dirname(absdst) |
35 os.makedirs(basedir) | 32 if dstdir and not os.path.isdir(dstdir): |
33 try: | |
34 os.makedirs(dstdir) | |
35 except: | |
36 raise util.Abort( | |
37 _("cannot create %s: unable to create destination directory") | |
38 % dst) | |
36 | 39 |
37 util.copyfile(abssrc, absdst) | 40 util.copyfile(abssrc, absdst) |
38 | 41 |
39 # public functions | 42 # public functions |
40 | 43 |
975 elif state == 'git': | 978 elif state == 'git': |
976 gitpatches = values | 979 gitpatches = values |
977 cwd = os.getcwd() | 980 cwd = os.getcwd() |
978 for gp in gitpatches: | 981 for gp in gitpatches: |
979 if gp.op in ('COPY', 'RENAME'): | 982 if gp.op in ('COPY', 'RENAME'): |
980 src, dst = [util.canonpath(cwd, cwd, x) | 983 copyfile(gp.oldpath, gp.path, cwd) |
981 for x in [gp.oldpath, gp.path]] | |
982 copyfile(src, dst) | |
983 changed[gp.path] = gp | 984 changed[gp.path] = gp |
984 else: | 985 else: |
985 raise util.Abort(_('unsupported parser state: %s') % state) | 986 raise util.Abort(_('unsupported parser state: %s') % state) |
986 | 987 |
987 rejects += closefile() | 988 rejects += closefile() |