Show More
@@ -1,1985 +1,1991 b'' | |||||
1 | # patch.py - patch file parsing routines |
|
1 | # patch.py - patch file parsing routines | |
2 | # |
|
2 | # | |
3 | # Copyright 2006 Brendan Cully <brendan@kublai.com> |
|
3 | # Copyright 2006 Brendan Cully <brendan@kublai.com> | |
4 | # Copyright 2007 Chris Mason <chris.mason@oracle.com> |
|
4 | # Copyright 2007 Chris Mason <chris.mason@oracle.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | import cStringIO, email, os, errno, re, posixpath |
|
9 | import cStringIO, email, os, errno, re, posixpath | |
10 | import tempfile, zlib, shutil |
|
10 | import tempfile, zlib, shutil | |
11 | # On python2.4 you have to import these by name or they fail to |
|
11 | # On python2.4 you have to import these by name or they fail to | |
12 | # load. This was not a problem on Python 2.7. |
|
12 | # load. This was not a problem on Python 2.7. | |
13 | import email.Generator |
|
13 | import email.Generator | |
14 | import email.Parser |
|
14 | import email.Parser | |
15 |
|
15 | |||
16 | from i18n import _ |
|
16 | from i18n import _ | |
17 | from node import hex, short |
|
17 | from node import hex, short | |
18 | import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error |
|
18 | import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error | |
19 |
|
19 | |||
20 | gitre = re.compile('diff --git a/(.*) b/(.*)') |
|
20 | gitre = re.compile('diff --git a/(.*) b/(.*)') | |
21 | tabsplitter = re.compile(r'(\t+|[^\t]+)') |
|
21 | tabsplitter = re.compile(r'(\t+|[^\t]+)') | |
22 |
|
22 | |||
23 | class PatchError(Exception): |
|
23 | class PatchError(Exception): | |
24 | pass |
|
24 | pass | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | # public functions |
|
27 | # public functions | |
28 |
|
28 | |||
29 | def split(stream): |
|
29 | def split(stream): | |
30 | '''return an iterator of individual patches from a stream''' |
|
30 | '''return an iterator of individual patches from a stream''' | |
31 | def isheader(line, inheader): |
|
31 | def isheader(line, inheader): | |
32 | if inheader and line[0] in (' ', '\t'): |
|
32 | if inheader and line[0] in (' ', '\t'): | |
33 | # continuation |
|
33 | # continuation | |
34 | return True |
|
34 | return True | |
35 | if line[0] in (' ', '-', '+'): |
|
35 | if line[0] in (' ', '-', '+'): | |
36 | # diff line - don't check for header pattern in there |
|
36 | # diff line - don't check for header pattern in there | |
37 | return False |
|
37 | return False | |
38 | l = line.split(': ', 1) |
|
38 | l = line.split(': ', 1) | |
39 | return len(l) == 2 and ' ' not in l[0] |
|
39 | return len(l) == 2 and ' ' not in l[0] | |
40 |
|
40 | |||
41 | def chunk(lines): |
|
41 | def chunk(lines): | |
42 | return cStringIO.StringIO(''.join(lines)) |
|
42 | return cStringIO.StringIO(''.join(lines)) | |
43 |
|
43 | |||
44 | def hgsplit(stream, cur): |
|
44 | def hgsplit(stream, cur): | |
45 | inheader = True |
|
45 | inheader = True | |
46 |
|
46 | |||
47 | for line in stream: |
|
47 | for line in stream: | |
48 | if not line.strip(): |
|
48 | if not line.strip(): | |
49 | inheader = False |
|
49 | inheader = False | |
50 | if not inheader and line.startswith('# HG changeset patch'): |
|
50 | if not inheader and line.startswith('# HG changeset patch'): | |
51 | yield chunk(cur) |
|
51 | yield chunk(cur) | |
52 | cur = [] |
|
52 | cur = [] | |
53 | inheader = True |
|
53 | inheader = True | |
54 |
|
54 | |||
55 | cur.append(line) |
|
55 | cur.append(line) | |
56 |
|
56 | |||
57 | if cur: |
|
57 | if cur: | |
58 | yield chunk(cur) |
|
58 | yield chunk(cur) | |
59 |
|
59 | |||
60 | def mboxsplit(stream, cur): |
|
60 | def mboxsplit(stream, cur): | |
61 | for line in stream: |
|
61 | for line in stream: | |
62 | if line.startswith('From '): |
|
62 | if line.startswith('From '): | |
63 | for c in split(chunk(cur[1:])): |
|
63 | for c in split(chunk(cur[1:])): | |
64 | yield c |
|
64 | yield c | |
65 | cur = [] |
|
65 | cur = [] | |
66 |
|
66 | |||
67 | cur.append(line) |
|
67 | cur.append(line) | |
68 |
|
68 | |||
69 | if cur: |
|
69 | if cur: | |
70 | for c in split(chunk(cur[1:])): |
|
70 | for c in split(chunk(cur[1:])): | |
71 | yield c |
|
71 | yield c | |
72 |
|
72 | |||
73 | def mimesplit(stream, cur): |
|
73 | def mimesplit(stream, cur): | |
74 | def msgfp(m): |
|
74 | def msgfp(m): | |
75 | fp = cStringIO.StringIO() |
|
75 | fp = cStringIO.StringIO() | |
76 | g = email.Generator.Generator(fp, mangle_from_=False) |
|
76 | g = email.Generator.Generator(fp, mangle_from_=False) | |
77 | g.flatten(m) |
|
77 | g.flatten(m) | |
78 | fp.seek(0) |
|
78 | fp.seek(0) | |
79 | return fp |
|
79 | return fp | |
80 |
|
80 | |||
81 | for line in stream: |
|
81 | for line in stream: | |
82 | cur.append(line) |
|
82 | cur.append(line) | |
83 | c = chunk(cur) |
|
83 | c = chunk(cur) | |
84 |
|
84 | |||
85 | m = email.Parser.Parser().parse(c) |
|
85 | m = email.Parser.Parser().parse(c) | |
86 | if not m.is_multipart(): |
|
86 | if not m.is_multipart(): | |
87 | yield msgfp(m) |
|
87 | yield msgfp(m) | |
88 | else: |
|
88 | else: | |
89 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') |
|
89 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') | |
90 | for part in m.walk(): |
|
90 | for part in m.walk(): | |
91 | ct = part.get_content_type() |
|
91 | ct = part.get_content_type() | |
92 | if ct not in ok_types: |
|
92 | if ct not in ok_types: | |
93 | continue |
|
93 | continue | |
94 | yield msgfp(part) |
|
94 | yield msgfp(part) | |
95 |
|
95 | |||
96 | def headersplit(stream, cur): |
|
96 | def headersplit(stream, cur): | |
97 | inheader = False |
|
97 | inheader = False | |
98 |
|
98 | |||
99 | for line in stream: |
|
99 | for line in stream: | |
100 | if not inheader and isheader(line, inheader): |
|
100 | if not inheader and isheader(line, inheader): | |
101 | yield chunk(cur) |
|
101 | yield chunk(cur) | |
102 | cur = [] |
|
102 | cur = [] | |
103 | inheader = True |
|
103 | inheader = True | |
104 | if inheader and not isheader(line, inheader): |
|
104 | if inheader and not isheader(line, inheader): | |
105 | inheader = False |
|
105 | inheader = False | |
106 |
|
106 | |||
107 | cur.append(line) |
|
107 | cur.append(line) | |
108 |
|
108 | |||
109 | if cur: |
|
109 | if cur: | |
110 | yield chunk(cur) |
|
110 | yield chunk(cur) | |
111 |
|
111 | |||
112 | def remainder(cur): |
|
112 | def remainder(cur): | |
113 | yield chunk(cur) |
|
113 | yield chunk(cur) | |
114 |
|
114 | |||
115 | class fiter(object): |
|
115 | class fiter(object): | |
116 | def __init__(self, fp): |
|
116 | def __init__(self, fp): | |
117 | self.fp = fp |
|
117 | self.fp = fp | |
118 |
|
118 | |||
119 | def __iter__(self): |
|
119 | def __iter__(self): | |
120 | return self |
|
120 | return self | |
121 |
|
121 | |||
122 | def next(self): |
|
122 | def next(self): | |
123 | l = self.fp.readline() |
|
123 | l = self.fp.readline() | |
124 | if not l: |
|
124 | if not l: | |
125 | raise StopIteration |
|
125 | raise StopIteration | |
126 | return l |
|
126 | return l | |
127 |
|
127 | |||
128 | inheader = False |
|
128 | inheader = False | |
129 | cur = [] |
|
129 | cur = [] | |
130 |
|
130 | |||
131 | mimeheaders = ['content-type'] |
|
131 | mimeheaders = ['content-type'] | |
132 |
|
132 | |||
133 | if not util.safehasattr(stream, 'next'): |
|
133 | if not util.safehasattr(stream, 'next'): | |
134 | # http responses, for example, have readline but not next |
|
134 | # http responses, for example, have readline but not next | |
135 | stream = fiter(stream) |
|
135 | stream = fiter(stream) | |
136 |
|
136 | |||
137 | for line in stream: |
|
137 | for line in stream: | |
138 | cur.append(line) |
|
138 | cur.append(line) | |
139 | if line.startswith('# HG changeset patch'): |
|
139 | if line.startswith('# HG changeset patch'): | |
140 | return hgsplit(stream, cur) |
|
140 | return hgsplit(stream, cur) | |
141 | elif line.startswith('From '): |
|
141 | elif line.startswith('From '): | |
142 | return mboxsplit(stream, cur) |
|
142 | return mboxsplit(stream, cur) | |
143 | elif isheader(line, inheader): |
|
143 | elif isheader(line, inheader): | |
144 | inheader = True |
|
144 | inheader = True | |
145 | if line.split(':', 1)[0].lower() in mimeheaders: |
|
145 | if line.split(':', 1)[0].lower() in mimeheaders: | |
146 | # let email parser handle this |
|
146 | # let email parser handle this | |
147 | return mimesplit(stream, cur) |
|
147 | return mimesplit(stream, cur) | |
148 | elif line.startswith('--- ') and inheader: |
|
148 | elif line.startswith('--- ') and inheader: | |
149 | # No evil headers seen by diff start, split by hand |
|
149 | # No evil headers seen by diff start, split by hand | |
150 | return headersplit(stream, cur) |
|
150 | return headersplit(stream, cur) | |
151 | # Not enough info, keep reading |
|
151 | # Not enough info, keep reading | |
152 |
|
152 | |||
153 | # if we are here, we have a very plain patch |
|
153 | # if we are here, we have a very plain patch | |
154 | return remainder(cur) |
|
154 | return remainder(cur) | |
155 |
|
155 | |||
156 | def extract(ui, fileobj): |
|
156 | def extract(ui, fileobj): | |
157 | '''extract patch from data read from fileobj. |
|
157 | '''extract patch from data read from fileobj. | |
158 |
|
158 | |||
159 | patch can be a normal patch or contained in an email message. |
|
159 | patch can be a normal patch or contained in an email message. | |
160 |
|
160 | |||
161 | return tuple (filename, message, user, date, branch, node, p1, p2). |
|
161 | return tuple (filename, message, user, date, branch, node, p1, p2). | |
162 | Any item in the returned tuple can be None. If filename is None, |
|
162 | Any item in the returned tuple can be None. If filename is None, | |
163 | fileobj did not contain a patch. Caller must unlink filename when done.''' |
|
163 | fileobj did not contain a patch. Caller must unlink filename when done.''' | |
164 |
|
164 | |||
165 | # attempt to detect the start of a patch |
|
165 | # attempt to detect the start of a patch | |
166 | # (this heuristic is borrowed from quilt) |
|
166 | # (this heuristic is borrowed from quilt) | |
167 | diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' |
|
167 | diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' | |
168 | r'retrieving revision [0-9]+(\.[0-9]+)*$|' |
|
168 | r'retrieving revision [0-9]+(\.[0-9]+)*$|' | |
169 | r'---[ \t].*?^\+\+\+[ \t]|' |
|
169 | r'---[ \t].*?^\+\+\+[ \t]|' | |
170 | r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL) |
|
170 | r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL) | |
171 |
|
171 | |||
172 | fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') |
|
172 | fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') | |
173 | tmpfp = os.fdopen(fd, 'w') |
|
173 | tmpfp = os.fdopen(fd, 'w') | |
174 | try: |
|
174 | try: | |
175 | msg = email.Parser.Parser().parse(fileobj) |
|
175 | msg = email.Parser.Parser().parse(fileobj) | |
176 |
|
176 | |||
177 | subject = msg['Subject'] |
|
177 | subject = msg['Subject'] | |
178 | user = msg['From'] |
|
178 | user = msg['From'] | |
179 | if not subject and not user: |
|
179 | if not subject and not user: | |
180 | # Not an email, restore parsed headers if any |
|
180 | # Not an email, restore parsed headers if any | |
181 | subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n' |
|
181 | subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n' | |
182 |
|
182 | |||
183 | # should try to parse msg['Date'] |
|
183 | # should try to parse msg['Date'] | |
184 | date = None |
|
184 | date = None | |
185 | nodeid = None |
|
185 | nodeid = None | |
186 | branch = None |
|
186 | branch = None | |
187 | parents = [] |
|
187 | parents = [] | |
188 |
|
188 | |||
189 | if subject: |
|
189 | if subject: | |
190 | if subject.startswith('[PATCH'): |
|
190 | if subject.startswith('[PATCH'): | |
191 | pend = subject.find(']') |
|
191 | pend = subject.find(']') | |
192 | if pend >= 0: |
|
192 | if pend >= 0: | |
193 | subject = subject[pend + 1:].lstrip() |
|
193 | subject = subject[pend + 1:].lstrip() | |
194 | subject = re.sub(r'\n[ \t]+', ' ', subject) |
|
194 | subject = re.sub(r'\n[ \t]+', ' ', subject) | |
195 | ui.debug('Subject: %s\n' % subject) |
|
195 | ui.debug('Subject: %s\n' % subject) | |
196 | if user: |
|
196 | if user: | |
197 | ui.debug('From: %s\n' % user) |
|
197 | ui.debug('From: %s\n' % user) | |
198 | diffs_seen = 0 |
|
198 | diffs_seen = 0 | |
199 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') |
|
199 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') | |
200 | message = '' |
|
200 | message = '' | |
201 | for part in msg.walk(): |
|
201 | for part in msg.walk(): | |
202 | content_type = part.get_content_type() |
|
202 | content_type = part.get_content_type() | |
203 | ui.debug('Content-Type: %s\n' % content_type) |
|
203 | ui.debug('Content-Type: %s\n' % content_type) | |
204 | if content_type not in ok_types: |
|
204 | if content_type not in ok_types: | |
205 | continue |
|
205 | continue | |
206 | payload = part.get_payload(decode=True) |
|
206 | payload = part.get_payload(decode=True) | |
207 | m = diffre.search(payload) |
|
207 | m = diffre.search(payload) | |
208 | if m: |
|
208 | if m: | |
209 | hgpatch = False |
|
209 | hgpatch = False | |
210 | hgpatchheader = False |
|
210 | hgpatchheader = False | |
211 | ignoretext = False |
|
211 | ignoretext = False | |
212 |
|
212 | |||
213 | ui.debug('found patch at byte %d\n' % m.start(0)) |
|
213 | ui.debug('found patch at byte %d\n' % m.start(0)) | |
214 | diffs_seen += 1 |
|
214 | diffs_seen += 1 | |
215 | cfp = cStringIO.StringIO() |
|
215 | cfp = cStringIO.StringIO() | |
216 | for line in payload[:m.start(0)].splitlines(): |
|
216 | for line in payload[:m.start(0)].splitlines(): | |
217 | if line.startswith('# HG changeset patch') and not hgpatch: |
|
217 | if line.startswith('# HG changeset patch') and not hgpatch: | |
218 | ui.debug('patch generated by hg export\n') |
|
218 | ui.debug('patch generated by hg export\n') | |
219 | hgpatch = True |
|
219 | hgpatch = True | |
220 | hgpatchheader = True |
|
220 | hgpatchheader = True | |
221 | # drop earlier commit message content |
|
221 | # drop earlier commit message content | |
222 | cfp.seek(0) |
|
222 | cfp.seek(0) | |
223 | cfp.truncate() |
|
223 | cfp.truncate() | |
224 | subject = None |
|
224 | subject = None | |
225 | elif hgpatchheader: |
|
225 | elif hgpatchheader: | |
226 | if line.startswith('# User '): |
|
226 | if line.startswith('# User '): | |
227 | user = line[7:] |
|
227 | user = line[7:] | |
228 | ui.debug('From: %s\n' % user) |
|
228 | ui.debug('From: %s\n' % user) | |
229 | elif line.startswith("# Date "): |
|
229 | elif line.startswith("# Date "): | |
230 | date = line[7:] |
|
230 | date = line[7:] | |
231 | elif line.startswith("# Branch "): |
|
231 | elif line.startswith("# Branch "): | |
232 | branch = line[9:] |
|
232 | branch = line[9:] | |
233 | elif line.startswith("# Node ID "): |
|
233 | elif line.startswith("# Node ID "): | |
234 | nodeid = line[10:] |
|
234 | nodeid = line[10:] | |
235 | elif line.startswith("# Parent "): |
|
235 | elif line.startswith("# Parent "): | |
236 | parents.append(line[9:].lstrip()) |
|
236 | parents.append(line[9:].lstrip()) | |
237 | elif not line.startswith("# "): |
|
237 | elif not line.startswith("# "): | |
238 | hgpatchheader = False |
|
238 | hgpatchheader = False | |
239 | elif line == '---': |
|
239 | elif line == '---': | |
240 | ignoretext = True |
|
240 | ignoretext = True | |
241 | if not hgpatchheader and not ignoretext: |
|
241 | if not hgpatchheader and not ignoretext: | |
242 | cfp.write(line) |
|
242 | cfp.write(line) | |
243 | cfp.write('\n') |
|
243 | cfp.write('\n') | |
244 | message = cfp.getvalue() |
|
244 | message = cfp.getvalue() | |
245 | if tmpfp: |
|
245 | if tmpfp: | |
246 | tmpfp.write(payload) |
|
246 | tmpfp.write(payload) | |
247 | if not payload.endswith('\n'): |
|
247 | if not payload.endswith('\n'): | |
248 | tmpfp.write('\n') |
|
248 | tmpfp.write('\n') | |
249 | elif not diffs_seen and message and content_type == 'text/plain': |
|
249 | elif not diffs_seen and message and content_type == 'text/plain': | |
250 | message += '\n' + payload |
|
250 | message += '\n' + payload | |
251 | except: # re-raises |
|
251 | except: # re-raises | |
252 | tmpfp.close() |
|
252 | tmpfp.close() | |
253 | os.unlink(tmpname) |
|
253 | os.unlink(tmpname) | |
254 | raise |
|
254 | raise | |
255 |
|
255 | |||
256 | if subject and not message.startswith(subject): |
|
256 | if subject and not message.startswith(subject): | |
257 | message = '%s\n%s' % (subject, message) |
|
257 | message = '%s\n%s' % (subject, message) | |
258 | tmpfp.close() |
|
258 | tmpfp.close() | |
259 | if not diffs_seen: |
|
259 | if not diffs_seen: | |
260 | os.unlink(tmpname) |
|
260 | os.unlink(tmpname) | |
261 | return None, message, user, date, branch, None, None, None |
|
261 | return None, message, user, date, branch, None, None, None | |
262 | p1 = parents and parents.pop(0) or None |
|
262 | p1 = parents and parents.pop(0) or None | |
263 | p2 = parents and parents.pop(0) or None |
|
263 | p2 = parents and parents.pop(0) or None | |
264 | return tmpname, message, user, date, branch, nodeid, p1, p2 |
|
264 | return tmpname, message, user, date, branch, nodeid, p1, p2 | |
265 |
|
265 | |||
266 | class patchmeta(object): |
|
266 | class patchmeta(object): | |
267 | """Patched file metadata |
|
267 | """Patched file metadata | |
268 |
|
268 | |||
269 | 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY |
|
269 | 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY | |
270 | or COPY. 'path' is patched file path. 'oldpath' is set to the |
|
270 | or COPY. 'path' is patched file path. 'oldpath' is set to the | |
271 | origin file when 'op' is either COPY or RENAME, None otherwise. If |
|
271 | origin file when 'op' is either COPY or RENAME, None otherwise. If | |
272 | file mode is changed, 'mode' is a tuple (islink, isexec) where |
|
272 | file mode is changed, 'mode' is a tuple (islink, isexec) where | |
273 | 'islink' is True if the file is a symlink and 'isexec' is True if |
|
273 | 'islink' is True if the file is a symlink and 'isexec' is True if | |
274 | the file is executable. Otherwise, 'mode' is None. |
|
274 | the file is executable. Otherwise, 'mode' is None. | |
275 | """ |
|
275 | """ | |
276 | def __init__(self, path): |
|
276 | def __init__(self, path): | |
277 | self.path = path |
|
277 | self.path = path | |
278 | self.oldpath = None |
|
278 | self.oldpath = None | |
279 | self.mode = None |
|
279 | self.mode = None | |
280 | self.op = 'MODIFY' |
|
280 | self.op = 'MODIFY' | |
281 | self.binary = False |
|
281 | self.binary = False | |
282 |
|
282 | |||
283 | def setmode(self, mode): |
|
283 | def setmode(self, mode): | |
284 | islink = mode & 020000 |
|
284 | islink = mode & 020000 | |
285 | isexec = mode & 0100 |
|
285 | isexec = mode & 0100 | |
286 | self.mode = (islink, isexec) |
|
286 | self.mode = (islink, isexec) | |
287 |
|
287 | |||
288 | def copy(self): |
|
288 | def copy(self): | |
289 | other = patchmeta(self.path) |
|
289 | other = patchmeta(self.path) | |
290 | other.oldpath = self.oldpath |
|
290 | other.oldpath = self.oldpath | |
291 | other.mode = self.mode |
|
291 | other.mode = self.mode | |
292 | other.op = self.op |
|
292 | other.op = self.op | |
293 | other.binary = self.binary |
|
293 | other.binary = self.binary | |
294 | return other |
|
294 | return other | |
295 |
|
295 | |||
296 | def _ispatchinga(self, afile): |
|
296 | def _ispatchinga(self, afile): | |
297 | if afile == '/dev/null': |
|
297 | if afile == '/dev/null': | |
298 | return self.op == 'ADD' |
|
298 | return self.op == 'ADD' | |
299 | return afile == 'a/' + (self.oldpath or self.path) |
|
299 | return afile == 'a/' + (self.oldpath or self.path) | |
300 |
|
300 | |||
301 | def _ispatchingb(self, bfile): |
|
301 | def _ispatchingb(self, bfile): | |
302 | if bfile == '/dev/null': |
|
302 | if bfile == '/dev/null': | |
303 | return self.op == 'DELETE' |
|
303 | return self.op == 'DELETE' | |
304 | return bfile == 'b/' + self.path |
|
304 | return bfile == 'b/' + self.path | |
305 |
|
305 | |||
306 | def ispatching(self, afile, bfile): |
|
306 | def ispatching(self, afile, bfile): | |
307 | return self._ispatchinga(afile) and self._ispatchingb(bfile) |
|
307 | return self._ispatchinga(afile) and self._ispatchingb(bfile) | |
308 |
|
308 | |||
309 | def __repr__(self): |
|
309 | def __repr__(self): | |
310 | return "<patchmeta %s %r>" % (self.op, self.path) |
|
310 | return "<patchmeta %s %r>" % (self.op, self.path) | |
311 |
|
311 | |||
312 | def readgitpatch(lr): |
|
312 | def readgitpatch(lr): | |
313 | """extract git-style metadata about patches from <patchname>""" |
|
313 | """extract git-style metadata about patches from <patchname>""" | |
314 |
|
314 | |||
315 | # Filter patch for git information |
|
315 | # Filter patch for git information | |
316 | gp = None |
|
316 | gp = None | |
317 | gitpatches = [] |
|
317 | gitpatches = [] | |
318 | for line in lr: |
|
318 | for line in lr: | |
319 | line = line.rstrip(' \r\n') |
|
319 | line = line.rstrip(' \r\n') | |
320 | if line.startswith('diff --git a/'): |
|
320 | if line.startswith('diff --git a/'): | |
321 | m = gitre.match(line) |
|
321 | m = gitre.match(line) | |
322 | if m: |
|
322 | if m: | |
323 | if gp: |
|
323 | if gp: | |
324 | gitpatches.append(gp) |
|
324 | gitpatches.append(gp) | |
325 | dst = m.group(2) |
|
325 | dst = m.group(2) | |
326 | gp = patchmeta(dst) |
|
326 | gp = patchmeta(dst) | |
327 | elif gp: |
|
327 | elif gp: | |
328 | if line.startswith('--- '): |
|
328 | if line.startswith('--- '): | |
329 | gitpatches.append(gp) |
|
329 | gitpatches.append(gp) | |
330 | gp = None |
|
330 | gp = None | |
331 | continue |
|
331 | continue | |
332 | if line.startswith('rename from '): |
|
332 | if line.startswith('rename from '): | |
333 | gp.op = 'RENAME' |
|
333 | gp.op = 'RENAME' | |
334 | gp.oldpath = line[12:] |
|
334 | gp.oldpath = line[12:] | |
335 | elif line.startswith('rename to '): |
|
335 | elif line.startswith('rename to '): | |
336 | gp.path = line[10:] |
|
336 | gp.path = line[10:] | |
337 | elif line.startswith('copy from '): |
|
337 | elif line.startswith('copy from '): | |
338 | gp.op = 'COPY' |
|
338 | gp.op = 'COPY' | |
339 | gp.oldpath = line[10:] |
|
339 | gp.oldpath = line[10:] | |
340 | elif line.startswith('copy to '): |
|
340 | elif line.startswith('copy to '): | |
341 | gp.path = line[8:] |
|
341 | gp.path = line[8:] | |
342 | elif line.startswith('deleted file'): |
|
342 | elif line.startswith('deleted file'): | |
343 | gp.op = 'DELETE' |
|
343 | gp.op = 'DELETE' | |
344 | elif line.startswith('new file mode '): |
|
344 | elif line.startswith('new file mode '): | |
345 | gp.op = 'ADD' |
|
345 | gp.op = 'ADD' | |
346 | gp.setmode(int(line[-6:], 8)) |
|
346 | gp.setmode(int(line[-6:], 8)) | |
347 | elif line.startswith('new mode '): |
|
347 | elif line.startswith('new mode '): | |
348 | gp.setmode(int(line[-6:], 8)) |
|
348 | gp.setmode(int(line[-6:], 8)) | |
349 | elif line.startswith('GIT binary patch'): |
|
349 | elif line.startswith('GIT binary patch'): | |
350 | gp.binary = True |
|
350 | gp.binary = True | |
351 | if gp: |
|
351 | if gp: | |
352 | gitpatches.append(gp) |
|
352 | gitpatches.append(gp) | |
353 |
|
353 | |||
354 | return gitpatches |
|
354 | return gitpatches | |
355 |
|
355 | |||
356 | class linereader(object): |
|
356 | class linereader(object): | |
357 | # simple class to allow pushing lines back into the input stream |
|
357 | # simple class to allow pushing lines back into the input stream | |
358 | def __init__(self, fp): |
|
358 | def __init__(self, fp): | |
359 | self.fp = fp |
|
359 | self.fp = fp | |
360 | self.buf = [] |
|
360 | self.buf = [] | |
361 |
|
361 | |||
362 | def push(self, line): |
|
362 | def push(self, line): | |
363 | if line is not None: |
|
363 | if line is not None: | |
364 | self.buf.append(line) |
|
364 | self.buf.append(line) | |
365 |
|
365 | |||
366 | def readline(self): |
|
366 | def readline(self): | |
367 | if self.buf: |
|
367 | if self.buf: | |
368 | l = self.buf[0] |
|
368 | l = self.buf[0] | |
369 | del self.buf[0] |
|
369 | del self.buf[0] | |
370 | return l |
|
370 | return l | |
371 | return self.fp.readline() |
|
371 | return self.fp.readline() | |
372 |
|
372 | |||
373 | def __iter__(self): |
|
373 | def __iter__(self): | |
374 | while True: |
|
374 | while True: | |
375 | l = self.readline() |
|
375 | l = self.readline() | |
376 | if not l: |
|
376 | if not l: | |
377 | break |
|
377 | break | |
378 | yield l |
|
378 | yield l | |
379 |
|
379 | |||
380 | class abstractbackend(object): |
|
380 | class abstractbackend(object): | |
381 | def __init__(self, ui): |
|
381 | def __init__(self, ui): | |
382 | self.ui = ui |
|
382 | self.ui = ui | |
383 |
|
383 | |||
384 | def getfile(self, fname): |
|
384 | def getfile(self, fname): | |
385 | """Return target file data and flags as a (data, (islink, |
|
385 | """Return target file data and flags as a (data, (islink, | |
386 | isexec)) tuple. Data is None if file is missing/deleted. |
|
386 | isexec)) tuple. Data is None if file is missing/deleted. | |
387 | """ |
|
387 | """ | |
388 | raise NotImplementedError |
|
388 | raise NotImplementedError | |
389 |
|
389 | |||
390 | def setfile(self, fname, data, mode, copysource): |
|
390 | def setfile(self, fname, data, mode, copysource): | |
391 | """Write data to target file fname and set its mode. mode is a |
|
391 | """Write data to target file fname and set its mode. mode is a | |
392 | (islink, isexec) tuple. If data is None, the file content should |
|
392 | (islink, isexec) tuple. If data is None, the file content should | |
393 | be left unchanged. If the file is modified after being copied, |
|
393 | be left unchanged. If the file is modified after being copied, | |
394 | copysource is set to the original file name. |
|
394 | copysource is set to the original file name. | |
395 | """ |
|
395 | """ | |
396 | raise NotImplementedError |
|
396 | raise NotImplementedError | |
397 |
|
397 | |||
398 | def unlink(self, fname): |
|
398 | def unlink(self, fname): | |
399 | """Unlink target file.""" |
|
399 | """Unlink target file.""" | |
400 | raise NotImplementedError |
|
400 | raise NotImplementedError | |
401 |
|
401 | |||
402 | def writerej(self, fname, failed, total, lines): |
|
402 | def writerej(self, fname, failed, total, lines): | |
403 | """Write rejected lines for fname. total is the number of hunks |
|
403 | """Write rejected lines for fname. total is the number of hunks | |
404 | which failed to apply and total the total number of hunks for this |
|
404 | which failed to apply and total the total number of hunks for this | |
405 | files. |
|
405 | files. | |
406 | """ |
|
406 | """ | |
407 | pass |
|
407 | pass | |
408 |
|
408 | |||
409 | def exists(self, fname): |
|
409 | def exists(self, fname): | |
410 | raise NotImplementedError |
|
410 | raise NotImplementedError | |
411 |
|
411 | |||
412 | class fsbackend(abstractbackend): |
|
412 | class fsbackend(abstractbackend): | |
413 | def __init__(self, ui, basedir): |
|
413 | def __init__(self, ui, basedir): | |
414 | super(fsbackend, self).__init__(ui) |
|
414 | super(fsbackend, self).__init__(ui) | |
415 | self.opener = scmutil.opener(basedir) |
|
415 | self.opener = scmutil.opener(basedir) | |
416 |
|
416 | |||
417 | def _join(self, f): |
|
417 | def _join(self, f): | |
418 | return os.path.join(self.opener.base, f) |
|
418 | return os.path.join(self.opener.base, f) | |
419 |
|
419 | |||
420 | def getfile(self, fname): |
|
420 | def getfile(self, fname): | |
421 | if self.opener.islink(fname): |
|
421 | if self.opener.islink(fname): | |
422 | return (self.opener.readlink(fname), (True, False)) |
|
422 | return (self.opener.readlink(fname), (True, False)) | |
423 |
|
423 | |||
424 | isexec = False |
|
424 | isexec = False | |
425 | try: |
|
425 | try: | |
426 | isexec = self.opener.lstat(fname).st_mode & 0100 != 0 |
|
426 | isexec = self.opener.lstat(fname).st_mode & 0100 != 0 | |
427 | except OSError, e: |
|
427 | except OSError, e: | |
428 | if e.errno != errno.ENOENT: |
|
428 | if e.errno != errno.ENOENT: | |
429 | raise |
|
429 | raise | |
430 | try: |
|
430 | try: | |
431 | return (self.opener.read(fname), (False, isexec)) |
|
431 | return (self.opener.read(fname), (False, isexec)) | |
432 | except IOError, e: |
|
432 | except IOError, e: | |
433 | if e.errno != errno.ENOENT: |
|
433 | if e.errno != errno.ENOENT: | |
434 | raise |
|
434 | raise | |
435 | return None, None |
|
435 | return None, None | |
436 |
|
436 | |||
437 | def setfile(self, fname, data, mode, copysource): |
|
437 | def setfile(self, fname, data, mode, copysource): | |
438 | islink, isexec = mode |
|
438 | islink, isexec = mode | |
439 | if data is None: |
|
439 | if data is None: | |
440 | self.opener.setflags(fname, islink, isexec) |
|
440 | self.opener.setflags(fname, islink, isexec) | |
441 | return |
|
441 | return | |
442 | if islink: |
|
442 | if islink: | |
443 | self.opener.symlink(data, fname) |
|
443 | self.opener.symlink(data, fname) | |
444 | else: |
|
444 | else: | |
445 | self.opener.write(fname, data) |
|
445 | self.opener.write(fname, data) | |
446 | if isexec: |
|
446 | if isexec: | |
447 | self.opener.setflags(fname, False, True) |
|
447 | self.opener.setflags(fname, False, True) | |
448 |
|
448 | |||
449 | def unlink(self, fname): |
|
449 | def unlink(self, fname): | |
450 | self.opener.unlinkpath(fname, ignoremissing=True) |
|
450 | self.opener.unlinkpath(fname, ignoremissing=True) | |
451 |
|
451 | |||
452 | def writerej(self, fname, failed, total, lines): |
|
452 | def writerej(self, fname, failed, total, lines): | |
453 | fname = fname + ".rej" |
|
453 | fname = fname + ".rej" | |
454 | self.ui.warn( |
|
454 | self.ui.warn( | |
455 | _("%d out of %d hunks FAILED -- saving rejects to file %s\n") % |
|
455 | _("%d out of %d hunks FAILED -- saving rejects to file %s\n") % | |
456 | (failed, total, fname)) |
|
456 | (failed, total, fname)) | |
457 | fp = self.opener(fname, 'w') |
|
457 | fp = self.opener(fname, 'w') | |
458 | fp.writelines(lines) |
|
458 | fp.writelines(lines) | |
459 | fp.close() |
|
459 | fp.close() | |
460 |
|
460 | |||
461 | def exists(self, fname): |
|
461 | def exists(self, fname): | |
462 | return self.opener.lexists(fname) |
|
462 | return self.opener.lexists(fname) | |
463 |
|
463 | |||
464 | class workingbackend(fsbackend): |
|
464 | class workingbackend(fsbackend): | |
465 | def __init__(self, ui, repo, similarity): |
|
465 | def __init__(self, ui, repo, similarity): | |
466 | super(workingbackend, self).__init__(ui, repo.root) |
|
466 | super(workingbackend, self).__init__(ui, repo.root) | |
467 | self.repo = repo |
|
467 | self.repo = repo | |
468 | self.similarity = similarity |
|
468 | self.similarity = similarity | |
469 | self.removed = set() |
|
469 | self.removed = set() | |
470 | self.changed = set() |
|
470 | self.changed = set() | |
471 | self.copied = [] |
|
471 | self.copied = [] | |
472 |
|
472 | |||
473 | def _checkknown(self, fname): |
|
473 | def _checkknown(self, fname): | |
474 | if self.repo.dirstate[fname] == '?' and self.exists(fname): |
|
474 | if self.repo.dirstate[fname] == '?' and self.exists(fname): | |
475 | raise PatchError(_('cannot patch %s: file is not tracked') % fname) |
|
475 | raise PatchError(_('cannot patch %s: file is not tracked') % fname) | |
476 |
|
476 | |||
477 | def setfile(self, fname, data, mode, copysource): |
|
477 | def setfile(self, fname, data, mode, copysource): | |
478 | self._checkknown(fname) |
|
478 | self._checkknown(fname) | |
479 | super(workingbackend, self).setfile(fname, data, mode, copysource) |
|
479 | super(workingbackend, self).setfile(fname, data, mode, copysource) | |
480 | if copysource is not None: |
|
480 | if copysource is not None: | |
481 | self.copied.append((copysource, fname)) |
|
481 | self.copied.append((copysource, fname)) | |
482 | self.changed.add(fname) |
|
482 | self.changed.add(fname) | |
483 |
|
483 | |||
484 | def unlink(self, fname): |
|
484 | def unlink(self, fname): | |
485 | self._checkknown(fname) |
|
485 | self._checkknown(fname) | |
486 | super(workingbackend, self).unlink(fname) |
|
486 | super(workingbackend, self).unlink(fname) | |
487 | self.removed.add(fname) |
|
487 | self.removed.add(fname) | |
488 | self.changed.add(fname) |
|
488 | self.changed.add(fname) | |
489 |
|
489 | |||
490 | def close(self): |
|
490 | def close(self): | |
491 | wctx = self.repo[None] |
|
491 | wctx = self.repo[None] | |
492 | changed = set(self.changed) |
|
492 | changed = set(self.changed) | |
493 | for src, dst in self.copied: |
|
493 | for src, dst in self.copied: | |
494 | scmutil.dirstatecopy(self.ui, self.repo, wctx, src, dst) |
|
494 | scmutil.dirstatecopy(self.ui, self.repo, wctx, src, dst) | |
495 | if self.removed: |
|
495 | if self.removed: | |
496 | wctx.forget(sorted(self.removed)) |
|
496 | wctx.forget(sorted(self.removed)) | |
497 | for f in self.removed: |
|
497 | for f in self.removed: | |
498 | if f not in self.repo.dirstate: |
|
498 | if f not in self.repo.dirstate: | |
499 | # File was deleted and no longer belongs to the |
|
499 | # File was deleted and no longer belongs to the | |
500 | # dirstate, it was probably marked added then |
|
500 | # dirstate, it was probably marked added then | |
501 | # deleted, and should not be considered by |
|
501 | # deleted, and should not be considered by | |
502 | # marktouched(). |
|
502 | # marktouched(). | |
503 | changed.discard(f) |
|
503 | changed.discard(f) | |
504 | if changed: |
|
504 | if changed: | |
505 | scmutil.marktouched(self.repo, changed, self.similarity) |
|
505 | scmutil.marktouched(self.repo, changed, self.similarity) | |
506 | return sorted(self.changed) |
|
506 | return sorted(self.changed) | |
507 |
|
507 | |||
508 | class filestore(object): |
|
508 | class filestore(object): | |
509 | def __init__(self, maxsize=None): |
|
509 | def __init__(self, maxsize=None): | |
510 | self.opener = None |
|
510 | self.opener = None | |
511 | self.files = {} |
|
511 | self.files = {} | |
512 | self.created = 0 |
|
512 | self.created = 0 | |
513 | self.maxsize = maxsize |
|
513 | self.maxsize = maxsize | |
514 | if self.maxsize is None: |
|
514 | if self.maxsize is None: | |
515 | self.maxsize = 4*(2**20) |
|
515 | self.maxsize = 4*(2**20) | |
516 | self.size = 0 |
|
516 | self.size = 0 | |
517 | self.data = {} |
|
517 | self.data = {} | |
518 |
|
518 | |||
519 | def setfile(self, fname, data, mode, copied=None): |
|
519 | def setfile(self, fname, data, mode, copied=None): | |
520 | if self.maxsize < 0 or (len(data) + self.size) <= self.maxsize: |
|
520 | if self.maxsize < 0 or (len(data) + self.size) <= self.maxsize: | |
521 | self.data[fname] = (data, mode, copied) |
|
521 | self.data[fname] = (data, mode, copied) | |
522 | self.size += len(data) |
|
522 | self.size += len(data) | |
523 | else: |
|
523 | else: | |
524 | if self.opener is None: |
|
524 | if self.opener is None: | |
525 | root = tempfile.mkdtemp(prefix='hg-patch-') |
|
525 | root = tempfile.mkdtemp(prefix='hg-patch-') | |
526 | self.opener = scmutil.opener(root) |
|
526 | self.opener = scmutil.opener(root) | |
527 | # Avoid filename issues with these simple names |
|
527 | # Avoid filename issues with these simple names | |
528 | fn = str(self.created) |
|
528 | fn = str(self.created) | |
529 | self.opener.write(fn, data) |
|
529 | self.opener.write(fn, data) | |
530 | self.created += 1 |
|
530 | self.created += 1 | |
531 | self.files[fname] = (fn, mode, copied) |
|
531 | self.files[fname] = (fn, mode, copied) | |
532 |
|
532 | |||
533 | def getfile(self, fname): |
|
533 | def getfile(self, fname): | |
534 | if fname in self.data: |
|
534 | if fname in self.data: | |
535 | return self.data[fname] |
|
535 | return self.data[fname] | |
536 | if not self.opener or fname not in self.files: |
|
536 | if not self.opener or fname not in self.files: | |
537 | return None, None, None |
|
537 | return None, None, None | |
538 | fn, mode, copied = self.files[fname] |
|
538 | fn, mode, copied = self.files[fname] | |
539 | return self.opener.read(fn), mode, copied |
|
539 | return self.opener.read(fn), mode, copied | |
540 |
|
540 | |||
541 | def close(self): |
|
541 | def close(self): | |
542 | if self.opener: |
|
542 | if self.opener: | |
543 | shutil.rmtree(self.opener.base) |
|
543 | shutil.rmtree(self.opener.base) | |
544 |
|
544 | |||
545 | class repobackend(abstractbackend): |
|
545 | class repobackend(abstractbackend): | |
546 | def __init__(self, ui, repo, ctx, store): |
|
546 | def __init__(self, ui, repo, ctx, store): | |
547 | super(repobackend, self).__init__(ui) |
|
547 | super(repobackend, self).__init__(ui) | |
548 | self.repo = repo |
|
548 | self.repo = repo | |
549 | self.ctx = ctx |
|
549 | self.ctx = ctx | |
550 | self.store = store |
|
550 | self.store = store | |
551 | self.changed = set() |
|
551 | self.changed = set() | |
552 | self.removed = set() |
|
552 | self.removed = set() | |
553 | self.copied = {} |
|
553 | self.copied = {} | |
554 |
|
554 | |||
555 | def _checkknown(self, fname): |
|
555 | def _checkknown(self, fname): | |
556 | if fname not in self.ctx: |
|
556 | if fname not in self.ctx: | |
557 | raise PatchError(_('cannot patch %s: file is not tracked') % fname) |
|
557 | raise PatchError(_('cannot patch %s: file is not tracked') % fname) | |
558 |
|
558 | |||
559 | def getfile(self, fname): |
|
559 | def getfile(self, fname): | |
560 | try: |
|
560 | try: | |
561 | fctx = self.ctx[fname] |
|
561 | fctx = self.ctx[fname] | |
562 | except error.LookupError: |
|
562 | except error.LookupError: | |
563 | return None, None |
|
563 | return None, None | |
564 | flags = fctx.flags() |
|
564 | flags = fctx.flags() | |
565 | return fctx.data(), ('l' in flags, 'x' in flags) |
|
565 | return fctx.data(), ('l' in flags, 'x' in flags) | |
566 |
|
566 | |||
567 | def setfile(self, fname, data, mode, copysource): |
|
567 | def setfile(self, fname, data, mode, copysource): | |
568 | if copysource: |
|
568 | if copysource: | |
569 | self._checkknown(copysource) |
|
569 | self._checkknown(copysource) | |
570 | if data is None: |
|
570 | if data is None: | |
571 | data = self.ctx[fname].data() |
|
571 | data = self.ctx[fname].data() | |
572 | self.store.setfile(fname, data, mode, copysource) |
|
572 | self.store.setfile(fname, data, mode, copysource) | |
573 | self.changed.add(fname) |
|
573 | self.changed.add(fname) | |
574 | if copysource: |
|
574 | if copysource: | |
575 | self.copied[fname] = copysource |
|
575 | self.copied[fname] = copysource | |
576 |
|
576 | |||
577 | def unlink(self, fname): |
|
577 | def unlink(self, fname): | |
578 | self._checkknown(fname) |
|
578 | self._checkknown(fname) | |
579 | self.removed.add(fname) |
|
579 | self.removed.add(fname) | |
580 |
|
580 | |||
581 | def exists(self, fname): |
|
581 | def exists(self, fname): | |
582 | return fname in self.ctx |
|
582 | return fname in self.ctx | |
583 |
|
583 | |||
584 | def close(self): |
|
584 | def close(self): | |
585 | return self.changed | self.removed |
|
585 | return self.changed | self.removed | |
586 |
|
586 | |||
587 | # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1 |
|
587 | # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1 | |
588 | unidesc = re.compile('@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@') |
|
588 | unidesc = re.compile('@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@') | |
589 | contextdesc = re.compile('(?:---|\*\*\*) (\d+)(?:,(\d+))? (?:---|\*\*\*)') |
|
589 | contextdesc = re.compile('(?:---|\*\*\*) (\d+)(?:,(\d+))? (?:---|\*\*\*)') | |
590 | eolmodes = ['strict', 'crlf', 'lf', 'auto'] |
|
590 | eolmodes = ['strict', 'crlf', 'lf', 'auto'] | |
591 |
|
591 | |||
592 | class patchfile(object): |
|
592 | class patchfile(object): | |
593 | def __init__(self, ui, gp, backend, store, eolmode='strict'): |
|
593 | def __init__(self, ui, gp, backend, store, eolmode='strict'): | |
594 | self.fname = gp.path |
|
594 | self.fname = gp.path | |
595 | self.eolmode = eolmode |
|
595 | self.eolmode = eolmode | |
596 | self.eol = None |
|
596 | self.eol = None | |
597 | self.backend = backend |
|
597 | self.backend = backend | |
598 | self.ui = ui |
|
598 | self.ui = ui | |
599 | self.lines = [] |
|
599 | self.lines = [] | |
600 | self.exists = False |
|
600 | self.exists = False | |
601 | self.missing = True |
|
601 | self.missing = True | |
602 | self.mode = gp.mode |
|
602 | self.mode = gp.mode | |
603 | self.copysource = gp.oldpath |
|
603 | self.copysource = gp.oldpath | |
604 | self.create = gp.op in ('ADD', 'COPY', 'RENAME') |
|
604 | self.create = gp.op in ('ADD', 'COPY', 'RENAME') | |
605 | self.remove = gp.op == 'DELETE' |
|
605 | self.remove = gp.op == 'DELETE' | |
606 | if self.copysource is None: |
|
606 | if self.copysource is None: | |
607 | data, mode = backend.getfile(self.fname) |
|
607 | data, mode = backend.getfile(self.fname) | |
608 | else: |
|
608 | else: | |
609 | data, mode = store.getfile(self.copysource)[:2] |
|
609 | data, mode = store.getfile(self.copysource)[:2] | |
610 | if data is not None: |
|
610 | if data is not None: | |
611 | self.exists = self.copysource is None or backend.exists(self.fname) |
|
611 | self.exists = self.copysource is None or backend.exists(self.fname) | |
612 | self.missing = False |
|
612 | self.missing = False | |
613 | if data: |
|
613 | if data: | |
614 | self.lines = mdiff.splitnewlines(data) |
|
614 | self.lines = mdiff.splitnewlines(data) | |
615 | if self.mode is None: |
|
615 | if self.mode is None: | |
616 | self.mode = mode |
|
616 | self.mode = mode | |
617 | if self.lines: |
|
617 | if self.lines: | |
618 | # Normalize line endings |
|
618 | # Normalize line endings | |
619 | if self.lines[0].endswith('\r\n'): |
|
619 | if self.lines[0].endswith('\r\n'): | |
620 | self.eol = '\r\n' |
|
620 | self.eol = '\r\n' | |
621 | elif self.lines[0].endswith('\n'): |
|
621 | elif self.lines[0].endswith('\n'): | |
622 | self.eol = '\n' |
|
622 | self.eol = '\n' | |
623 | if eolmode != 'strict': |
|
623 | if eolmode != 'strict': | |
624 | nlines = [] |
|
624 | nlines = [] | |
625 | for l in self.lines: |
|
625 | for l in self.lines: | |
626 | if l.endswith('\r\n'): |
|
626 | if l.endswith('\r\n'): | |
627 | l = l[:-2] + '\n' |
|
627 | l = l[:-2] + '\n' | |
628 | nlines.append(l) |
|
628 | nlines.append(l) | |
629 | self.lines = nlines |
|
629 | self.lines = nlines | |
630 | else: |
|
630 | else: | |
631 | if self.create: |
|
631 | if self.create: | |
632 | self.missing = False |
|
632 | self.missing = False | |
633 | if self.mode is None: |
|
633 | if self.mode is None: | |
634 | self.mode = (False, False) |
|
634 | self.mode = (False, False) | |
635 | if self.missing: |
|
635 | if self.missing: | |
636 | self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) |
|
636 | self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) | |
637 |
|
637 | |||
638 | self.hash = {} |
|
638 | self.hash = {} | |
639 | self.dirty = 0 |
|
639 | self.dirty = 0 | |
640 | self.offset = 0 |
|
640 | self.offset = 0 | |
641 | self.skew = 0 |
|
641 | self.skew = 0 | |
642 | self.rej = [] |
|
642 | self.rej = [] | |
643 | self.fileprinted = False |
|
643 | self.fileprinted = False | |
644 | self.printfile(False) |
|
644 | self.printfile(False) | |
645 | self.hunks = 0 |
|
645 | self.hunks = 0 | |
646 |
|
646 | |||
647 | def writelines(self, fname, lines, mode): |
|
647 | def writelines(self, fname, lines, mode): | |
648 | if self.eolmode == 'auto': |
|
648 | if self.eolmode == 'auto': | |
649 | eol = self.eol |
|
649 | eol = self.eol | |
650 | elif self.eolmode == 'crlf': |
|
650 | elif self.eolmode == 'crlf': | |
651 | eol = '\r\n' |
|
651 | eol = '\r\n' | |
652 | else: |
|
652 | else: | |
653 | eol = '\n' |
|
653 | eol = '\n' | |
654 |
|
654 | |||
655 | if self.eolmode != 'strict' and eol and eol != '\n': |
|
655 | if self.eolmode != 'strict' and eol and eol != '\n': | |
656 | rawlines = [] |
|
656 | rawlines = [] | |
657 | for l in lines: |
|
657 | for l in lines: | |
658 | if l and l[-1] == '\n': |
|
658 | if l and l[-1] == '\n': | |
659 | l = l[:-1] + eol |
|
659 | l = l[:-1] + eol | |
660 | rawlines.append(l) |
|
660 | rawlines.append(l) | |
661 | lines = rawlines |
|
661 | lines = rawlines | |
662 |
|
662 | |||
663 | self.backend.setfile(fname, ''.join(lines), mode, self.copysource) |
|
663 | self.backend.setfile(fname, ''.join(lines), mode, self.copysource) | |
664 |
|
664 | |||
665 | def printfile(self, warn): |
|
665 | def printfile(self, warn): | |
666 | if self.fileprinted: |
|
666 | if self.fileprinted: | |
667 | return |
|
667 | return | |
668 | if warn or self.ui.verbose: |
|
668 | if warn or self.ui.verbose: | |
669 | self.fileprinted = True |
|
669 | self.fileprinted = True | |
670 | s = _("patching file %s\n") % self.fname |
|
670 | s = _("patching file %s\n") % self.fname | |
671 | if warn: |
|
671 | if warn: | |
672 | self.ui.warn(s) |
|
672 | self.ui.warn(s) | |
673 | else: |
|
673 | else: | |
674 | self.ui.note(s) |
|
674 | self.ui.note(s) | |
675 |
|
675 | |||
676 |
|
676 | |||
677 | def findlines(self, l, linenum): |
|
677 | def findlines(self, l, linenum): | |
678 | # looks through the hash and finds candidate lines. The |
|
678 | # looks through the hash and finds candidate lines. The | |
679 | # result is a list of line numbers sorted based on distance |
|
679 | # result is a list of line numbers sorted based on distance | |
680 | # from linenum |
|
680 | # from linenum | |
681 |
|
681 | |||
682 | cand = self.hash.get(l, []) |
|
682 | cand = self.hash.get(l, []) | |
683 | if len(cand) > 1: |
|
683 | if len(cand) > 1: | |
684 | # resort our list of potentials forward then back. |
|
684 | # resort our list of potentials forward then back. | |
685 | cand.sort(key=lambda x: abs(x - linenum)) |
|
685 | cand.sort(key=lambda x: abs(x - linenum)) | |
686 | return cand |
|
686 | return cand | |
687 |
|
687 | |||
688 | def write_rej(self): |
|
688 | def write_rej(self): | |
689 | # our rejects are a little different from patch(1). This always |
|
689 | # our rejects are a little different from patch(1). This always | |
690 | # creates rejects in the same form as the original patch. A file |
|
690 | # creates rejects in the same form as the original patch. A file | |
691 | # header is inserted so that you can run the reject through patch again |
|
691 | # header is inserted so that you can run the reject through patch again | |
692 | # without having to type the filename. |
|
692 | # without having to type the filename. | |
693 | if not self.rej: |
|
693 | if not self.rej: | |
694 | return |
|
694 | return | |
695 | base = os.path.basename(self.fname) |
|
695 | base = os.path.basename(self.fname) | |
696 | lines = ["--- %s\n+++ %s\n" % (base, base)] |
|
696 | lines = ["--- %s\n+++ %s\n" % (base, base)] | |
697 | for x in self.rej: |
|
697 | for x in self.rej: | |
698 | for l in x.hunk: |
|
698 | for l in x.hunk: | |
699 | lines.append(l) |
|
699 | lines.append(l) | |
700 | if l[-1] != '\n': |
|
700 | if l[-1] != '\n': | |
701 | lines.append("\n\ No newline at end of file\n") |
|
701 | lines.append("\n\ No newline at end of file\n") | |
702 | self.backend.writerej(self.fname, len(self.rej), self.hunks, lines) |
|
702 | self.backend.writerej(self.fname, len(self.rej), self.hunks, lines) | |
703 |
|
703 | |||
704 | def apply(self, h): |
|
704 | def apply(self, h): | |
705 | if not h.complete(): |
|
705 | if not h.complete(): | |
706 | raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") % |
|
706 | raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") % | |
707 | (h.number, h.desc, len(h.a), h.lena, len(h.b), |
|
707 | (h.number, h.desc, len(h.a), h.lena, len(h.b), | |
708 | h.lenb)) |
|
708 | h.lenb)) | |
709 |
|
709 | |||
710 | self.hunks += 1 |
|
710 | self.hunks += 1 | |
711 |
|
711 | |||
712 | if self.missing: |
|
712 | if self.missing: | |
713 | self.rej.append(h) |
|
713 | self.rej.append(h) | |
714 | return -1 |
|
714 | return -1 | |
715 |
|
715 | |||
716 | if self.exists and self.create: |
|
716 | if self.exists and self.create: | |
717 | if self.copysource: |
|
717 | if self.copysource: | |
718 | self.ui.warn(_("cannot create %s: destination already " |
|
718 | self.ui.warn(_("cannot create %s: destination already " | |
719 | "exists\n") % self.fname) |
|
719 | "exists\n") % self.fname) | |
720 | else: |
|
720 | else: | |
721 | self.ui.warn(_("file %s already exists\n") % self.fname) |
|
721 | self.ui.warn(_("file %s already exists\n") % self.fname) | |
722 | self.rej.append(h) |
|
722 | self.rej.append(h) | |
723 | return -1 |
|
723 | return -1 | |
724 |
|
724 | |||
725 | if isinstance(h, binhunk): |
|
725 | if isinstance(h, binhunk): | |
726 | if self.remove: |
|
726 | if self.remove: | |
727 | self.backend.unlink(self.fname) |
|
727 | self.backend.unlink(self.fname) | |
728 | else: |
|
728 | else: | |
729 | l = h.new(self.lines) |
|
729 | l = h.new(self.lines) | |
730 | self.lines[:] = l |
|
730 | self.lines[:] = l | |
731 | self.offset += len(l) |
|
731 | self.offset += len(l) | |
732 | self.dirty = True |
|
732 | self.dirty = True | |
733 | return 0 |
|
733 | return 0 | |
734 |
|
734 | |||
735 | horig = h |
|
735 | horig = h | |
736 | if (self.eolmode in ('crlf', 'lf') |
|
736 | if (self.eolmode in ('crlf', 'lf') | |
737 | or self.eolmode == 'auto' and self.eol): |
|
737 | or self.eolmode == 'auto' and self.eol): | |
738 | # If new eols are going to be normalized, then normalize |
|
738 | # If new eols are going to be normalized, then normalize | |
739 | # hunk data before patching. Otherwise, preserve input |
|
739 | # hunk data before patching. Otherwise, preserve input | |
740 | # line-endings. |
|
740 | # line-endings. | |
741 | h = h.getnormalized() |
|
741 | h = h.getnormalized() | |
742 |
|
742 | |||
743 | # fast case first, no offsets, no fuzz |
|
743 | # fast case first, no offsets, no fuzz | |
744 | old, oldstart, new, newstart = h.fuzzit(0, False) |
|
744 | old, oldstart, new, newstart = h.fuzzit(0, False) | |
745 | oldstart += self.offset |
|
745 | oldstart += self.offset | |
746 | orig_start = oldstart |
|
746 | orig_start = oldstart | |
747 | # if there's skew we want to emit the "(offset %d lines)" even |
|
747 | # if there's skew we want to emit the "(offset %d lines)" even | |
748 | # when the hunk cleanly applies at start + skew, so skip the |
|
748 | # when the hunk cleanly applies at start + skew, so skip the | |
749 | # fast case code |
|
749 | # fast case code | |
750 | if (self.skew == 0 and |
|
750 | if (self.skew == 0 and | |
751 | diffhelpers.testhunk(old, self.lines, oldstart) == 0): |
|
751 | diffhelpers.testhunk(old, self.lines, oldstart) == 0): | |
752 | if self.remove: |
|
752 | if self.remove: | |
753 | self.backend.unlink(self.fname) |
|
753 | self.backend.unlink(self.fname) | |
754 | else: |
|
754 | else: | |
755 | self.lines[oldstart:oldstart + len(old)] = new |
|
755 | self.lines[oldstart:oldstart + len(old)] = new | |
756 | self.offset += len(new) - len(old) |
|
756 | self.offset += len(new) - len(old) | |
757 | self.dirty = True |
|
757 | self.dirty = True | |
758 | return 0 |
|
758 | return 0 | |
759 |
|
759 | |||
760 | # ok, we couldn't match the hunk. Lets look for offsets and fuzz it |
|
760 | # ok, we couldn't match the hunk. Lets look for offsets and fuzz it | |
761 | self.hash = {} |
|
761 | self.hash = {} | |
762 | for x, s in enumerate(self.lines): |
|
762 | for x, s in enumerate(self.lines): | |
763 | self.hash.setdefault(s, []).append(x) |
|
763 | self.hash.setdefault(s, []).append(x) | |
764 |
|
764 | |||
765 | for fuzzlen in xrange(3): |
|
765 | for fuzzlen in xrange(3): | |
766 | for toponly in [True, False]: |
|
766 | for toponly in [True, False]: | |
767 | old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly) |
|
767 | old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly) | |
768 | oldstart = oldstart + self.offset + self.skew |
|
768 | oldstart = oldstart + self.offset + self.skew | |
769 | oldstart = min(oldstart, len(self.lines)) |
|
769 | oldstart = min(oldstart, len(self.lines)) | |
770 | if old: |
|
770 | if old: | |
771 | cand = self.findlines(old[0][1:], oldstart) |
|
771 | cand = self.findlines(old[0][1:], oldstart) | |
772 | else: |
|
772 | else: | |
773 | # Only adding lines with no or fuzzed context, just |
|
773 | # Only adding lines with no or fuzzed context, just | |
774 | # take the skew in account |
|
774 | # take the skew in account | |
775 | cand = [oldstart] |
|
775 | cand = [oldstart] | |
776 |
|
776 | |||
777 | for l in cand: |
|
777 | for l in cand: | |
778 | if not old or diffhelpers.testhunk(old, self.lines, l) == 0: |
|
778 | if not old or diffhelpers.testhunk(old, self.lines, l) == 0: | |
779 | self.lines[l : l + len(old)] = new |
|
779 | self.lines[l : l + len(old)] = new | |
780 | self.offset += len(new) - len(old) |
|
780 | self.offset += len(new) - len(old) | |
781 | self.skew = l - orig_start |
|
781 | self.skew = l - orig_start | |
782 | self.dirty = True |
|
782 | self.dirty = True | |
783 | offset = l - orig_start - fuzzlen |
|
783 | offset = l - orig_start - fuzzlen | |
784 | if fuzzlen: |
|
784 | if fuzzlen: | |
785 | msg = _("Hunk #%d succeeded at %d " |
|
785 | msg = _("Hunk #%d succeeded at %d " | |
786 | "with fuzz %d " |
|
786 | "with fuzz %d " | |
787 | "(offset %d lines).\n") |
|
787 | "(offset %d lines).\n") | |
788 | self.printfile(True) |
|
788 | self.printfile(True) | |
789 | self.ui.warn(msg % |
|
789 | self.ui.warn(msg % | |
790 | (h.number, l + 1, fuzzlen, offset)) |
|
790 | (h.number, l + 1, fuzzlen, offset)) | |
791 | else: |
|
791 | else: | |
792 | msg = _("Hunk #%d succeeded at %d " |
|
792 | msg = _("Hunk #%d succeeded at %d " | |
793 | "(offset %d lines).\n") |
|
793 | "(offset %d lines).\n") | |
794 | self.ui.note(msg % (h.number, l + 1, offset)) |
|
794 | self.ui.note(msg % (h.number, l + 1, offset)) | |
795 | return fuzzlen |
|
795 | return fuzzlen | |
796 | self.printfile(True) |
|
796 | self.printfile(True) | |
797 | self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start)) |
|
797 | self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start)) | |
798 | self.rej.append(horig) |
|
798 | self.rej.append(horig) | |
799 | return -1 |
|
799 | return -1 | |
800 |
|
800 | |||
801 | def close(self): |
|
801 | def close(self): | |
802 | if self.dirty: |
|
802 | if self.dirty: | |
803 | self.writelines(self.fname, self.lines, self.mode) |
|
803 | self.writelines(self.fname, self.lines, self.mode) | |
804 | self.write_rej() |
|
804 | self.write_rej() | |
805 | return len(self.rej) |
|
805 | return len(self.rej) | |
806 |
|
806 | |||
807 | class hunk(object): |
|
807 | class hunk(object): | |
808 | def __init__(self, desc, num, lr, context): |
|
808 | def __init__(self, desc, num, lr, context): | |
809 | self.number = num |
|
809 | self.number = num | |
810 | self.desc = desc |
|
810 | self.desc = desc | |
811 | self.hunk = [desc] |
|
811 | self.hunk = [desc] | |
812 | self.a = [] |
|
812 | self.a = [] | |
813 | self.b = [] |
|
813 | self.b = [] | |
814 | self.starta = self.lena = None |
|
814 | self.starta = self.lena = None | |
815 | self.startb = self.lenb = None |
|
815 | self.startb = self.lenb = None | |
816 | if lr is not None: |
|
816 | if lr is not None: | |
817 | if context: |
|
817 | if context: | |
818 | self.read_context_hunk(lr) |
|
818 | self.read_context_hunk(lr) | |
819 | else: |
|
819 | else: | |
820 | self.read_unified_hunk(lr) |
|
820 | self.read_unified_hunk(lr) | |
821 |
|
821 | |||
822 | def getnormalized(self): |
|
822 | def getnormalized(self): | |
823 | """Return a copy with line endings normalized to LF.""" |
|
823 | """Return a copy with line endings normalized to LF.""" | |
824 |
|
824 | |||
825 | def normalize(lines): |
|
825 | def normalize(lines): | |
826 | nlines = [] |
|
826 | nlines = [] | |
827 | for line in lines: |
|
827 | for line in lines: | |
828 | if line.endswith('\r\n'): |
|
828 | if line.endswith('\r\n'): | |
829 | line = line[:-2] + '\n' |
|
829 | line = line[:-2] + '\n' | |
830 | nlines.append(line) |
|
830 | nlines.append(line) | |
831 | return nlines |
|
831 | return nlines | |
832 |
|
832 | |||
833 | # Dummy object, it is rebuilt manually |
|
833 | # Dummy object, it is rebuilt manually | |
834 | nh = hunk(self.desc, self.number, None, None) |
|
834 | nh = hunk(self.desc, self.number, None, None) | |
835 | nh.number = self.number |
|
835 | nh.number = self.number | |
836 | nh.desc = self.desc |
|
836 | nh.desc = self.desc | |
837 | nh.hunk = self.hunk |
|
837 | nh.hunk = self.hunk | |
838 | nh.a = normalize(self.a) |
|
838 | nh.a = normalize(self.a) | |
839 | nh.b = normalize(self.b) |
|
839 | nh.b = normalize(self.b) | |
840 | nh.starta = self.starta |
|
840 | nh.starta = self.starta | |
841 | nh.startb = self.startb |
|
841 | nh.startb = self.startb | |
842 | nh.lena = self.lena |
|
842 | nh.lena = self.lena | |
843 | nh.lenb = self.lenb |
|
843 | nh.lenb = self.lenb | |
844 | return nh |
|
844 | return nh | |
845 |
|
845 | |||
846 | def read_unified_hunk(self, lr): |
|
846 | def read_unified_hunk(self, lr): | |
847 | m = unidesc.match(self.desc) |
|
847 | m = unidesc.match(self.desc) | |
848 | if not m: |
|
848 | if not m: | |
849 | raise PatchError(_("bad hunk #%d") % self.number) |
|
849 | raise PatchError(_("bad hunk #%d") % self.number) | |
850 | self.starta, self.lena, self.startb, self.lenb = m.groups() |
|
850 | self.starta, self.lena, self.startb, self.lenb = m.groups() | |
851 | if self.lena is None: |
|
851 | if self.lena is None: | |
852 | self.lena = 1 |
|
852 | self.lena = 1 | |
853 | else: |
|
853 | else: | |
854 | self.lena = int(self.lena) |
|
854 | self.lena = int(self.lena) | |
855 | if self.lenb is None: |
|
855 | if self.lenb is None: | |
856 | self.lenb = 1 |
|
856 | self.lenb = 1 | |
857 | else: |
|
857 | else: | |
858 | self.lenb = int(self.lenb) |
|
858 | self.lenb = int(self.lenb) | |
859 | self.starta = int(self.starta) |
|
859 | self.starta = int(self.starta) | |
860 | self.startb = int(self.startb) |
|
860 | self.startb = int(self.startb) | |
861 | diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a, |
|
861 | diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a, | |
862 | self.b) |
|
862 | self.b) | |
863 | # if we hit eof before finishing out the hunk, the last line will |
|
863 | # if we hit eof before finishing out the hunk, the last line will | |
864 | # be zero length. Lets try to fix it up. |
|
864 | # be zero length. Lets try to fix it up. | |
865 | while len(self.hunk[-1]) == 0: |
|
865 | while len(self.hunk[-1]) == 0: | |
866 | del self.hunk[-1] |
|
866 | del self.hunk[-1] | |
867 | del self.a[-1] |
|
867 | del self.a[-1] | |
868 | del self.b[-1] |
|
868 | del self.b[-1] | |
869 | self.lena -= 1 |
|
869 | self.lena -= 1 | |
870 | self.lenb -= 1 |
|
870 | self.lenb -= 1 | |
871 | self._fixnewline(lr) |
|
871 | self._fixnewline(lr) | |
872 |
|
872 | |||
873 | def read_context_hunk(self, lr): |
|
873 | def read_context_hunk(self, lr): | |
874 | self.desc = lr.readline() |
|
874 | self.desc = lr.readline() | |
875 | m = contextdesc.match(self.desc) |
|
875 | m = contextdesc.match(self.desc) | |
876 | if not m: |
|
876 | if not m: | |
877 | raise PatchError(_("bad hunk #%d") % self.number) |
|
877 | raise PatchError(_("bad hunk #%d") % self.number) | |
878 | self.starta, aend = m.groups() |
|
878 | self.starta, aend = m.groups() | |
879 | self.starta = int(self.starta) |
|
879 | self.starta = int(self.starta) | |
880 | if aend is None: |
|
880 | if aend is None: | |
881 | aend = self.starta |
|
881 | aend = self.starta | |
882 | self.lena = int(aend) - self.starta |
|
882 | self.lena = int(aend) - self.starta | |
883 | if self.starta: |
|
883 | if self.starta: | |
884 | self.lena += 1 |
|
884 | self.lena += 1 | |
885 | for x in xrange(self.lena): |
|
885 | for x in xrange(self.lena): | |
886 | l = lr.readline() |
|
886 | l = lr.readline() | |
887 | if l.startswith('---'): |
|
887 | if l.startswith('---'): | |
888 | # lines addition, old block is empty |
|
888 | # lines addition, old block is empty | |
889 | lr.push(l) |
|
889 | lr.push(l) | |
890 | break |
|
890 | break | |
891 | s = l[2:] |
|
891 | s = l[2:] | |
892 | if l.startswith('- ') or l.startswith('! '): |
|
892 | if l.startswith('- ') or l.startswith('! '): | |
893 | u = '-' + s |
|
893 | u = '-' + s | |
894 | elif l.startswith(' '): |
|
894 | elif l.startswith(' '): | |
895 | u = ' ' + s |
|
895 | u = ' ' + s | |
896 | else: |
|
896 | else: | |
897 | raise PatchError(_("bad hunk #%d old text line %d") % |
|
897 | raise PatchError(_("bad hunk #%d old text line %d") % | |
898 | (self.number, x)) |
|
898 | (self.number, x)) | |
899 | self.a.append(u) |
|
899 | self.a.append(u) | |
900 | self.hunk.append(u) |
|
900 | self.hunk.append(u) | |
901 |
|
901 | |||
902 | l = lr.readline() |
|
902 | l = lr.readline() | |
903 | if l.startswith('\ '): |
|
903 | if l.startswith('\ '): | |
904 | s = self.a[-1][:-1] |
|
904 | s = self.a[-1][:-1] | |
905 | self.a[-1] = s |
|
905 | self.a[-1] = s | |
906 | self.hunk[-1] = s |
|
906 | self.hunk[-1] = s | |
907 | l = lr.readline() |
|
907 | l = lr.readline() | |
908 | m = contextdesc.match(l) |
|
908 | m = contextdesc.match(l) | |
909 | if not m: |
|
909 | if not m: | |
910 | raise PatchError(_("bad hunk #%d") % self.number) |
|
910 | raise PatchError(_("bad hunk #%d") % self.number) | |
911 | self.startb, bend = m.groups() |
|
911 | self.startb, bend = m.groups() | |
912 | self.startb = int(self.startb) |
|
912 | self.startb = int(self.startb) | |
913 | if bend is None: |
|
913 | if bend is None: | |
914 | bend = self.startb |
|
914 | bend = self.startb | |
915 | self.lenb = int(bend) - self.startb |
|
915 | self.lenb = int(bend) - self.startb | |
916 | if self.startb: |
|
916 | if self.startb: | |
917 | self.lenb += 1 |
|
917 | self.lenb += 1 | |
918 | hunki = 1 |
|
918 | hunki = 1 | |
919 | for x in xrange(self.lenb): |
|
919 | for x in xrange(self.lenb): | |
920 | l = lr.readline() |
|
920 | l = lr.readline() | |
921 | if l.startswith('\ '): |
|
921 | if l.startswith('\ '): | |
922 | # XXX: the only way to hit this is with an invalid line range. |
|
922 | # XXX: the only way to hit this is with an invalid line range. | |
923 | # The no-eol marker is not counted in the line range, but I |
|
923 | # The no-eol marker is not counted in the line range, but I | |
924 | # guess there are diff(1) out there which behave differently. |
|
924 | # guess there are diff(1) out there which behave differently. | |
925 | s = self.b[-1][:-1] |
|
925 | s = self.b[-1][:-1] | |
926 | self.b[-1] = s |
|
926 | self.b[-1] = s | |
927 | self.hunk[hunki - 1] = s |
|
927 | self.hunk[hunki - 1] = s | |
928 | continue |
|
928 | continue | |
929 | if not l: |
|
929 | if not l: | |
930 | # line deletions, new block is empty and we hit EOF |
|
930 | # line deletions, new block is empty and we hit EOF | |
931 | lr.push(l) |
|
931 | lr.push(l) | |
932 | break |
|
932 | break | |
933 | s = l[2:] |
|
933 | s = l[2:] | |
934 | if l.startswith('+ ') or l.startswith('! '): |
|
934 | if l.startswith('+ ') or l.startswith('! '): | |
935 | u = '+' + s |
|
935 | u = '+' + s | |
936 | elif l.startswith(' '): |
|
936 | elif l.startswith(' '): | |
937 | u = ' ' + s |
|
937 | u = ' ' + s | |
938 | elif len(self.b) == 0: |
|
938 | elif len(self.b) == 0: | |
939 | # line deletions, new block is empty |
|
939 | # line deletions, new block is empty | |
940 | lr.push(l) |
|
940 | lr.push(l) | |
941 | break |
|
941 | break | |
942 | else: |
|
942 | else: | |
943 | raise PatchError(_("bad hunk #%d old text line %d") % |
|
943 | raise PatchError(_("bad hunk #%d old text line %d") % | |
944 | (self.number, x)) |
|
944 | (self.number, x)) | |
945 | self.b.append(s) |
|
945 | self.b.append(s) | |
946 | while True: |
|
946 | while True: | |
947 | if hunki >= len(self.hunk): |
|
947 | if hunki >= len(self.hunk): | |
948 | h = "" |
|
948 | h = "" | |
949 | else: |
|
949 | else: | |
950 | h = self.hunk[hunki] |
|
950 | h = self.hunk[hunki] | |
951 | hunki += 1 |
|
951 | hunki += 1 | |
952 | if h == u: |
|
952 | if h == u: | |
953 | break |
|
953 | break | |
954 | elif h.startswith('-'): |
|
954 | elif h.startswith('-'): | |
955 | continue |
|
955 | continue | |
956 | else: |
|
956 | else: | |
957 | self.hunk.insert(hunki - 1, u) |
|
957 | self.hunk.insert(hunki - 1, u) | |
958 | break |
|
958 | break | |
959 |
|
959 | |||
960 | if not self.a: |
|
960 | if not self.a: | |
961 | # this happens when lines were only added to the hunk |
|
961 | # this happens when lines were only added to the hunk | |
962 | for x in self.hunk: |
|
962 | for x in self.hunk: | |
963 | if x.startswith('-') or x.startswith(' '): |
|
963 | if x.startswith('-') or x.startswith(' '): | |
964 | self.a.append(x) |
|
964 | self.a.append(x) | |
965 | if not self.b: |
|
965 | if not self.b: | |
966 | # this happens when lines were only deleted from the hunk |
|
966 | # this happens when lines were only deleted from the hunk | |
967 | for x in self.hunk: |
|
967 | for x in self.hunk: | |
968 | if x.startswith('+') or x.startswith(' '): |
|
968 | if x.startswith('+') or x.startswith(' '): | |
969 | self.b.append(x[1:]) |
|
969 | self.b.append(x[1:]) | |
970 | # @@ -start,len +start,len @@ |
|
970 | # @@ -start,len +start,len @@ | |
971 | self.desc = "@@ -%d,%d +%d,%d @@\n" % (self.starta, self.lena, |
|
971 | self.desc = "@@ -%d,%d +%d,%d @@\n" % (self.starta, self.lena, | |
972 | self.startb, self.lenb) |
|
972 | self.startb, self.lenb) | |
973 | self.hunk[0] = self.desc |
|
973 | self.hunk[0] = self.desc | |
974 | self._fixnewline(lr) |
|
974 | self._fixnewline(lr) | |
975 |
|
975 | |||
976 | def _fixnewline(self, lr): |
|
976 | def _fixnewline(self, lr): | |
977 | l = lr.readline() |
|
977 | l = lr.readline() | |
978 | if l.startswith('\ '): |
|
978 | if l.startswith('\ '): | |
979 | diffhelpers.fix_newline(self.hunk, self.a, self.b) |
|
979 | diffhelpers.fix_newline(self.hunk, self.a, self.b) | |
980 | else: |
|
980 | else: | |
981 | lr.push(l) |
|
981 | lr.push(l) | |
982 |
|
982 | |||
983 | def complete(self): |
|
983 | def complete(self): | |
984 | return len(self.a) == self.lena and len(self.b) == self.lenb |
|
984 | return len(self.a) == self.lena and len(self.b) == self.lenb | |
985 |
|
985 | |||
986 | def _fuzzit(self, old, new, fuzz, toponly): |
|
986 | def _fuzzit(self, old, new, fuzz, toponly): | |
987 | # this removes context lines from the top and bottom of list 'l'. It |
|
987 | # this removes context lines from the top and bottom of list 'l'. It | |
988 | # checks the hunk to make sure only context lines are removed, and then |
|
988 | # checks the hunk to make sure only context lines are removed, and then | |
989 | # returns a new shortened list of lines. |
|
989 | # returns a new shortened list of lines. | |
990 | fuzz = min(fuzz, len(old)) |
|
990 | fuzz = min(fuzz, len(old)) | |
991 | if fuzz: |
|
991 | if fuzz: | |
992 | top = 0 |
|
992 | top = 0 | |
993 | bot = 0 |
|
993 | bot = 0 | |
994 | hlen = len(self.hunk) |
|
994 | hlen = len(self.hunk) | |
995 | for x in xrange(hlen - 1): |
|
995 | for x in xrange(hlen - 1): | |
996 | # the hunk starts with the @@ line, so use x+1 |
|
996 | # the hunk starts with the @@ line, so use x+1 | |
997 | if self.hunk[x + 1][0] == ' ': |
|
997 | if self.hunk[x + 1][0] == ' ': | |
998 | top += 1 |
|
998 | top += 1 | |
999 | else: |
|
999 | else: | |
1000 | break |
|
1000 | break | |
1001 | if not toponly: |
|
1001 | if not toponly: | |
1002 | for x in xrange(hlen - 1): |
|
1002 | for x in xrange(hlen - 1): | |
1003 | if self.hunk[hlen - bot - 1][0] == ' ': |
|
1003 | if self.hunk[hlen - bot - 1][0] == ' ': | |
1004 | bot += 1 |
|
1004 | bot += 1 | |
1005 | else: |
|
1005 | else: | |
1006 | break |
|
1006 | break | |
1007 |
|
1007 | |||
1008 | bot = min(fuzz, bot) |
|
1008 | bot = min(fuzz, bot) | |
1009 | top = min(fuzz, top) |
|
1009 | top = min(fuzz, top) | |
1010 | return old[top:len(old) - bot], new[top:len(new) - bot], top |
|
1010 | return old[top:len(old) - bot], new[top:len(new) - bot], top | |
1011 | return old, new, 0 |
|
1011 | return old, new, 0 | |
1012 |
|
1012 | |||
1013 | def fuzzit(self, fuzz, toponly): |
|
1013 | def fuzzit(self, fuzz, toponly): | |
1014 | old, new, top = self._fuzzit(self.a, self.b, fuzz, toponly) |
|
1014 | old, new, top = self._fuzzit(self.a, self.b, fuzz, toponly) | |
1015 | oldstart = self.starta + top |
|
1015 | oldstart = self.starta + top | |
1016 | newstart = self.startb + top |
|
1016 | newstart = self.startb + top | |
1017 | # zero length hunk ranges already have their start decremented |
|
1017 | # zero length hunk ranges already have their start decremented | |
1018 | if self.lena and oldstart > 0: |
|
1018 | if self.lena and oldstart > 0: | |
1019 | oldstart -= 1 |
|
1019 | oldstart -= 1 | |
1020 | if self.lenb and newstart > 0: |
|
1020 | if self.lenb and newstart > 0: | |
1021 | newstart -= 1 |
|
1021 | newstart -= 1 | |
1022 | return old, oldstart, new, newstart |
|
1022 | return old, oldstart, new, newstart | |
1023 |
|
1023 | |||
1024 | class binhunk(object): |
|
1024 | class binhunk(object): | |
1025 | 'A binary patch file.' |
|
1025 | 'A binary patch file.' | |
1026 | def __init__(self, lr, fname): |
|
1026 | def __init__(self, lr, fname): | |
1027 | self.text = None |
|
1027 | self.text = None | |
1028 | self.delta = False |
|
1028 | self.delta = False | |
1029 | self.hunk = ['GIT binary patch\n'] |
|
1029 | self.hunk = ['GIT binary patch\n'] | |
1030 | self._fname = fname |
|
1030 | self._fname = fname | |
1031 | self._read(lr) |
|
1031 | self._read(lr) | |
1032 |
|
1032 | |||
1033 | def complete(self): |
|
1033 | def complete(self): | |
1034 | return self.text is not None |
|
1034 | return self.text is not None | |
1035 |
|
1035 | |||
1036 | def new(self, lines): |
|
1036 | def new(self, lines): | |
1037 | if self.delta: |
|
1037 | if self.delta: | |
1038 | return [applybindelta(self.text, ''.join(lines))] |
|
1038 | return [applybindelta(self.text, ''.join(lines))] | |
1039 | return [self.text] |
|
1039 | return [self.text] | |
1040 |
|
1040 | |||
1041 | def _read(self, lr): |
|
1041 | def _read(self, lr): | |
1042 | def getline(lr, hunk): |
|
1042 | def getline(lr, hunk): | |
1043 | l = lr.readline() |
|
1043 | l = lr.readline() | |
1044 | hunk.append(l) |
|
1044 | hunk.append(l) | |
1045 | return l.rstrip('\r\n') |
|
1045 | return l.rstrip('\r\n') | |
1046 |
|
1046 | |||
1047 | size = 0 |
|
1047 | size = 0 | |
1048 | while True: |
|
1048 | while True: | |
1049 | line = getline(lr, self.hunk) |
|
1049 | line = getline(lr, self.hunk) | |
1050 | if not line: |
|
1050 | if not line: | |
1051 | raise PatchError(_('could not extract "%s" binary data') |
|
1051 | raise PatchError(_('could not extract "%s" binary data') | |
1052 | % self._fname) |
|
1052 | % self._fname) | |
1053 | if line.startswith('literal '): |
|
1053 | if line.startswith('literal '): | |
1054 | size = int(line[8:].rstrip()) |
|
1054 | size = int(line[8:].rstrip()) | |
1055 | break |
|
1055 | break | |
1056 | if line.startswith('delta '): |
|
1056 | if line.startswith('delta '): | |
1057 | size = int(line[6:].rstrip()) |
|
1057 | size = int(line[6:].rstrip()) | |
1058 | self.delta = True |
|
1058 | self.delta = True | |
1059 | break |
|
1059 | break | |
1060 | dec = [] |
|
1060 | dec = [] | |
1061 | line = getline(lr, self.hunk) |
|
1061 | line = getline(lr, self.hunk) | |
1062 | while len(line) > 1: |
|
1062 | while len(line) > 1: | |
1063 | l = line[0] |
|
1063 | l = line[0] | |
1064 | if l <= 'Z' and l >= 'A': |
|
1064 | if l <= 'Z' and l >= 'A': | |
1065 | l = ord(l) - ord('A') + 1 |
|
1065 | l = ord(l) - ord('A') + 1 | |
1066 | else: |
|
1066 | else: | |
1067 | l = ord(l) - ord('a') + 27 |
|
1067 | l = ord(l) - ord('a') + 27 | |
1068 | try: |
|
1068 | try: | |
1069 | dec.append(base85.b85decode(line[1:])[:l]) |
|
1069 | dec.append(base85.b85decode(line[1:])[:l]) | |
1070 | except ValueError, e: |
|
1070 | except ValueError, e: | |
1071 | raise PatchError(_('could not decode "%s" binary patch: %s') |
|
1071 | raise PatchError(_('could not decode "%s" binary patch: %s') | |
1072 | % (self._fname, str(e))) |
|
1072 | % (self._fname, str(e))) | |
1073 | line = getline(lr, self.hunk) |
|
1073 | line = getline(lr, self.hunk) | |
1074 | text = zlib.decompress(''.join(dec)) |
|
1074 | text = zlib.decompress(''.join(dec)) | |
1075 | if len(text) != size: |
|
1075 | if len(text) != size: | |
1076 | raise PatchError(_('"%s" length is %d bytes, should be %d') |
|
1076 | raise PatchError(_('"%s" length is %d bytes, should be %d') | |
1077 | % (self._fname, len(text), size)) |
|
1077 | % (self._fname, len(text), size)) | |
1078 | self.text = text |
|
1078 | self.text = text | |
1079 |
|
1079 | |||
1080 | def parsefilename(str): |
|
1080 | def parsefilename(str): | |
1081 | # --- filename \t|space stuff |
|
1081 | # --- filename \t|space stuff | |
1082 | s = str[4:].rstrip('\r\n') |
|
1082 | s = str[4:].rstrip('\r\n') | |
1083 | i = s.find('\t') |
|
1083 | i = s.find('\t') | |
1084 | if i < 0: |
|
1084 | if i < 0: | |
1085 | i = s.find(' ') |
|
1085 | i = s.find(' ') | |
1086 | if i < 0: |
|
1086 | if i < 0: | |
1087 | return s |
|
1087 | return s | |
1088 | return s[:i] |
|
1088 | return s[:i] | |
1089 |
|
1089 | |||
1090 | def pathstrip(path, strip): |
|
1090 | def pathstrip(path, strip): | |
1091 | pathlen = len(path) |
|
1091 | pathlen = len(path) | |
1092 | i = 0 |
|
1092 | i = 0 | |
1093 | if strip == 0: |
|
1093 | if strip == 0: | |
1094 | return '', path.rstrip() |
|
1094 | return '', path.rstrip() | |
1095 | count = strip |
|
1095 | count = strip | |
1096 | while count > 0: |
|
1096 | while count > 0: | |
1097 | i = path.find('/', i) |
|
1097 | i = path.find('/', i) | |
1098 | if i == -1: |
|
1098 | if i == -1: | |
1099 | raise PatchError(_("unable to strip away %d of %d dirs from %s") % |
|
1099 | raise PatchError(_("unable to strip away %d of %d dirs from %s") % | |
1100 | (count, strip, path)) |
|
1100 | (count, strip, path)) | |
1101 | i += 1 |
|
1101 | i += 1 | |
1102 | # consume '//' in the path |
|
1102 | # consume '//' in the path | |
1103 | while i < pathlen - 1 and path[i] == '/': |
|
1103 | while i < pathlen - 1 and path[i] == '/': | |
1104 | i += 1 |
|
1104 | i += 1 | |
1105 | count -= 1 |
|
1105 | count -= 1 | |
1106 | return path[:i].lstrip(), path[i:].rstrip() |
|
1106 | return path[:i].lstrip(), path[i:].rstrip() | |
1107 |
|
1107 | |||
1108 | def makepatchmeta(backend, afile_orig, bfile_orig, hunk, strip): |
|
1108 | def makepatchmeta(backend, afile_orig, bfile_orig, hunk, strip): | |
1109 | nulla = afile_orig == "/dev/null" |
|
1109 | nulla = afile_orig == "/dev/null" | |
1110 | nullb = bfile_orig == "/dev/null" |
|
1110 | nullb = bfile_orig == "/dev/null" | |
1111 | create = nulla and hunk.starta == 0 and hunk.lena == 0 |
|
1111 | create = nulla and hunk.starta == 0 and hunk.lena == 0 | |
1112 | remove = nullb and hunk.startb == 0 and hunk.lenb == 0 |
|
1112 | remove = nullb and hunk.startb == 0 and hunk.lenb == 0 | |
1113 | abase, afile = pathstrip(afile_orig, strip) |
|
1113 | abase, afile = pathstrip(afile_orig, strip) | |
1114 | gooda = not nulla and backend.exists(afile) |
|
1114 | gooda = not nulla and backend.exists(afile) | |
1115 | bbase, bfile = pathstrip(bfile_orig, strip) |
|
1115 | bbase, bfile = pathstrip(bfile_orig, strip) | |
1116 | if afile == bfile: |
|
1116 | if afile == bfile: | |
1117 | goodb = gooda |
|
1117 | goodb = gooda | |
1118 | else: |
|
1118 | else: | |
1119 | goodb = not nullb and backend.exists(bfile) |
|
1119 | goodb = not nullb and backend.exists(bfile) | |
1120 | missing = not goodb and not gooda and not create |
|
1120 | missing = not goodb and not gooda and not create | |
1121 |
|
1121 | |||
1122 | # some diff programs apparently produce patches where the afile is |
|
1122 | # some diff programs apparently produce patches where the afile is | |
1123 | # not /dev/null, but afile starts with bfile |
|
1123 | # not /dev/null, but afile starts with bfile | |
1124 | abasedir = afile[:afile.rfind('/') + 1] |
|
1124 | abasedir = afile[:afile.rfind('/') + 1] | |
1125 | bbasedir = bfile[:bfile.rfind('/') + 1] |
|
1125 | bbasedir = bfile[:bfile.rfind('/') + 1] | |
1126 | if (missing and abasedir == bbasedir and afile.startswith(bfile) |
|
1126 | if (missing and abasedir == bbasedir and afile.startswith(bfile) | |
1127 | and hunk.starta == 0 and hunk.lena == 0): |
|
1127 | and hunk.starta == 0 and hunk.lena == 0): | |
1128 | create = True |
|
1128 | create = True | |
1129 | missing = False |
|
1129 | missing = False | |
1130 |
|
1130 | |||
1131 | # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the |
|
1131 | # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the | |
1132 | # diff is between a file and its backup. In this case, the original |
|
1132 | # diff is between a file and its backup. In this case, the original | |
1133 | # file should be patched (see original mpatch code). |
|
1133 | # file should be patched (see original mpatch code). | |
1134 | isbackup = (abase == bbase and bfile.startswith(afile)) |
|
1134 | isbackup = (abase == bbase and bfile.startswith(afile)) | |
1135 | fname = None |
|
1135 | fname = None | |
1136 | if not missing: |
|
1136 | if not missing: | |
1137 | if gooda and goodb: |
|
1137 | if gooda and goodb: | |
1138 | fname = isbackup and afile or bfile |
|
1138 | fname = isbackup and afile or bfile | |
1139 | elif gooda: |
|
1139 | elif gooda: | |
1140 | fname = afile |
|
1140 | fname = afile | |
1141 |
|
1141 | |||
1142 | if not fname: |
|
1142 | if not fname: | |
1143 | if not nullb: |
|
1143 | if not nullb: | |
1144 | fname = isbackup and afile or bfile |
|
1144 | fname = isbackup and afile or bfile | |
1145 | elif not nulla: |
|
1145 | elif not nulla: | |
1146 | fname = afile |
|
1146 | fname = afile | |
1147 | else: |
|
1147 | else: | |
1148 | raise PatchError(_("undefined source and destination files")) |
|
1148 | raise PatchError(_("undefined source and destination files")) | |
1149 |
|
1149 | |||
1150 | gp = patchmeta(fname) |
|
1150 | gp = patchmeta(fname) | |
1151 | if create: |
|
1151 | if create: | |
1152 | gp.op = 'ADD' |
|
1152 | gp.op = 'ADD' | |
1153 | elif remove: |
|
1153 | elif remove: | |
1154 | gp.op = 'DELETE' |
|
1154 | gp.op = 'DELETE' | |
1155 | return gp |
|
1155 | return gp | |
1156 |
|
1156 | |||
1157 | def scangitpatch(lr, firstline): |
|
1157 | def scangitpatch(lr, firstline): | |
1158 | """ |
|
1158 | """ | |
1159 | Git patches can emit: |
|
1159 | Git patches can emit: | |
1160 | - rename a to b |
|
1160 | - rename a to b | |
1161 | - change b |
|
1161 | - change b | |
1162 | - copy a to c |
|
1162 | - copy a to c | |
1163 | - change c |
|
1163 | - change c | |
1164 |
|
1164 | |||
1165 | We cannot apply this sequence as-is, the renamed 'a' could not be |
|
1165 | We cannot apply this sequence as-is, the renamed 'a' could not be | |
1166 | found for it would have been renamed already. And we cannot copy |
|
1166 | found for it would have been renamed already. And we cannot copy | |
1167 | from 'b' instead because 'b' would have been changed already. So |
|
1167 | from 'b' instead because 'b' would have been changed already. So | |
1168 | we scan the git patch for copy and rename commands so we can |
|
1168 | we scan the git patch for copy and rename commands so we can | |
1169 | perform the copies ahead of time. |
|
1169 | perform the copies ahead of time. | |
1170 | """ |
|
1170 | """ | |
1171 | pos = 0 |
|
1171 | pos = 0 | |
1172 | try: |
|
1172 | try: | |
1173 | pos = lr.fp.tell() |
|
1173 | pos = lr.fp.tell() | |
1174 | fp = lr.fp |
|
1174 | fp = lr.fp | |
1175 | except IOError: |
|
1175 | except IOError: | |
1176 | fp = cStringIO.StringIO(lr.fp.read()) |
|
1176 | fp = cStringIO.StringIO(lr.fp.read()) | |
1177 | gitlr = linereader(fp) |
|
1177 | gitlr = linereader(fp) | |
1178 | gitlr.push(firstline) |
|
1178 | gitlr.push(firstline) | |
1179 | gitpatches = readgitpatch(gitlr) |
|
1179 | gitpatches = readgitpatch(gitlr) | |
1180 | fp.seek(pos) |
|
1180 | fp.seek(pos) | |
1181 | return gitpatches |
|
1181 | return gitpatches | |
1182 |
|
1182 | |||
1183 | def iterhunks(fp): |
|
1183 | def iterhunks(fp): | |
1184 | """Read a patch and yield the following events: |
|
1184 | """Read a patch and yield the following events: | |
1185 | - ("file", afile, bfile, firsthunk): select a new target file. |
|
1185 | - ("file", afile, bfile, firsthunk): select a new target file. | |
1186 | - ("hunk", hunk): a new hunk is ready to be applied, follows a |
|
1186 | - ("hunk", hunk): a new hunk is ready to be applied, follows a | |
1187 | "file" event. |
|
1187 | "file" event. | |
1188 | - ("git", gitchanges): current diff is in git format, gitchanges |
|
1188 | - ("git", gitchanges): current diff is in git format, gitchanges | |
1189 | maps filenames to gitpatch records. Unique event. |
|
1189 | maps filenames to gitpatch records. Unique event. | |
1190 | """ |
|
1190 | """ | |
1191 | afile = "" |
|
1191 | afile = "" | |
1192 | bfile = "" |
|
1192 | bfile = "" | |
1193 | state = None |
|
1193 | state = None | |
1194 | hunknum = 0 |
|
1194 | hunknum = 0 | |
1195 | emitfile = newfile = False |
|
1195 | emitfile = newfile = False | |
1196 | gitpatches = None |
|
1196 | gitpatches = None | |
1197 |
|
1197 | |||
1198 | # our states |
|
1198 | # our states | |
1199 | BFILE = 1 |
|
1199 | BFILE = 1 | |
1200 | context = None |
|
1200 | context = None | |
1201 | lr = linereader(fp) |
|
1201 | lr = linereader(fp) | |
1202 |
|
1202 | |||
1203 | while True: |
|
1203 | while True: | |
1204 | x = lr.readline() |
|
1204 | x = lr.readline() | |
1205 | if not x: |
|
1205 | if not x: | |
1206 | break |
|
1206 | break | |
1207 | if state == BFILE and ( |
|
1207 | if state == BFILE and ( | |
1208 | (not context and x[0] == '@') |
|
1208 | (not context and x[0] == '@') | |
1209 | or (context is not False and x.startswith('***************')) |
|
1209 | or (context is not False and x.startswith('***************')) | |
1210 | or x.startswith('GIT binary patch')): |
|
1210 | or x.startswith('GIT binary patch')): | |
1211 | gp = None |
|
1211 | gp = None | |
1212 | if (gitpatches and |
|
1212 | if (gitpatches and | |
1213 | gitpatches[-1].ispatching(afile, bfile)): |
|
1213 | gitpatches[-1].ispatching(afile, bfile)): | |
1214 | gp = gitpatches.pop() |
|
1214 | gp = gitpatches.pop() | |
1215 | if x.startswith('GIT binary patch'): |
|
1215 | if x.startswith('GIT binary patch'): | |
1216 | h = binhunk(lr, gp.path) |
|
1216 | h = binhunk(lr, gp.path) | |
1217 | else: |
|
1217 | else: | |
1218 | if context is None and x.startswith('***************'): |
|
1218 | if context is None and x.startswith('***************'): | |
1219 | context = True |
|
1219 | context = True | |
1220 | h = hunk(x, hunknum + 1, lr, context) |
|
1220 | h = hunk(x, hunknum + 1, lr, context) | |
1221 | hunknum += 1 |
|
1221 | hunknum += 1 | |
1222 | if emitfile: |
|
1222 | if emitfile: | |
1223 | emitfile = False |
|
1223 | emitfile = False | |
1224 | yield 'file', (afile, bfile, h, gp and gp.copy() or None) |
|
1224 | yield 'file', (afile, bfile, h, gp and gp.copy() or None) | |
1225 | yield 'hunk', h |
|
1225 | yield 'hunk', h | |
1226 | elif x.startswith('diff --git a/'): |
|
1226 | elif x.startswith('diff --git a/'): | |
1227 | m = gitre.match(x.rstrip(' \r\n')) |
|
1227 | m = gitre.match(x.rstrip(' \r\n')) | |
1228 | if not m: |
|
1228 | if not m: | |
1229 | continue |
|
1229 | continue | |
1230 | if gitpatches is None: |
|
1230 | if gitpatches is None: | |
1231 | # scan whole input for git metadata |
|
1231 | # scan whole input for git metadata | |
1232 | gitpatches = scangitpatch(lr, x) |
|
1232 | gitpatches = scangitpatch(lr, x) | |
1233 | yield 'git', [g.copy() for g in gitpatches |
|
1233 | yield 'git', [g.copy() for g in gitpatches | |
1234 | if g.op in ('COPY', 'RENAME')] |
|
1234 | if g.op in ('COPY', 'RENAME')] | |
1235 | gitpatches.reverse() |
|
1235 | gitpatches.reverse() | |
1236 | afile = 'a/' + m.group(1) |
|
1236 | afile = 'a/' + m.group(1) | |
1237 | bfile = 'b/' + m.group(2) |
|
1237 | bfile = 'b/' + m.group(2) | |
1238 | while gitpatches and not gitpatches[-1].ispatching(afile, bfile): |
|
1238 | while gitpatches and not gitpatches[-1].ispatching(afile, bfile): | |
1239 | gp = gitpatches.pop() |
|
1239 | gp = gitpatches.pop() | |
1240 | yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy()) |
|
1240 | yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy()) | |
1241 | if not gitpatches: |
|
1241 | if not gitpatches: | |
1242 | raise PatchError(_('failed to synchronize metadata for "%s"') |
|
1242 | raise PatchError(_('failed to synchronize metadata for "%s"') | |
1243 | % afile[2:]) |
|
1243 | % afile[2:]) | |
1244 | gp = gitpatches[-1] |
|
1244 | gp = gitpatches[-1] | |
1245 | newfile = True |
|
1245 | newfile = True | |
1246 | elif x.startswith('---'): |
|
1246 | elif x.startswith('---'): | |
1247 | # check for a unified diff |
|
1247 | # check for a unified diff | |
1248 | l2 = lr.readline() |
|
1248 | l2 = lr.readline() | |
1249 | if not l2.startswith('+++'): |
|
1249 | if not l2.startswith('+++'): | |
1250 | lr.push(l2) |
|
1250 | lr.push(l2) | |
1251 | continue |
|
1251 | continue | |
1252 | newfile = True |
|
1252 | newfile = True | |
1253 | context = False |
|
1253 | context = False | |
1254 | afile = parsefilename(x) |
|
1254 | afile = parsefilename(x) | |
1255 | bfile = parsefilename(l2) |
|
1255 | bfile = parsefilename(l2) | |
1256 | elif x.startswith('***'): |
|
1256 | elif x.startswith('***'): | |
1257 | # check for a context diff |
|
1257 | # check for a context diff | |
1258 | l2 = lr.readline() |
|
1258 | l2 = lr.readline() | |
1259 | if not l2.startswith('---'): |
|
1259 | if not l2.startswith('---'): | |
1260 | lr.push(l2) |
|
1260 | lr.push(l2) | |
1261 | continue |
|
1261 | continue | |
1262 | l3 = lr.readline() |
|
1262 | l3 = lr.readline() | |
1263 | lr.push(l3) |
|
1263 | lr.push(l3) | |
1264 | if not l3.startswith("***************"): |
|
1264 | if not l3.startswith("***************"): | |
1265 | lr.push(l2) |
|
1265 | lr.push(l2) | |
1266 | continue |
|
1266 | continue | |
1267 | newfile = True |
|
1267 | newfile = True | |
1268 | context = True |
|
1268 | context = True | |
1269 | afile = parsefilename(x) |
|
1269 | afile = parsefilename(x) | |
1270 | bfile = parsefilename(l2) |
|
1270 | bfile = parsefilename(l2) | |
1271 |
|
1271 | |||
1272 | if newfile: |
|
1272 | if newfile: | |
1273 | newfile = False |
|
1273 | newfile = False | |
1274 | emitfile = True |
|
1274 | emitfile = True | |
1275 | state = BFILE |
|
1275 | state = BFILE | |
1276 | hunknum = 0 |
|
1276 | hunknum = 0 | |
1277 |
|
1277 | |||
1278 | while gitpatches: |
|
1278 | while gitpatches: | |
1279 | gp = gitpatches.pop() |
|
1279 | gp = gitpatches.pop() | |
1280 | yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy()) |
|
1280 | yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy()) | |
1281 |
|
1281 | |||
1282 | def applybindelta(binchunk, data): |
|
1282 | def applybindelta(binchunk, data): | |
1283 | """Apply a binary delta hunk |
|
1283 | """Apply a binary delta hunk | |
1284 | The algorithm used is the algorithm from git's patch-delta.c |
|
1284 | The algorithm used is the algorithm from git's patch-delta.c | |
1285 | """ |
|
1285 | """ | |
1286 | def deltahead(binchunk): |
|
1286 | def deltahead(binchunk): | |
1287 | i = 0 |
|
1287 | i = 0 | |
1288 | for c in binchunk: |
|
1288 | for c in binchunk: | |
1289 | i += 1 |
|
1289 | i += 1 | |
1290 | if not (ord(c) & 0x80): |
|
1290 | if not (ord(c) & 0x80): | |
1291 | return i |
|
1291 | return i | |
1292 | return i |
|
1292 | return i | |
1293 | out = "" |
|
1293 | out = "" | |
1294 | s = deltahead(binchunk) |
|
1294 | s = deltahead(binchunk) | |
1295 | binchunk = binchunk[s:] |
|
1295 | binchunk = binchunk[s:] | |
1296 | s = deltahead(binchunk) |
|
1296 | s = deltahead(binchunk) | |
1297 | binchunk = binchunk[s:] |
|
1297 | binchunk = binchunk[s:] | |
1298 | i = 0 |
|
1298 | i = 0 | |
1299 | while i < len(binchunk): |
|
1299 | while i < len(binchunk): | |
1300 | cmd = ord(binchunk[i]) |
|
1300 | cmd = ord(binchunk[i]) | |
1301 | i += 1 |
|
1301 | i += 1 | |
1302 | if (cmd & 0x80): |
|
1302 | if (cmd & 0x80): | |
1303 | offset = 0 |
|
1303 | offset = 0 | |
1304 | size = 0 |
|
1304 | size = 0 | |
1305 | if (cmd & 0x01): |
|
1305 | if (cmd & 0x01): | |
1306 | offset = ord(binchunk[i]) |
|
1306 | offset = ord(binchunk[i]) | |
1307 | i += 1 |
|
1307 | i += 1 | |
1308 | if (cmd & 0x02): |
|
1308 | if (cmd & 0x02): | |
1309 | offset |= ord(binchunk[i]) << 8 |
|
1309 | offset |= ord(binchunk[i]) << 8 | |
1310 | i += 1 |
|
1310 | i += 1 | |
1311 | if (cmd & 0x04): |
|
1311 | if (cmd & 0x04): | |
1312 | offset |= ord(binchunk[i]) << 16 |
|
1312 | offset |= ord(binchunk[i]) << 16 | |
1313 | i += 1 |
|
1313 | i += 1 | |
1314 | if (cmd & 0x08): |
|
1314 | if (cmd & 0x08): | |
1315 | offset |= ord(binchunk[i]) << 24 |
|
1315 | offset |= ord(binchunk[i]) << 24 | |
1316 | i += 1 |
|
1316 | i += 1 | |
1317 | if (cmd & 0x10): |
|
1317 | if (cmd & 0x10): | |
1318 | size = ord(binchunk[i]) |
|
1318 | size = ord(binchunk[i]) | |
1319 | i += 1 |
|
1319 | i += 1 | |
1320 | if (cmd & 0x20): |
|
1320 | if (cmd & 0x20): | |
1321 | size |= ord(binchunk[i]) << 8 |
|
1321 | size |= ord(binchunk[i]) << 8 | |
1322 | i += 1 |
|
1322 | i += 1 | |
1323 | if (cmd & 0x40): |
|
1323 | if (cmd & 0x40): | |
1324 | size |= ord(binchunk[i]) << 16 |
|
1324 | size |= ord(binchunk[i]) << 16 | |
1325 | i += 1 |
|
1325 | i += 1 | |
1326 | if size == 0: |
|
1326 | if size == 0: | |
1327 | size = 0x10000 |
|
1327 | size = 0x10000 | |
1328 | offset_end = offset + size |
|
1328 | offset_end = offset + size | |
1329 | out += data[offset:offset_end] |
|
1329 | out += data[offset:offset_end] | |
1330 | elif cmd != 0: |
|
1330 | elif cmd != 0: | |
1331 | offset_end = i + cmd |
|
1331 | offset_end = i + cmd | |
1332 | out += binchunk[i:offset_end] |
|
1332 | out += binchunk[i:offset_end] | |
1333 | i += cmd |
|
1333 | i += cmd | |
1334 | else: |
|
1334 | else: | |
1335 | raise PatchError(_('unexpected delta opcode 0')) |
|
1335 | raise PatchError(_('unexpected delta opcode 0')) | |
1336 | return out |
|
1336 | return out | |
1337 |
|
1337 | |||
1338 | def applydiff(ui, fp, backend, store, strip=1, eolmode='strict'): |
|
1338 | def applydiff(ui, fp, backend, store, strip=1, eolmode='strict'): | |
1339 | """Reads a patch from fp and tries to apply it. |
|
1339 | """Reads a patch from fp and tries to apply it. | |
1340 |
|
1340 | |||
1341 | Returns 0 for a clean patch, -1 if any rejects were found and 1 if |
|
1341 | Returns 0 for a clean patch, -1 if any rejects were found and 1 if | |
1342 | there was any fuzz. |
|
1342 | there was any fuzz. | |
1343 |
|
1343 | |||
1344 | If 'eolmode' is 'strict', the patch content and patched file are |
|
1344 | If 'eolmode' is 'strict', the patch content and patched file are | |
1345 | read in binary mode. Otherwise, line endings are ignored when |
|
1345 | read in binary mode. Otherwise, line endings are ignored when | |
1346 | patching then normalized according to 'eolmode'. |
|
1346 | patching then normalized according to 'eolmode'. | |
1347 | """ |
|
1347 | """ | |
1348 | return _applydiff(ui, fp, patchfile, backend, store, strip=strip, |
|
1348 | return _applydiff(ui, fp, patchfile, backend, store, strip=strip, | |
1349 | eolmode=eolmode) |
|
1349 | eolmode=eolmode) | |
1350 |
|
1350 | |||
1351 | def _applydiff(ui, fp, patcher, backend, store, strip=1, |
|
1351 | def _applydiff(ui, fp, patcher, backend, store, strip=1, | |
1352 | eolmode='strict'): |
|
1352 | eolmode='strict'): | |
1353 |
|
1353 | |||
1354 | def pstrip(p): |
|
1354 | def pstrip(p): | |
1355 | return pathstrip(p, strip - 1)[1] |
|
1355 | return pathstrip(p, strip - 1)[1] | |
1356 |
|
1356 | |||
1357 | rejects = 0 |
|
1357 | rejects = 0 | |
1358 | err = 0 |
|
1358 | err = 0 | |
1359 | current_file = None |
|
1359 | current_file = None | |
1360 |
|
1360 | |||
1361 | for state, values in iterhunks(fp): |
|
1361 | for state, values in iterhunks(fp): | |
1362 | if state == 'hunk': |
|
1362 | if state == 'hunk': | |
1363 | if not current_file: |
|
1363 | if not current_file: | |
1364 | continue |
|
1364 | continue | |
1365 | ret = current_file.apply(values) |
|
1365 | ret = current_file.apply(values) | |
1366 | if ret > 0: |
|
1366 | if ret > 0: | |
1367 | err = 1 |
|
1367 | err = 1 | |
1368 | elif state == 'file': |
|
1368 | elif state == 'file': | |
1369 | if current_file: |
|
1369 | if current_file: | |
1370 | rejects += current_file.close() |
|
1370 | rejects += current_file.close() | |
1371 | current_file = None |
|
1371 | current_file = None | |
1372 | afile, bfile, first_hunk, gp = values |
|
1372 | afile, bfile, first_hunk, gp = values | |
1373 | if gp: |
|
1373 | if gp: | |
1374 | gp.path = pstrip(gp.path) |
|
1374 | gp.path = pstrip(gp.path) | |
1375 | if gp.oldpath: |
|
1375 | if gp.oldpath: | |
1376 | gp.oldpath = pstrip(gp.oldpath) |
|
1376 | gp.oldpath = pstrip(gp.oldpath) | |
1377 | else: |
|
1377 | else: | |
1378 | gp = makepatchmeta(backend, afile, bfile, first_hunk, strip) |
|
1378 | gp = makepatchmeta(backend, afile, bfile, first_hunk, strip) | |
1379 | if gp.op == 'RENAME': |
|
1379 | if gp.op == 'RENAME': | |
1380 | backend.unlink(gp.oldpath) |
|
1380 | backend.unlink(gp.oldpath) | |
1381 | if not first_hunk: |
|
1381 | if not first_hunk: | |
1382 | if gp.op == 'DELETE': |
|
1382 | if gp.op == 'DELETE': | |
1383 | backend.unlink(gp.path) |
|
1383 | backend.unlink(gp.path) | |
1384 | continue |
|
1384 | continue | |
1385 | data, mode = None, None |
|
1385 | data, mode = None, None | |
1386 | if gp.op in ('RENAME', 'COPY'): |
|
1386 | if gp.op in ('RENAME', 'COPY'): | |
1387 | data, mode = store.getfile(gp.oldpath)[:2] |
|
1387 | data, mode = store.getfile(gp.oldpath)[:2] | |
1388 | # FIXME: failing getfile has never been handled here |
|
1388 | # FIXME: failing getfile has never been handled here | |
1389 | assert data is not None |
|
1389 | assert data is not None | |
1390 | if gp.mode: |
|
1390 | if gp.mode: | |
1391 | mode = gp.mode |
|
1391 | mode = gp.mode | |
1392 | if gp.op == 'ADD': |
|
1392 | if gp.op == 'ADD': | |
1393 | # Added files without content have no hunk and |
|
1393 | # Added files without content have no hunk and | |
1394 | # must be created |
|
1394 | # must be created | |
1395 | data = '' |
|
1395 | data = '' | |
1396 | if data or mode: |
|
1396 | if data or mode: | |
1397 | if (gp.op in ('ADD', 'RENAME', 'COPY') |
|
1397 | if (gp.op in ('ADD', 'RENAME', 'COPY') | |
1398 | and backend.exists(gp.path)): |
|
1398 | and backend.exists(gp.path)): | |
1399 | raise PatchError(_("cannot create %s: destination " |
|
1399 | raise PatchError(_("cannot create %s: destination " | |
1400 | "already exists") % gp.path) |
|
1400 | "already exists") % gp.path) | |
1401 | backend.setfile(gp.path, data, mode, gp.oldpath) |
|
1401 | backend.setfile(gp.path, data, mode, gp.oldpath) | |
1402 | continue |
|
1402 | continue | |
1403 | try: |
|
1403 | try: | |
1404 | current_file = patcher(ui, gp, backend, store, |
|
1404 | current_file = patcher(ui, gp, backend, store, | |
1405 | eolmode=eolmode) |
|
1405 | eolmode=eolmode) | |
1406 | except PatchError, inst: |
|
1406 | except PatchError, inst: | |
1407 | ui.warn(str(inst) + '\n') |
|
1407 | ui.warn(str(inst) + '\n') | |
1408 | current_file = None |
|
1408 | current_file = None | |
1409 | rejects += 1 |
|
1409 | rejects += 1 | |
1410 | continue |
|
1410 | continue | |
1411 | elif state == 'git': |
|
1411 | elif state == 'git': | |
1412 | for gp in values: |
|
1412 | for gp in values: | |
1413 | path = pstrip(gp.oldpath) |
|
1413 | path = pstrip(gp.oldpath) | |
1414 | data, mode = backend.getfile(path) |
|
1414 | data, mode = backend.getfile(path) | |
1415 | if data is None: |
|
1415 | if data is None: | |
1416 | # The error ignored here will trigger a getfile() |
|
1416 | # The error ignored here will trigger a getfile() | |
1417 | # error in a place more appropriate for error |
|
1417 | # error in a place more appropriate for error | |
1418 | # handling, and will not interrupt the patching |
|
1418 | # handling, and will not interrupt the patching | |
1419 | # process. |
|
1419 | # process. | |
1420 | pass |
|
1420 | pass | |
1421 | else: |
|
1421 | else: | |
1422 | store.setfile(path, data, mode) |
|
1422 | store.setfile(path, data, mode) | |
1423 | else: |
|
1423 | else: | |
1424 | raise util.Abort(_('unsupported parser state: %s') % state) |
|
1424 | raise util.Abort(_('unsupported parser state: %s') % state) | |
1425 |
|
1425 | |||
1426 | if current_file: |
|
1426 | if current_file: | |
1427 | rejects += current_file.close() |
|
1427 | rejects += current_file.close() | |
1428 |
|
1428 | |||
1429 | if rejects: |
|
1429 | if rejects: | |
1430 | return -1 |
|
1430 | return -1 | |
1431 | return err |
|
1431 | return err | |
1432 |
|
1432 | |||
1433 | def _externalpatch(ui, repo, patcher, patchname, strip, files, |
|
1433 | def _externalpatch(ui, repo, patcher, patchname, strip, files, | |
1434 | similarity): |
|
1434 | similarity): | |
1435 | """use <patcher> to apply <patchname> to the working directory. |
|
1435 | """use <patcher> to apply <patchname> to the working directory. | |
1436 | returns whether patch was applied with fuzz factor.""" |
|
1436 | returns whether patch was applied with fuzz factor.""" | |
1437 |
|
1437 | |||
1438 | fuzz = False |
|
1438 | fuzz = False | |
1439 | args = [] |
|
1439 | args = [] | |
1440 | cwd = repo.root |
|
1440 | cwd = repo.root | |
1441 | if cwd: |
|
1441 | if cwd: | |
1442 | args.append('-d %s' % util.shellquote(cwd)) |
|
1442 | args.append('-d %s' % util.shellquote(cwd)) | |
1443 | fp = util.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, |
|
1443 | fp = util.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, | |
1444 | util.shellquote(patchname))) |
|
1444 | util.shellquote(patchname))) | |
1445 | try: |
|
1445 | try: | |
1446 | for line in fp: |
|
1446 | for line in fp: | |
1447 | line = line.rstrip() |
|
1447 | line = line.rstrip() | |
1448 | ui.note(line + '\n') |
|
1448 | ui.note(line + '\n') | |
1449 | if line.startswith('patching file '): |
|
1449 | if line.startswith('patching file '): | |
1450 | pf = util.parsepatchoutput(line) |
|
1450 | pf = util.parsepatchoutput(line) | |
1451 | printed_file = False |
|
1451 | printed_file = False | |
1452 | files.add(pf) |
|
1452 | files.add(pf) | |
1453 | elif line.find('with fuzz') >= 0: |
|
1453 | elif line.find('with fuzz') >= 0: | |
1454 | fuzz = True |
|
1454 | fuzz = True | |
1455 | if not printed_file: |
|
1455 | if not printed_file: | |
1456 | ui.warn(pf + '\n') |
|
1456 | ui.warn(pf + '\n') | |
1457 | printed_file = True |
|
1457 | printed_file = True | |
1458 | ui.warn(line + '\n') |
|
1458 | ui.warn(line + '\n') | |
1459 | elif line.find('saving rejects to file') >= 0: |
|
1459 | elif line.find('saving rejects to file') >= 0: | |
1460 | ui.warn(line + '\n') |
|
1460 | ui.warn(line + '\n') | |
1461 | elif line.find('FAILED') >= 0: |
|
1461 | elif line.find('FAILED') >= 0: | |
1462 | if not printed_file: |
|
1462 | if not printed_file: | |
1463 | ui.warn(pf + '\n') |
|
1463 | ui.warn(pf + '\n') | |
1464 | printed_file = True |
|
1464 | printed_file = True | |
1465 | ui.warn(line + '\n') |
|
1465 | ui.warn(line + '\n') | |
1466 | finally: |
|
1466 | finally: | |
1467 | if files: |
|
1467 | if files: | |
1468 | scmutil.marktouched(repo, files, similarity) |
|
1468 | scmutil.marktouched(repo, files, similarity) | |
1469 | code = fp.close() |
|
1469 | code = fp.close() | |
1470 | if code: |
|
1470 | if code: | |
1471 | raise PatchError(_("patch command failed: %s") % |
|
1471 | raise PatchError(_("patch command failed: %s") % | |
1472 | util.explainexit(code)[0]) |
|
1472 | util.explainexit(code)[0]) | |
1473 | return fuzz |
|
1473 | return fuzz | |
1474 |
|
1474 | |||
1475 | def patchbackend(ui, backend, patchobj, strip, files=None, eolmode='strict'): |
|
1475 | def patchbackend(ui, backend, patchobj, strip, files=None, eolmode='strict'): | |
1476 | if files is None: |
|
1476 | if files is None: | |
1477 | files = set() |
|
1477 | files = set() | |
1478 | if eolmode is None: |
|
1478 | if eolmode is None: | |
1479 | eolmode = ui.config('patch', 'eol', 'strict') |
|
1479 | eolmode = ui.config('patch', 'eol', 'strict') | |
1480 | if eolmode.lower() not in eolmodes: |
|
1480 | if eolmode.lower() not in eolmodes: | |
1481 | raise util.Abort(_('unsupported line endings type: %s') % eolmode) |
|
1481 | raise util.Abort(_('unsupported line endings type: %s') % eolmode) | |
1482 | eolmode = eolmode.lower() |
|
1482 | eolmode = eolmode.lower() | |
1483 |
|
1483 | |||
1484 | store = filestore() |
|
1484 | store = filestore() | |
1485 | try: |
|
1485 | try: | |
1486 | fp = open(patchobj, 'rb') |
|
1486 | fp = open(patchobj, 'rb') | |
1487 | except TypeError: |
|
1487 | except TypeError: | |
1488 | fp = patchobj |
|
1488 | fp = patchobj | |
1489 | try: |
|
1489 | try: | |
1490 | ret = applydiff(ui, fp, backend, store, strip=strip, |
|
1490 | ret = applydiff(ui, fp, backend, store, strip=strip, | |
1491 | eolmode=eolmode) |
|
1491 | eolmode=eolmode) | |
1492 | finally: |
|
1492 | finally: | |
1493 | if fp != patchobj: |
|
1493 | if fp != patchobj: | |
1494 | fp.close() |
|
1494 | fp.close() | |
1495 | files.update(backend.close()) |
|
1495 | files.update(backend.close()) | |
1496 | store.close() |
|
1496 | store.close() | |
1497 | if ret < 0: |
|
1497 | if ret < 0: | |
1498 | raise PatchError(_('patch failed to apply')) |
|
1498 | raise PatchError(_('patch failed to apply')) | |
1499 | return ret > 0 |
|
1499 | return ret > 0 | |
1500 |
|
1500 | |||
1501 | def internalpatch(ui, repo, patchobj, strip, files=None, eolmode='strict', |
|
1501 | def internalpatch(ui, repo, patchobj, strip, files=None, eolmode='strict', | |
1502 | similarity=0): |
|
1502 | similarity=0): | |
1503 | """use builtin patch to apply <patchobj> to the working directory. |
|
1503 | """use builtin patch to apply <patchobj> to the working directory. | |
1504 | returns whether patch was applied with fuzz factor.""" |
|
1504 | returns whether patch was applied with fuzz factor.""" | |
1505 | backend = workingbackend(ui, repo, similarity) |
|
1505 | backend = workingbackend(ui, repo, similarity) | |
1506 | return patchbackend(ui, backend, patchobj, strip, files, eolmode) |
|
1506 | return patchbackend(ui, backend, patchobj, strip, files, eolmode) | |
1507 |
|
1507 | |||
1508 | def patchrepo(ui, repo, ctx, store, patchobj, strip, files=None, |
|
1508 | def patchrepo(ui, repo, ctx, store, patchobj, strip, files=None, | |
1509 | eolmode='strict'): |
|
1509 | eolmode='strict'): | |
1510 | backend = repobackend(ui, repo, ctx, store) |
|
1510 | backend = repobackend(ui, repo, ctx, store) | |
1511 | return patchbackend(ui, backend, patchobj, strip, files, eolmode) |
|
1511 | return patchbackend(ui, backend, patchobj, strip, files, eolmode) | |
1512 |
|
1512 | |||
1513 | def patch(ui, repo, patchname, strip=1, files=None, eolmode='strict', |
|
1513 | def patch(ui, repo, patchname, strip=1, files=None, eolmode='strict', | |
1514 | similarity=0): |
|
1514 | similarity=0): | |
1515 | """Apply <patchname> to the working directory. |
|
1515 | """Apply <patchname> to the working directory. | |
1516 |
|
1516 | |||
1517 | 'eolmode' specifies how end of lines should be handled. It can be: |
|
1517 | 'eolmode' specifies how end of lines should be handled. It can be: | |
1518 | - 'strict': inputs are read in binary mode, EOLs are preserved |
|
1518 | - 'strict': inputs are read in binary mode, EOLs are preserved | |
1519 | - 'crlf': EOLs are ignored when patching and reset to CRLF |
|
1519 | - 'crlf': EOLs are ignored when patching and reset to CRLF | |
1520 | - 'lf': EOLs are ignored when patching and reset to LF |
|
1520 | - 'lf': EOLs are ignored when patching and reset to LF | |
1521 | - None: get it from user settings, default to 'strict' |
|
1521 | - None: get it from user settings, default to 'strict' | |
1522 | 'eolmode' is ignored when using an external patcher program. |
|
1522 | 'eolmode' is ignored when using an external patcher program. | |
1523 |
|
1523 | |||
1524 | Returns whether patch was applied with fuzz factor. |
|
1524 | Returns whether patch was applied with fuzz factor. | |
1525 | """ |
|
1525 | """ | |
1526 | patcher = ui.config('ui', 'patch') |
|
1526 | patcher = ui.config('ui', 'patch') | |
1527 | if files is None: |
|
1527 | if files is None: | |
1528 | files = set() |
|
1528 | files = set() | |
1529 | if patcher: |
|
1529 | if patcher: | |
1530 | return _externalpatch(ui, repo, patcher, patchname, strip, |
|
1530 | return _externalpatch(ui, repo, patcher, patchname, strip, | |
1531 | files, similarity) |
|
1531 | files, similarity) | |
1532 | return internalpatch(ui, repo, patchname, strip, files, eolmode, |
|
1532 | return internalpatch(ui, repo, patchname, strip, files, eolmode, | |
1533 | similarity) |
|
1533 | similarity) | |
1534 |
|
1534 | |||
1535 | def changedfiles(ui, repo, patchpath, strip=1): |
|
1535 | def changedfiles(ui, repo, patchpath, strip=1): | |
1536 | backend = fsbackend(ui, repo.root) |
|
1536 | backend = fsbackend(ui, repo.root) | |
1537 | fp = open(patchpath, 'rb') |
|
1537 | fp = open(patchpath, 'rb') | |
1538 | try: |
|
1538 | try: | |
1539 | changed = set() |
|
1539 | changed = set() | |
1540 | for state, values in iterhunks(fp): |
|
1540 | for state, values in iterhunks(fp): | |
1541 | if state == 'file': |
|
1541 | if state == 'file': | |
1542 | afile, bfile, first_hunk, gp = values |
|
1542 | afile, bfile, first_hunk, gp = values | |
1543 | if gp: |
|
1543 | if gp: | |
1544 | gp.path = pathstrip(gp.path, strip - 1)[1] |
|
1544 | gp.path = pathstrip(gp.path, strip - 1)[1] | |
1545 | if gp.oldpath: |
|
1545 | if gp.oldpath: | |
1546 | gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1] |
|
1546 | gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1] | |
1547 | else: |
|
1547 | else: | |
1548 | gp = makepatchmeta(backend, afile, bfile, first_hunk, strip) |
|
1548 | gp = makepatchmeta(backend, afile, bfile, first_hunk, strip) | |
1549 | changed.add(gp.path) |
|
1549 | changed.add(gp.path) | |
1550 | if gp.op == 'RENAME': |
|
1550 | if gp.op == 'RENAME': | |
1551 | changed.add(gp.oldpath) |
|
1551 | changed.add(gp.oldpath) | |
1552 | elif state not in ('hunk', 'git'): |
|
1552 | elif state not in ('hunk', 'git'): | |
1553 | raise util.Abort(_('unsupported parser state: %s') % state) |
|
1553 | raise util.Abort(_('unsupported parser state: %s') % state) | |
1554 | return changed |
|
1554 | return changed | |
1555 | finally: |
|
1555 | finally: | |
1556 | fp.close() |
|
1556 | fp.close() | |
1557 |
|
1557 | |||
1558 | class GitDiffRequired(Exception): |
|
1558 | class GitDiffRequired(Exception): | |
1559 | pass |
|
1559 | pass | |
1560 |
|
1560 | |||
1561 | def diffallopts(ui, opts=None, untrusted=False, section='diff'): |
|
1561 | def diffallopts(ui, opts=None, untrusted=False, section='diff'): | |
1562 | '''return diffopts with all features supported and parsed''' |
|
1562 | '''return diffopts with all features supported and parsed''' | |
1563 | return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section, |
|
1563 | return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section, | |
1564 | git=True, whitespace=True, formatchanging=True) |
|
1564 | git=True, whitespace=True, formatchanging=True) | |
1565 |
|
1565 | |||
1566 | diffopts = diffallopts |
|
1566 | diffopts = diffallopts | |
1567 |
|
1567 | |||
1568 | def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False, |
|
1568 | def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False, | |
1569 | whitespace=False, formatchanging=False): |
|
1569 | whitespace=False, formatchanging=False): | |
1570 | '''return diffopts with only opted-in features parsed |
|
1570 | '''return diffopts with only opted-in features parsed | |
1571 |
|
1571 | |||
1572 | Features: |
|
1572 | Features: | |
1573 | - git: git-style diffs |
|
1573 | - git: git-style diffs | |
1574 | - whitespace: whitespace options like ignoreblanklines and ignorews |
|
1574 | - whitespace: whitespace options like ignoreblanklines and ignorews | |
1575 | - formatchanging: options that will likely break or cause correctness issues |
|
1575 | - formatchanging: options that will likely break or cause correctness issues | |
1576 | with most diff parsers |
|
1576 | with most diff parsers | |
1577 | ''' |
|
1577 | ''' | |
1578 | def get(key, name=None, getter=ui.configbool, forceplain=None): |
|
1578 | def get(key, name=None, getter=ui.configbool, forceplain=None): | |
1579 | if opts: |
|
1579 | if opts: | |
1580 | v = opts.get(key) |
|
1580 | v = opts.get(key) | |
1581 | if v: |
|
1581 | if v: | |
1582 | return v |
|
1582 | return v | |
1583 | if forceplain is not None and ui.plain(): |
|
1583 | if forceplain is not None and ui.plain(): | |
1584 | return forceplain |
|
1584 | return forceplain | |
1585 | return getter(section, name or key, None, untrusted=untrusted) |
|
1585 | return getter(section, name or key, None, untrusted=untrusted) | |
1586 |
|
1586 | |||
1587 | # core options, expected to be understood by every diff parser |
|
1587 | # core options, expected to be understood by every diff parser | |
1588 | buildopts = { |
|
1588 | buildopts = { | |
1589 | 'nodates': get('nodates'), |
|
1589 | 'nodates': get('nodates'), | |
1590 | 'showfunc': get('show_function', 'showfunc'), |
|
1590 | 'showfunc': get('show_function', 'showfunc'), | |
1591 | 'context': get('unified', getter=ui.config), |
|
1591 | 'context': get('unified', getter=ui.config), | |
1592 | } |
|
1592 | } | |
1593 |
|
1593 | |||
1594 | if git: |
|
1594 | if git: | |
1595 | buildopts['git'] = get('git') |
|
1595 | buildopts['git'] = get('git') | |
1596 | if whitespace: |
|
1596 | if whitespace: | |
1597 | buildopts['ignorews'] = get('ignore_all_space', 'ignorews') |
|
1597 | buildopts['ignorews'] = get('ignore_all_space', 'ignorews') | |
1598 | buildopts['ignorewsamount'] = get('ignore_space_change', |
|
1598 | buildopts['ignorewsamount'] = get('ignore_space_change', | |
1599 | 'ignorewsamount') |
|
1599 | 'ignorewsamount') | |
1600 | buildopts['ignoreblanklines'] = get('ignore_blank_lines', |
|
1600 | buildopts['ignoreblanklines'] = get('ignore_blank_lines', | |
1601 | 'ignoreblanklines') |
|
1601 | 'ignoreblanklines') | |
1602 | if formatchanging: |
|
1602 | if formatchanging: | |
1603 | buildopts['text'] = opts and opts.get('text') |
|
1603 | buildopts['text'] = opts and opts.get('text') | |
1604 | buildopts['nobinary'] = get('nobinary') |
|
1604 | buildopts['nobinary'] = get('nobinary') | |
1605 | buildopts['noprefix'] = get('noprefix', forceplain=False) |
|
1605 | buildopts['noprefix'] = get('noprefix', forceplain=False) | |
1606 |
|
1606 | |||
1607 | return mdiff.diffopts(**buildopts) |
|
1607 | return mdiff.diffopts(**buildopts) | |
1608 |
|
1608 | |||
1609 | def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, |
|
1609 | def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, | |
1610 | losedatafn=None, prefix=''): |
|
1610 | losedatafn=None, prefix=''): | |
1611 | '''yields diff of changes to files between two nodes, or node and |
|
1611 | '''yields diff of changes to files between two nodes, or node and | |
1612 | working directory. |
|
1612 | working directory. | |
1613 |
|
1613 | |||
1614 | if node1 is None, use first dirstate parent instead. |
|
1614 | if node1 is None, use first dirstate parent instead. | |
1615 | if node2 is None, compare node1 with working directory. |
|
1615 | if node2 is None, compare node1 with working directory. | |
1616 |
|
1616 | |||
1617 | losedatafn(**kwarg) is a callable run when opts.upgrade=True and |
|
1617 | losedatafn(**kwarg) is a callable run when opts.upgrade=True and | |
1618 | every time some change cannot be represented with the current |
|
1618 | every time some change cannot be represented with the current | |
1619 | patch format. Return False to upgrade to git patch format, True to |
|
1619 | patch format. Return False to upgrade to git patch format, True to | |
1620 | accept the loss or raise an exception to abort the diff. It is |
|
1620 | accept the loss or raise an exception to abort the diff. It is | |
1621 | called with the name of current file being diffed as 'fn'. If set |
|
1621 | called with the name of current file being diffed as 'fn'. If set | |
1622 | to None, patches will always be upgraded to git format when |
|
1622 | to None, patches will always be upgraded to git format when | |
1623 | necessary. |
|
1623 | necessary. | |
1624 |
|
1624 | |||
1625 | prefix is a filename prefix that is prepended to all filenames on |
|
1625 | prefix is a filename prefix that is prepended to all filenames on | |
1626 | display (used for subrepos). |
|
1626 | display (used for subrepos). | |
1627 | ''' |
|
1627 | ''' | |
1628 |
|
1628 | |||
1629 | if opts is None: |
|
1629 | if opts is None: | |
1630 | opts = mdiff.defaultopts |
|
1630 | opts = mdiff.defaultopts | |
1631 |
|
1631 | |||
1632 | if not node1 and not node2: |
|
1632 | if not node1 and not node2: | |
1633 | node1 = repo.dirstate.p1() |
|
1633 | node1 = repo.dirstate.p1() | |
1634 |
|
1634 | |||
1635 | def lrugetfilectx(): |
|
1635 | def lrugetfilectx(): | |
1636 | cache = {} |
|
1636 | cache = {} | |
1637 | order = util.deque() |
|
1637 | order = util.deque() | |
1638 | def getfilectx(f, ctx): |
|
1638 | def getfilectx(f, ctx): | |
1639 | fctx = ctx.filectx(f, filelog=cache.get(f)) |
|
1639 | fctx = ctx.filectx(f, filelog=cache.get(f)) | |
1640 | if f not in cache: |
|
1640 | if f not in cache: | |
1641 | if len(cache) > 20: |
|
1641 | if len(cache) > 20: | |
1642 | del cache[order.popleft()] |
|
1642 | del cache[order.popleft()] | |
1643 | cache[f] = fctx.filelog() |
|
1643 | cache[f] = fctx.filelog() | |
1644 | else: |
|
1644 | else: | |
1645 | order.remove(f) |
|
1645 | order.remove(f) | |
1646 | order.append(f) |
|
1646 | order.append(f) | |
1647 | return fctx |
|
1647 | return fctx | |
1648 | return getfilectx |
|
1648 | return getfilectx | |
1649 | getfilectx = lrugetfilectx() |
|
1649 | getfilectx = lrugetfilectx() | |
1650 |
|
1650 | |||
1651 | ctx1 = repo[node1] |
|
1651 | ctx1 = repo[node1] | |
1652 | ctx2 = repo[node2] |
|
1652 | ctx2 = repo[node2] | |
1653 |
|
1653 | |||
1654 | if not changes: |
|
1654 | if not changes: | |
1655 | changes = repo.status(ctx1, ctx2, match=match) |
|
1655 | changes = repo.status(ctx1, ctx2, match=match) | |
1656 | modified, added, removed = changes[:3] |
|
1656 | modified, added, removed = changes[:3] | |
1657 |
|
1657 | |||
1658 | if not modified and not added and not removed: |
|
1658 | if not modified and not added and not removed: | |
1659 | return [] |
|
1659 | return [] | |
1660 |
|
1660 | |||
1661 | revs = None |
|
1661 | revs = None | |
1662 | hexfunc = repo.ui.debugflag and hex or short |
|
1662 | hexfunc = repo.ui.debugflag and hex or short | |
1663 | revs = [hexfunc(node) for node in [ctx1.node(), ctx2.node()] if node] |
|
1663 | revs = [hexfunc(node) for node in [ctx1.node(), ctx2.node()] if node] | |
1664 |
|
1664 | |||
1665 | copy = {} |
|
1665 | copy = {} | |
1666 | if opts.git or opts.upgrade: |
|
1666 | if opts.git or opts.upgrade: | |
1667 | copy = copies.pathcopies(ctx1, ctx2) |
|
1667 | copy = copies.pathcopies(ctx1, ctx2) | |
1668 |
|
1668 | |||
1669 | def difffn(opts, losedata): |
|
1669 | def difffn(opts, losedata): | |
1670 | return trydiff(repo, revs, ctx1, ctx2, modified, added, removed, |
|
1670 | return trydiff(repo, revs, ctx1, ctx2, modified, added, removed, | |
1671 | copy, getfilectx, opts, losedata, prefix) |
|
1671 | copy, getfilectx, opts, losedata, prefix) | |
1672 | if opts.upgrade and not opts.git: |
|
1672 | if opts.upgrade and not opts.git: | |
1673 | try: |
|
1673 | try: | |
1674 | def losedata(fn): |
|
1674 | def losedata(fn): | |
1675 | if not losedatafn or not losedatafn(fn=fn): |
|
1675 | if not losedatafn or not losedatafn(fn=fn): | |
1676 | raise GitDiffRequired |
|
1676 | raise GitDiffRequired | |
1677 | # Buffer the whole output until we are sure it can be generated |
|
1677 | # Buffer the whole output until we are sure it can be generated | |
1678 | return list(difffn(opts.copy(git=False), losedata)) |
|
1678 | return list(difffn(opts.copy(git=False), losedata)) | |
1679 | except GitDiffRequired: |
|
1679 | except GitDiffRequired: | |
1680 | return difffn(opts.copy(git=True), None) |
|
1680 | return difffn(opts.copy(git=True), None) | |
1681 | else: |
|
1681 | else: | |
1682 | return difffn(opts, None) |
|
1682 | return difffn(opts, None) | |
1683 |
|
1683 | |||
1684 | def difflabel(func, *args, **kw): |
|
1684 | def difflabel(func, *args, **kw): | |
1685 | '''yields 2-tuples of (output, label) based on the output of func()''' |
|
1685 | '''yields 2-tuples of (output, label) based on the output of func()''' | |
1686 | headprefixes = [('diff', 'diff.diffline'), |
|
1686 | headprefixes = [('diff', 'diff.diffline'), | |
1687 | ('copy', 'diff.extended'), |
|
1687 | ('copy', 'diff.extended'), | |
1688 | ('rename', 'diff.extended'), |
|
1688 | ('rename', 'diff.extended'), | |
1689 | ('old', 'diff.extended'), |
|
1689 | ('old', 'diff.extended'), | |
1690 | ('new', 'diff.extended'), |
|
1690 | ('new', 'diff.extended'), | |
1691 | ('deleted', 'diff.extended'), |
|
1691 | ('deleted', 'diff.extended'), | |
1692 | ('---', 'diff.file_a'), |
|
1692 | ('---', 'diff.file_a'), | |
1693 | ('+++', 'diff.file_b')] |
|
1693 | ('+++', 'diff.file_b')] | |
1694 | textprefixes = [('@', 'diff.hunk'), |
|
1694 | textprefixes = [('@', 'diff.hunk'), | |
1695 | ('-', 'diff.deleted'), |
|
1695 | ('-', 'diff.deleted'), | |
1696 | ('+', 'diff.inserted')] |
|
1696 | ('+', 'diff.inserted')] | |
1697 | head = False |
|
1697 | head = False | |
1698 | for chunk in func(*args, **kw): |
|
1698 | for chunk in func(*args, **kw): | |
1699 | lines = chunk.split('\n') |
|
1699 | lines = chunk.split('\n') | |
1700 | for i, line in enumerate(lines): |
|
1700 | for i, line in enumerate(lines): | |
1701 | if i != 0: |
|
1701 | if i != 0: | |
1702 | yield ('\n', '') |
|
1702 | yield ('\n', '') | |
1703 | if head: |
|
1703 | if head: | |
1704 | if line.startswith('@'): |
|
1704 | if line.startswith('@'): | |
1705 | head = False |
|
1705 | head = False | |
1706 | else: |
|
1706 | else: | |
1707 | if line and line[0] not in ' +-@\\': |
|
1707 | if line and line[0] not in ' +-@\\': | |
1708 | head = True |
|
1708 | head = True | |
1709 | stripline = line |
|
1709 | stripline = line | |
1710 | diffline = False |
|
1710 | diffline = False | |
1711 | if not head and line and line[0] in '+-': |
|
1711 | if not head and line and line[0] in '+-': | |
1712 | # highlight tabs and trailing whitespace, but only in |
|
1712 | # highlight tabs and trailing whitespace, but only in | |
1713 | # changed lines |
|
1713 | # changed lines | |
1714 | stripline = line.rstrip() |
|
1714 | stripline = line.rstrip() | |
1715 | diffline = True |
|
1715 | diffline = True | |
1716 |
|
1716 | |||
1717 | prefixes = textprefixes |
|
1717 | prefixes = textprefixes | |
1718 | if head: |
|
1718 | if head: | |
1719 | prefixes = headprefixes |
|
1719 | prefixes = headprefixes | |
1720 | for prefix, label in prefixes: |
|
1720 | for prefix, label in prefixes: | |
1721 | if stripline.startswith(prefix): |
|
1721 | if stripline.startswith(prefix): | |
1722 | if diffline: |
|
1722 | if diffline: | |
1723 | for token in tabsplitter.findall(stripline): |
|
1723 | for token in tabsplitter.findall(stripline): | |
1724 | if '\t' == token[0]: |
|
1724 | if '\t' == token[0]: | |
1725 | yield (token, 'diff.tab') |
|
1725 | yield (token, 'diff.tab') | |
1726 | else: |
|
1726 | else: | |
1727 | yield (token, label) |
|
1727 | yield (token, label) | |
1728 | else: |
|
1728 | else: | |
1729 | yield (stripline, label) |
|
1729 | yield (stripline, label) | |
1730 | break |
|
1730 | break | |
1731 | else: |
|
1731 | else: | |
1732 | yield (line, '') |
|
1732 | yield (line, '') | |
1733 | if line != stripline: |
|
1733 | if line != stripline: | |
1734 | yield (line[len(stripline):], 'diff.trailingwhitespace') |
|
1734 | yield (line[len(stripline):], 'diff.trailingwhitespace') | |
1735 |
|
1735 | |||
1736 | def diffui(*args, **kw): |
|
1736 | def diffui(*args, **kw): | |
1737 | '''like diff(), but yields 2-tuples of (output, label) for ui.write()''' |
|
1737 | '''like diff(), but yields 2-tuples of (output, label) for ui.write()''' | |
1738 | return difflabel(diff, *args, **kw) |
|
1738 | return difflabel(diff, *args, **kw) | |
1739 |
|
1739 | |||
1740 | def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, |
|
1740 | def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, | |
1741 | copy, getfilectx, opts, losedatafn, prefix): |
|
1741 | copy, getfilectx, opts, losedatafn, prefix): | |
1742 |
|
1742 | |||
1743 | def join(f): |
|
1743 | def join(f): | |
1744 | return posixpath.join(prefix, f) |
|
1744 | return posixpath.join(prefix, f) | |
1745 |
|
1745 | |||
1746 | def addmodehdr(header, omode, nmode): |
|
1746 | def addmodehdr(header, omode, nmode): | |
1747 | if omode != nmode: |
|
1747 | if omode != nmode: | |
1748 | header.append('old mode %s\n' % omode) |
|
1748 | header.append('old mode %s\n' % omode) | |
1749 | header.append('new mode %s\n' % nmode) |
|
1749 | header.append('new mode %s\n' % nmode) | |
1750 |
|
1750 | |||
1751 | def addindexmeta(meta, revs): |
|
1751 | def addindexmeta(meta, revs): | |
1752 | if opts.git: |
|
1752 | if opts.git: | |
1753 | i = len(revs) |
|
1753 | i = len(revs) | |
1754 | if i==2: |
|
1754 | if i==2: | |
1755 | meta.append('index %s..%s\n' % tuple(revs)) |
|
1755 | meta.append('index %s..%s\n' % tuple(revs)) | |
1756 | elif i==3: |
|
1756 | elif i==3: | |
1757 | meta.append('index %s,%s..%s\n' % tuple(revs)) |
|
1757 | meta.append('index %s,%s..%s\n' % tuple(revs)) | |
1758 |
|
1758 | |||
1759 | def gitindex(text): |
|
1759 | def gitindex(text): | |
1760 | if not text: |
|
1760 | if not text: | |
1761 | text = "" |
|
1761 | text = "" | |
1762 | l = len(text) |
|
1762 | l = len(text) | |
1763 | s = util.sha1('blob %d\0' % l) |
|
1763 | s = util.sha1('blob %d\0' % l) | |
1764 | s.update(text) |
|
1764 | s.update(text) | |
1765 | return s.hexdigest() |
|
1765 | return s.hexdigest() | |
1766 |
|
1766 | |||
1767 | if opts.noprefix: |
|
1767 | if opts.noprefix: | |
1768 | aprefix = bprefix = '' |
|
1768 | aprefix = bprefix = '' | |
1769 | else: |
|
1769 | else: | |
1770 | aprefix = 'a/' |
|
1770 | aprefix = 'a/' | |
1771 | bprefix = 'b/' |
|
1771 | bprefix = 'b/' | |
1772 |
|
1772 | |||
1773 | def diffline(a, b, revs): |
|
1773 | def diffline(a, b, revs): | |
1774 | if opts.git: |
|
1774 | if opts.git: | |
1775 | line = 'diff --git %s%s %s%s\n' % (aprefix, a, bprefix, b) |
|
1775 | line = 'diff --git %s%s %s%s\n' % (aprefix, a, bprefix, b) | |
1776 | elif not repo.ui.quiet: |
|
1776 | elif not repo.ui.quiet: | |
1777 | if revs: |
|
1777 | if revs: | |
1778 | revinfo = ' '.join(["-r %s" % rev for rev in revs]) |
|
1778 | revinfo = ' '.join(["-r %s" % rev for rev in revs]) | |
1779 | line = 'diff %s %s\n' % (revinfo, a) |
|
1779 | line = 'diff %s %s\n' % (revinfo, a) | |
1780 | else: |
|
1780 | else: | |
1781 | line = 'diff %s\n' % a |
|
1781 | line = 'diff %s\n' % a | |
1782 | else: |
|
1782 | else: | |
1783 | line = '' |
|
1783 | line = '' | |
1784 | return line |
|
1784 | return line | |
1785 |
|
1785 | |||
1786 | date1 = util.datestr(ctx1.date()) |
|
1786 | date1 = util.datestr(ctx1.date()) | |
1787 | date2 = util.datestr(ctx2.date()) |
|
1787 | date2 = util.datestr(ctx2.date()) | |
1788 | man1 = ctx1.manifest() |
|
1788 | man1 = ctx1.manifest() | |
1789 |
|
1789 | |||
1790 | gone = set() |
|
1790 | gone = set() | |
1791 | gitmode = {'l': '120000', 'x': '100755', '': '100644'} |
|
1791 | gitmode = {'l': '120000', 'x': '100755', '': '100644'} | |
1792 |
|
1792 | |||
1793 | copyto = dict([(v, k) for k, v in copy.items()]) |
|
1793 | copyto = dict([(v, k) for k, v in copy.items()]) | |
1794 |
|
1794 | |||
1795 | if opts.git: |
|
1795 | if opts.git: | |
1796 | revs = None |
|
1796 | revs = None | |
1797 |
|
1797 | |||
1798 | modifiedset, addedset, removedset = set(modified), set(added), set(removed) |
|
1798 | modifiedset, addedset, removedset = set(modified), set(added), set(removed) | |
|
1799 | # Fix up modified and added, since merged-in additions appear as | |||
|
1800 | # modifications during merges | |||
|
1801 | for f in modifiedset.copy(): | |||
|
1802 | if f not in ctx1: | |||
|
1803 | addedset.add(f) | |||
|
1804 | modifiedset.remove(f) | |||
1799 | for f in sorted(modified + added + removed): |
|
1805 | for f in sorted(modified + added + removed): | |
1800 | to = None |
|
1806 | to = None | |
1801 | tn = None |
|
1807 | tn = None | |
1802 | dodiff = True |
|
1808 | dodiff = True | |
1803 | header = [] |
|
1809 | header = [] | |
1804 | if f in man1: |
|
1810 | if f in man1: | |
1805 | to = getfilectx(f, ctx1).data() |
|
1811 | to = getfilectx(f, ctx1).data() | |
1806 | if f not in removedset: |
|
1812 | if f not in removedset: | |
1807 | tn = getfilectx(f, ctx2).data() |
|
1813 | tn = getfilectx(f, ctx2).data() | |
1808 | a, b = f, f |
|
1814 | a, b = f, f | |
1809 | if opts.git or losedatafn: |
|
1815 | if opts.git or losedatafn: | |
1810 |
if f in addedset |
|
1816 | if f in addedset: | |
1811 | mode = gitmode[ctx2.flags(f)] |
|
1817 | mode = gitmode[ctx2.flags(f)] | |
1812 | if f in copy or f in copyto: |
|
1818 | if f in copy or f in copyto: | |
1813 | if opts.git: |
|
1819 | if opts.git: | |
1814 | if f in copy: |
|
1820 | if f in copy: | |
1815 | a = copy[f] |
|
1821 | a = copy[f] | |
1816 | else: |
|
1822 | else: | |
1817 | a = copyto[f] |
|
1823 | a = copyto[f] | |
1818 | omode = gitmode[man1.flags(a)] |
|
1824 | omode = gitmode[man1.flags(a)] | |
1819 | addmodehdr(header, omode, mode) |
|
1825 | addmodehdr(header, omode, mode) | |
1820 | if a in removedset and a not in gone: |
|
1826 | if a in removedset and a not in gone: | |
1821 | op = 'rename' |
|
1827 | op = 'rename' | |
1822 | gone.add(a) |
|
1828 | gone.add(a) | |
1823 | else: |
|
1829 | else: | |
1824 | op = 'copy' |
|
1830 | op = 'copy' | |
1825 | header.append('%s from %s\n' % (op, join(a))) |
|
1831 | header.append('%s from %s\n' % (op, join(a))) | |
1826 | header.append('%s to %s\n' % (op, join(f))) |
|
1832 | header.append('%s to %s\n' % (op, join(f))) | |
1827 | to = getfilectx(a, ctx1).data() |
|
1833 | to = getfilectx(a, ctx1).data() | |
1828 | else: |
|
1834 | else: | |
1829 | losedatafn(f) |
|
1835 | losedatafn(f) | |
1830 | else: |
|
1836 | else: | |
1831 | if opts.git: |
|
1837 | if opts.git: | |
1832 | header.append('new file mode %s\n' % mode) |
|
1838 | header.append('new file mode %s\n' % mode) | |
1833 | elif ctx2.flags(f): |
|
1839 | elif ctx2.flags(f): | |
1834 | losedatafn(f) |
|
1840 | losedatafn(f) | |
1835 | # In theory, if tn was copied or renamed we should check |
|
1841 | # In theory, if tn was copied or renamed we should check | |
1836 | # if the source is binary too but the copy record already |
|
1842 | # if the source is binary too but the copy record already | |
1837 | # forces git mode. |
|
1843 | # forces git mode. | |
1838 | if util.binary(tn): |
|
1844 | if util.binary(tn): | |
1839 | if opts.git: |
|
1845 | if opts.git: | |
1840 | dodiff = 'binary' |
|
1846 | dodiff = 'binary' | |
1841 | else: |
|
1847 | else: | |
1842 | losedatafn(f) |
|
1848 | losedatafn(f) | |
1843 | if not opts.git and not tn: |
|
1849 | if not opts.git and not tn: | |
1844 | # regular diffs cannot represent new empty file |
|
1850 | # regular diffs cannot represent new empty file | |
1845 | losedatafn(f) |
|
1851 | losedatafn(f) | |
1846 |
elif f in removedset |
|
1852 | elif f in removedset: | |
1847 | if opts.git: |
|
1853 | if opts.git: | |
1848 | # have we already reported a copy above? |
|
1854 | # have we already reported a copy above? | |
1849 | if ((f in copy and copy[f] in addedset |
|
1855 | if ((f in copy and copy[f] in addedset | |
1850 | and copyto[copy[f]] == f) or |
|
1856 | and copyto[copy[f]] == f) or | |
1851 | (f in copyto and copyto[f] in addedset |
|
1857 | (f in copyto and copyto[f] in addedset | |
1852 | and copy[copyto[f]] == f)): |
|
1858 | and copy[copyto[f]] == f)): | |
1853 | dodiff = False |
|
1859 | dodiff = False | |
1854 | else: |
|
1860 | else: | |
1855 | header.append('deleted file mode %s\n' % |
|
1861 | header.append('deleted file mode %s\n' % | |
1856 | gitmode[man1.flags(f)]) |
|
1862 | gitmode[man1.flags(f)]) | |
1857 | if util.binary(to): |
|
1863 | if util.binary(to): | |
1858 | dodiff = 'binary' |
|
1864 | dodiff = 'binary' | |
1859 | elif not to or util.binary(to): |
|
1865 | elif not to or util.binary(to): | |
1860 | # regular diffs cannot represent empty file deletion |
|
1866 | # regular diffs cannot represent empty file deletion | |
1861 | losedatafn(f) |
|
1867 | losedatafn(f) | |
1862 | else: |
|
1868 | else: | |
1863 | oflag = man1.flags(f) |
|
1869 | oflag = man1.flags(f) | |
1864 | nflag = ctx2.flags(f) |
|
1870 | nflag = ctx2.flags(f) | |
1865 | binary = util.binary(to) or util.binary(tn) |
|
1871 | binary = util.binary(to) or util.binary(tn) | |
1866 | if opts.git: |
|
1872 | if opts.git: | |
1867 | addmodehdr(header, gitmode[oflag], gitmode[nflag]) |
|
1873 | addmodehdr(header, gitmode[oflag], gitmode[nflag]) | |
1868 | if binary: |
|
1874 | if binary: | |
1869 | dodiff = 'binary' |
|
1875 | dodiff = 'binary' | |
1870 | elif binary or nflag != oflag: |
|
1876 | elif binary or nflag != oflag: | |
1871 | losedatafn(f) |
|
1877 | losedatafn(f) | |
1872 |
|
1878 | |||
1873 | if dodiff: |
|
1879 | if dodiff: | |
1874 | if opts.git or revs: |
|
1880 | if opts.git or revs: | |
1875 | header.insert(0, diffline(join(a), join(b), revs)) |
|
1881 | header.insert(0, diffline(join(a), join(b), revs)) | |
1876 | if dodiff == 'binary' and not opts.nobinary: |
|
1882 | if dodiff == 'binary' and not opts.nobinary: | |
1877 | text = mdiff.b85diff(to, tn) |
|
1883 | text = mdiff.b85diff(to, tn) | |
1878 | if text: |
|
1884 | if text: | |
1879 | addindexmeta(header, [gitindex(to), gitindex(tn)]) |
|
1885 | addindexmeta(header, [gitindex(to), gitindex(tn)]) | |
1880 | else: |
|
1886 | else: | |
1881 | text = mdiff.unidiff(to, date1, |
|
1887 | text = mdiff.unidiff(to, date1, | |
1882 | tn, date2, |
|
1888 | tn, date2, | |
1883 | join(a), join(b), opts=opts) |
|
1889 | join(a), join(b), opts=opts) | |
1884 | if header and (text or len(header) > 1): |
|
1890 | if header and (text or len(header) > 1): | |
1885 | yield ''.join(header) |
|
1891 | yield ''.join(header) | |
1886 | if text: |
|
1892 | if text: | |
1887 | yield text |
|
1893 | yield text | |
1888 |
|
1894 | |||
1889 | def diffstatsum(stats): |
|
1895 | def diffstatsum(stats): | |
1890 | maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False |
|
1896 | maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False | |
1891 | for f, a, r, b in stats: |
|
1897 | for f, a, r, b in stats: | |
1892 | maxfile = max(maxfile, encoding.colwidth(f)) |
|
1898 | maxfile = max(maxfile, encoding.colwidth(f)) | |
1893 | maxtotal = max(maxtotal, a + r) |
|
1899 | maxtotal = max(maxtotal, a + r) | |
1894 | addtotal += a |
|
1900 | addtotal += a | |
1895 | removetotal += r |
|
1901 | removetotal += r | |
1896 | binary = binary or b |
|
1902 | binary = binary or b | |
1897 |
|
1903 | |||
1898 | return maxfile, maxtotal, addtotal, removetotal, binary |
|
1904 | return maxfile, maxtotal, addtotal, removetotal, binary | |
1899 |
|
1905 | |||
1900 | def diffstatdata(lines): |
|
1906 | def diffstatdata(lines): | |
1901 | diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$') |
|
1907 | diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$') | |
1902 |
|
1908 | |||
1903 | results = [] |
|
1909 | results = [] | |
1904 | filename, adds, removes, isbinary = None, 0, 0, False |
|
1910 | filename, adds, removes, isbinary = None, 0, 0, False | |
1905 |
|
1911 | |||
1906 | def addresult(): |
|
1912 | def addresult(): | |
1907 | if filename: |
|
1913 | if filename: | |
1908 | results.append((filename, adds, removes, isbinary)) |
|
1914 | results.append((filename, adds, removes, isbinary)) | |
1909 |
|
1915 | |||
1910 | for line in lines: |
|
1916 | for line in lines: | |
1911 | if line.startswith('diff'): |
|
1917 | if line.startswith('diff'): | |
1912 | addresult() |
|
1918 | addresult() | |
1913 | # set numbers to 0 anyway when starting new file |
|
1919 | # set numbers to 0 anyway when starting new file | |
1914 | adds, removes, isbinary = 0, 0, False |
|
1920 | adds, removes, isbinary = 0, 0, False | |
1915 | if line.startswith('diff --git a/'): |
|
1921 | if line.startswith('diff --git a/'): | |
1916 | filename = gitre.search(line).group(2) |
|
1922 | filename = gitre.search(line).group(2) | |
1917 | elif line.startswith('diff -r'): |
|
1923 | elif line.startswith('diff -r'): | |
1918 | # format: "diff -r ... -r ... filename" |
|
1924 | # format: "diff -r ... -r ... filename" | |
1919 | filename = diffre.search(line).group(1) |
|
1925 | filename = diffre.search(line).group(1) | |
1920 | elif line.startswith('+') and not line.startswith('+++ '): |
|
1926 | elif line.startswith('+') and not line.startswith('+++ '): | |
1921 | adds += 1 |
|
1927 | adds += 1 | |
1922 | elif line.startswith('-') and not line.startswith('--- '): |
|
1928 | elif line.startswith('-') and not line.startswith('--- '): | |
1923 | removes += 1 |
|
1929 | removes += 1 | |
1924 | elif (line.startswith('GIT binary patch') or |
|
1930 | elif (line.startswith('GIT binary patch') or | |
1925 | line.startswith('Binary file')): |
|
1931 | line.startswith('Binary file')): | |
1926 | isbinary = True |
|
1932 | isbinary = True | |
1927 | addresult() |
|
1933 | addresult() | |
1928 | return results |
|
1934 | return results | |
1929 |
|
1935 | |||
1930 | def diffstat(lines, width=80, git=False): |
|
1936 | def diffstat(lines, width=80, git=False): | |
1931 | output = [] |
|
1937 | output = [] | |
1932 | stats = diffstatdata(lines) |
|
1938 | stats = diffstatdata(lines) | |
1933 | maxname, maxtotal, totaladds, totalremoves, hasbinary = diffstatsum(stats) |
|
1939 | maxname, maxtotal, totaladds, totalremoves, hasbinary = diffstatsum(stats) | |
1934 |
|
1940 | |||
1935 | countwidth = len(str(maxtotal)) |
|
1941 | countwidth = len(str(maxtotal)) | |
1936 | if hasbinary and countwidth < 3: |
|
1942 | if hasbinary and countwidth < 3: | |
1937 | countwidth = 3 |
|
1943 | countwidth = 3 | |
1938 | graphwidth = width - countwidth - maxname - 6 |
|
1944 | graphwidth = width - countwidth - maxname - 6 | |
1939 | if graphwidth < 10: |
|
1945 | if graphwidth < 10: | |
1940 | graphwidth = 10 |
|
1946 | graphwidth = 10 | |
1941 |
|
1947 | |||
1942 | def scale(i): |
|
1948 | def scale(i): | |
1943 | if maxtotal <= graphwidth: |
|
1949 | if maxtotal <= graphwidth: | |
1944 | return i |
|
1950 | return i | |
1945 | # If diffstat runs out of room it doesn't print anything, |
|
1951 | # If diffstat runs out of room it doesn't print anything, | |
1946 | # which isn't very useful, so always print at least one + or - |
|
1952 | # which isn't very useful, so always print at least one + or - | |
1947 | # if there were at least some changes. |
|
1953 | # if there were at least some changes. | |
1948 | return max(i * graphwidth // maxtotal, int(bool(i))) |
|
1954 | return max(i * graphwidth // maxtotal, int(bool(i))) | |
1949 |
|
1955 | |||
1950 | for filename, adds, removes, isbinary in stats: |
|
1956 | for filename, adds, removes, isbinary in stats: | |
1951 | if isbinary: |
|
1957 | if isbinary: | |
1952 | count = 'Bin' |
|
1958 | count = 'Bin' | |
1953 | else: |
|
1959 | else: | |
1954 | count = adds + removes |
|
1960 | count = adds + removes | |
1955 | pluses = '+' * scale(adds) |
|
1961 | pluses = '+' * scale(adds) | |
1956 | minuses = '-' * scale(removes) |
|
1962 | minuses = '-' * scale(removes) | |
1957 | output.append(' %s%s | %*s %s%s\n' % |
|
1963 | output.append(' %s%s | %*s %s%s\n' % | |
1958 | (filename, ' ' * (maxname - encoding.colwidth(filename)), |
|
1964 | (filename, ' ' * (maxname - encoding.colwidth(filename)), | |
1959 | countwidth, count, pluses, minuses)) |
|
1965 | countwidth, count, pluses, minuses)) | |
1960 |
|
1966 | |||
1961 | if stats: |
|
1967 | if stats: | |
1962 | output.append(_(' %d files changed, %d insertions(+), ' |
|
1968 | output.append(_(' %d files changed, %d insertions(+), ' | |
1963 | '%d deletions(-)\n') |
|
1969 | '%d deletions(-)\n') | |
1964 | % (len(stats), totaladds, totalremoves)) |
|
1970 | % (len(stats), totaladds, totalremoves)) | |
1965 |
|
1971 | |||
1966 | return ''.join(output) |
|
1972 | return ''.join(output) | |
1967 |
|
1973 | |||
1968 | def diffstatui(*args, **kw): |
|
1974 | def diffstatui(*args, **kw): | |
1969 | '''like diffstat(), but yields 2-tuples of (output, label) for |
|
1975 | '''like diffstat(), but yields 2-tuples of (output, label) for | |
1970 | ui.write() |
|
1976 | ui.write() | |
1971 | ''' |
|
1977 | ''' | |
1972 |
|
1978 | |||
1973 | for line in diffstat(*args, **kw).splitlines(): |
|
1979 | for line in diffstat(*args, **kw).splitlines(): | |
1974 | if line and line[-1] in '+-': |
|
1980 | if line and line[-1] in '+-': | |
1975 | name, graph = line.rsplit(' ', 1) |
|
1981 | name, graph = line.rsplit(' ', 1) | |
1976 | yield (name + ' ', '') |
|
1982 | yield (name + ' ', '') | |
1977 | m = re.search(r'\++', graph) |
|
1983 | m = re.search(r'\++', graph) | |
1978 | if m: |
|
1984 | if m: | |
1979 | yield (m.group(0), 'diffstat.inserted') |
|
1985 | yield (m.group(0), 'diffstat.inserted') | |
1980 | m = re.search(r'-+', graph) |
|
1986 | m = re.search(r'-+', graph) | |
1981 | if m: |
|
1987 | if m: | |
1982 | yield (m.group(0), 'diffstat.deleted') |
|
1988 | yield (m.group(0), 'diffstat.deleted') | |
1983 | else: |
|
1989 | else: | |
1984 | yield (line, '') |
|
1990 | yield (line, '') | |
1985 | yield ('\n', '') |
|
1991 | yield ('\n', '') |
@@ -1,749 +1,743 b'' | |||||
1 | $ cat <<EOF >> $HGRCPATH |
|
1 | $ cat <<EOF >> $HGRCPATH | |
2 | > [extensions] |
|
2 | > [extensions] | |
3 | > mq = |
|
3 | > mq = | |
4 | > shelve = |
|
4 | > shelve = | |
5 | > [defaults] |
|
5 | > [defaults] | |
6 | > diff = --nodates --git |
|
6 | > diff = --nodates --git | |
7 | > qnew = --date '0 0' |
|
7 | > qnew = --date '0 0' | |
8 | > EOF |
|
8 | > EOF | |
9 |
|
9 | |||
10 | $ hg init repo |
|
10 | $ hg init repo | |
11 | $ cd repo |
|
11 | $ cd repo | |
12 | $ mkdir a b |
|
12 | $ mkdir a b | |
13 | $ echo a > a/a |
|
13 | $ echo a > a/a | |
14 | $ echo b > b/b |
|
14 | $ echo b > b/b | |
15 | $ echo c > c |
|
15 | $ echo c > c | |
16 | $ echo d > d |
|
16 | $ echo d > d | |
17 | $ echo x > x |
|
17 | $ echo x > x | |
18 | $ hg addremove -q |
|
18 | $ hg addremove -q | |
19 |
|
19 | |||
20 | shelving in an empty repo should be possible |
|
20 | shelving in an empty repo should be possible | |
21 | (this tests also that editor is not invoked, if '--edit' is not |
|
21 | (this tests also that editor is not invoked, if '--edit' is not | |
22 | specified) |
|
22 | specified) | |
23 |
|
23 | |||
24 | $ HGEDITOR=cat hg shelve |
|
24 | $ HGEDITOR=cat hg shelve | |
25 | shelved as default |
|
25 | shelved as default | |
26 | 0 files updated, 0 files merged, 5 files removed, 0 files unresolved |
|
26 | 0 files updated, 0 files merged, 5 files removed, 0 files unresolved | |
27 |
|
27 | |||
28 | $ hg unshelve |
|
28 | $ hg unshelve | |
29 | unshelving change 'default' |
|
29 | unshelving change 'default' | |
30 |
|
30 | |||
31 | $ hg commit -q -m 'initial commit' |
|
31 | $ hg commit -q -m 'initial commit' | |
32 |
|
32 | |||
33 | $ hg shelve |
|
33 | $ hg shelve | |
34 | nothing changed |
|
34 | nothing changed | |
35 | [1] |
|
35 | [1] | |
36 |
|
36 | |||
37 | create an mq patch - shelving should work fine with a patch applied |
|
37 | create an mq patch - shelving should work fine with a patch applied | |
38 |
|
38 | |||
39 | $ echo n > n |
|
39 | $ echo n > n | |
40 | $ hg add n |
|
40 | $ hg add n | |
41 | $ hg commit n -m second |
|
41 | $ hg commit n -m second | |
42 | $ hg qnew second.patch |
|
42 | $ hg qnew second.patch | |
43 |
|
43 | |||
44 | shelve a change that we will delete later |
|
44 | shelve a change that we will delete later | |
45 |
|
45 | |||
46 | $ echo a >> a/a |
|
46 | $ echo a >> a/a | |
47 | $ hg shelve |
|
47 | $ hg shelve | |
48 | shelved as default |
|
48 | shelved as default | |
49 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
49 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
50 |
|
50 | |||
51 | set up some more complex changes to shelve |
|
51 | set up some more complex changes to shelve | |
52 |
|
52 | |||
53 | $ echo a >> a/a |
|
53 | $ echo a >> a/a | |
54 | $ hg mv b b.rename |
|
54 | $ hg mv b b.rename | |
55 | moving b/b to b.rename/b (glob) |
|
55 | moving b/b to b.rename/b (glob) | |
56 | $ hg cp c c.copy |
|
56 | $ hg cp c c.copy | |
57 | $ hg status -C |
|
57 | $ hg status -C | |
58 | M a/a |
|
58 | M a/a | |
59 | A b.rename/b |
|
59 | A b.rename/b | |
60 | b/b |
|
60 | b/b | |
61 | A c.copy |
|
61 | A c.copy | |
62 | c |
|
62 | c | |
63 | R b/b |
|
63 | R b/b | |
64 |
|
64 | |||
65 | prevent some foot-shooting |
|
65 | prevent some foot-shooting | |
66 |
|
66 | |||
67 | $ hg shelve -n foo/bar |
|
67 | $ hg shelve -n foo/bar | |
68 | abort: shelved change names may not contain slashes |
|
68 | abort: shelved change names may not contain slashes | |
69 | [255] |
|
69 | [255] | |
70 | $ hg shelve -n .baz |
|
70 | $ hg shelve -n .baz | |
71 | abort: shelved change names may not start with '.' |
|
71 | abort: shelved change names may not start with '.' | |
72 | [255] |
|
72 | [255] | |
73 |
|
73 | |||
74 | the common case - no options or filenames |
|
74 | the common case - no options or filenames | |
75 |
|
75 | |||
76 | $ hg shelve |
|
76 | $ hg shelve | |
77 | shelved as default-01 |
|
77 | shelved as default-01 | |
78 | 2 files updated, 0 files merged, 2 files removed, 0 files unresolved |
|
78 | 2 files updated, 0 files merged, 2 files removed, 0 files unresolved | |
79 | $ hg status -C |
|
79 | $ hg status -C | |
80 |
|
80 | |||
81 | ensure that our shelved changes exist |
|
81 | ensure that our shelved changes exist | |
82 |
|
82 | |||
83 | $ hg shelve -l |
|
83 | $ hg shelve -l | |
84 | default-01 (*) changes to '[mq]: second.patch' (glob) |
|
84 | default-01 (*) changes to '[mq]: second.patch' (glob) | |
85 | default (*) changes to '[mq]: second.patch' (glob) |
|
85 | default (*) changes to '[mq]: second.patch' (glob) | |
86 |
|
86 | |||
87 | $ hg shelve -l -p default |
|
87 | $ hg shelve -l -p default | |
88 | default (*) changes to '[mq]: second.patch' (glob) |
|
88 | default (*) changes to '[mq]: second.patch' (glob) | |
89 |
|
89 | |||
90 | diff --git a/a/a b/a/a |
|
90 | diff --git a/a/a b/a/a | |
91 | --- a/a/a |
|
91 | --- a/a/a | |
92 | +++ b/a/a |
|
92 | +++ b/a/a | |
93 | @@ -1,1 +1,2 @@ |
|
93 | @@ -1,1 +1,2 @@ | |
94 | a |
|
94 | a | |
95 | +a |
|
95 | +a | |
96 |
|
96 | |||
97 | $ hg shelve --list --addremove |
|
97 | $ hg shelve --list --addremove | |
98 | abort: options '--list' and '--addremove' may not be used together |
|
98 | abort: options '--list' and '--addremove' may not be used together | |
99 | [255] |
|
99 | [255] | |
100 |
|
100 | |||
101 | delete our older shelved change |
|
101 | delete our older shelved change | |
102 |
|
102 | |||
103 | $ hg shelve -d default |
|
103 | $ hg shelve -d default | |
104 | $ hg qfinish -a -q |
|
104 | $ hg qfinish -a -q | |
105 |
|
105 | |||
106 | local edits should not prevent a shelved change from applying |
|
106 | local edits should not prevent a shelved change from applying | |
107 |
|
107 | |||
108 | $ printf "z\na\n" > a/a |
|
108 | $ printf "z\na\n" > a/a | |
109 | $ hg unshelve --keep |
|
109 | $ hg unshelve --keep | |
110 | unshelving change 'default-01' |
|
110 | unshelving change 'default-01' | |
111 | temporarily committing pending changes (restore with 'hg unshelve --abort') |
|
111 | temporarily committing pending changes (restore with 'hg unshelve --abort') | |
112 | rebasing shelved changes |
|
112 | rebasing shelved changes | |
113 | rebasing 4:4702e8911fe0 "changes to '[mq]: second.patch'" (tip) |
|
113 | rebasing 4:4702e8911fe0 "changes to '[mq]: second.patch'" (tip) | |
114 | merging a/a |
|
114 | merging a/a | |
115 |
|
115 | |||
116 | $ hg revert --all -q |
|
116 | $ hg revert --all -q | |
117 | $ rm a/a.orig b.rename/b c.copy |
|
117 | $ rm a/a.orig b.rename/b c.copy | |
118 |
|
118 | |||
119 | apply it and make sure our state is as expected |
|
119 | apply it and make sure our state is as expected | |
120 |
|
120 | |||
121 | $ hg unshelve |
|
121 | $ hg unshelve | |
122 | unshelving change 'default-01' |
|
122 | unshelving change 'default-01' | |
123 | $ hg status -C |
|
123 | $ hg status -C | |
124 | M a/a |
|
124 | M a/a | |
125 | A b.rename/b |
|
125 | A b.rename/b | |
126 | b/b |
|
126 | b/b | |
127 | A c.copy |
|
127 | A c.copy | |
128 | c |
|
128 | c | |
129 | R b/b |
|
129 | R b/b | |
130 | $ hg shelve -l |
|
130 | $ hg shelve -l | |
131 |
|
131 | |||
132 | $ hg unshelve |
|
132 | $ hg unshelve | |
133 | abort: no shelved changes to apply! |
|
133 | abort: no shelved changes to apply! | |
134 | [255] |
|
134 | [255] | |
135 | $ hg unshelve foo |
|
135 | $ hg unshelve foo | |
136 | abort: shelved change 'foo' not found |
|
136 | abort: shelved change 'foo' not found | |
137 | [255] |
|
137 | [255] | |
138 |
|
138 | |||
139 | named shelves, specific filenames, and "commit messages" should all work |
|
139 | named shelves, specific filenames, and "commit messages" should all work | |
140 | (this tests also that editor is invoked, if '--edit' is specified) |
|
140 | (this tests also that editor is invoked, if '--edit' is specified) | |
141 |
|
141 | |||
142 | $ hg status -C |
|
142 | $ hg status -C | |
143 | M a/a |
|
143 | M a/a | |
144 | A b.rename/b |
|
144 | A b.rename/b | |
145 | b/b |
|
145 | b/b | |
146 | A c.copy |
|
146 | A c.copy | |
147 | c |
|
147 | c | |
148 | R b/b |
|
148 | R b/b | |
149 | $ HGEDITOR=cat hg shelve -q -n wibble -m wat -e a |
|
149 | $ HGEDITOR=cat hg shelve -q -n wibble -m wat -e a | |
150 | wat |
|
150 | wat | |
151 |
|
151 | |||
152 |
|
152 | |||
153 | HG: Enter commit message. Lines beginning with 'HG:' are removed. |
|
153 | HG: Enter commit message. Lines beginning with 'HG:' are removed. | |
154 | HG: Leave message empty to abort commit. |
|
154 | HG: Leave message empty to abort commit. | |
155 | HG: -- |
|
155 | HG: -- | |
156 | HG: user: shelve@localhost |
|
156 | HG: user: shelve@localhost | |
157 | HG: branch 'default' |
|
157 | HG: branch 'default' | |
158 | HG: changed a/a |
|
158 | HG: changed a/a | |
159 |
|
159 | |||
160 | expect "a" to no longer be present, but status otherwise unchanged |
|
160 | expect "a" to no longer be present, but status otherwise unchanged | |
161 |
|
161 | |||
162 | $ hg status -C |
|
162 | $ hg status -C | |
163 | A b.rename/b |
|
163 | A b.rename/b | |
164 | b/b |
|
164 | b/b | |
165 | A c.copy |
|
165 | A c.copy | |
166 | c |
|
166 | c | |
167 | R b/b |
|
167 | R b/b | |
168 | $ hg shelve -l --stat |
|
168 | $ hg shelve -l --stat | |
169 | wibble (*) wat (glob) |
|
169 | wibble (*) wat (glob) | |
170 | a/a | 1 + |
|
170 | a/a | 1 + | |
171 | 1 files changed, 1 insertions(+), 0 deletions(-) |
|
171 | 1 files changed, 1 insertions(+), 0 deletions(-) | |
172 |
|
172 | |||
173 | and now "a/a" should reappear |
|
173 | and now "a/a" should reappear | |
174 |
|
174 | |||
175 | $ cd a |
|
175 | $ cd a | |
176 | $ hg unshelve -q wibble |
|
176 | $ hg unshelve -q wibble | |
177 | $ cd .. |
|
177 | $ cd .. | |
178 | $ hg status -C |
|
178 | $ hg status -C | |
179 | M a/a |
|
179 | M a/a | |
180 | A b.rename/b |
|
180 | A b.rename/b | |
181 | b/b |
|
181 | b/b | |
182 | A c.copy |
|
182 | A c.copy | |
183 | c |
|
183 | c | |
184 | R b/b |
|
184 | R b/b | |
185 |
|
185 | |||
186 | cause unshelving to result in a merge with 'a' conflicting |
|
186 | cause unshelving to result in a merge with 'a' conflicting | |
187 |
|
187 | |||
188 | $ hg shelve -q |
|
188 | $ hg shelve -q | |
189 | $ echo c>>a/a |
|
189 | $ echo c>>a/a | |
190 | $ hg commit -m second |
|
190 | $ hg commit -m second | |
191 | $ hg tip --template '{files}\n' |
|
191 | $ hg tip --template '{files}\n' | |
192 | a/a |
|
192 | a/a | |
193 |
|
193 | |||
194 | add an unrelated change that should be preserved |
|
194 | add an unrelated change that should be preserved | |
195 |
|
195 | |||
196 | $ mkdir foo |
|
196 | $ mkdir foo | |
197 | $ echo foo > foo/foo |
|
197 | $ echo foo > foo/foo | |
198 | $ hg add foo/foo |
|
198 | $ hg add foo/foo | |
199 |
|
199 | |||
200 | force a conflicted merge to occur |
|
200 | force a conflicted merge to occur | |
201 |
|
201 | |||
202 | $ hg unshelve |
|
202 | $ hg unshelve | |
203 | unshelving change 'default' |
|
203 | unshelving change 'default' | |
204 | temporarily committing pending changes (restore with 'hg unshelve --abort') |
|
204 | temporarily committing pending changes (restore with 'hg unshelve --abort') | |
205 | rebasing shelved changes |
|
205 | rebasing shelved changes | |
206 | rebasing 5:4702e8911fe0 "changes to '[mq]: second.patch'" (tip) |
|
206 | rebasing 5:4702e8911fe0 "changes to '[mq]: second.patch'" (tip) | |
207 | merging a/a |
|
207 | merging a/a | |
208 | warning: conflicts during merge. |
|
208 | warning: conflicts during merge. | |
209 | merging a/a incomplete! (edit conflicts, then use 'hg resolve --mark') |
|
209 | merging a/a incomplete! (edit conflicts, then use 'hg resolve --mark') | |
210 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') |
|
210 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') | |
211 | [1] |
|
211 | [1] | |
212 |
|
212 | |||
213 | ensure that we have a merge with unresolved conflicts |
|
213 | ensure that we have a merge with unresolved conflicts | |
214 |
|
214 | |||
215 | $ hg heads -q --template '{rev}\n' |
|
215 | $ hg heads -q --template '{rev}\n' | |
216 | 5 |
|
216 | 5 | |
217 | 4 |
|
217 | 4 | |
218 | $ hg parents -q --template '{rev}\n' |
|
218 | $ hg parents -q --template '{rev}\n' | |
219 | 4 |
|
219 | 4 | |
220 | 5 |
|
220 | 5 | |
221 | $ hg status |
|
221 | $ hg status | |
222 | M a/a |
|
222 | M a/a | |
223 | M b.rename/b |
|
223 | M b.rename/b | |
224 | M c.copy |
|
224 | M c.copy | |
225 | R b/b |
|
225 | R b/b | |
226 | ? a/a.orig |
|
226 | ? a/a.orig | |
227 | $ hg diff |
|
227 | $ hg diff | |
228 | diff --git a/a/a b/a/a |
|
228 | diff --git a/a/a b/a/a | |
229 | --- a/a/a |
|
229 | --- a/a/a | |
230 | +++ b/a/a |
|
230 | +++ b/a/a | |
231 | @@ -1,2 +1,6 @@ |
|
231 | @@ -1,2 +1,6 @@ | |
232 | a |
|
232 | a | |
233 | +<<<<<<< dest: * - shelve: pending changes temporary commit (glob) |
|
233 | +<<<<<<< dest: * - shelve: pending changes temporary commit (glob) | |
234 | c |
|
234 | c | |
235 | +======= |
|
235 | +======= | |
236 | +a |
|
236 | +a | |
237 | +>>>>>>> source: 4702e8911fe0 - shelve: changes to '[mq]: second.patch' |
|
237 | +>>>>>>> source: 4702e8911fe0 - shelve: changes to '[mq]: second.patch' | |
238 | diff --git a/b/b b/b.rename/b |
|
238 | diff --git a/b/b b/b.rename/b | |
239 | rename from b/b |
|
239 | rename from b/b | |
240 | rename to b.rename/b |
|
240 | rename to b.rename/b | |
241 | diff --git a/b/b b/b/b |
|
|||
242 | deleted file mode 100644 |
|
|||
243 | --- a/b/b |
|
|||
244 | +++ /dev/null |
|
|||
245 | @@ -1,1 +0,0 @@ |
|
|||
246 | -b |
|
|||
247 | diff --git a/c b/c.copy |
|
241 | diff --git a/c b/c.copy | |
248 | copy from c |
|
242 | copy from c | |
249 | copy to c.copy |
|
243 | copy to c.copy | |
250 | $ hg resolve -l |
|
244 | $ hg resolve -l | |
251 | U a/a |
|
245 | U a/a | |
252 |
|
246 | |||
253 | $ hg shelve |
|
247 | $ hg shelve | |
254 | abort: unshelve already in progress |
|
248 | abort: unshelve already in progress | |
255 | (use 'hg unshelve --continue' or 'hg unshelve --abort') |
|
249 | (use 'hg unshelve --continue' or 'hg unshelve --abort') | |
256 | [255] |
|
250 | [255] | |
257 |
|
251 | |||
258 | abort the unshelve and be happy |
|
252 | abort the unshelve and be happy | |
259 |
|
253 | |||
260 | $ hg status |
|
254 | $ hg status | |
261 | M a/a |
|
255 | M a/a | |
262 | M b.rename/b |
|
256 | M b.rename/b | |
263 | M c.copy |
|
257 | M c.copy | |
264 | R b/b |
|
258 | R b/b | |
265 | ? a/a.orig |
|
259 | ? a/a.orig | |
266 | $ hg unshelve -a |
|
260 | $ hg unshelve -a | |
267 | rebase aborted |
|
261 | rebase aborted | |
268 | unshelve of 'default' aborted |
|
262 | unshelve of 'default' aborted | |
269 | $ hg heads -q |
|
263 | $ hg heads -q | |
270 | 3:2e69b451d1ea |
|
264 | 3:2e69b451d1ea | |
271 | $ hg parents |
|
265 | $ hg parents | |
272 | changeset: 3:2e69b451d1ea |
|
266 | changeset: 3:2e69b451d1ea | |
273 | tag: tip |
|
267 | tag: tip | |
274 | user: test |
|
268 | user: test | |
275 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
269 | date: Thu Jan 01 00:00:00 1970 +0000 | |
276 | summary: second |
|
270 | summary: second | |
277 |
|
271 | |||
278 | $ hg resolve -l |
|
272 | $ hg resolve -l | |
279 | $ hg status |
|
273 | $ hg status | |
280 | A foo/foo |
|
274 | A foo/foo | |
281 | ? a/a.orig |
|
275 | ? a/a.orig | |
282 |
|
276 | |||
283 | try to continue with no unshelve underway |
|
277 | try to continue with no unshelve underway | |
284 |
|
278 | |||
285 | $ hg unshelve -c |
|
279 | $ hg unshelve -c | |
286 | abort: no unshelve operation underway |
|
280 | abort: no unshelve operation underway | |
287 | [255] |
|
281 | [255] | |
288 | $ hg status |
|
282 | $ hg status | |
289 | A foo/foo |
|
283 | A foo/foo | |
290 | ? a/a.orig |
|
284 | ? a/a.orig | |
291 |
|
285 | |||
292 | redo the unshelve to get a conflict |
|
286 | redo the unshelve to get a conflict | |
293 |
|
287 | |||
294 | $ hg unshelve -q |
|
288 | $ hg unshelve -q | |
295 | warning: conflicts during merge. |
|
289 | warning: conflicts during merge. | |
296 | merging a/a incomplete! (edit conflicts, then use 'hg resolve --mark') |
|
290 | merging a/a incomplete! (edit conflicts, then use 'hg resolve --mark') | |
297 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') |
|
291 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') | |
298 | [1] |
|
292 | [1] | |
299 |
|
293 | |||
300 | attempt to continue |
|
294 | attempt to continue | |
301 |
|
295 | |||
302 | $ hg unshelve -c |
|
296 | $ hg unshelve -c | |
303 | abort: unresolved conflicts, can't continue |
|
297 | abort: unresolved conflicts, can't continue | |
304 | (see 'hg resolve', then 'hg unshelve --continue') |
|
298 | (see 'hg resolve', then 'hg unshelve --continue') | |
305 | [255] |
|
299 | [255] | |
306 |
|
300 | |||
307 | $ hg revert -r . a/a |
|
301 | $ hg revert -r . a/a | |
308 | $ hg resolve -m a/a |
|
302 | $ hg resolve -m a/a | |
309 | (no more unresolved files) |
|
303 | (no more unresolved files) | |
310 |
|
304 | |||
311 | $ hg commit -m 'commit while unshelve in progress' |
|
305 | $ hg commit -m 'commit while unshelve in progress' | |
312 | abort: unshelve already in progress |
|
306 | abort: unshelve already in progress | |
313 | (use 'hg unshelve --continue' or 'hg unshelve --abort') |
|
307 | (use 'hg unshelve --continue' or 'hg unshelve --abort') | |
314 | [255] |
|
308 | [255] | |
315 |
|
309 | |||
316 | $ hg unshelve -c |
|
310 | $ hg unshelve -c | |
317 | rebasing 5:4702e8911fe0 "changes to '[mq]: second.patch'" (tip) |
|
311 | rebasing 5:4702e8911fe0 "changes to '[mq]: second.patch'" (tip) | |
318 | unshelve of 'default' complete |
|
312 | unshelve of 'default' complete | |
319 |
|
313 | |||
320 | ensure the repo is as we hope |
|
314 | ensure the repo is as we hope | |
321 |
|
315 | |||
322 | $ hg parents |
|
316 | $ hg parents | |
323 | changeset: 3:2e69b451d1ea |
|
317 | changeset: 3:2e69b451d1ea | |
324 | tag: tip |
|
318 | tag: tip | |
325 | user: test |
|
319 | user: test | |
326 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
320 | date: Thu Jan 01 00:00:00 1970 +0000 | |
327 | summary: second |
|
321 | summary: second | |
328 |
|
322 | |||
329 | $ hg heads -q |
|
323 | $ hg heads -q | |
330 | 3:2e69b451d1ea |
|
324 | 3:2e69b451d1ea | |
331 |
|
325 | |||
332 | $ hg status -C |
|
326 | $ hg status -C | |
333 | A b.rename/b |
|
327 | A b.rename/b | |
334 | b/b |
|
328 | b/b | |
335 | A c.copy |
|
329 | A c.copy | |
336 | c |
|
330 | c | |
337 | A foo/foo |
|
331 | A foo/foo | |
338 | R b/b |
|
332 | R b/b | |
339 | ? a/a.orig |
|
333 | ? a/a.orig | |
340 |
|
334 | |||
341 | there should be no shelves left |
|
335 | there should be no shelves left | |
342 |
|
336 | |||
343 | $ hg shelve -l |
|
337 | $ hg shelve -l | |
344 |
|
338 | |||
345 | #if execbit |
|
339 | #if execbit | |
346 |
|
340 | |||
347 | ensure that metadata-only changes are shelved |
|
341 | ensure that metadata-only changes are shelved | |
348 |
|
342 | |||
349 | $ chmod +x a/a |
|
343 | $ chmod +x a/a | |
350 | $ hg shelve -q -n execbit a/a |
|
344 | $ hg shelve -q -n execbit a/a | |
351 | $ hg status a/a |
|
345 | $ hg status a/a | |
352 | $ hg unshelve -q execbit |
|
346 | $ hg unshelve -q execbit | |
353 | $ hg status a/a |
|
347 | $ hg status a/a | |
354 | M a/a |
|
348 | M a/a | |
355 | $ hg revert a/a |
|
349 | $ hg revert a/a | |
356 |
|
350 | |||
357 | #endif |
|
351 | #endif | |
358 |
|
352 | |||
359 | #if symlink |
|
353 | #if symlink | |
360 |
|
354 | |||
361 | $ rm a/a |
|
355 | $ rm a/a | |
362 | $ ln -s foo a/a |
|
356 | $ ln -s foo a/a | |
363 | $ hg shelve -q -n symlink a/a |
|
357 | $ hg shelve -q -n symlink a/a | |
364 | $ hg status a/a |
|
358 | $ hg status a/a | |
365 | $ hg unshelve -q symlink |
|
359 | $ hg unshelve -q symlink | |
366 | $ hg status a/a |
|
360 | $ hg status a/a | |
367 | M a/a |
|
361 | M a/a | |
368 | $ hg revert a/a |
|
362 | $ hg revert a/a | |
369 |
|
363 | |||
370 | #endif |
|
364 | #endif | |
371 |
|
365 | |||
372 | set up another conflict between a commit and a shelved change |
|
366 | set up another conflict between a commit and a shelved change | |
373 |
|
367 | |||
374 | $ hg revert -q -C -a |
|
368 | $ hg revert -q -C -a | |
375 | $ rm a/a.orig b.rename/b c.copy |
|
369 | $ rm a/a.orig b.rename/b c.copy | |
376 | $ echo a >> a/a |
|
370 | $ echo a >> a/a | |
377 | $ hg shelve -q |
|
371 | $ hg shelve -q | |
378 | $ echo x >> a/a |
|
372 | $ echo x >> a/a | |
379 | $ hg ci -m 'create conflict' |
|
373 | $ hg ci -m 'create conflict' | |
380 | $ hg add foo/foo |
|
374 | $ hg add foo/foo | |
381 |
|
375 | |||
382 | if we resolve a conflict while unshelving, the unshelve should succeed |
|
376 | if we resolve a conflict while unshelving, the unshelve should succeed | |
383 |
|
377 | |||
384 | $ HGMERGE=true hg unshelve |
|
378 | $ HGMERGE=true hg unshelve | |
385 | unshelving change 'default' |
|
379 | unshelving change 'default' | |
386 | temporarily committing pending changes (restore with 'hg unshelve --abort') |
|
380 | temporarily committing pending changes (restore with 'hg unshelve --abort') | |
387 | rebasing shelved changes |
|
381 | rebasing shelved changes | |
388 | rebasing 6:c5e6910e7601 "changes to 'second'" (tip) |
|
382 | rebasing 6:c5e6910e7601 "changes to 'second'" (tip) | |
389 | merging a/a |
|
383 | merging a/a | |
390 | note: rebase of 6:c5e6910e7601 created no changes to commit |
|
384 | note: rebase of 6:c5e6910e7601 created no changes to commit | |
391 | $ hg parents -q |
|
385 | $ hg parents -q | |
392 | 4:33f7f61e6c5e |
|
386 | 4:33f7f61e6c5e | |
393 | $ hg shelve -l |
|
387 | $ hg shelve -l | |
394 | $ hg status |
|
388 | $ hg status | |
395 | A foo/foo |
|
389 | A foo/foo | |
396 | $ cat a/a |
|
390 | $ cat a/a | |
397 | a |
|
391 | a | |
398 | c |
|
392 | c | |
399 | x |
|
393 | x | |
400 |
|
394 | |||
401 | test keep and cleanup |
|
395 | test keep and cleanup | |
402 |
|
396 | |||
403 | $ hg shelve |
|
397 | $ hg shelve | |
404 | shelved as default |
|
398 | shelved as default | |
405 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
399 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
406 | $ hg shelve --list |
|
400 | $ hg shelve --list | |
407 | default (*) changes to 'create conflict' (glob) |
|
401 | default (*) changes to 'create conflict' (glob) | |
408 | $ hg unshelve --keep |
|
402 | $ hg unshelve --keep | |
409 | unshelving change 'default' |
|
403 | unshelving change 'default' | |
410 | $ hg shelve --list |
|
404 | $ hg shelve --list | |
411 | default (*) changes to 'create conflict' (glob) |
|
405 | default (*) changes to 'create conflict' (glob) | |
412 | $ hg shelve --cleanup |
|
406 | $ hg shelve --cleanup | |
413 | $ hg shelve --list |
|
407 | $ hg shelve --list | |
414 |
|
408 | |||
415 | $ hg shelve --cleanup --delete |
|
409 | $ hg shelve --cleanup --delete | |
416 | abort: options '--cleanup' and '--delete' may not be used together |
|
410 | abort: options '--cleanup' and '--delete' may not be used together | |
417 | [255] |
|
411 | [255] | |
418 | $ hg shelve --cleanup --patch |
|
412 | $ hg shelve --cleanup --patch | |
419 | abort: options '--cleanup' and '--patch' may not be used together |
|
413 | abort: options '--cleanup' and '--patch' may not be used together | |
420 | [255] |
|
414 | [255] | |
421 | $ hg shelve --cleanup --message MESSAGE |
|
415 | $ hg shelve --cleanup --message MESSAGE | |
422 | abort: options '--cleanup' and '--message' may not be used together |
|
416 | abort: options '--cleanup' and '--message' may not be used together | |
423 | [255] |
|
417 | [255] | |
424 |
|
418 | |||
425 | test bookmarks |
|
419 | test bookmarks | |
426 |
|
420 | |||
427 | $ hg bookmark test |
|
421 | $ hg bookmark test | |
428 | $ hg bookmark |
|
422 | $ hg bookmark | |
429 | * test 4:33f7f61e6c5e |
|
423 | * test 4:33f7f61e6c5e | |
430 | $ hg shelve |
|
424 | $ hg shelve | |
431 | shelved as test |
|
425 | shelved as test | |
432 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
426 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
433 | $ hg bookmark |
|
427 | $ hg bookmark | |
434 | * test 4:33f7f61e6c5e |
|
428 | * test 4:33f7f61e6c5e | |
435 | $ hg unshelve |
|
429 | $ hg unshelve | |
436 | unshelving change 'test' |
|
430 | unshelving change 'test' | |
437 | $ hg bookmark |
|
431 | $ hg bookmark | |
438 | * test 4:33f7f61e6c5e |
|
432 | * test 4:33f7f61e6c5e | |
439 |
|
433 | |||
440 | shelve should still work even if mq is disabled |
|
434 | shelve should still work even if mq is disabled | |
441 |
|
435 | |||
442 | $ hg --config extensions.mq=! shelve |
|
436 | $ hg --config extensions.mq=! shelve | |
443 | shelved as test |
|
437 | shelved as test | |
444 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
438 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
445 | $ hg --config extensions.mq=! shelve --list |
|
439 | $ hg --config extensions.mq=! shelve --list | |
446 | test (*) changes to 'create conflict' (glob) |
|
440 | test (*) changes to 'create conflict' (glob) | |
447 | $ hg --config extensions.mq=! unshelve |
|
441 | $ hg --config extensions.mq=! unshelve | |
448 | unshelving change 'test' |
|
442 | unshelving change 'test' | |
449 |
|
443 | |||
450 | shelve should leave dirstate clean (issue4055) |
|
444 | shelve should leave dirstate clean (issue4055) | |
451 |
|
445 | |||
452 | $ cd .. |
|
446 | $ cd .. | |
453 | $ hg init shelverebase |
|
447 | $ hg init shelverebase | |
454 | $ cd shelverebase |
|
448 | $ cd shelverebase | |
455 | $ printf 'x\ny\n' > x |
|
449 | $ printf 'x\ny\n' > x | |
456 | $ echo z > z |
|
450 | $ echo z > z | |
457 | $ hg commit -Aqm xy |
|
451 | $ hg commit -Aqm xy | |
458 | $ echo z >> x |
|
452 | $ echo z >> x | |
459 | $ hg commit -Aqm z |
|
453 | $ hg commit -Aqm z | |
460 | $ hg up 0 |
|
454 | $ hg up 0 | |
461 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
455 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
462 | $ printf 'a\nx\ny\nz\n' > x |
|
456 | $ printf 'a\nx\ny\nz\n' > x | |
463 | $ hg commit -Aqm xyz |
|
457 | $ hg commit -Aqm xyz | |
464 | $ echo c >> z |
|
458 | $ echo c >> z | |
465 | $ hg shelve |
|
459 | $ hg shelve | |
466 | shelved as default |
|
460 | shelved as default | |
467 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
461 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
468 | $ hg rebase -d 1 --config extensions.rebase= |
|
462 | $ hg rebase -d 1 --config extensions.rebase= | |
469 | rebasing 2:323bfa07f744 "xyz" (tip) |
|
463 | rebasing 2:323bfa07f744 "xyz" (tip) | |
470 | merging x |
|
464 | merging x | |
471 | saved backup bundle to $TESTTMP/shelverebase/.hg/strip-backup/323bfa07f744-backup.hg (glob) |
|
465 | saved backup bundle to $TESTTMP/shelverebase/.hg/strip-backup/323bfa07f744-backup.hg (glob) | |
472 | $ hg unshelve |
|
466 | $ hg unshelve | |
473 | unshelving change 'default' |
|
467 | unshelving change 'default' | |
474 | rebasing shelved changes |
|
468 | rebasing shelved changes | |
475 | rebasing 4:b8fefe789ed0 "changes to 'xyz'" (tip) |
|
469 | rebasing 4:b8fefe789ed0 "changes to 'xyz'" (tip) | |
476 | $ hg status |
|
470 | $ hg status | |
477 | M z |
|
471 | M z | |
478 |
|
472 | |||
479 | $ cd .. |
|
473 | $ cd .. | |
480 |
|
474 | |||
481 | shelve should only unshelve pending changes (issue4068) |
|
475 | shelve should only unshelve pending changes (issue4068) | |
482 |
|
476 | |||
483 | $ hg init onlypendingchanges |
|
477 | $ hg init onlypendingchanges | |
484 | $ cd onlypendingchanges |
|
478 | $ cd onlypendingchanges | |
485 | $ touch a |
|
479 | $ touch a | |
486 | $ hg ci -Aqm a |
|
480 | $ hg ci -Aqm a | |
487 | $ touch b |
|
481 | $ touch b | |
488 | $ hg ci -Aqm b |
|
482 | $ hg ci -Aqm b | |
489 | $ hg up -q 0 |
|
483 | $ hg up -q 0 | |
490 | $ touch c |
|
484 | $ touch c | |
491 | $ hg ci -Aqm c |
|
485 | $ hg ci -Aqm c | |
492 |
|
486 | |||
493 | $ touch d |
|
487 | $ touch d | |
494 | $ hg add d |
|
488 | $ hg add d | |
495 | $ hg shelve |
|
489 | $ hg shelve | |
496 | shelved as default |
|
490 | shelved as default | |
497 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
491 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
498 | $ hg up -q 1 |
|
492 | $ hg up -q 1 | |
499 | $ hg unshelve |
|
493 | $ hg unshelve | |
500 | unshelving change 'default' |
|
494 | unshelving change 'default' | |
501 | rebasing shelved changes |
|
495 | rebasing shelved changes | |
502 | rebasing 3:0cae6656c016 "changes to 'c'" (tip) |
|
496 | rebasing 3:0cae6656c016 "changes to 'c'" (tip) | |
503 | $ hg status |
|
497 | $ hg status | |
504 | A d |
|
498 | A d | |
505 |
|
499 | |||
506 | unshelve should work on an ancestor of the original commit |
|
500 | unshelve should work on an ancestor of the original commit | |
507 |
|
501 | |||
508 | $ hg shelve |
|
502 | $ hg shelve | |
509 | shelved as default |
|
503 | shelved as default | |
510 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
504 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
511 | $ hg up 0 |
|
505 | $ hg up 0 | |
512 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
506 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
513 | $ hg unshelve |
|
507 | $ hg unshelve | |
514 | unshelving change 'default' |
|
508 | unshelving change 'default' | |
515 | rebasing shelved changes |
|
509 | rebasing shelved changes | |
516 | rebasing 3:be58f65f55fb "changes to 'b'" (tip) |
|
510 | rebasing 3:be58f65f55fb "changes to 'b'" (tip) | |
517 | $ hg status |
|
511 | $ hg status | |
518 | A d |
|
512 | A d | |
519 |
|
513 | |||
520 | test bug 4073 we need to enable obsolete markers for it |
|
514 | test bug 4073 we need to enable obsolete markers for it | |
521 |
|
515 | |||
522 | $ cat >> $HGRCPATH << EOF |
|
516 | $ cat >> $HGRCPATH << EOF | |
523 | > [experimental] |
|
517 | > [experimental] | |
524 | > evolution=createmarkers |
|
518 | > evolution=createmarkers | |
525 | > EOF |
|
519 | > EOF | |
526 | $ hg shelve |
|
520 | $ hg shelve | |
527 | shelved as default |
|
521 | shelved as default | |
528 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
522 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
529 | $ hg debugobsolete `hg --debug id -i -r 1` |
|
523 | $ hg debugobsolete `hg --debug id -i -r 1` | |
530 | $ hg unshelve |
|
524 | $ hg unshelve | |
531 | unshelving change 'default' |
|
525 | unshelving change 'default' | |
532 |
|
526 | |||
533 | unshelve should leave unknown files alone (issue4113) |
|
527 | unshelve should leave unknown files alone (issue4113) | |
534 |
|
528 | |||
535 | $ echo e > e |
|
529 | $ echo e > e | |
536 | $ hg shelve |
|
530 | $ hg shelve | |
537 | shelved as default |
|
531 | shelved as default | |
538 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
532 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
539 | $ hg status |
|
533 | $ hg status | |
540 | ? e |
|
534 | ? e | |
541 | $ hg unshelve |
|
535 | $ hg unshelve | |
542 | unshelving change 'default' |
|
536 | unshelving change 'default' | |
543 | $ hg status |
|
537 | $ hg status | |
544 | A d |
|
538 | A d | |
545 | ? e |
|
539 | ? e | |
546 | $ cat e |
|
540 | $ cat e | |
547 | e |
|
541 | e | |
548 |
|
542 | |||
549 | unshelve should keep a copy of unknown files |
|
543 | unshelve should keep a copy of unknown files | |
550 |
|
544 | |||
551 | $ hg add e |
|
545 | $ hg add e | |
552 | $ hg shelve |
|
546 | $ hg shelve | |
553 | shelved as default |
|
547 | shelved as default | |
554 | 0 files updated, 0 files merged, 2 files removed, 0 files unresolved |
|
548 | 0 files updated, 0 files merged, 2 files removed, 0 files unresolved | |
555 | $ echo z > e |
|
549 | $ echo z > e | |
556 | $ hg unshelve |
|
550 | $ hg unshelve | |
557 | unshelving change 'default' |
|
551 | unshelving change 'default' | |
558 | $ cat e |
|
552 | $ cat e | |
559 | e |
|
553 | e | |
560 | $ cat e.orig |
|
554 | $ cat e.orig | |
561 | z |
|
555 | z | |
562 |
|
556 | |||
563 |
|
557 | |||
564 | unshelve and conflicts with tracked and untracked files |
|
558 | unshelve and conflicts with tracked and untracked files | |
565 |
|
559 | |||
566 | preparing: |
|
560 | preparing: | |
567 |
|
561 | |||
568 | $ rm *.orig |
|
562 | $ rm *.orig | |
569 | $ hg ci -qm 'commit stuff' |
|
563 | $ hg ci -qm 'commit stuff' | |
570 | $ hg phase -p null: |
|
564 | $ hg phase -p null: | |
571 |
|
565 | |||
572 | no other changes - no merge: |
|
566 | no other changes - no merge: | |
573 |
|
567 | |||
574 | $ echo f > f |
|
568 | $ echo f > f | |
575 | $ hg add f |
|
569 | $ hg add f | |
576 | $ hg shelve |
|
570 | $ hg shelve | |
577 | shelved as default |
|
571 | shelved as default | |
578 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
572 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
579 | $ echo g > f |
|
573 | $ echo g > f | |
580 | $ hg unshelve |
|
574 | $ hg unshelve | |
581 | unshelving change 'default' |
|
575 | unshelving change 'default' | |
582 | $ hg st |
|
576 | $ hg st | |
583 | A f |
|
577 | A f | |
584 | ? f.orig |
|
578 | ? f.orig | |
585 | $ cat f |
|
579 | $ cat f | |
586 | f |
|
580 | f | |
587 | $ cat f.orig |
|
581 | $ cat f.orig | |
588 | g |
|
582 | g | |
589 |
|
583 | |||
590 | other uncommitted changes - merge: |
|
584 | other uncommitted changes - merge: | |
591 |
|
585 | |||
592 | $ hg st |
|
586 | $ hg st | |
593 | A f |
|
587 | A f | |
594 | ? f.orig |
|
588 | ? f.orig | |
595 | $ hg shelve |
|
589 | $ hg shelve | |
596 | shelved as default |
|
590 | shelved as default | |
597 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
591 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
598 | $ hg log -G --template '{rev} {desc|firstline} {author}' -R bundle://.hg/shelved/default.hg -r 'bundle()' |
|
592 | $ hg log -G --template '{rev} {desc|firstline} {author}' -R bundle://.hg/shelved/default.hg -r 'bundle()' | |
599 | o 4 changes to 'commit stuff' shelve@localhost |
|
593 | o 4 changes to 'commit stuff' shelve@localhost | |
600 | | |
|
594 | | | |
601 | $ hg log -G --template '{rev} {desc|firstline} {author}' |
|
595 | $ hg log -G --template '{rev} {desc|firstline} {author}' | |
602 | @ 3 commit stuff test |
|
596 | @ 3 commit stuff test | |
603 | | |
|
597 | | | |
604 | | o 2 c test |
|
598 | | o 2 c test | |
605 | |/ |
|
599 | |/ | |
606 | o 0 a test |
|
600 | o 0 a test | |
607 |
|
601 | |||
608 | $ mv f.orig f |
|
602 | $ mv f.orig f | |
609 | $ echo 1 > a |
|
603 | $ echo 1 > a | |
610 | $ hg unshelve --date '1073741824 0' |
|
604 | $ hg unshelve --date '1073741824 0' | |
611 | unshelving change 'default' |
|
605 | unshelving change 'default' | |
612 | temporarily committing pending changes (restore with 'hg unshelve --abort') |
|
606 | temporarily committing pending changes (restore with 'hg unshelve --abort') | |
613 | rebasing shelved changes |
|
607 | rebasing shelved changes | |
614 | rebasing 5:23b29cada8ba "changes to 'commit stuff'" (tip) |
|
608 | rebasing 5:23b29cada8ba "changes to 'commit stuff'" (tip) | |
615 | merging f |
|
609 | merging f | |
616 | warning: conflicts during merge. |
|
610 | warning: conflicts during merge. | |
617 | merging f incomplete! (edit conflicts, then use 'hg resolve --mark') |
|
611 | merging f incomplete! (edit conflicts, then use 'hg resolve --mark') | |
618 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') |
|
612 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') | |
619 | [1] |
|
613 | [1] | |
620 | $ hg log -G --template '{rev} {desc|firstline} {author} {date|isodate}' |
|
614 | $ hg log -G --template '{rev} {desc|firstline} {author} {date|isodate}' | |
621 | @ 5 changes to 'commit stuff' shelve@localhost 1970-01-01 00:00 +0000 |
|
615 | @ 5 changes to 'commit stuff' shelve@localhost 1970-01-01 00:00 +0000 | |
622 | | |
|
616 | | | |
623 | | @ 4 pending changes temporary commit shelve@localhost 2004-01-10 13:37 +0000 |
|
617 | | @ 4 pending changes temporary commit shelve@localhost 2004-01-10 13:37 +0000 | |
624 | |/ |
|
618 | |/ | |
625 | o 3 commit stuff test 1970-01-01 00:00 +0000 |
|
619 | o 3 commit stuff test 1970-01-01 00:00 +0000 | |
626 | | |
|
620 | | | |
627 | | o 2 c test 1970-01-01 00:00 +0000 |
|
621 | | o 2 c test 1970-01-01 00:00 +0000 | |
628 | |/ |
|
622 | |/ | |
629 | o 0 a test 1970-01-01 00:00 +0000 |
|
623 | o 0 a test 1970-01-01 00:00 +0000 | |
630 |
|
624 | |||
631 | $ hg st |
|
625 | $ hg st | |
632 | M f |
|
626 | M f | |
633 | ? f.orig |
|
627 | ? f.orig | |
634 | $ cat f |
|
628 | $ cat f | |
635 | <<<<<<< dest: 5f6b880e719b - shelve: pending changes temporary commit |
|
629 | <<<<<<< dest: 5f6b880e719b - shelve: pending changes temporary commit | |
636 | g |
|
630 | g | |
637 | ======= |
|
631 | ======= | |
638 | f |
|
632 | f | |
639 | >>>>>>> source: 23b29cada8ba - shelve: changes to 'commit stuff' |
|
633 | >>>>>>> source: 23b29cada8ba - shelve: changes to 'commit stuff' | |
640 | $ cat f.orig |
|
634 | $ cat f.orig | |
641 | g |
|
635 | g | |
642 | $ hg unshelve --abort |
|
636 | $ hg unshelve --abort | |
643 | rebase aborted |
|
637 | rebase aborted | |
644 | unshelve of 'default' aborted |
|
638 | unshelve of 'default' aborted | |
645 | $ hg st |
|
639 | $ hg st | |
646 | M a |
|
640 | M a | |
647 | ? f.orig |
|
641 | ? f.orig | |
648 | $ cat f.orig |
|
642 | $ cat f.orig | |
649 | g |
|
643 | g | |
650 | $ hg unshelve |
|
644 | $ hg unshelve | |
651 | unshelving change 'default' |
|
645 | unshelving change 'default' | |
652 | temporarily committing pending changes (restore with 'hg unshelve --abort') |
|
646 | temporarily committing pending changes (restore with 'hg unshelve --abort') | |
653 | rebasing shelved changes |
|
647 | rebasing shelved changes | |
654 | rebasing 5:23b29cada8ba "changes to 'commit stuff'" (tip) |
|
648 | rebasing 5:23b29cada8ba "changes to 'commit stuff'" (tip) | |
655 | $ hg st |
|
649 | $ hg st | |
656 | M a |
|
650 | M a | |
657 | A f |
|
651 | A f | |
658 | ? f.orig |
|
652 | ? f.orig | |
659 |
|
653 | |||
660 | other committed changes - merge: |
|
654 | other committed changes - merge: | |
661 |
|
655 | |||
662 | $ hg shelve f |
|
656 | $ hg shelve f | |
663 | shelved as default |
|
657 | shelved as default | |
664 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
658 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved | |
665 | $ hg ci a -m 'intermediate other change' |
|
659 | $ hg ci a -m 'intermediate other change' | |
666 | $ mv f.orig f |
|
660 | $ mv f.orig f | |
667 | $ hg unshelve |
|
661 | $ hg unshelve | |
668 | unshelving change 'default' |
|
662 | unshelving change 'default' | |
669 | rebasing shelved changes |
|
663 | rebasing shelved changes | |
670 | rebasing 5:23b29cada8ba "changes to 'commit stuff'" (tip) |
|
664 | rebasing 5:23b29cada8ba "changes to 'commit stuff'" (tip) | |
671 | merging f |
|
665 | merging f | |
672 | warning: conflicts during merge. |
|
666 | warning: conflicts during merge. | |
673 | merging f incomplete! (edit conflicts, then use 'hg resolve --mark') |
|
667 | merging f incomplete! (edit conflicts, then use 'hg resolve --mark') | |
674 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') |
|
668 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') | |
675 | [1] |
|
669 | [1] | |
676 | $ hg st |
|
670 | $ hg st | |
677 | M f |
|
671 | M f | |
678 | ? f.orig |
|
672 | ? f.orig | |
679 | $ cat f |
|
673 | $ cat f | |
680 | <<<<<<< dest: * - test: intermediate other change (glob) |
|
674 | <<<<<<< dest: * - test: intermediate other change (glob) | |
681 | g |
|
675 | g | |
682 | ======= |
|
676 | ======= | |
683 | f |
|
677 | f | |
684 | >>>>>>> source: 23b29cada8ba - shelve: changes to 'commit stuff' |
|
678 | >>>>>>> source: 23b29cada8ba - shelve: changes to 'commit stuff' | |
685 | $ cat f.orig |
|
679 | $ cat f.orig | |
686 | g |
|
680 | g | |
687 | $ hg unshelve --abort |
|
681 | $ hg unshelve --abort | |
688 | rebase aborted |
|
682 | rebase aborted | |
689 | unshelve of 'default' aborted |
|
683 | unshelve of 'default' aborted | |
690 | $ hg st |
|
684 | $ hg st | |
691 | ? f.orig |
|
685 | ? f.orig | |
692 | $ cat f.orig |
|
686 | $ cat f.orig | |
693 | g |
|
687 | g | |
694 | $ hg shelve --delete default |
|
688 | $ hg shelve --delete default | |
695 |
|
689 | |||
696 | Recreate some conflict again |
|
690 | Recreate some conflict again | |
697 |
|
691 | |||
698 | $ cd ../repo |
|
692 | $ cd ../repo | |
699 | $ hg up -C -r 3 |
|
693 | $ hg up -C -r 3 | |
700 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
694 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
701 | (leaving bookmark test) |
|
695 | (leaving bookmark test) | |
702 | $ echo y >> a/a |
|
696 | $ echo y >> a/a | |
703 | $ hg shelve |
|
697 | $ hg shelve | |
704 | shelved as default |
|
698 | shelved as default | |
705 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
699 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
706 | $ hg up test |
|
700 | $ hg up test | |
707 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
701 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
708 | (activating bookmark test) |
|
702 | (activating bookmark test) | |
709 | $ hg unshelve |
|
703 | $ hg unshelve | |
710 | unshelving change 'default' |
|
704 | unshelving change 'default' | |
711 | rebasing shelved changes |
|
705 | rebasing shelved changes | |
712 | rebasing 5:4b555fdb4e96 "changes to 'second'" (tip) |
|
706 | rebasing 5:4b555fdb4e96 "changes to 'second'" (tip) | |
713 | merging a/a |
|
707 | merging a/a | |
714 | warning: conflicts during merge. |
|
708 | warning: conflicts during merge. | |
715 | merging a/a incomplete! (edit conflicts, then use 'hg resolve --mark') |
|
709 | merging a/a incomplete! (edit conflicts, then use 'hg resolve --mark') | |
716 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') |
|
710 | unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue') | |
717 | [1] |
|
711 | [1] | |
718 |
|
712 | |||
719 | Test that resolving all conflicts in one direction (so that the rebase |
|
713 | Test that resolving all conflicts in one direction (so that the rebase | |
720 | is a no-op), works (issue4398) |
|
714 | is a no-op), works (issue4398) | |
721 |
|
715 | |||
722 | $ hg revert -a -r . |
|
716 | $ hg revert -a -r . | |
723 | reverting a/a (glob) |
|
717 | reverting a/a (glob) | |
724 | $ hg resolve -m a/a |
|
718 | $ hg resolve -m a/a | |
725 | (no more unresolved files) |
|
719 | (no more unresolved files) | |
726 | $ hg unshelve -c |
|
720 | $ hg unshelve -c | |
727 | rebasing 5:4b555fdb4e96 "changes to 'second'" (tip) |
|
721 | rebasing 5:4b555fdb4e96 "changes to 'second'" (tip) | |
728 | note: rebase of 5:4b555fdb4e96 created no changes to commit |
|
722 | note: rebase of 5:4b555fdb4e96 created no changes to commit | |
729 | unshelve of 'default' complete |
|
723 | unshelve of 'default' complete | |
730 | $ hg diff |
|
724 | $ hg diff | |
731 | $ hg status |
|
725 | $ hg status | |
732 | ? a/a.orig |
|
726 | ? a/a.orig | |
733 | ? foo/foo |
|
727 | ? foo/foo | |
734 | $ hg summary |
|
728 | $ hg summary | |
735 | parent: 4:33f7f61e6c5e tip |
|
729 | parent: 4:33f7f61e6c5e tip | |
736 | create conflict |
|
730 | create conflict | |
737 | branch: default |
|
731 | branch: default | |
738 | bookmarks: *test |
|
732 | bookmarks: *test | |
739 | commit: 2 unknown (clean) |
|
733 | commit: 2 unknown (clean) | |
740 | update: (current) |
|
734 | update: (current) | |
741 |
|
735 | |||
742 | $ hg shelve --delete --stat |
|
736 | $ hg shelve --delete --stat | |
743 | abort: options '--delete' and '--stat' may not be used together |
|
737 | abort: options '--delete' and '--stat' may not be used together | |
744 | [255] |
|
738 | [255] | |
745 | $ hg shelve --delete --name NAME |
|
739 | $ hg shelve --delete --name NAME | |
746 | abort: options '--delete' and '--name' may not be used together |
|
740 | abort: options '--delete' and '--name' may not be used together | |
747 | [255] |
|
741 | [255] | |
748 |
|
742 | |||
749 | $ cd .. |
|
743 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now