equal
deleted
inserted
replaced
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() |