Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/patch.py @ 2865:71e78f2ca5ae
merge git patch code.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Sat, 12 Aug 2006 12:47:18 -0700 |
parents | f3c68e0ca37d |
children | 2893e51407a4 |
rev | line source |
---|---|
2861
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
1 # patch.py - patch file parsing routines |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
2 # |
2865
71e78f2ca5ae
merge git patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2863
diff
changeset
|
3 # Copyright 2006 Brendan Cully <brendan@kublai.com> |
71e78f2ca5ae
merge git patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2863
diff
changeset
|
4 # |
2861
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
7 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
8 from demandload import demandload |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
9 demandload(globals(), "util") |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
10 demandload(globals(), "os re shutil tempfile") |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
11 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
12 def readgitpatch(patchname): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
13 """extract git-style metadata about patches from <patchname>""" |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
14 class gitpatch: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
15 "op is one of ADD, DELETE, RENAME, MODIFY or COPY" |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
16 def __init__(self, path): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
17 self.path = path |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
18 self.oldpath = None |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
19 self.mode = None |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
20 self.op = 'MODIFY' |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
21 self.copymod = False |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
22 self.lineno = 0 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
23 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
24 # Filter patch for git information |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
25 gitre = re.compile('diff --git a/(.*) b/(.*)') |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
26 pf = file(patchname) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
27 gp = None |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
28 gitpatches = [] |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
29 # Can have a git patch with only metadata, causing patch to complain |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
30 dopatch = False |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
31 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
32 lineno = 0 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
33 for line in pf: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
34 lineno += 1 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
35 if line.startswith('diff --git'): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
36 m = gitre.match(line) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
37 if m: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
38 if gp: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
39 gitpatches.append(gp) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
40 src, dst = m.group(1,2) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
41 gp = gitpatch(dst) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
42 gp.lineno = lineno |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
43 elif gp: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
44 if line.startswith('--- '): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
45 if gp.op in ('COPY', 'RENAME'): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
46 gp.copymod = True |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
47 dopatch = 'filter' |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
48 gitpatches.append(gp) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
49 gp = None |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
50 if not dopatch: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
51 dopatch = True |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
52 continue |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
53 if line.startswith('rename from '): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
54 gp.op = 'RENAME' |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
55 gp.oldpath = line[12:].rstrip() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
56 elif line.startswith('rename to '): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
57 gp.path = line[10:].rstrip() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
58 elif line.startswith('copy from '): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
59 gp.op = 'COPY' |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
60 gp.oldpath = line[10:].rstrip() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
61 elif line.startswith('copy to '): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
62 gp.path = line[8:].rstrip() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
63 elif line.startswith('deleted file'): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
64 gp.op = 'DELETE' |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
65 elif line.startswith('new file mode '): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
66 gp.op = 'ADD' |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
67 gp.mode = int(line.rstrip()[-3:], 8) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
68 elif line.startswith('new mode '): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
69 gp.mode = int(line.rstrip()[-3:], 8) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
70 if gp: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
71 gitpatches.append(gp) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
72 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
73 if not gitpatches: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
74 dopatch = True |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
75 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
76 return (dopatch, gitpatches) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
77 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
78 def dogitpatch(patchname, gitpatches): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
79 """Preprocess git patch so that vanilla patch can handle it""" |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
80 pf = file(patchname) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
81 pfline = 1 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
82 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
83 fd, patchname = tempfile.mkstemp(prefix='hg-patch-') |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
84 tmpfp = os.fdopen(fd, 'w') |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
85 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
86 try: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
87 for i in range(len(gitpatches)): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
88 p = gitpatches[i] |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
89 if not p.copymod: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
90 continue |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
91 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
92 if os.path.exists(p.path): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
93 raise util.Abort(_("cannot create %s: destination already exists") % |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
94 p.path) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
95 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
96 (src, dst) = [os.path.join(os.getcwd(), n) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
97 for n in (p.oldpath, p.path)] |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
98 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
99 targetdir = os.path.dirname(dst) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
100 if not os.path.isdir(targetdir): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
101 os.makedirs(targetdir) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
102 try: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
103 shutil.copyfile(src, dst) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
104 shutil.copymode(src, dst) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
105 except shutil.Error, inst: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
106 raise util.Abort(str(inst)) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
107 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
108 # rewrite patch hunk |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
109 while pfline < p.lineno: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
110 tmpfp.write(pf.readline()) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
111 pfline += 1 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
112 tmpfp.write('diff --git a/%s b/%s\n' % (p.path, p.path)) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
113 line = pf.readline() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
114 pfline += 1 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
115 while not line.startswith('--- a/'): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
116 tmpfp.write(line) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
117 line = pf.readline() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
118 pfline += 1 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
119 tmpfp.write('--- a/%s\n' % p.path) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
120 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
121 line = pf.readline() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
122 while line: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
123 tmpfp.write(line) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
124 line = pf.readline() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
125 except: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
126 tmpfp.close() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
127 os.unlink(patchname) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
128 raise |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
129 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
130 tmpfp.close() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
131 return patchname |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
132 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
133 def patch(strip, patchname, ui, cwd=None): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
134 """apply the patch <patchname> to the working directory. |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
135 a list of patched files is returned""" |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
136 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
137 (dopatch, gitpatches) = readgitpatch(patchname) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
138 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
139 files = {} |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
140 if dopatch: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
141 if dopatch == 'filter': |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
142 patchname = dogitpatch(patchname, gitpatches) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
143 patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
144 args = [] |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
145 if cwd: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
146 args.append('-d %s' % util.shellquote(cwd)) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
147 fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
148 util.shellquote(patchname))) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
149 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
150 if dopatch == 'filter': |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
151 False and os.unlink(patchname) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
152 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
153 for line in fp: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
154 line = line.rstrip() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
155 ui.status("%s\n" % line) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
156 if line.startswith('patching file '): |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
157 pf = util.parse_patch_output(line) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
158 files.setdefault(pf, (None, None)) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
159 code = fp.close() |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
160 if code: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
161 raise util.Abort(_("patch command failed: %s") % explain_exit(code)[0]) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
162 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
163 for gp in gitpatches: |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
164 files[gp.path] = (gp.op, gp) |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
165 |
0f08f2c042ec
Move patch-related code into its own module.
Brendan Cully <brendan@kublai.com>
parents:
diff
changeset
|
166 return files |