Show More
@@ -1,2185 +1,2188 b'' | |||||
1 | # queue.py - patch queues for mercurial |
|
1 | # queue.py - patch queues for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> |
|
3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | '''patch management and development |
|
8 | '''patch management and development | |
9 |
|
9 | |||
10 | This extension lets you work with a stack of patches in a Mercurial |
|
10 | This extension lets you work with a stack of patches in a Mercurial | |
11 | repository. It manages two stacks of patches - all known patches, and |
|
11 | repository. It manages two stacks of patches - all known patches, and | |
12 | applied patches (subset of known patches). |
|
12 | applied patches (subset of known patches). | |
13 |
|
13 | |||
14 | Known patches are represented as patch files in the .hg/patches |
|
14 | Known patches are represented as patch files in the .hg/patches | |
15 | directory. Applied patches are both patch files and changesets. |
|
15 | directory. Applied patches are both patch files and changesets. | |
16 |
|
16 | |||
17 | Common tasks (use "hg help command" for more details): |
|
17 | Common tasks (use "hg help command" for more details): | |
18 |
|
18 | |||
19 | prepare repository to work with patches qinit |
|
19 | prepare repository to work with patches qinit | |
20 | create new patch qnew |
|
20 | create new patch qnew | |
21 | import existing patch qimport |
|
21 | import existing patch qimport | |
22 |
|
22 | |||
23 | print patch series qseries |
|
23 | print patch series qseries | |
24 | print applied patches qapplied |
|
24 | print applied patches qapplied | |
25 | print name of top applied patch qtop |
|
25 | print name of top applied patch qtop | |
26 |
|
26 | |||
27 | add known patch to applied stack qpush |
|
27 | add known patch to applied stack qpush | |
28 | remove patch from applied stack qpop |
|
28 | remove patch from applied stack qpop | |
29 | refresh contents of top applied patch qrefresh |
|
29 | refresh contents of top applied patch qrefresh | |
30 | ''' |
|
30 | ''' | |
31 |
|
31 | |||
32 | from mercurial.i18n import _ |
|
32 | from mercurial.i18n import _ | |
33 | from mercurial import commands, cmdutil, hg, patch, revlog, util, changegroup |
|
33 | from mercurial import commands, cmdutil, hg, patch, revlog, util, changegroup | |
34 | import os, sys, re, errno |
|
34 | import os, sys, re, errno | |
35 |
|
35 | |||
36 | commands.norepo += " qclone qversion" |
|
36 | commands.norepo += " qclone qversion" | |
37 |
|
37 | |||
38 | # Patch names looks like unix-file names. |
|
38 | # Patch names looks like unix-file names. | |
39 | # They must be joinable with queue directory and result in the patch path. |
|
39 | # They must be joinable with queue directory and result in the patch path. | |
40 | normname = util.normpath |
|
40 | normname = util.normpath | |
41 |
|
41 | |||
42 | class statusentry: |
|
42 | class statusentry: | |
43 | def __init__(self, rev, name=None): |
|
43 | def __init__(self, rev, name=None): | |
44 | if not name: |
|
44 | if not name: | |
45 | fields = rev.split(':', 1) |
|
45 | fields = rev.split(':', 1) | |
46 | if len(fields) == 2: |
|
46 | if len(fields) == 2: | |
47 | self.rev, self.name = fields |
|
47 | self.rev, self.name = fields | |
48 | else: |
|
48 | else: | |
49 | self.rev, self.name = None, None |
|
49 | self.rev, self.name = None, None | |
50 | else: |
|
50 | else: | |
51 | self.rev, self.name = rev, name |
|
51 | self.rev, self.name = rev, name | |
52 |
|
52 | |||
53 | def __str__(self): |
|
53 | def __str__(self): | |
54 | return self.rev + ':' + self.name |
|
54 | return self.rev + ':' + self.name | |
55 |
|
55 | |||
56 | class queue: |
|
56 | class queue: | |
57 | def __init__(self, ui, path, patchdir=None): |
|
57 | def __init__(self, ui, path, patchdir=None): | |
58 | self.basepath = path |
|
58 | self.basepath = path | |
59 | self.path = patchdir or os.path.join(path, "patches") |
|
59 | self.path = patchdir or os.path.join(path, "patches") | |
60 | self.opener = util.opener(self.path) |
|
60 | self.opener = util.opener(self.path) | |
61 | self.ui = ui |
|
61 | self.ui = ui | |
62 | self.applied = [] |
|
62 | self.applied = [] | |
63 | self.full_series = [] |
|
63 | self.full_series = [] | |
64 | self.applied_dirty = 0 |
|
64 | self.applied_dirty = 0 | |
65 | self.series_dirty = 0 |
|
65 | self.series_dirty = 0 | |
66 | self.series_path = "series" |
|
66 | self.series_path = "series" | |
67 | self.status_path = "status" |
|
67 | self.status_path = "status" | |
68 | self.guards_path = "guards" |
|
68 | self.guards_path = "guards" | |
69 | self.active_guards = None |
|
69 | self.active_guards = None | |
70 | self.guards_dirty = False |
|
70 | self.guards_dirty = False | |
71 | self._diffopts = None |
|
71 | self._diffopts = None | |
72 |
|
72 | |||
73 | if os.path.exists(self.join(self.series_path)): |
|
73 | if os.path.exists(self.join(self.series_path)): | |
74 | self.full_series = self.opener(self.series_path).read().splitlines() |
|
74 | self.full_series = self.opener(self.series_path).read().splitlines() | |
75 | self.parse_series() |
|
75 | self.parse_series() | |
76 |
|
76 | |||
77 | if os.path.exists(self.join(self.status_path)): |
|
77 | if os.path.exists(self.join(self.status_path)): | |
78 | lines = self.opener(self.status_path).read().splitlines() |
|
78 | lines = self.opener(self.status_path).read().splitlines() | |
79 | self.applied = [statusentry(l) for l in lines] |
|
79 | self.applied = [statusentry(l) for l in lines] | |
80 |
|
80 | |||
81 | def diffopts(self): |
|
81 | def diffopts(self): | |
82 | if self._diffopts is None: |
|
82 | if self._diffopts is None: | |
83 | self._diffopts = patch.diffopts(self.ui) |
|
83 | self._diffopts = patch.diffopts(self.ui) | |
84 | return self._diffopts |
|
84 | return self._diffopts | |
85 |
|
85 | |||
86 | def join(self, *p): |
|
86 | def join(self, *p): | |
87 | return os.path.join(self.path, *p) |
|
87 | return os.path.join(self.path, *p) | |
88 |
|
88 | |||
89 | def find_series(self, patch): |
|
89 | def find_series(self, patch): | |
90 | pre = re.compile("(\s*)([^#]+)") |
|
90 | pre = re.compile("(\s*)([^#]+)") | |
91 | index = 0 |
|
91 | index = 0 | |
92 | for l in self.full_series: |
|
92 | for l in self.full_series: | |
93 | m = pre.match(l) |
|
93 | m = pre.match(l) | |
94 | if m: |
|
94 | if m: | |
95 | s = m.group(2) |
|
95 | s = m.group(2) | |
96 | s = s.rstrip() |
|
96 | s = s.rstrip() | |
97 | if s == patch: |
|
97 | if s == patch: | |
98 | return index |
|
98 | return index | |
99 | index += 1 |
|
99 | index += 1 | |
100 | return None |
|
100 | return None | |
101 |
|
101 | |||
102 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') |
|
102 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') | |
103 |
|
103 | |||
104 | def parse_series(self): |
|
104 | def parse_series(self): | |
105 | self.series = [] |
|
105 | self.series = [] | |
106 | self.series_guards = [] |
|
106 | self.series_guards = [] | |
107 | for l in self.full_series: |
|
107 | for l in self.full_series: | |
108 | h = l.find('#') |
|
108 | h = l.find('#') | |
109 | if h == -1: |
|
109 | if h == -1: | |
110 | patch = l |
|
110 | patch = l | |
111 | comment = '' |
|
111 | comment = '' | |
112 | elif h == 0: |
|
112 | elif h == 0: | |
113 | continue |
|
113 | continue | |
114 | else: |
|
114 | else: | |
115 | patch = l[:h] |
|
115 | patch = l[:h] | |
116 | comment = l[h:] |
|
116 | comment = l[h:] | |
117 | patch = patch.strip() |
|
117 | patch = patch.strip() | |
118 | if patch: |
|
118 | if patch: | |
119 | if patch in self.series: |
|
119 | if patch in self.series: | |
120 | raise util.Abort(_('%s appears more than once in %s') % |
|
120 | raise util.Abort(_('%s appears more than once in %s') % | |
121 | (patch, self.join(self.series_path))) |
|
121 | (patch, self.join(self.series_path))) | |
122 | self.series.append(patch) |
|
122 | self.series.append(patch) | |
123 | self.series_guards.append(self.guard_re.findall(comment)) |
|
123 | self.series_guards.append(self.guard_re.findall(comment)) | |
124 |
|
124 | |||
125 | def check_guard(self, guard): |
|
125 | def check_guard(self, guard): | |
126 | bad_chars = '# \t\r\n\f' |
|
126 | bad_chars = '# \t\r\n\f' | |
127 | first = guard[0] |
|
127 | first = guard[0] | |
128 | for c in '-+': |
|
128 | for c in '-+': | |
129 | if first == c: |
|
129 | if first == c: | |
130 | return (_('guard %r starts with invalid character: %r') % |
|
130 | return (_('guard %r starts with invalid character: %r') % | |
131 | (guard, c)) |
|
131 | (guard, c)) | |
132 | for c in bad_chars: |
|
132 | for c in bad_chars: | |
133 | if c in guard: |
|
133 | if c in guard: | |
134 | return _('invalid character in guard %r: %r') % (guard, c) |
|
134 | return _('invalid character in guard %r: %r') % (guard, c) | |
135 |
|
135 | |||
136 | def set_active(self, guards): |
|
136 | def set_active(self, guards): | |
137 | for guard in guards: |
|
137 | for guard in guards: | |
138 | bad = self.check_guard(guard) |
|
138 | bad = self.check_guard(guard) | |
139 | if bad: |
|
139 | if bad: | |
140 | raise util.Abort(bad) |
|
140 | raise util.Abort(bad) | |
141 | guards = dict.fromkeys(guards).keys() |
|
141 | guards = dict.fromkeys(guards).keys() | |
142 | guards.sort() |
|
142 | guards.sort() | |
143 | self.ui.debug('active guards: %s\n' % ' '.join(guards)) |
|
143 | self.ui.debug('active guards: %s\n' % ' '.join(guards)) | |
144 | self.active_guards = guards |
|
144 | self.active_guards = guards | |
145 | self.guards_dirty = True |
|
145 | self.guards_dirty = True | |
146 |
|
146 | |||
147 | def active(self): |
|
147 | def active(self): | |
148 | if self.active_guards is None: |
|
148 | if self.active_guards is None: | |
149 | self.active_guards = [] |
|
149 | self.active_guards = [] | |
150 | try: |
|
150 | try: | |
151 | guards = self.opener(self.guards_path).read().split() |
|
151 | guards = self.opener(self.guards_path).read().split() | |
152 | except IOError, err: |
|
152 | except IOError, err: | |
153 | if err.errno != errno.ENOENT: raise |
|
153 | if err.errno != errno.ENOENT: raise | |
154 | guards = [] |
|
154 | guards = [] | |
155 | for i, guard in enumerate(guards): |
|
155 | for i, guard in enumerate(guards): | |
156 | bad = self.check_guard(guard) |
|
156 | bad = self.check_guard(guard) | |
157 | if bad: |
|
157 | if bad: | |
158 | self.ui.warn('%s:%d: %s\n' % |
|
158 | self.ui.warn('%s:%d: %s\n' % | |
159 | (self.join(self.guards_path), i + 1, bad)) |
|
159 | (self.join(self.guards_path), i + 1, bad)) | |
160 | else: |
|
160 | else: | |
161 | self.active_guards.append(guard) |
|
161 | self.active_guards.append(guard) | |
162 | return self.active_guards |
|
162 | return self.active_guards | |
163 |
|
163 | |||
164 | def set_guards(self, idx, guards): |
|
164 | def set_guards(self, idx, guards): | |
165 | for g in guards: |
|
165 | for g in guards: | |
166 | if len(g) < 2: |
|
166 | if len(g) < 2: | |
167 | raise util.Abort(_('guard %r too short') % g) |
|
167 | raise util.Abort(_('guard %r too short') % g) | |
168 | if g[0] not in '-+': |
|
168 | if g[0] not in '-+': | |
169 | raise util.Abort(_('guard %r starts with invalid char') % g) |
|
169 | raise util.Abort(_('guard %r starts with invalid char') % g) | |
170 | bad = self.check_guard(g[1:]) |
|
170 | bad = self.check_guard(g[1:]) | |
171 | if bad: |
|
171 | if bad: | |
172 | raise util.Abort(bad) |
|
172 | raise util.Abort(bad) | |
173 | drop = self.guard_re.sub('', self.full_series[idx]) |
|
173 | drop = self.guard_re.sub('', self.full_series[idx]) | |
174 | self.full_series[idx] = drop + ''.join([' #' + g for g in guards]) |
|
174 | self.full_series[idx] = drop + ''.join([' #' + g for g in guards]) | |
175 | self.parse_series() |
|
175 | self.parse_series() | |
176 | self.series_dirty = True |
|
176 | self.series_dirty = True | |
177 |
|
177 | |||
178 | def pushable(self, idx): |
|
178 | def pushable(self, idx): | |
179 | if isinstance(idx, str): |
|
179 | if isinstance(idx, str): | |
180 | idx = self.series.index(idx) |
|
180 | idx = self.series.index(idx) | |
181 | patchguards = self.series_guards[idx] |
|
181 | patchguards = self.series_guards[idx] | |
182 | if not patchguards: |
|
182 | if not patchguards: | |
183 | return True, None |
|
183 | return True, None | |
184 | default = False |
|
184 | default = False | |
185 | guards = self.active() |
|
185 | guards = self.active() | |
186 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] |
|
186 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] | |
187 | if exactneg: |
|
187 | if exactneg: | |
188 | return False, exactneg[0] |
|
188 | return False, exactneg[0] | |
189 | pos = [g for g in patchguards if g[0] == '+'] |
|
189 | pos = [g for g in patchguards if g[0] == '+'] | |
190 | exactpos = [g for g in pos if g[1:] in guards] |
|
190 | exactpos = [g for g in pos if g[1:] in guards] | |
191 | if pos: |
|
191 | if pos: | |
192 | if exactpos: |
|
192 | if exactpos: | |
193 | return True, exactpos[0] |
|
193 | return True, exactpos[0] | |
194 | return False, pos |
|
194 | return False, pos | |
195 | return True, '' |
|
195 | return True, '' | |
196 |
|
196 | |||
197 | def explain_pushable(self, idx, all_patches=False): |
|
197 | def explain_pushable(self, idx, all_patches=False): | |
198 | write = all_patches and self.ui.write or self.ui.warn |
|
198 | write = all_patches and self.ui.write or self.ui.warn | |
199 | if all_patches or self.ui.verbose: |
|
199 | if all_patches or self.ui.verbose: | |
200 | if isinstance(idx, str): |
|
200 | if isinstance(idx, str): | |
201 | idx = self.series.index(idx) |
|
201 | idx = self.series.index(idx) | |
202 | pushable, why = self.pushable(idx) |
|
202 | pushable, why = self.pushable(idx) | |
203 | if all_patches and pushable: |
|
203 | if all_patches and pushable: | |
204 | if why is None: |
|
204 | if why is None: | |
205 | write(_('allowing %s - no guards in effect\n') % |
|
205 | write(_('allowing %s - no guards in effect\n') % | |
206 | self.series[idx]) |
|
206 | self.series[idx]) | |
207 | else: |
|
207 | else: | |
208 | if not why: |
|
208 | if not why: | |
209 | write(_('allowing %s - no matching negative guards\n') % |
|
209 | write(_('allowing %s - no matching negative guards\n') % | |
210 | self.series[idx]) |
|
210 | self.series[idx]) | |
211 | else: |
|
211 | else: | |
212 | write(_('allowing %s - guarded by %r\n') % |
|
212 | write(_('allowing %s - guarded by %r\n') % | |
213 | (self.series[idx], why)) |
|
213 | (self.series[idx], why)) | |
214 | if not pushable: |
|
214 | if not pushable: | |
215 | if why: |
|
215 | if why: | |
216 | write(_('skipping %s - guarded by %r\n') % |
|
216 | write(_('skipping %s - guarded by %r\n') % | |
217 | (self.series[idx], why)) |
|
217 | (self.series[idx], why)) | |
218 | else: |
|
218 | else: | |
219 | write(_('skipping %s - no matching guards\n') % |
|
219 | write(_('skipping %s - no matching guards\n') % | |
220 | self.series[idx]) |
|
220 | self.series[idx]) | |
221 |
|
221 | |||
222 | def save_dirty(self): |
|
222 | def save_dirty(self): | |
223 | def write_list(items, path): |
|
223 | def write_list(items, path): | |
224 | fp = self.opener(path, 'w') |
|
224 | fp = self.opener(path, 'w') | |
225 | for i in items: |
|
225 | for i in items: | |
226 | print >> fp, i |
|
226 | print >> fp, i | |
227 | fp.close() |
|
227 | fp.close() | |
228 | if self.applied_dirty: write_list(map(str, self.applied), self.status_path) |
|
228 | if self.applied_dirty: write_list(map(str, self.applied), self.status_path) | |
229 | if self.series_dirty: write_list(self.full_series, self.series_path) |
|
229 | if self.series_dirty: write_list(self.full_series, self.series_path) | |
230 | if self.guards_dirty: write_list(self.active_guards, self.guards_path) |
|
230 | if self.guards_dirty: write_list(self.active_guards, self.guards_path) | |
231 |
|
231 | |||
232 | def readheaders(self, patch): |
|
232 | def readheaders(self, patch): | |
233 | def eatdiff(lines): |
|
233 | def eatdiff(lines): | |
234 | while lines: |
|
234 | while lines: | |
235 | l = lines[-1] |
|
235 | l = lines[-1] | |
236 | if (l.startswith("diff -") or |
|
236 | if (l.startswith("diff -") or | |
237 | l.startswith("Index:") or |
|
237 | l.startswith("Index:") or | |
238 | l.startswith("===========")): |
|
238 | l.startswith("===========")): | |
239 | del lines[-1] |
|
239 | del lines[-1] | |
240 | else: |
|
240 | else: | |
241 | break |
|
241 | break | |
242 | def eatempty(lines): |
|
242 | def eatempty(lines): | |
243 | while lines: |
|
243 | while lines: | |
244 | l = lines[-1] |
|
244 | l = lines[-1] | |
245 | if re.match('\s*$', l): |
|
245 | if re.match('\s*$', l): | |
246 | del lines[-1] |
|
246 | del lines[-1] | |
247 | else: |
|
247 | else: | |
248 | break |
|
248 | break | |
249 |
|
249 | |||
250 | pf = self.join(patch) |
|
250 | pf = self.join(patch) | |
251 | message = [] |
|
251 | message = [] | |
252 | comments = [] |
|
252 | comments = [] | |
253 | user = None |
|
253 | user = None | |
254 | date = None |
|
254 | date = None | |
255 | format = None |
|
255 | format = None | |
256 | subject = None |
|
256 | subject = None | |
257 | diffstart = 0 |
|
257 | diffstart = 0 | |
258 |
|
258 | |||
259 | for line in file(pf): |
|
259 | for line in file(pf): | |
260 | line = line.rstrip() |
|
260 | line = line.rstrip() | |
261 | if line.startswith('diff --git'): |
|
261 | if line.startswith('diff --git'): | |
262 | diffstart = 2 |
|
262 | diffstart = 2 | |
263 | break |
|
263 | break | |
264 | if diffstart: |
|
264 | if diffstart: | |
265 | if line.startswith('+++ '): |
|
265 | if line.startswith('+++ '): | |
266 | diffstart = 2 |
|
266 | diffstart = 2 | |
267 | break |
|
267 | break | |
268 | if line.startswith("--- "): |
|
268 | if line.startswith("--- "): | |
269 | diffstart = 1 |
|
269 | diffstart = 1 | |
270 | continue |
|
270 | continue | |
271 | elif format == "hgpatch": |
|
271 | elif format == "hgpatch": | |
272 | # parse values when importing the result of an hg export |
|
272 | # parse values when importing the result of an hg export | |
273 | if line.startswith("# User "): |
|
273 | if line.startswith("# User "): | |
274 | user = line[7:] |
|
274 | user = line[7:] | |
275 | elif line.startswith("# Date "): |
|
275 | elif line.startswith("# Date "): | |
276 | date = line[7:] |
|
276 | date = line[7:] | |
277 | elif not line.startswith("# ") and line: |
|
277 | elif not line.startswith("# ") and line: | |
278 | message.append(line) |
|
278 | message.append(line) | |
279 | format = None |
|
279 | format = None | |
280 | elif line == '# HG changeset patch': |
|
280 | elif line == '# HG changeset patch': | |
281 | format = "hgpatch" |
|
281 | format = "hgpatch" | |
282 | elif (format != "tagdone" and (line.startswith("Subject: ") or |
|
282 | elif (format != "tagdone" and (line.startswith("Subject: ") or | |
283 | line.startswith("subject: "))): |
|
283 | line.startswith("subject: "))): | |
284 | subject = line[9:] |
|
284 | subject = line[9:] | |
285 | format = "tag" |
|
285 | format = "tag" | |
286 | elif (format != "tagdone" and (line.startswith("From: ") or |
|
286 | elif (format != "tagdone" and (line.startswith("From: ") or | |
287 | line.startswith("from: "))): |
|
287 | line.startswith("from: "))): | |
288 | user = line[6:] |
|
288 | user = line[6:] | |
289 | format = "tag" |
|
289 | format = "tag" | |
290 | elif format == "tag" and line == "": |
|
290 | elif format == "tag" and line == "": | |
291 | # when looking for tags (subject: from: etc) they |
|
291 | # when looking for tags (subject: from: etc) they | |
292 | # end once you find a blank line in the source |
|
292 | # end once you find a blank line in the source | |
293 | format = "tagdone" |
|
293 | format = "tagdone" | |
294 | elif message or line: |
|
294 | elif message or line: | |
295 | message.append(line) |
|
295 | message.append(line) | |
296 | comments.append(line) |
|
296 | comments.append(line) | |
297 |
|
297 | |||
298 | eatdiff(message) |
|
298 | eatdiff(message) | |
299 | eatdiff(comments) |
|
299 | eatdiff(comments) | |
300 | eatempty(message) |
|
300 | eatempty(message) | |
301 | eatempty(comments) |
|
301 | eatempty(comments) | |
302 |
|
302 | |||
303 | # make sure message isn't empty |
|
303 | # make sure message isn't empty | |
304 | if format and format.startswith("tag") and subject: |
|
304 | if format and format.startswith("tag") and subject: | |
305 | message.insert(0, "") |
|
305 | message.insert(0, "") | |
306 | message.insert(0, subject) |
|
306 | message.insert(0, subject) | |
307 | return (message, comments, user, date, diffstart > 1) |
|
307 | return (message, comments, user, date, diffstart > 1) | |
308 |
|
308 | |||
309 | def printdiff(self, repo, node1, node2=None, files=None, |
|
309 | def printdiff(self, repo, node1, node2=None, files=None, | |
310 | fp=None, changes=None, opts={}): |
|
310 | fp=None, changes=None, opts={}): | |
311 | fns, matchfn, anypats = cmdutil.matchpats(repo, files, opts) |
|
311 | fns, matchfn, anypats = cmdutil.matchpats(repo, files, opts) | |
312 |
|
312 | |||
313 | patch.diff(repo, node1, node2, fns, match=matchfn, |
|
313 | patch.diff(repo, node1, node2, fns, match=matchfn, | |
314 | fp=fp, changes=changes, opts=self.diffopts()) |
|
314 | fp=fp, changes=changes, opts=self.diffopts()) | |
315 |
|
315 | |||
316 | def mergeone(self, repo, mergeq, head, patch, rev, wlock): |
|
316 | def mergeone(self, repo, mergeq, head, patch, rev, wlock): | |
317 | # first try just applying the patch |
|
317 | # first try just applying the patch | |
318 | (err, n) = self.apply(repo, [ patch ], update_status=False, |
|
318 | (err, n) = self.apply(repo, [ patch ], update_status=False, | |
319 | strict=True, merge=rev, wlock=wlock) |
|
319 | strict=True, merge=rev, wlock=wlock) | |
320 |
|
320 | |||
321 | if err == 0: |
|
321 | if err == 0: | |
322 | return (err, n) |
|
322 | return (err, n) | |
323 |
|
323 | |||
324 | if n is None: |
|
324 | if n is None: | |
325 | raise util.Abort(_("apply failed for patch %s") % patch) |
|
325 | raise util.Abort(_("apply failed for patch %s") % patch) | |
326 |
|
326 | |||
327 | self.ui.warn("patch didn't work out, merging %s\n" % patch) |
|
327 | self.ui.warn("patch didn't work out, merging %s\n" % patch) | |
328 |
|
328 | |||
329 | # apply failed, strip away that rev and merge. |
|
329 | # apply failed, strip away that rev and merge. | |
330 | hg.clean(repo, head, wlock=wlock) |
|
330 | hg.clean(repo, head, wlock=wlock) | |
331 | self.strip(repo, n, update=False, backup='strip', wlock=wlock) |
|
331 | self.strip(repo, n, update=False, backup='strip', wlock=wlock) | |
332 |
|
332 | |||
333 | ctx = repo.changectx(rev) |
|
333 | ctx = repo.changectx(rev) | |
334 | ret = hg.merge(repo, rev, wlock=wlock) |
|
334 | ret = hg.merge(repo, rev, wlock=wlock) | |
335 | if ret: |
|
335 | if ret: | |
336 | raise util.Abort(_("update returned %d") % ret) |
|
336 | raise util.Abort(_("update returned %d") % ret) | |
337 | n = repo.commit(None, ctx.description(), ctx.user(), |
|
337 | n = repo.commit(None, ctx.description(), ctx.user(), | |
338 | force=1, wlock=wlock) |
|
338 | force=1, wlock=wlock) | |
339 | if n == None: |
|
339 | if n == None: | |
340 | raise util.Abort(_("repo commit failed")) |
|
340 | raise util.Abort(_("repo commit failed")) | |
341 | try: |
|
341 | try: | |
342 | message, comments, user, date, patchfound = mergeq.readheaders(patch) |
|
342 | message, comments, user, date, patchfound = mergeq.readheaders(patch) | |
343 | except: |
|
343 | except: | |
344 | raise util.Abort(_("unable to read %s") % patch) |
|
344 | raise util.Abort(_("unable to read %s") % patch) | |
345 |
|
345 | |||
346 | patchf = self.opener(patch, "w") |
|
346 | patchf = self.opener(patch, "w") | |
347 | if comments: |
|
347 | if comments: | |
348 | comments = "\n".join(comments) + '\n\n' |
|
348 | comments = "\n".join(comments) + '\n\n' | |
349 | patchf.write(comments) |
|
349 | patchf.write(comments) | |
350 | self.printdiff(repo, head, n, fp=patchf) |
|
350 | self.printdiff(repo, head, n, fp=patchf) | |
351 | patchf.close() |
|
351 | patchf.close() | |
352 | return (0, n) |
|
352 | return (0, n) | |
353 |
|
353 | |||
354 | def qparents(self, repo, rev=None): |
|
354 | def qparents(self, repo, rev=None): | |
355 | if rev is None: |
|
355 | if rev is None: | |
356 | (p1, p2) = repo.dirstate.parents() |
|
356 | (p1, p2) = repo.dirstate.parents() | |
357 | if p2 == revlog.nullid: |
|
357 | if p2 == revlog.nullid: | |
358 | return p1 |
|
358 | return p1 | |
359 | if len(self.applied) == 0: |
|
359 | if len(self.applied) == 0: | |
360 | return None |
|
360 | return None | |
361 | return revlog.bin(self.applied[-1].rev) |
|
361 | return revlog.bin(self.applied[-1].rev) | |
362 | pp = repo.changelog.parents(rev) |
|
362 | pp = repo.changelog.parents(rev) | |
363 | if pp[1] != revlog.nullid: |
|
363 | if pp[1] != revlog.nullid: | |
364 | arevs = [ x.rev for x in self.applied ] |
|
364 | arevs = [ x.rev for x in self.applied ] | |
365 | p0 = revlog.hex(pp[0]) |
|
365 | p0 = revlog.hex(pp[0]) | |
366 | p1 = revlog.hex(pp[1]) |
|
366 | p1 = revlog.hex(pp[1]) | |
367 | if p0 in arevs: |
|
367 | if p0 in arevs: | |
368 | return pp[0] |
|
368 | return pp[0] | |
369 | if p1 in arevs: |
|
369 | if p1 in arevs: | |
370 | return pp[1] |
|
370 | return pp[1] | |
371 | return pp[0] |
|
371 | return pp[0] | |
372 |
|
372 | |||
373 | def mergepatch(self, repo, mergeq, series, wlock): |
|
373 | def mergepatch(self, repo, mergeq, series, wlock): | |
374 | if len(self.applied) == 0: |
|
374 | if len(self.applied) == 0: | |
375 | # each of the patches merged in will have two parents. This |
|
375 | # each of the patches merged in will have two parents. This | |
376 | # can confuse the qrefresh, qdiff, and strip code because it |
|
376 | # can confuse the qrefresh, qdiff, and strip code because it | |
377 | # needs to know which parent is actually in the patch queue. |
|
377 | # needs to know which parent is actually in the patch queue. | |
378 | # so, we insert a merge marker with only one parent. This way |
|
378 | # so, we insert a merge marker with only one parent. This way | |
379 | # the first patch in the queue is never a merge patch |
|
379 | # the first patch in the queue is never a merge patch | |
380 | # |
|
380 | # | |
381 | pname = ".hg.patches.merge.marker" |
|
381 | pname = ".hg.patches.merge.marker" | |
382 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1, |
|
382 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1, | |
383 | wlock=wlock) |
|
383 | wlock=wlock) | |
384 | self.applied.append(statusentry(revlog.hex(n), pname)) |
|
384 | self.applied.append(statusentry(revlog.hex(n), pname)) | |
385 | self.applied_dirty = 1 |
|
385 | self.applied_dirty = 1 | |
386 |
|
386 | |||
387 | head = self.qparents(repo) |
|
387 | head = self.qparents(repo) | |
388 |
|
388 | |||
389 | for patch in series: |
|
389 | for patch in series: | |
390 | patch = mergeq.lookup(patch, strict=True) |
|
390 | patch = mergeq.lookup(patch, strict=True) | |
391 | if not patch: |
|
391 | if not patch: | |
392 | self.ui.warn("patch %s does not exist\n" % patch) |
|
392 | self.ui.warn("patch %s does not exist\n" % patch) | |
393 | return (1, None) |
|
393 | return (1, None) | |
394 | pushable, reason = self.pushable(patch) |
|
394 | pushable, reason = self.pushable(patch) | |
395 | if not pushable: |
|
395 | if not pushable: | |
396 | self.explain_pushable(patch, all_patches=True) |
|
396 | self.explain_pushable(patch, all_patches=True) | |
397 | continue |
|
397 | continue | |
398 | info = mergeq.isapplied(patch) |
|
398 | info = mergeq.isapplied(patch) | |
399 | if not info: |
|
399 | if not info: | |
400 | self.ui.warn("patch %s is not applied\n" % patch) |
|
400 | self.ui.warn("patch %s is not applied\n" % patch) | |
401 | return (1, None) |
|
401 | return (1, None) | |
402 | rev = revlog.bin(info[1]) |
|
402 | rev = revlog.bin(info[1]) | |
403 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) |
|
403 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) | |
404 | if head: |
|
404 | if head: | |
405 | self.applied.append(statusentry(revlog.hex(head), patch)) |
|
405 | self.applied.append(statusentry(revlog.hex(head), patch)) | |
406 | self.applied_dirty = 1 |
|
406 | self.applied_dirty = 1 | |
407 | if err: |
|
407 | if err: | |
408 | return (err, head) |
|
408 | return (err, head) | |
409 | return (0, head) |
|
409 | return (0, head) | |
410 |
|
410 | |||
411 | def patch(self, repo, patchfile): |
|
411 | def patch(self, repo, patchfile): | |
412 | '''Apply patchfile to the working directory. |
|
412 | '''Apply patchfile to the working directory. | |
413 | patchfile: file name of patch''' |
|
413 | patchfile: file name of patch''' | |
414 | files = {} |
|
414 | files = {} | |
415 | try: |
|
415 | try: | |
416 | fuzz = patch.patch(patchfile, self.ui, strip=1, cwd=repo.root, |
|
416 | fuzz = patch.patch(patchfile, self.ui, strip=1, cwd=repo.root, | |
417 | files=files) |
|
417 | files=files) | |
418 | except Exception, inst: |
|
418 | except Exception, inst: | |
419 | self.ui.note(str(inst) + '\n') |
|
419 | self.ui.note(str(inst) + '\n') | |
420 | if not self.ui.verbose: |
|
420 | if not self.ui.verbose: | |
421 | self.ui.warn("patch failed, unable to continue (try -v)\n") |
|
421 | self.ui.warn("patch failed, unable to continue (try -v)\n") | |
422 | return (False, files, False) |
|
422 | return (False, files, False) | |
423 |
|
423 | |||
424 | return (True, files, fuzz) |
|
424 | return (True, files, fuzz) | |
425 |
|
425 | |||
426 | def apply(self, repo, series, list=False, update_status=True, |
|
426 | def apply(self, repo, series, list=False, update_status=True, | |
427 | strict=False, patchdir=None, merge=None, wlock=None): |
|
427 | strict=False, patchdir=None, merge=None, wlock=None): | |
428 | # TODO unify with commands.py |
|
428 | # TODO unify with commands.py | |
429 | if not patchdir: |
|
429 | if not patchdir: | |
430 | patchdir = self.path |
|
430 | patchdir = self.path | |
431 | err = 0 |
|
431 | err = 0 | |
432 | if not wlock: |
|
432 | if not wlock: | |
433 | wlock = repo.wlock() |
|
433 | wlock = repo.wlock() | |
434 | lock = repo.lock() |
|
434 | lock = repo.lock() | |
435 | tr = repo.transaction() |
|
435 | tr = repo.transaction() | |
436 | n = None |
|
436 | n = None | |
437 | for patchname in series: |
|
437 | for patchname in series: | |
438 | pushable, reason = self.pushable(patchname) |
|
438 | pushable, reason = self.pushable(patchname) | |
439 | if not pushable: |
|
439 | if not pushable: | |
440 | self.explain_pushable(patchname, all_patches=True) |
|
440 | self.explain_pushable(patchname, all_patches=True) | |
441 | continue |
|
441 | continue | |
442 | self.ui.warn("applying %s\n" % patchname) |
|
442 | self.ui.warn("applying %s\n" % patchname) | |
443 | pf = os.path.join(patchdir, patchname) |
|
443 | pf = os.path.join(patchdir, patchname) | |
444 |
|
444 | |||
445 | try: |
|
445 | try: | |
446 | message, comments, user, date, patchfound = self.readheaders(patchname) |
|
446 | message, comments, user, date, patchfound = self.readheaders(patchname) | |
447 | except: |
|
447 | except: | |
448 | self.ui.warn("Unable to read %s\n" % patchname) |
|
448 | self.ui.warn("Unable to read %s\n" % patchname) | |
449 | err = 1 |
|
449 | err = 1 | |
450 | break |
|
450 | break | |
451 |
|
451 | |||
452 | if not message: |
|
452 | if not message: | |
453 | message = "imported patch %s\n" % patchname |
|
453 | message = "imported patch %s\n" % patchname | |
454 | else: |
|
454 | else: | |
455 | if list: |
|
455 | if list: | |
456 | message.append("\nimported patch %s" % patchname) |
|
456 | message.append("\nimported patch %s" % patchname) | |
457 | message = '\n'.join(message) |
|
457 | message = '\n'.join(message) | |
458 |
|
458 | |||
459 | (patcherr, files, fuzz) = self.patch(repo, pf) |
|
459 | (patcherr, files, fuzz) = self.patch(repo, pf) | |
460 | patcherr = not patcherr |
|
460 | patcherr = not patcherr | |
461 |
|
461 | |||
462 | if merge and files: |
|
462 | if merge and files: | |
463 | # Mark as merged and update dirstate parent info |
|
463 | # Mark as merged and update dirstate parent info | |
464 | repo.dirstate.update(repo.dirstate.filterfiles(files.keys()), 'm') |
|
464 | repo.dirstate.update(repo.dirstate.filterfiles(files.keys()), 'm') | |
465 | p1, p2 = repo.dirstate.parents() |
|
465 | p1, p2 = repo.dirstate.parents() | |
466 | repo.dirstate.setparents(p1, merge) |
|
466 | repo.dirstate.setparents(p1, merge) | |
467 | files = patch.updatedir(self.ui, repo, files, wlock=wlock) |
|
467 | files = patch.updatedir(self.ui, repo, files, wlock=wlock) | |
468 | n = repo.commit(files, message, user, date, force=1, lock=lock, |
|
468 | n = repo.commit(files, message, user, date, force=1, lock=lock, | |
469 | wlock=wlock) |
|
469 | wlock=wlock) | |
470 |
|
470 | |||
471 | if n == None: |
|
471 | if n == None: | |
472 | raise util.Abort(_("repo commit failed")) |
|
472 | raise util.Abort(_("repo commit failed")) | |
473 |
|
473 | |||
474 | if update_status: |
|
474 | if update_status: | |
475 | self.applied.append(statusentry(revlog.hex(n), patchname)) |
|
475 | self.applied.append(statusentry(revlog.hex(n), patchname)) | |
476 |
|
476 | |||
477 | if patcherr: |
|
477 | if patcherr: | |
478 | if not patchfound: |
|
478 | if not patchfound: | |
479 | self.ui.warn("patch %s is empty\n" % patchname) |
|
479 | self.ui.warn("patch %s is empty\n" % patchname) | |
480 | err = 0 |
|
480 | err = 0 | |
481 | else: |
|
481 | else: | |
482 | self.ui.warn("patch failed, rejects left in working dir\n") |
|
482 | self.ui.warn("patch failed, rejects left in working dir\n") | |
483 | err = 1 |
|
483 | err = 1 | |
484 | break |
|
484 | break | |
485 |
|
485 | |||
486 | if fuzz and strict: |
|
486 | if fuzz and strict: | |
487 | self.ui.warn("fuzz found when applying patch, stopping\n") |
|
487 | self.ui.warn("fuzz found when applying patch, stopping\n") | |
488 | err = 1 |
|
488 | err = 1 | |
489 | break |
|
489 | break | |
490 | tr.close() |
|
490 | tr.close() | |
491 | return (err, n) |
|
491 | return (err, n) | |
492 |
|
492 | |||
493 | def delete(self, repo, patches, opts): |
|
493 | def delete(self, repo, patches, opts): | |
494 | realpatches = [] |
|
494 | realpatches = [] | |
495 | for patch in patches: |
|
495 | for patch in patches: | |
496 | patch = self.lookup(patch, strict=True) |
|
496 | patch = self.lookup(patch, strict=True) | |
497 | info = self.isapplied(patch) |
|
497 | info = self.isapplied(patch) | |
498 | if info: |
|
498 | if info: | |
499 | raise util.Abort(_("cannot delete applied patch %s") % patch) |
|
499 | raise util.Abort(_("cannot delete applied patch %s") % patch) | |
500 | if patch not in self.series: |
|
500 | if patch not in self.series: | |
501 | raise util.Abort(_("patch %s not in series file") % patch) |
|
501 | raise util.Abort(_("patch %s not in series file") % patch) | |
502 | realpatches.append(patch) |
|
502 | realpatches.append(patch) | |
503 |
|
503 | |||
504 | appliedbase = 0 |
|
504 | appliedbase = 0 | |
505 | if opts.get('rev'): |
|
505 | if opts.get('rev'): | |
506 | if not self.applied: |
|
506 | if not self.applied: | |
507 | raise util.Abort(_('no patches applied')) |
|
507 | raise util.Abort(_('no patches applied')) | |
508 | revs = cmdutil.revrange(repo, opts['rev']) |
|
508 | revs = cmdutil.revrange(repo, opts['rev']) | |
509 | if len(revs) > 1 and revs[0] > revs[1]: |
|
509 | if len(revs) > 1 and revs[0] > revs[1]: | |
510 | revs.reverse() |
|
510 | revs.reverse() | |
511 | for rev in revs: |
|
511 | for rev in revs: | |
512 | if appliedbase >= len(self.applied): |
|
512 | if appliedbase >= len(self.applied): | |
513 | raise util.Abort(_("revision %d is not managed") % rev) |
|
513 | raise util.Abort(_("revision %d is not managed") % rev) | |
514 |
|
514 | |||
515 | base = revlog.bin(self.applied[appliedbase].rev) |
|
515 | base = revlog.bin(self.applied[appliedbase].rev) | |
516 | node = repo.changelog.node(rev) |
|
516 | node = repo.changelog.node(rev) | |
517 | if node != base: |
|
517 | if node != base: | |
518 | raise util.Abort(_("cannot delete revision %d above " |
|
518 | raise util.Abort(_("cannot delete revision %d above " | |
519 | "applied patches") % rev) |
|
519 | "applied patches") % rev) | |
520 | realpatches.append(self.applied[appliedbase].name) |
|
520 | realpatches.append(self.applied[appliedbase].name) | |
521 | appliedbase += 1 |
|
521 | appliedbase += 1 | |
522 |
|
522 | |||
523 | if not opts.get('keep'): |
|
523 | if not opts.get('keep'): | |
524 | r = self.qrepo() |
|
524 | r = self.qrepo() | |
525 | if r: |
|
525 | if r: | |
526 | r.remove(realpatches, True) |
|
526 | r.remove(realpatches, True) | |
527 | else: |
|
527 | else: | |
528 | for p in realpatches: |
|
528 | for p in realpatches: | |
529 | os.unlink(self.join(p)) |
|
529 | os.unlink(self.join(p)) | |
530 |
|
530 | |||
531 | if appliedbase: |
|
531 | if appliedbase: | |
532 | del self.applied[:appliedbase] |
|
532 | del self.applied[:appliedbase] | |
533 | self.applied_dirty = 1 |
|
533 | self.applied_dirty = 1 | |
534 | indices = [self.find_series(p) for p in realpatches] |
|
534 | indices = [self.find_series(p) for p in realpatches] | |
535 | indices.sort() |
|
535 | indices.sort() | |
536 | for i in indices[-1::-1]: |
|
536 | for i in indices[-1::-1]: | |
537 | del self.full_series[i] |
|
537 | del self.full_series[i] | |
538 | self.parse_series() |
|
538 | self.parse_series() | |
539 | self.series_dirty = 1 |
|
539 | self.series_dirty = 1 | |
540 |
|
540 | |||
541 | def check_toppatch(self, repo): |
|
541 | def check_toppatch(self, repo): | |
542 | if len(self.applied) > 0: |
|
542 | if len(self.applied) > 0: | |
543 | top = revlog.bin(self.applied[-1].rev) |
|
543 | top = revlog.bin(self.applied[-1].rev) | |
544 | pp = repo.dirstate.parents() |
|
544 | pp = repo.dirstate.parents() | |
545 | if top not in pp: |
|
545 | if top not in pp: | |
546 | raise util.Abort(_("queue top not at same revision as working directory")) |
|
546 | raise util.Abort(_("queue top not at same revision as working directory")) | |
547 | return top |
|
547 | return top | |
548 | return None |
|
548 | return None | |
549 | def check_localchanges(self, repo, force=False, refresh=True): |
|
549 | def check_localchanges(self, repo, force=False, refresh=True): | |
550 | m, a, r, d = repo.status()[:4] |
|
550 | m, a, r, d = repo.status()[:4] | |
551 | if m or a or r or d: |
|
551 | if m or a or r or d: | |
552 | if not force: |
|
552 | if not force: | |
553 | if refresh: |
|
553 | if refresh: | |
554 | raise util.Abort(_("local changes found, refresh first")) |
|
554 | raise util.Abort(_("local changes found, refresh first")) | |
555 | else: |
|
555 | else: | |
556 | raise util.Abort(_("local changes found")) |
|
556 | raise util.Abort(_("local changes found")) | |
557 | return m, a, r, d |
|
557 | return m, a, r, d | |
558 | def new(self, repo, patch, msg=None, force=None): |
|
558 | def new(self, repo, patch, msg=None, force=None): | |
559 | if os.path.exists(self.join(patch)): |
|
559 | if os.path.exists(self.join(patch)): | |
560 | raise util.Abort(_('patch "%s" already exists') % patch) |
|
560 | raise util.Abort(_('patch "%s" already exists') % patch) | |
561 | m, a, r, d = self.check_localchanges(repo, force) |
|
561 | m, a, r, d = self.check_localchanges(repo, force) | |
562 | commitfiles = m + a + r |
|
562 | commitfiles = m + a + r | |
563 | self.check_toppatch(repo) |
|
563 | self.check_toppatch(repo) | |
564 | wlock = repo.wlock() |
|
564 | wlock = repo.wlock() | |
565 | insert = self.full_series_end() |
|
565 | insert = self.full_series_end() | |
566 | if msg: |
|
566 | if msg: | |
567 | n = repo.commit(commitfiles, "[mq]: %s" % msg, force=True, |
|
567 | n = repo.commit(commitfiles, "[mq]: %s" % msg, force=True, | |
568 | wlock=wlock) |
|
568 | wlock=wlock) | |
569 | else: |
|
569 | else: | |
570 | n = repo.commit(commitfiles, |
|
570 | n = repo.commit(commitfiles, | |
571 | "New patch: %s" % patch, force=True, wlock=wlock) |
|
571 | "New patch: %s" % patch, force=True, wlock=wlock) | |
572 | if n == None: |
|
572 | if n == None: | |
573 | raise util.Abort(_("repo commit failed")) |
|
573 | raise util.Abort(_("repo commit failed")) | |
574 | self.full_series[insert:insert] = [patch] |
|
574 | self.full_series[insert:insert] = [patch] | |
575 | self.applied.append(statusentry(revlog.hex(n), patch)) |
|
575 | self.applied.append(statusentry(revlog.hex(n), patch)) | |
576 | self.parse_series() |
|
576 | self.parse_series() | |
577 | self.series_dirty = 1 |
|
577 | self.series_dirty = 1 | |
578 | self.applied_dirty = 1 |
|
578 | self.applied_dirty = 1 | |
579 | p = self.opener(patch, "w") |
|
579 | p = self.opener(patch, "w") | |
580 | if msg: |
|
580 | if msg: | |
581 | msg = msg + "\n" |
|
581 | msg = msg + "\n" | |
582 | p.write(msg) |
|
582 | p.write(msg) | |
583 | p.close() |
|
583 | p.close() | |
584 | wlock = None |
|
584 | wlock = None | |
585 | r = self.qrepo() |
|
585 | r = self.qrepo() | |
586 | if r: r.add([patch]) |
|
586 | if r: r.add([patch]) | |
587 | if commitfiles: |
|
587 | if commitfiles: | |
588 | self.refresh(repo, short=True) |
|
588 | self.refresh(repo, short=True) | |
589 |
|
589 | |||
590 | def strip(self, repo, rev, update=True, backup="all", wlock=None): |
|
590 | def strip(self, repo, rev, update=True, backup="all", wlock=None): | |
591 | def limitheads(chlog, stop): |
|
591 | def limitheads(chlog, stop): | |
592 | """return the list of all nodes that have no children""" |
|
592 | """return the list of all nodes that have no children""" | |
593 | p = {} |
|
593 | p = {} | |
594 | h = [] |
|
594 | h = [] | |
595 | stoprev = 0 |
|
595 | stoprev = 0 | |
596 | if stop in chlog.nodemap: |
|
596 | if stop in chlog.nodemap: | |
597 | stoprev = chlog.rev(stop) |
|
597 | stoprev = chlog.rev(stop) | |
598 |
|
598 | |||
599 | for r in xrange(chlog.count() - 1, -1, -1): |
|
599 | for r in xrange(chlog.count() - 1, -1, -1): | |
600 | n = chlog.node(r) |
|
600 | n = chlog.node(r) | |
601 | if n not in p: |
|
601 | if n not in p: | |
602 | h.append(n) |
|
602 | h.append(n) | |
603 | if n == stop: |
|
603 | if n == stop: | |
604 | break |
|
604 | break | |
605 | if r < stoprev: |
|
605 | if r < stoprev: | |
606 | break |
|
606 | break | |
607 | for pn in chlog.parents(n): |
|
607 | for pn in chlog.parents(n): | |
608 | p[pn] = 1 |
|
608 | p[pn] = 1 | |
609 | return h |
|
609 | return h | |
610 |
|
610 | |||
611 | def bundle(cg): |
|
611 | def bundle(cg): | |
612 | backupdir = repo.join("strip-backup") |
|
612 | backupdir = repo.join("strip-backup") | |
613 | if not os.path.isdir(backupdir): |
|
613 | if not os.path.isdir(backupdir): | |
614 | os.mkdir(backupdir) |
|
614 | os.mkdir(backupdir) | |
615 | name = os.path.join(backupdir, "%s" % revlog.short(rev)) |
|
615 | name = os.path.join(backupdir, "%s" % revlog.short(rev)) | |
616 | name = savename(name) |
|
616 | name = savename(name) | |
617 | self.ui.warn("saving bundle to %s\n" % name) |
|
617 | self.ui.warn("saving bundle to %s\n" % name) | |
618 | return changegroup.writebundle(cg, name, "HG10BZ") |
|
618 | return changegroup.writebundle(cg, name, "HG10BZ") | |
619 |
|
619 | |||
620 | def stripall(revnum): |
|
620 | def stripall(revnum): | |
621 | mm = repo.changectx(rev).manifest() |
|
621 | mm = repo.changectx(rev).manifest() | |
622 | seen = {} |
|
622 | seen = {} | |
623 |
|
623 | |||
624 | for x in xrange(revnum, repo.changelog.count()): |
|
624 | for x in xrange(revnum, repo.changelog.count()): | |
625 | for f in repo.changectx(x).files(): |
|
625 | for f in repo.changectx(x).files(): | |
626 | if f in seen: |
|
626 | if f in seen: | |
627 | continue |
|
627 | continue | |
628 | seen[f] = 1 |
|
628 | seen[f] = 1 | |
629 | if f in mm: |
|
629 | if f in mm: | |
630 | filerev = mm[f] |
|
630 | filerev = mm[f] | |
631 | else: |
|
631 | else: | |
632 | filerev = 0 |
|
632 | filerev = 0 | |
633 | seen[f] = filerev |
|
633 | seen[f] = filerev | |
634 | # we go in two steps here so the strip loop happens in a |
|
634 | # we go in two steps here so the strip loop happens in a | |
635 | # sensible order. When stripping many files, this helps keep |
|
635 | # sensible order. When stripping many files, this helps keep | |
636 | # our disk access patterns under control. |
|
636 | # our disk access patterns under control. | |
637 | seen_list = seen.keys() |
|
637 | seen_list = seen.keys() | |
638 | seen_list.sort() |
|
638 | seen_list.sort() | |
639 | for f in seen_list: |
|
639 | for f in seen_list: | |
640 | ff = repo.file(f) |
|
640 | ff = repo.file(f) | |
641 | filerev = seen[f] |
|
641 | filerev = seen[f] | |
642 | if filerev != 0: |
|
642 | if filerev != 0: | |
643 | if filerev in ff.nodemap: |
|
643 | if filerev in ff.nodemap: | |
644 | filerev = ff.rev(filerev) |
|
644 | filerev = ff.rev(filerev) | |
645 | else: |
|
645 | else: | |
646 | filerev = 0 |
|
646 | filerev = 0 | |
647 | ff.strip(filerev, revnum) |
|
647 | ff.strip(filerev, revnum) | |
648 |
|
648 | |||
649 | if not wlock: |
|
649 | if not wlock: | |
650 | wlock = repo.wlock() |
|
650 | wlock = repo.wlock() | |
651 | lock = repo.lock() |
|
651 | lock = repo.lock() | |
652 | chlog = repo.changelog |
|
652 | chlog = repo.changelog | |
653 | # TODO delete the undo files, and handle undo of merge sets |
|
653 | # TODO delete the undo files, and handle undo of merge sets | |
654 | pp = chlog.parents(rev) |
|
654 | pp = chlog.parents(rev) | |
655 | revnum = chlog.rev(rev) |
|
655 | revnum = chlog.rev(rev) | |
656 |
|
656 | |||
657 | if update: |
|
657 | if update: | |
658 | self.check_localchanges(repo, refresh=False) |
|
658 | self.check_localchanges(repo, refresh=False) | |
659 | urev = self.qparents(repo, rev) |
|
659 | urev = self.qparents(repo, rev) | |
660 | hg.clean(repo, urev, wlock=wlock) |
|
660 | hg.clean(repo, urev, wlock=wlock) | |
661 | repo.dirstate.write() |
|
661 | repo.dirstate.write() | |
662 |
|
662 | |||
663 | # save is a list of all the branches we are truncating away |
|
663 | # save is a list of all the branches we are truncating away | |
664 | # that we actually want to keep. changegroup will be used |
|
664 | # that we actually want to keep. changegroup will be used | |
665 | # to preserve them and add them back after the truncate |
|
665 | # to preserve them and add them back after the truncate | |
666 | saveheads = [] |
|
666 | saveheads = [] | |
667 | savebases = {} |
|
667 | savebases = {} | |
668 |
|
668 | |||
669 | heads = limitheads(chlog, rev) |
|
669 | heads = limitheads(chlog, rev) | |
670 | seen = {} |
|
670 | seen = {} | |
671 |
|
671 | |||
672 | # search through all the heads, finding those where the revision |
|
672 | # search through all the heads, finding those where the revision | |
673 | # we want to strip away is an ancestor. Also look for merges |
|
673 | # we want to strip away is an ancestor. Also look for merges | |
674 | # that might be turned into new heads by the strip. |
|
674 | # that might be turned into new heads by the strip. | |
675 | while heads: |
|
675 | while heads: | |
676 | h = heads.pop() |
|
676 | h = heads.pop() | |
677 | n = h |
|
677 | n = h | |
678 | while True: |
|
678 | while True: | |
679 | seen[n] = 1 |
|
679 | seen[n] = 1 | |
680 | pp = chlog.parents(n) |
|
680 | pp = chlog.parents(n) | |
681 | if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: |
|
681 | if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: | |
682 | if pp[1] not in seen: |
|
682 | if pp[1] not in seen: | |
683 | heads.append(pp[1]) |
|
683 | heads.append(pp[1]) | |
684 | if pp[0] == revlog.nullid: |
|
684 | if pp[0] == revlog.nullid: | |
685 | break |
|
685 | break | |
686 | if chlog.rev(pp[0]) < revnum: |
|
686 | if chlog.rev(pp[0]) < revnum: | |
687 | break |
|
687 | break | |
688 | n = pp[0] |
|
688 | n = pp[0] | |
689 | if n == rev: |
|
689 | if n == rev: | |
690 | break |
|
690 | break | |
691 | r = chlog.reachable(h, rev) |
|
691 | r = chlog.reachable(h, rev) | |
692 | if rev not in r: |
|
692 | if rev not in r: | |
693 | saveheads.append(h) |
|
693 | saveheads.append(h) | |
694 | for x in r: |
|
694 | for x in r: | |
695 | if chlog.rev(x) > revnum: |
|
695 | if chlog.rev(x) > revnum: | |
696 | savebases[x] = 1 |
|
696 | savebases[x] = 1 | |
697 |
|
697 | |||
698 | # create a changegroup for all the branches we need to keep |
|
698 | # create a changegroup for all the branches we need to keep | |
699 | if backup == "all": |
|
699 | if backup == "all": | |
700 | backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') |
|
700 | backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') | |
701 | bundle(backupch) |
|
701 | bundle(backupch) | |
702 | if saveheads: |
|
702 | if saveheads: | |
703 | backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') |
|
703 | backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') | |
704 | chgrpfile = bundle(backupch) |
|
704 | chgrpfile = bundle(backupch) | |
705 |
|
705 | |||
706 | stripall(revnum) |
|
706 | stripall(revnum) | |
707 |
|
707 | |||
708 | change = chlog.read(rev) |
|
708 | change = chlog.read(rev) | |
709 | chlog.strip(revnum, revnum) |
|
709 | chlog.strip(revnum, revnum) | |
710 | repo.manifest.strip(repo.manifest.rev(change[0]), revnum) |
|
710 | repo.manifest.strip(repo.manifest.rev(change[0]), revnum) | |
711 | if saveheads: |
|
711 | if saveheads: | |
712 | self.ui.status("adding branch\n") |
|
712 | self.ui.status("adding branch\n") | |
713 | commands.unbundle(self.ui, repo, "file:%s" % chgrpfile, |
|
713 | commands.unbundle(self.ui, repo, "file:%s" % chgrpfile, | |
714 | update=False) |
|
714 | update=False) | |
715 | if backup != "strip": |
|
715 | if backup != "strip": | |
716 | os.unlink(chgrpfile) |
|
716 | os.unlink(chgrpfile) | |
717 |
|
717 | |||
718 | def isapplied(self, patch): |
|
718 | def isapplied(self, patch): | |
719 | """returns (index, rev, patch)""" |
|
719 | """returns (index, rev, patch)""" | |
720 | for i in xrange(len(self.applied)): |
|
720 | for i in xrange(len(self.applied)): | |
721 | a = self.applied[i] |
|
721 | a = self.applied[i] | |
722 | if a.name == patch: |
|
722 | if a.name == patch: | |
723 | return (i, a.rev, a.name) |
|
723 | return (i, a.rev, a.name) | |
724 | return None |
|
724 | return None | |
725 |
|
725 | |||
726 | # if the exact patch name does not exist, we try a few |
|
726 | # if the exact patch name does not exist, we try a few | |
727 | # variations. If strict is passed, we try only #1 |
|
727 | # variations. If strict is passed, we try only #1 | |
728 | # |
|
728 | # | |
729 | # 1) a number to indicate an offset in the series file |
|
729 | # 1) a number to indicate an offset in the series file | |
730 | # 2) a unique substring of the patch name was given |
|
730 | # 2) a unique substring of the patch name was given | |
731 | # 3) patchname[-+]num to indicate an offset in the series file |
|
731 | # 3) patchname[-+]num to indicate an offset in the series file | |
732 | def lookup(self, patch, strict=False): |
|
732 | def lookup(self, patch, strict=False): | |
733 | patch = patch and str(patch) |
|
733 | patch = patch and str(patch) | |
734 |
|
734 | |||
735 | def partial_name(s): |
|
735 | def partial_name(s): | |
736 | if s in self.series: |
|
736 | if s in self.series: | |
737 | return s |
|
737 | return s | |
738 | matches = [x for x in self.series if s in x] |
|
738 | matches = [x for x in self.series if s in x] | |
739 | if len(matches) > 1: |
|
739 | if len(matches) > 1: | |
740 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) |
|
740 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) | |
741 | for m in matches: |
|
741 | for m in matches: | |
742 | self.ui.warn(' %s\n' % m) |
|
742 | self.ui.warn(' %s\n' % m) | |
743 | return None |
|
743 | return None | |
744 | if matches: |
|
744 | if matches: | |
745 | return matches[0] |
|
745 | return matches[0] | |
746 | if len(self.series) > 0 and len(self.applied) > 0: |
|
746 | if len(self.series) > 0 and len(self.applied) > 0: | |
747 | if s == 'qtip': |
|
747 | if s == 'qtip': | |
748 | return self.series[self.series_end(True)-1] |
|
748 | return self.series[self.series_end(True)-1] | |
749 | if s == 'qbase': |
|
749 | if s == 'qbase': | |
750 | return self.series[0] |
|
750 | return self.series[0] | |
751 | return None |
|
751 | return None | |
752 | if patch == None: |
|
752 | if patch == None: | |
753 | return None |
|
753 | return None | |
754 |
|
754 | |||
755 | # we don't want to return a partial match until we make |
|
755 | # we don't want to return a partial match until we make | |
756 | # sure the file name passed in does not exist (checked below) |
|
756 | # sure the file name passed in does not exist (checked below) | |
757 | res = partial_name(patch) |
|
757 | res = partial_name(patch) | |
758 | if res and res == patch: |
|
758 | if res and res == patch: | |
759 | return res |
|
759 | return res | |
760 |
|
760 | |||
761 | if not os.path.isfile(self.join(patch)): |
|
761 | if not os.path.isfile(self.join(patch)): | |
762 | try: |
|
762 | try: | |
763 | sno = int(patch) |
|
763 | sno = int(patch) | |
764 | except(ValueError, OverflowError): |
|
764 | except(ValueError, OverflowError): | |
765 | pass |
|
765 | pass | |
766 | else: |
|
766 | else: | |
767 | if sno < len(self.series): |
|
767 | if sno < len(self.series): | |
768 | return self.series[sno] |
|
768 | return self.series[sno] | |
769 | if not strict: |
|
769 | if not strict: | |
770 | # return any partial match made above |
|
770 | # return any partial match made above | |
771 | if res: |
|
771 | if res: | |
772 | return res |
|
772 | return res | |
773 | minus = patch.rfind('-') |
|
773 | minus = patch.rfind('-') | |
774 | if minus >= 0: |
|
774 | if minus >= 0: | |
775 | res = partial_name(patch[:minus]) |
|
775 | res = partial_name(patch[:minus]) | |
776 | if res: |
|
776 | if res: | |
777 | i = self.series.index(res) |
|
777 | i = self.series.index(res) | |
778 | try: |
|
778 | try: | |
779 | off = int(patch[minus+1:] or 1) |
|
779 | off = int(patch[minus+1:] or 1) | |
780 | except(ValueError, OverflowError): |
|
780 | except(ValueError, OverflowError): | |
781 | pass |
|
781 | pass | |
782 | else: |
|
782 | else: | |
783 | if i - off >= 0: |
|
783 | if i - off >= 0: | |
784 | return self.series[i - off] |
|
784 | return self.series[i - off] | |
785 | plus = patch.rfind('+') |
|
785 | plus = patch.rfind('+') | |
786 | if plus >= 0: |
|
786 | if plus >= 0: | |
787 | res = partial_name(patch[:plus]) |
|
787 | res = partial_name(patch[:plus]) | |
788 | if res: |
|
788 | if res: | |
789 | i = self.series.index(res) |
|
789 | i = self.series.index(res) | |
790 | try: |
|
790 | try: | |
791 | off = int(patch[plus+1:] or 1) |
|
791 | off = int(patch[plus+1:] or 1) | |
792 | except(ValueError, OverflowError): |
|
792 | except(ValueError, OverflowError): | |
793 | pass |
|
793 | pass | |
794 | else: |
|
794 | else: | |
795 | if i + off < len(self.series): |
|
795 | if i + off < len(self.series): | |
796 | return self.series[i + off] |
|
796 | return self.series[i + off] | |
797 | raise util.Abort(_("patch %s not in series") % patch) |
|
797 | raise util.Abort(_("patch %s not in series") % patch) | |
798 |
|
798 | |||
799 | def push(self, repo, patch=None, force=False, list=False, |
|
799 | def push(self, repo, patch=None, force=False, list=False, | |
800 | mergeq=None, wlock=None): |
|
800 | mergeq=None, wlock=None): | |
801 | if not wlock: |
|
801 | if not wlock: | |
802 | wlock = repo.wlock() |
|
802 | wlock = repo.wlock() | |
803 | patch = self.lookup(patch) |
|
803 | patch = self.lookup(patch) | |
804 | if patch and self.isapplied(patch): |
|
804 | if patch and self.isapplied(patch): | |
805 | raise util.Abort(_("patch %s is already applied") % patch) |
|
805 | raise util.Abort(_("patch %s is already applied") % patch) | |
806 | if self.series_end() == len(self.series): |
|
806 | if self.series_end() == len(self.series): | |
807 | raise util.Abort(_("patch series fully applied")) |
|
807 | raise util.Abort(_("patch series fully applied")) | |
808 | if not force: |
|
808 | if not force: | |
809 | self.check_localchanges(repo) |
|
809 | self.check_localchanges(repo) | |
810 |
|
810 | |||
811 | self.applied_dirty = 1; |
|
811 | self.applied_dirty = 1; | |
812 | start = self.series_end() |
|
812 | start = self.series_end() | |
813 | if start > 0: |
|
813 | if start > 0: | |
814 | self.check_toppatch(repo) |
|
814 | self.check_toppatch(repo) | |
815 | if not patch: |
|
815 | if not patch: | |
816 | patch = self.series[start] |
|
816 | patch = self.series[start] | |
817 | end = start + 1 |
|
817 | end = start + 1 | |
818 | else: |
|
818 | else: | |
819 | end = self.series.index(patch, start) + 1 |
|
819 | end = self.series.index(patch, start) + 1 | |
820 | s = self.series[start:end] |
|
820 | s = self.series[start:end] | |
821 | if mergeq: |
|
821 | if mergeq: | |
822 | ret = self.mergepatch(repo, mergeq, s, wlock) |
|
822 | ret = self.mergepatch(repo, mergeq, s, wlock) | |
823 | else: |
|
823 | else: | |
824 | ret = self.apply(repo, s, list, wlock=wlock) |
|
824 | ret = self.apply(repo, s, list, wlock=wlock) | |
825 | top = self.applied[-1].name |
|
825 | top = self.applied[-1].name | |
826 | if ret[0]: |
|
826 | if ret[0]: | |
827 | self.ui.write("Errors during apply, please fix and refresh %s\n" % |
|
827 | self.ui.write("Errors during apply, please fix and refresh %s\n" % | |
828 | top) |
|
828 | top) | |
829 | else: |
|
829 | else: | |
830 | self.ui.write("Now at: %s\n" % top) |
|
830 | self.ui.write("Now at: %s\n" % top) | |
831 | return ret[0] |
|
831 | return ret[0] | |
832 |
|
832 | |||
833 | def pop(self, repo, patch=None, force=False, update=True, all=False, |
|
833 | def pop(self, repo, patch=None, force=False, update=True, all=False, | |
834 | wlock=None): |
|
834 | wlock=None): | |
835 | def getfile(f, rev): |
|
835 | def getfile(f, rev): | |
836 | t = repo.file(f).read(rev) |
|
836 | t = repo.file(f).read(rev) | |
837 | repo.wfile(f, "w").write(t) |
|
837 | repo.wfile(f, "w").write(t) | |
838 |
|
838 | |||
839 | if not wlock: |
|
839 | if not wlock: | |
840 | wlock = repo.wlock() |
|
840 | wlock = repo.wlock() | |
841 | if patch: |
|
841 | if patch: | |
842 | # index, rev, patch |
|
842 | # index, rev, patch | |
843 | info = self.isapplied(patch) |
|
843 | info = self.isapplied(patch) | |
844 | if not info: |
|
844 | if not info: | |
845 | patch = self.lookup(patch) |
|
845 | patch = self.lookup(patch) | |
846 | info = self.isapplied(patch) |
|
846 | info = self.isapplied(patch) | |
847 | if not info: |
|
847 | if not info: | |
848 | raise util.Abort(_("patch %s is not applied") % patch) |
|
848 | raise util.Abort(_("patch %s is not applied") % patch) | |
849 | if len(self.applied) == 0: |
|
849 | if len(self.applied) == 0: | |
850 | raise util.Abort(_("no patches applied")) |
|
850 | raise util.Abort(_("no patches applied")) | |
851 |
|
851 | |||
852 | if not update: |
|
852 | if not update: | |
853 | parents = repo.dirstate.parents() |
|
853 | parents = repo.dirstate.parents() | |
854 | rr = [ revlog.bin(x.rev) for x in self.applied ] |
|
854 | rr = [ revlog.bin(x.rev) for x in self.applied ] | |
855 | for p in parents: |
|
855 | for p in parents: | |
856 | if p in rr: |
|
856 | if p in rr: | |
857 | self.ui.warn("qpop: forcing dirstate update\n") |
|
857 | self.ui.warn("qpop: forcing dirstate update\n") | |
858 | update = True |
|
858 | update = True | |
859 |
|
859 | |||
860 | if not force and update: |
|
860 | if not force and update: | |
861 | self.check_localchanges(repo) |
|
861 | self.check_localchanges(repo) | |
862 |
|
862 | |||
863 | self.applied_dirty = 1; |
|
863 | self.applied_dirty = 1; | |
864 | end = len(self.applied) |
|
864 | end = len(self.applied) | |
865 | if not patch: |
|
865 | if not patch: | |
866 | if all: |
|
866 | if all: | |
867 | popi = 0 |
|
867 | popi = 0 | |
868 | else: |
|
868 | else: | |
869 | popi = len(self.applied) - 1 |
|
869 | popi = len(self.applied) - 1 | |
870 | else: |
|
870 | else: | |
871 | popi = info[0] + 1 |
|
871 | popi = info[0] + 1 | |
872 | if popi >= end: |
|
872 | if popi >= end: | |
873 | self.ui.warn("qpop: %s is already at the top\n" % patch) |
|
873 | self.ui.warn("qpop: %s is already at the top\n" % patch) | |
874 | return |
|
874 | return | |
875 | info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name] |
|
875 | info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name] | |
876 |
|
876 | |||
877 | start = info[0] |
|
877 | start = info[0] | |
878 | rev = revlog.bin(info[1]) |
|
878 | rev = revlog.bin(info[1]) | |
879 |
|
879 | |||
880 | # we know there are no local changes, so we can make a simplified |
|
880 | # we know there are no local changes, so we can make a simplified | |
881 | # form of hg.update. |
|
881 | # form of hg.update. | |
882 | if update: |
|
882 | if update: | |
883 | top = self.check_toppatch(repo) |
|
883 | top = self.check_toppatch(repo) | |
884 | qp = self.qparents(repo, rev) |
|
884 | qp = self.qparents(repo, rev) | |
885 | changes = repo.changelog.read(qp) |
|
885 | changes = repo.changelog.read(qp) | |
886 | mmap = repo.manifest.read(changes[0]) |
|
886 | mmap = repo.manifest.read(changes[0]) | |
887 | m, a, r, d, u = repo.status(qp, top)[:5] |
|
887 | m, a, r, d, u = repo.status(qp, top)[:5] | |
888 | if d: |
|
888 | if d: | |
889 | raise util.Abort("deletions found between repo revs") |
|
889 | raise util.Abort("deletions found between repo revs") | |
890 | for f in m: |
|
890 | for f in m: | |
891 | getfile(f, mmap[f]) |
|
891 | getfile(f, mmap[f]) | |
892 | for f in r: |
|
892 | for f in r: | |
893 | getfile(f, mmap[f]) |
|
893 | getfile(f, mmap[f]) | |
894 | util.set_exec(repo.wjoin(f), mmap.execf(f)) |
|
894 | util.set_exec(repo.wjoin(f), mmap.execf(f)) | |
895 | repo.dirstate.update(m + r, 'n') |
|
895 | repo.dirstate.update(m + r, 'n') | |
896 | for f in a: |
|
896 | for f in a: | |
897 | try: |
|
897 | try: | |
898 | os.unlink(repo.wjoin(f)) |
|
898 | os.unlink(repo.wjoin(f)) | |
899 | except OSError, e: |
|
899 | except OSError, e: | |
900 | if e.errno != errno.ENOENT: |
|
900 | if e.errno != errno.ENOENT: | |
901 | raise |
|
901 | raise | |
902 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
|
902 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) | |
903 | except: pass |
|
903 | except: pass | |
904 | if a: |
|
904 | if a: | |
905 | repo.dirstate.forget(a) |
|
905 | repo.dirstate.forget(a) | |
906 | repo.dirstate.setparents(qp, revlog.nullid) |
|
906 | repo.dirstate.setparents(qp, revlog.nullid) | |
907 | self.strip(repo, rev, update=False, backup='strip', wlock=wlock) |
|
907 | self.strip(repo, rev, update=False, backup='strip', wlock=wlock) | |
908 | del self.applied[start:end] |
|
908 | del self.applied[start:end] | |
909 | if len(self.applied): |
|
909 | if len(self.applied): | |
910 | self.ui.write("Now at: %s\n" % self.applied[-1].name) |
|
910 | self.ui.write("Now at: %s\n" % self.applied[-1].name) | |
911 | else: |
|
911 | else: | |
912 | self.ui.write("Patch queue now empty\n") |
|
912 | self.ui.write("Patch queue now empty\n") | |
913 |
|
913 | |||
914 | def diff(self, repo, pats, opts): |
|
914 | def diff(self, repo, pats, opts): | |
915 | top = self.check_toppatch(repo) |
|
915 | top = self.check_toppatch(repo) | |
916 | if not top: |
|
916 | if not top: | |
917 | self.ui.write("No patches applied\n") |
|
917 | self.ui.write("No patches applied\n") | |
918 | return |
|
918 | return | |
919 | qp = self.qparents(repo, top) |
|
919 | qp = self.qparents(repo, top) | |
920 | if opts.get('git'): |
|
920 | if opts.get('git'): | |
921 | self.diffopts().git = True |
|
921 | self.diffopts().git = True | |
922 | self.printdiff(repo, qp, files=pats, opts=opts) |
|
922 | self.printdiff(repo, qp, files=pats, opts=opts) | |
923 |
|
923 | |||
924 | def refresh(self, repo, pats=None, **opts): |
|
924 | def refresh(self, repo, pats=None, **opts): | |
925 | if len(self.applied) == 0: |
|
925 | if len(self.applied) == 0: | |
926 | self.ui.write("No patches applied\n") |
|
926 | self.ui.write("No patches applied\n") | |
927 | return 1 |
|
927 | return 1 | |
928 | wlock = repo.wlock() |
|
928 | wlock = repo.wlock() | |
929 | self.check_toppatch(repo) |
|
929 | self.check_toppatch(repo) | |
930 | (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name) |
|
930 | (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name) | |
931 | top = revlog.bin(top) |
|
931 | top = revlog.bin(top) | |
932 | cparents = repo.changelog.parents(top) |
|
932 | cparents = repo.changelog.parents(top) | |
933 | patchparent = self.qparents(repo, top) |
|
933 | patchparent = self.qparents(repo, top) | |
934 | message, comments, user, date, patchfound = self.readheaders(patchfn) |
|
934 | message, comments, user, date, patchfound = self.readheaders(patchfn) | |
935 |
|
935 | |||
936 | patchf = self.opener(patchfn, "w") |
|
936 | patchf = self.opener(patchfn, "w") | |
937 | msg = opts.get('msg', '').rstrip() |
|
937 | msg = opts.get('msg', '').rstrip() | |
938 | if msg: |
|
938 | if msg: | |
939 | if comments: |
|
939 | if comments: | |
940 | # Remove existing message. |
|
940 | # Remove existing message. | |
941 | ci = 0 |
|
941 | ci = 0 | |
942 | for mi in xrange(len(message)): |
|
942 | for mi in xrange(len(message)): | |
943 | while message[mi] != comments[ci]: |
|
943 | while message[mi] != comments[ci]: | |
944 | ci += 1 |
|
944 | ci += 1 | |
945 | del comments[ci] |
|
945 | del comments[ci] | |
946 | comments.append(msg) |
|
946 | comments.append(msg) | |
947 | if comments: |
|
947 | if comments: | |
948 | comments = "\n".join(comments) + '\n\n' |
|
948 | comments = "\n".join(comments) + '\n\n' | |
949 | patchf.write(comments) |
|
949 | patchf.write(comments) | |
950 |
|
950 | |||
951 | if opts.get('git'): |
|
951 | if opts.get('git'): | |
952 | self.diffopts().git = True |
|
952 | self.diffopts().git = True | |
953 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
953 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
954 | tip = repo.changelog.tip() |
|
954 | tip = repo.changelog.tip() | |
955 | if top == tip: |
|
955 | if top == tip: | |
956 | # if the top of our patch queue is also the tip, there is an |
|
956 | # if the top of our patch queue is also the tip, there is an | |
957 | # optimization here. We update the dirstate in place and strip |
|
957 | # optimization here. We update the dirstate in place and strip | |
958 | # off the tip commit. Then just commit the current directory |
|
958 | # off the tip commit. Then just commit the current directory | |
959 | # tree. We can also send repo.commit the list of files |
|
959 | # tree. We can also send repo.commit the list of files | |
960 | # changed to speed up the diff |
|
960 | # changed to speed up the diff | |
961 | # |
|
961 | # | |
962 | # in short mode, we only diff the files included in the |
|
962 | # in short mode, we only diff the files included in the | |
963 | # patch already |
|
963 | # patch already | |
964 | # |
|
964 | # | |
965 | # this should really read: |
|
965 | # this should really read: | |
966 | # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5] |
|
966 | # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5] | |
967 | # but we do it backwards to take advantage of manifest/chlog |
|
967 | # but we do it backwards to take advantage of manifest/chlog | |
968 | # caching against the next repo.status call |
|
968 | # caching against the next repo.status call | |
969 | # |
|
969 | # | |
970 | mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5] |
|
970 | mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5] | |
971 | changes = repo.changelog.read(tip) |
|
971 | changes = repo.changelog.read(tip) | |
972 | man = repo.manifest.read(changes[0]) |
|
972 | man = repo.manifest.read(changes[0]) | |
973 | aaa = aa[:] |
|
973 | aaa = aa[:] | |
974 | if opts.get('short'): |
|
974 | if opts.get('short'): | |
975 | filelist = mm + aa + dd |
|
975 | filelist = mm + aa + dd | |
976 | else: |
|
976 | else: | |
977 | filelist = None |
|
977 | filelist = None | |
978 | m, a, r, d, u = repo.status(files=filelist)[:5] |
|
978 | m, a, r, d, u = repo.status(files=filelist)[:5] | |
979 |
|
979 | |||
980 | # we might end up with files that were added between tip and |
|
980 | # we might end up with files that were added between tip and | |
981 | # the dirstate parent, but then changed in the local dirstate. |
|
981 | # the dirstate parent, but then changed in the local dirstate. | |
982 | # in this case, we want them to only show up in the added section |
|
982 | # in this case, we want them to only show up in the added section | |
983 | for x in m: |
|
983 | for x in m: | |
984 | if x not in aa: |
|
984 | if x not in aa: | |
985 | mm.append(x) |
|
985 | mm.append(x) | |
986 | # we might end up with files added by the local dirstate that |
|
986 | # we might end up with files added by the local dirstate that | |
987 | # were deleted by the patch. In this case, they should only |
|
987 | # were deleted by the patch. In this case, they should only | |
988 | # show up in the changed section. |
|
988 | # show up in the changed section. | |
989 | for x in a: |
|
989 | for x in a: | |
990 | if x in dd: |
|
990 | if x in dd: | |
991 | del dd[dd.index(x)] |
|
991 | del dd[dd.index(x)] | |
992 | mm.append(x) |
|
992 | mm.append(x) | |
993 | else: |
|
993 | else: | |
994 | aa.append(x) |
|
994 | aa.append(x) | |
995 | # make sure any files deleted in the local dirstate |
|
995 | # make sure any files deleted in the local dirstate | |
996 | # are not in the add or change column of the patch |
|
996 | # are not in the add or change column of the patch | |
997 | forget = [] |
|
997 | forget = [] | |
998 | for x in d + r: |
|
998 | for x in d + r: | |
999 | if x in aa: |
|
999 | if x in aa: | |
1000 | del aa[aa.index(x)] |
|
1000 | del aa[aa.index(x)] | |
1001 | forget.append(x) |
|
1001 | forget.append(x) | |
1002 | continue |
|
1002 | continue | |
1003 | elif x in mm: |
|
1003 | elif x in mm: | |
1004 | del mm[mm.index(x)] |
|
1004 | del mm[mm.index(x)] | |
1005 | dd.append(x) |
|
1005 | dd.append(x) | |
1006 |
|
1006 | |||
1007 | m = util.unique(mm) |
|
1007 | m = util.unique(mm) | |
1008 | r = util.unique(dd) |
|
1008 | r = util.unique(dd) | |
1009 | a = util.unique(aa) |
|
1009 | a = util.unique(aa) | |
1010 | filelist = filter(matchfn, util.unique(m + r + a)) |
|
1010 | filelist = filter(matchfn, util.unique(m + r + a)) | |
1011 | patch.diff(repo, patchparent, files=filelist, match=matchfn, |
|
1011 | patch.diff(repo, patchparent, files=filelist, match=matchfn, | |
1012 | fp=patchf, changes=(m, a, r, [], u), |
|
1012 | fp=patchf, changes=(m, a, r, [], u), | |
1013 | opts=self.diffopts()) |
|
1013 | opts=self.diffopts()) | |
1014 | patchf.close() |
|
1014 | patchf.close() | |
1015 |
|
1015 | |||
1016 | repo.dirstate.setparents(*cparents) |
|
1016 | repo.dirstate.setparents(*cparents) | |
1017 | copies = {} |
|
1017 | copies = {} | |
1018 | for dst in a: |
|
1018 | for dst in a: | |
1019 | src = repo.dirstate.copied(dst) |
|
1019 | src = repo.dirstate.copied(dst) | |
1020 | if src is None: |
|
1020 | if src is None: | |
1021 | continue |
|
1021 | continue | |
1022 | copies.setdefault(src, []).append(dst) |
|
1022 | copies.setdefault(src, []).append(dst) | |
1023 | repo.dirstate.update(a, 'a') |
|
1023 | repo.dirstate.update(a, 'a') | |
1024 | # remember the copies between patchparent and tip |
|
1024 | # remember the copies between patchparent and tip | |
1025 | # this may be slow, so don't do it if we're not tracking copies |
|
1025 | # this may be slow, so don't do it if we're not tracking copies | |
1026 | if self.diffopts().git: |
|
1026 | if self.diffopts().git: | |
1027 | for dst in aaa: |
|
1027 | for dst in aaa: | |
1028 | f = repo.file(dst) |
|
1028 | f = repo.file(dst) | |
1029 | src = f.renamed(man[dst]) |
|
1029 | src = f.renamed(man[dst]) | |
1030 | if src: |
|
1030 | if src: | |
1031 | copies[src[0]] = copies.get(dst, []) |
|
1031 | copies[src[0]] = copies.get(dst, []) | |
1032 | if dst in a: |
|
1032 | if dst in a: | |
1033 | copies[src[0]].append(dst) |
|
1033 | copies[src[0]].append(dst) | |
1034 | # we can't copy a file created by the patch itself |
|
1034 | # we can't copy a file created by the patch itself | |
1035 | if dst in copies: |
|
1035 | if dst in copies: | |
1036 | del copies[dst] |
|
1036 | del copies[dst] | |
1037 | for src, dsts in copies.iteritems(): |
|
1037 | for src, dsts in copies.iteritems(): | |
1038 | for dst in dsts: |
|
1038 | for dst in dsts: | |
1039 | repo.dirstate.copy(src, dst) |
|
1039 | repo.dirstate.copy(src, dst) | |
1040 | repo.dirstate.update(r, 'r') |
|
1040 | repo.dirstate.update(r, 'r') | |
1041 | # if the patch excludes a modified file, mark that file with mtime=0 |
|
1041 | # if the patch excludes a modified file, mark that file with mtime=0 | |
1042 | # so status can see it. |
|
1042 | # so status can see it. | |
1043 | mm = [] |
|
1043 | mm = [] | |
1044 | for i in xrange(len(m)-1, -1, -1): |
|
1044 | for i in xrange(len(m)-1, -1, -1): | |
1045 | if not matchfn(m[i]): |
|
1045 | if not matchfn(m[i]): | |
1046 | mm.append(m[i]) |
|
1046 | mm.append(m[i]) | |
1047 | del m[i] |
|
1047 | del m[i] | |
1048 | repo.dirstate.update(m, 'n') |
|
1048 | repo.dirstate.update(m, 'n') | |
1049 | repo.dirstate.update(mm, 'n', st_mtime=0) |
|
1049 | repo.dirstate.update(mm, 'n', st_mtime=0) | |
1050 | repo.dirstate.forget(forget) |
|
1050 | repo.dirstate.forget(forget) | |
1051 |
|
1051 | |||
1052 | if not msg: |
|
1052 | if not msg: | |
1053 | if not message: |
|
1053 | if not message: | |
1054 | message = "patch queue: %s\n" % patchfn |
|
1054 | message = "patch queue: %s\n" % patchfn | |
1055 | else: |
|
1055 | else: | |
1056 | message = "\n".join(message) |
|
1056 | message = "\n".join(message) | |
1057 | else: |
|
1057 | else: | |
1058 | message = msg |
|
1058 | message = msg | |
1059 |
|
1059 | |||
1060 | self.strip(repo, top, update=False, backup='strip', wlock=wlock) |
|
1060 | self.strip(repo, top, update=False, backup='strip', wlock=wlock) | |
1061 | n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) |
|
1061 | n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) | |
1062 | self.applied[-1] = statusentry(revlog.hex(n), patchfn) |
|
1062 | self.applied[-1] = statusentry(revlog.hex(n), patchfn) | |
1063 | self.applied_dirty = 1 |
|
1063 | self.applied_dirty = 1 | |
1064 | else: |
|
1064 | else: | |
1065 | self.printdiff(repo, patchparent, fp=patchf) |
|
1065 | self.printdiff(repo, patchparent, fp=patchf) | |
1066 | patchf.close() |
|
1066 | patchf.close() | |
1067 | added = repo.status()[1] |
|
1067 | added = repo.status()[1] | |
1068 | for a in added: |
|
1068 | for a in added: | |
1069 | f = repo.wjoin(a) |
|
1069 | f = repo.wjoin(a) | |
1070 | try: |
|
1070 | try: | |
1071 | os.unlink(f) |
|
1071 | os.unlink(f) | |
1072 | except OSError, e: |
|
1072 | except OSError, e: | |
1073 | if e.errno != errno.ENOENT: |
|
1073 | if e.errno != errno.ENOENT: | |
1074 | raise |
|
1074 | raise | |
1075 | try: os.removedirs(os.path.dirname(f)) |
|
1075 | try: os.removedirs(os.path.dirname(f)) | |
1076 | except: pass |
|
1076 | except: pass | |
1077 | # forget the file copies in the dirstate |
|
1077 | # forget the file copies in the dirstate | |
1078 | # push should readd the files later on |
|
1078 | # push should readd the files later on | |
1079 | repo.dirstate.forget(added) |
|
1079 | repo.dirstate.forget(added) | |
1080 | self.pop(repo, force=True, wlock=wlock) |
|
1080 | self.pop(repo, force=True, wlock=wlock) | |
1081 | self.push(repo, force=True, wlock=wlock) |
|
1081 | self.push(repo, force=True, wlock=wlock) | |
1082 |
|
1082 | |||
1083 | def init(self, repo, create=False): |
|
1083 | def init(self, repo, create=False): | |
1084 | if os.path.isdir(self.path): |
|
1084 | if os.path.isdir(self.path): | |
1085 | raise util.Abort(_("patch queue directory already exists")) |
|
1085 | raise util.Abort(_("patch queue directory already exists")) | |
1086 | os.mkdir(self.path) |
|
1086 | os.mkdir(self.path) | |
1087 | if create: |
|
1087 | if create: | |
1088 | return self.qrepo(create=True) |
|
1088 | return self.qrepo(create=True) | |
1089 |
|
1089 | |||
1090 | def unapplied(self, repo, patch=None): |
|
1090 | def unapplied(self, repo, patch=None): | |
1091 | if patch and patch not in self.series: |
|
1091 | if patch and patch not in self.series: | |
1092 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1092 | raise util.Abort(_("patch %s is not in series file") % patch) | |
1093 | if not patch: |
|
1093 | if not patch: | |
1094 | start = self.series_end() |
|
1094 | start = self.series_end() | |
1095 | else: |
|
1095 | else: | |
1096 | start = self.series.index(patch) + 1 |
|
1096 | start = self.series.index(patch) + 1 | |
1097 | unapplied = [] |
|
1097 | unapplied = [] | |
1098 | for i in xrange(start, len(self.series)): |
|
1098 | for i in xrange(start, len(self.series)): | |
1099 | pushable, reason = self.pushable(i) |
|
1099 | pushable, reason = self.pushable(i) | |
1100 | if pushable: |
|
1100 | if pushable: | |
1101 | unapplied.append((i, self.series[i])) |
|
1101 | unapplied.append((i, self.series[i])) | |
1102 | self.explain_pushable(i) |
|
1102 | self.explain_pushable(i) | |
1103 | return unapplied |
|
1103 | return unapplied | |
1104 |
|
1104 | |||
1105 | def qseries(self, repo, missing=None, start=0, length=0, status=None, |
|
1105 | def qseries(self, repo, missing=None, start=0, length=0, status=None, | |
1106 | summary=False): |
|
1106 | summary=False): | |
1107 | def displayname(patchname): |
|
1107 | def displayname(patchname): | |
1108 | if summary: |
|
1108 | if summary: | |
1109 | msg = self.readheaders(patchname)[0] |
|
1109 | msg = self.readheaders(patchname)[0] | |
1110 | msg = msg and ': ' + msg[0] or ': ' |
|
1110 | msg = msg and ': ' + msg[0] or ': ' | |
1111 | else: |
|
1111 | else: | |
1112 | msg = '' |
|
1112 | msg = '' | |
1113 | return '%s%s' % (patchname, msg) |
|
1113 | return '%s%s' % (patchname, msg) | |
1114 |
|
1114 | |||
1115 | def pname(i): |
|
1115 | def pname(i): | |
1116 | if status == 'A': |
|
1116 | if status == 'A': | |
1117 | return self.applied[i].name |
|
1117 | return self.applied[i].name | |
1118 | else: |
|
1118 | else: | |
1119 | return self.series[i] |
|
1119 | return self.series[i] | |
1120 |
|
1120 | |||
1121 | applied = dict.fromkeys([p.name for p in self.applied]) |
|
1121 | applied = dict.fromkeys([p.name for p in self.applied]) | |
1122 | if not length: |
|
1122 | if not length: | |
1123 | length = len(self.series) - start |
|
1123 | length = len(self.series) - start | |
1124 | if not missing: |
|
1124 | if not missing: | |
1125 | for i in xrange(start, start+length): |
|
1125 | for i in xrange(start, start+length): | |
1126 | pfx = '' |
|
1126 | pfx = '' | |
1127 | patch = pname(i) |
|
1127 | patch = pname(i) | |
1128 | if self.ui.verbose: |
|
1128 | if self.ui.verbose: | |
1129 | if patch in applied: |
|
1129 | if patch in applied: | |
1130 | stat = 'A' |
|
1130 | stat = 'A' | |
1131 | elif self.pushable(i)[0]: |
|
1131 | elif self.pushable(i)[0]: | |
1132 | stat = 'U' |
|
1132 | stat = 'U' | |
1133 | else: |
|
1133 | else: | |
1134 | stat = 'G' |
|
1134 | stat = 'G' | |
1135 | pfx = '%d %s ' % (i, stat) |
|
1135 | pfx = '%d %s ' % (i, stat) | |
1136 | self.ui.write('%s%s\n' % (pfx, displayname(patch))) |
|
1136 | self.ui.write('%s%s\n' % (pfx, displayname(patch))) | |
1137 | else: |
|
1137 | else: | |
1138 | msng_list = [] |
|
1138 | msng_list = [] | |
1139 | for root, dirs, files in os.walk(self.path): |
|
1139 | for root, dirs, files in os.walk(self.path): | |
1140 | d = root[len(self.path) + 1:] |
|
1140 | d = root[len(self.path) + 1:] | |
1141 | for f in files: |
|
1141 | for f in files: | |
1142 | fl = os.path.join(d, f) |
|
1142 | fl = os.path.join(d, f) | |
1143 | if (fl not in self.series and |
|
1143 | if (fl not in self.series and | |
1144 | fl not in (self.status_path, self.series_path) |
|
1144 | fl not in (self.status_path, self.series_path) | |
1145 | and not fl.startswith('.')): |
|
1145 | and not fl.startswith('.')): | |
1146 | msng_list.append(fl) |
|
1146 | msng_list.append(fl) | |
1147 | msng_list.sort() |
|
1147 | msng_list.sort() | |
1148 | for x in msng_list: |
|
1148 | for x in msng_list: | |
1149 | pfx = self.ui.verbose and ('D ') or '' |
|
1149 | pfx = self.ui.verbose and ('D ') or '' | |
1150 | self.ui.write("%s%s\n" % (pfx, displayname(x))) |
|
1150 | self.ui.write("%s%s\n" % (pfx, displayname(x))) | |
1151 |
|
1151 | |||
1152 | def issaveline(self, l): |
|
1152 | def issaveline(self, l): | |
1153 | if l.name == '.hg.patches.save.line': |
|
1153 | if l.name == '.hg.patches.save.line': | |
1154 | return True |
|
1154 | return True | |
1155 |
|
1155 | |||
1156 | def qrepo(self, create=False): |
|
1156 | def qrepo(self, create=False): | |
1157 | if create or os.path.isdir(self.join(".hg")): |
|
1157 | if create or os.path.isdir(self.join(".hg")): | |
1158 | return hg.repository(self.ui, path=self.path, create=create) |
|
1158 | return hg.repository(self.ui, path=self.path, create=create) | |
1159 |
|
1159 | |||
1160 | def restore(self, repo, rev, delete=None, qupdate=None): |
|
1160 | def restore(self, repo, rev, delete=None, qupdate=None): | |
1161 | c = repo.changelog.read(rev) |
|
1161 | c = repo.changelog.read(rev) | |
1162 | desc = c[4].strip() |
|
1162 | desc = c[4].strip() | |
1163 | lines = desc.splitlines() |
|
1163 | lines = desc.splitlines() | |
1164 | i = 0 |
|
1164 | i = 0 | |
1165 | datastart = None |
|
1165 | datastart = None | |
1166 | series = [] |
|
1166 | series = [] | |
1167 | applied = [] |
|
1167 | applied = [] | |
1168 | qpp = None |
|
1168 | qpp = None | |
1169 | for i in xrange(0, len(lines)): |
|
1169 | for i in xrange(0, len(lines)): | |
1170 | if lines[i] == 'Patch Data:': |
|
1170 | if lines[i] == 'Patch Data:': | |
1171 | datastart = i + 1 |
|
1171 | datastart = i + 1 | |
1172 | elif lines[i].startswith('Dirstate:'): |
|
1172 | elif lines[i].startswith('Dirstate:'): | |
1173 | l = lines[i].rstrip() |
|
1173 | l = lines[i].rstrip() | |
1174 | l = l[10:].split(' ') |
|
1174 | l = l[10:].split(' ') | |
1175 | qpp = [ hg.bin(x) for x in l ] |
|
1175 | qpp = [ hg.bin(x) for x in l ] | |
1176 | elif datastart != None: |
|
1176 | elif datastart != None: | |
1177 | l = lines[i].rstrip() |
|
1177 | l = lines[i].rstrip() | |
1178 | se = statusentry(l) |
|
1178 | se = statusentry(l) | |
1179 | file_ = se.name |
|
1179 | file_ = se.name | |
1180 | if se.rev: |
|
1180 | if se.rev: | |
1181 | applied.append(se) |
|
1181 | applied.append(se) | |
1182 | else: |
|
1182 | else: | |
1183 | series.append(file_) |
|
1183 | series.append(file_) | |
1184 | if datastart == None: |
|
1184 | if datastart == None: | |
1185 | self.ui.warn("No saved patch data found\n") |
|
1185 | self.ui.warn("No saved patch data found\n") | |
1186 | return 1 |
|
1186 | return 1 | |
1187 | self.ui.warn("restoring status: %s\n" % lines[0]) |
|
1187 | self.ui.warn("restoring status: %s\n" % lines[0]) | |
1188 | self.full_series = series |
|
1188 | self.full_series = series | |
1189 | self.applied = applied |
|
1189 | self.applied = applied | |
1190 | self.parse_series() |
|
1190 | self.parse_series() | |
1191 | self.series_dirty = 1 |
|
1191 | self.series_dirty = 1 | |
1192 | self.applied_dirty = 1 |
|
1192 | self.applied_dirty = 1 | |
1193 | heads = repo.changelog.heads() |
|
1193 | heads = repo.changelog.heads() | |
1194 | if delete: |
|
1194 | if delete: | |
1195 | if rev not in heads: |
|
1195 | if rev not in heads: | |
1196 | self.ui.warn("save entry has children, leaving it alone\n") |
|
1196 | self.ui.warn("save entry has children, leaving it alone\n") | |
1197 | else: |
|
1197 | else: | |
1198 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) |
|
1198 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) | |
1199 | pp = repo.dirstate.parents() |
|
1199 | pp = repo.dirstate.parents() | |
1200 | if rev in pp: |
|
1200 | if rev in pp: | |
1201 | update = True |
|
1201 | update = True | |
1202 | else: |
|
1202 | else: | |
1203 | update = False |
|
1203 | update = False | |
1204 | self.strip(repo, rev, update=update, backup='strip') |
|
1204 | self.strip(repo, rev, update=update, backup='strip') | |
1205 | if qpp: |
|
1205 | if qpp: | |
1206 | self.ui.warn("saved queue repository parents: %s %s\n" % |
|
1206 | self.ui.warn("saved queue repository parents: %s %s\n" % | |
1207 | (hg.short(qpp[0]), hg.short(qpp[1]))) |
|
1207 | (hg.short(qpp[0]), hg.short(qpp[1]))) | |
1208 | if qupdate: |
|
1208 | if qupdate: | |
1209 | print "queue directory updating" |
|
1209 | print "queue directory updating" | |
1210 | r = self.qrepo() |
|
1210 | r = self.qrepo() | |
1211 | if not r: |
|
1211 | if not r: | |
1212 | self.ui.warn("Unable to load queue repository\n") |
|
1212 | self.ui.warn("Unable to load queue repository\n") | |
1213 | return 1 |
|
1213 | return 1 | |
1214 | hg.clean(r, qpp[0]) |
|
1214 | hg.clean(r, qpp[0]) | |
1215 |
|
1215 | |||
1216 | def save(self, repo, msg=None): |
|
1216 | def save(self, repo, msg=None): | |
1217 | if len(self.applied) == 0: |
|
1217 | if len(self.applied) == 0: | |
1218 | self.ui.warn("save: no patches applied, exiting\n") |
|
1218 | self.ui.warn("save: no patches applied, exiting\n") | |
1219 | return 1 |
|
1219 | return 1 | |
1220 | if self.issaveline(self.applied[-1]): |
|
1220 | if self.issaveline(self.applied[-1]): | |
1221 | self.ui.warn("status is already saved\n") |
|
1221 | self.ui.warn("status is already saved\n") | |
1222 | return 1 |
|
1222 | return 1 | |
1223 |
|
1223 | |||
1224 | ar = [ ':' + x for x in self.full_series ] |
|
1224 | ar = [ ':' + x for x in self.full_series ] | |
1225 | if not msg: |
|
1225 | if not msg: | |
1226 | msg = "hg patches saved state" |
|
1226 | msg = "hg patches saved state" | |
1227 | else: |
|
1227 | else: | |
1228 | msg = "hg patches: " + msg.rstrip('\r\n') |
|
1228 | msg = "hg patches: " + msg.rstrip('\r\n') | |
1229 | r = self.qrepo() |
|
1229 | r = self.qrepo() | |
1230 | if r: |
|
1230 | if r: | |
1231 | pp = r.dirstate.parents() |
|
1231 | pp = r.dirstate.parents() | |
1232 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) |
|
1232 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) | |
1233 | msg += "\n\nPatch Data:\n" |
|
1233 | msg += "\n\nPatch Data:\n" | |
1234 | text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and |
|
1234 | text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and | |
1235 | "\n".join(ar) + '\n' or "") |
|
1235 | "\n".join(ar) + '\n' or "") | |
1236 | n = repo.commit(None, text, user=None, force=1) |
|
1236 | n = repo.commit(None, text, user=None, force=1) | |
1237 | if not n: |
|
1237 | if not n: | |
1238 | self.ui.warn("repo commit failed\n") |
|
1238 | self.ui.warn("repo commit failed\n") | |
1239 | return 1 |
|
1239 | return 1 | |
1240 | self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line')) |
|
1240 | self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line')) | |
1241 | self.applied_dirty = 1 |
|
1241 | self.applied_dirty = 1 | |
1242 |
|
1242 | |||
1243 | def full_series_end(self): |
|
1243 | def full_series_end(self): | |
1244 | if len(self.applied) > 0: |
|
1244 | if len(self.applied) > 0: | |
1245 | p = self.applied[-1].name |
|
1245 | p = self.applied[-1].name | |
1246 | end = self.find_series(p) |
|
1246 | end = self.find_series(p) | |
1247 | if end == None: |
|
1247 | if end == None: | |
1248 | return len(self.full_series) |
|
1248 | return len(self.full_series) | |
1249 | return end + 1 |
|
1249 | return end + 1 | |
1250 | return 0 |
|
1250 | return 0 | |
1251 |
|
1251 | |||
1252 | def series_end(self, all_patches=False): |
|
1252 | def series_end(self, all_patches=False): | |
1253 | end = 0 |
|
1253 | end = 0 | |
1254 | def next(start): |
|
1254 | def next(start): | |
1255 | if all_patches: |
|
1255 | if all_patches: | |
1256 | return start |
|
1256 | return start | |
1257 | i = start |
|
1257 | i = start | |
1258 | while i < len(self.series): |
|
1258 | while i < len(self.series): | |
1259 | p, reason = self.pushable(i) |
|
1259 | p, reason = self.pushable(i) | |
1260 | if p: |
|
1260 | if p: | |
1261 | break |
|
1261 | break | |
1262 | self.explain_pushable(i) |
|
1262 | self.explain_pushable(i) | |
1263 | i += 1 |
|
1263 | i += 1 | |
1264 | return i |
|
1264 | return i | |
1265 | if len(self.applied) > 0: |
|
1265 | if len(self.applied) > 0: | |
1266 | p = self.applied[-1].name |
|
1266 | p = self.applied[-1].name | |
1267 | try: |
|
1267 | try: | |
1268 | end = self.series.index(p) |
|
1268 | end = self.series.index(p) | |
1269 | except ValueError: |
|
1269 | except ValueError: | |
1270 | return 0 |
|
1270 | return 0 | |
1271 | return next(end + 1) |
|
1271 | return next(end + 1) | |
1272 | return next(end) |
|
1272 | return next(end) | |
1273 |
|
1273 | |||
1274 | def appliedname(self, index): |
|
1274 | def appliedname(self, index): | |
1275 | pname = self.applied[index].name |
|
1275 | pname = self.applied[index].name | |
1276 | if not self.ui.verbose: |
|
1276 | if not self.ui.verbose: | |
1277 | p = pname |
|
1277 | p = pname | |
1278 | else: |
|
1278 | else: | |
1279 | p = str(self.series.index(pname)) + " " + pname |
|
1279 | p = str(self.series.index(pname)) + " " + pname | |
1280 | return p |
|
1280 | return p | |
1281 |
|
1281 | |||
1282 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, |
|
1282 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, | |
1283 | force=None, git=False): |
|
1283 | force=None, git=False): | |
1284 | def checkseries(patchname): |
|
1284 | def checkseries(patchname): | |
1285 | if patchname in self.series: |
|
1285 | if patchname in self.series: | |
1286 | raise util.Abort(_('patch %s is already in the series file') |
|
1286 | raise util.Abort(_('patch %s is already in the series file') | |
1287 | % patchname) |
|
1287 | % patchname) | |
1288 | def checkfile(patchname): |
|
1288 | def checkfile(patchname): | |
1289 | if not force and os.path.exists(self.join(patchname)): |
|
1289 | if not force and os.path.exists(self.join(patchname)): | |
1290 | raise util.Abort(_('patch "%s" already exists') |
|
1290 | raise util.Abort(_('patch "%s" already exists') | |
1291 | % patchname) |
|
1291 | % patchname) | |
1292 |
|
1292 | |||
1293 | if rev: |
|
1293 | if rev: | |
1294 | if files: |
|
1294 | if files: | |
1295 | raise util.Abort(_('option "-r" not valid when importing ' |
|
1295 | raise util.Abort(_('option "-r" not valid when importing ' | |
1296 | 'files')) |
|
1296 | 'files')) | |
1297 | rev = cmdutil.revrange(repo, rev) |
|
1297 | rev = cmdutil.revrange(repo, rev) | |
1298 | rev.sort(lambda x, y: cmp(y, x)) |
|
1298 | rev.sort(lambda x, y: cmp(y, x)) | |
1299 | if (len(files) > 1 or len(rev) > 1) and patchname: |
|
1299 | if (len(files) > 1 or len(rev) > 1) and patchname: | |
1300 | raise util.Abort(_('option "-n" not valid when importing multiple ' |
|
1300 | raise util.Abort(_('option "-n" not valid when importing multiple ' | |
1301 | 'patches')) |
|
1301 | 'patches')) | |
1302 | i = 0 |
|
1302 | i = 0 | |
1303 | added = [] |
|
1303 | added = [] | |
1304 | if rev: |
|
1304 | if rev: | |
1305 | # If mq patches are applied, we can only import revisions |
|
1305 | # If mq patches are applied, we can only import revisions | |
1306 | # that form a linear path to qbase. |
|
1306 | # that form a linear path to qbase. | |
1307 | # Otherwise, they should form a linear path to a head. |
|
1307 | # Otherwise, they should form a linear path to a head. | |
1308 | heads = repo.changelog.heads(repo.changelog.node(rev[-1])) |
|
1308 | heads = repo.changelog.heads(repo.changelog.node(rev[-1])) | |
1309 | if len(heads) > 1: |
|
1309 | if len(heads) > 1: | |
1310 | raise util.Abort(_('revision %d is the root of more than one ' |
|
1310 | raise util.Abort(_('revision %d is the root of more than one ' | |
1311 | 'branch') % rev[-1]) |
|
1311 | 'branch') % rev[-1]) | |
1312 | if self.applied: |
|
1312 | if self.applied: | |
1313 | base = revlog.hex(repo.changelog.node(rev[0])) |
|
1313 | base = revlog.hex(repo.changelog.node(rev[0])) | |
1314 | if base in [n.rev for n in self.applied]: |
|
1314 | if base in [n.rev for n in self.applied]: | |
1315 | raise util.Abort(_('revision %d is already managed') |
|
1315 | raise util.Abort(_('revision %d is already managed') | |
1316 | % rev[0]) |
|
1316 | % rev[0]) | |
1317 | if heads != [revlog.bin(self.applied[-1].rev)]: |
|
1317 | if heads != [revlog.bin(self.applied[-1].rev)]: | |
1318 | raise util.Abort(_('revision %d is not the parent of ' |
|
1318 | raise util.Abort(_('revision %d is not the parent of ' | |
1319 | 'the queue') % rev[0]) |
|
1319 | 'the queue') % rev[0]) | |
1320 | base = repo.changelog.rev(revlog.bin(self.applied[0].rev)) |
|
1320 | base = repo.changelog.rev(revlog.bin(self.applied[0].rev)) | |
1321 | lastparent = repo.changelog.parentrevs(base)[0] |
|
1321 | lastparent = repo.changelog.parentrevs(base)[0] | |
1322 | else: |
|
1322 | else: | |
1323 | if heads != [repo.changelog.node(rev[0])]: |
|
1323 | if heads != [repo.changelog.node(rev[0])]: | |
1324 | raise util.Abort(_('revision %d has unmanaged children') |
|
1324 | raise util.Abort(_('revision %d has unmanaged children') | |
1325 | % rev[0]) |
|
1325 | % rev[0]) | |
1326 | lastparent = None |
|
1326 | lastparent = None | |
1327 |
|
1327 | |||
1328 | if git: |
|
1328 | if git: | |
1329 | self.diffopts().git = True |
|
1329 | self.diffopts().git = True | |
1330 |
|
1330 | |||
1331 | for r in rev: |
|
1331 | for r in rev: | |
1332 | p1, p2 = repo.changelog.parentrevs(r) |
|
1332 | p1, p2 = repo.changelog.parentrevs(r) | |
1333 | n = repo.changelog.node(r) |
|
1333 | n = repo.changelog.node(r) | |
1334 | if p2 != revlog.nullrev: |
|
1334 | if p2 != revlog.nullrev: | |
1335 | raise util.Abort(_('cannot import merge revision %d') % r) |
|
1335 | raise util.Abort(_('cannot import merge revision %d') % r) | |
1336 | if lastparent and lastparent != r: |
|
1336 | if lastparent and lastparent != r: | |
1337 | raise util.Abort(_('revision %d is not the parent of %d') |
|
1337 | raise util.Abort(_('revision %d is not the parent of %d') | |
1338 | % (r, lastparent)) |
|
1338 | % (r, lastparent)) | |
1339 | lastparent = p1 |
|
1339 | lastparent = p1 | |
1340 |
|
1340 | |||
1341 | if not patchname: |
|
1341 | if not patchname: | |
1342 | patchname = normname('%d.diff' % r) |
|
1342 | patchname = normname('%d.diff' % r) | |
1343 | checkseries(patchname) |
|
1343 | checkseries(patchname) | |
1344 | checkfile(patchname) |
|
1344 | checkfile(patchname) | |
1345 | self.full_series.insert(0, patchname) |
|
1345 | self.full_series.insert(0, patchname) | |
1346 |
|
1346 | |||
1347 | patchf = self.opener(patchname, "w") |
|
1347 | patchf = self.opener(patchname, "w") | |
1348 | patch.export(repo, [n], fp=patchf, opts=self.diffopts()) |
|
1348 | patch.export(repo, [n], fp=patchf, opts=self.diffopts()) | |
1349 | patchf.close() |
|
1349 | patchf.close() | |
1350 |
|
1350 | |||
1351 | se = statusentry(revlog.hex(n), patchname) |
|
1351 | se = statusentry(revlog.hex(n), patchname) | |
1352 | self.applied.insert(0, se) |
|
1352 | self.applied.insert(0, se) | |
1353 |
|
1353 | |||
1354 | added.append(patchname) |
|
1354 | added.append(patchname) | |
1355 | patchname = None |
|
1355 | patchname = None | |
1356 | self.parse_series() |
|
1356 | self.parse_series() | |
1357 | self.applied_dirty = 1 |
|
1357 | self.applied_dirty = 1 | |
1358 |
|
1358 | |||
1359 | for filename in files: |
|
1359 | for filename in files: | |
1360 | if existing: |
|
1360 | if existing: | |
1361 | if filename == '-': |
|
1361 | if filename == '-': | |
1362 | raise util.Abort(_('-e is incompatible with import from -')) |
|
1362 | raise util.Abort(_('-e is incompatible with import from -')) | |
1363 | if not patchname: |
|
1363 | if not patchname: | |
1364 | patchname = normname(filename) |
|
1364 | patchname = normname(filename) | |
1365 | if not os.path.isfile(self.join(patchname)): |
|
1365 | if not os.path.isfile(self.join(patchname)): | |
1366 | raise util.Abort(_("patch %s does not exist") % patchname) |
|
1366 | raise util.Abort(_("patch %s does not exist") % patchname) | |
1367 | else: |
|
1367 | else: | |
1368 | try: |
|
1368 | try: | |
1369 | if filename == '-': |
|
1369 | if filename == '-': | |
1370 | if not patchname: |
|
1370 | if not patchname: | |
1371 | raise util.Abort(_('need --name to import a patch from -')) |
|
1371 | raise util.Abort(_('need --name to import a patch from -')) | |
1372 | text = sys.stdin.read() |
|
1372 | text = sys.stdin.read() | |
1373 | else: |
|
1373 | else: | |
1374 | text = file(filename).read() |
|
1374 | text = file(filename).read() | |
1375 | except IOError: |
|
1375 | except IOError: | |
1376 | raise util.Abort(_("unable to read %s") % patchname) |
|
1376 | raise util.Abort(_("unable to read %s") % patchname) | |
1377 | if not patchname: |
|
1377 | if not patchname: | |
1378 | patchname = normname(os.path.basename(filename)) |
|
1378 | patchname = normname(os.path.basename(filename)) | |
1379 | checkfile(patchname) |
|
1379 | checkfile(patchname) | |
1380 | patchf = self.opener(patchname, "w") |
|
1380 | patchf = self.opener(patchname, "w") | |
1381 | patchf.write(text) |
|
1381 | patchf.write(text) | |
1382 | checkseries(patchname) |
|
1382 | checkseries(patchname) | |
1383 | index = self.full_series_end() + i |
|
1383 | index = self.full_series_end() + i | |
1384 | self.full_series[index:index] = [patchname] |
|
1384 | self.full_series[index:index] = [patchname] | |
1385 | self.parse_series() |
|
1385 | self.parse_series() | |
1386 | self.ui.warn("adding %s to series file\n" % patchname) |
|
1386 | self.ui.warn("adding %s to series file\n" % patchname) | |
1387 | i += 1 |
|
1387 | i += 1 | |
1388 | added.append(patchname) |
|
1388 | added.append(patchname) | |
1389 | patchname = None |
|
1389 | patchname = None | |
1390 | self.series_dirty = 1 |
|
1390 | self.series_dirty = 1 | |
1391 | qrepo = self.qrepo() |
|
1391 | qrepo = self.qrepo() | |
1392 | if qrepo: |
|
1392 | if qrepo: | |
1393 | qrepo.add(added) |
|
1393 | qrepo.add(added) | |
1394 |
|
1394 | |||
1395 | def delete(ui, repo, *patches, **opts): |
|
1395 | def delete(ui, repo, *patches, **opts): | |
1396 | """remove patches from queue |
|
1396 | """remove patches from queue | |
1397 |
|
1397 | |||
1398 | With --rev, mq will stop managing the named revisions. The |
|
1398 | With --rev, mq will stop managing the named revisions. The | |
1399 | patches must be applied and at the base of the stack. This option |
|
1399 | patches must be applied and at the base of the stack. This option | |
1400 | is useful when the patches have been applied upstream. |
|
1400 | is useful when the patches have been applied upstream. | |
1401 |
|
1401 | |||
1402 | Otherwise, the patches must not be applied. |
|
1402 | Otherwise, the patches must not be applied. | |
1403 |
|
1403 | |||
1404 | With --keep, the patch files are preserved in the patch directory.""" |
|
1404 | With --keep, the patch files are preserved in the patch directory.""" | |
1405 | q = repo.mq |
|
1405 | q = repo.mq | |
1406 | q.delete(repo, patches, opts) |
|
1406 | q.delete(repo, patches, opts) | |
1407 | q.save_dirty() |
|
1407 | q.save_dirty() | |
1408 | return 0 |
|
1408 | return 0 | |
1409 |
|
1409 | |||
1410 | def applied(ui, repo, patch=None, **opts): |
|
1410 | def applied(ui, repo, patch=None, **opts): | |
1411 | """print the patches already applied""" |
|
1411 | """print the patches already applied""" | |
1412 | q = repo.mq |
|
1412 | q = repo.mq | |
1413 | if patch: |
|
1413 | if patch: | |
1414 | if patch not in q.series: |
|
1414 | if patch not in q.series: | |
1415 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1415 | raise util.Abort(_("patch %s is not in series file") % patch) | |
1416 | end = q.series.index(patch) + 1 |
|
1416 | end = q.series.index(patch) + 1 | |
1417 | else: |
|
1417 | else: | |
1418 | end = len(q.applied) |
|
1418 | end = len(q.applied) | |
1419 | if not end: |
|
1419 | if not end: | |
1420 | return |
|
1420 | return | |
1421 |
|
1421 | |||
1422 | return q.qseries(repo, length=end, status='A', summary=opts.get('summary')) |
|
1422 | return q.qseries(repo, length=end, status='A', summary=opts.get('summary')) | |
1423 |
|
1423 | |||
1424 | def unapplied(ui, repo, patch=None, **opts): |
|
1424 | def unapplied(ui, repo, patch=None, **opts): | |
1425 | """print the patches not yet applied""" |
|
1425 | """print the patches not yet applied""" | |
1426 | q = repo.mq |
|
1426 | q = repo.mq | |
1427 | if patch: |
|
1427 | if patch: | |
1428 | if patch not in q.series: |
|
1428 | if patch not in q.series: | |
1429 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1429 | raise util.Abort(_("patch %s is not in series file") % patch) | |
1430 | start = q.series.index(patch) + 1 |
|
1430 | start = q.series.index(patch) + 1 | |
1431 | else: |
|
1431 | else: | |
1432 | start = q.series_end() |
|
1432 | start = q.series_end() | |
1433 | q.qseries(repo, start=start, summary=opts.get('summary')) |
|
1433 | q.qseries(repo, start=start, summary=opts.get('summary')) | |
1434 |
|
1434 | |||
1435 | def qimport(ui, repo, *filename, **opts): |
|
1435 | def qimport(ui, repo, *filename, **opts): | |
1436 | """import a patch |
|
1436 | """import a patch | |
1437 |
|
1437 | |||
1438 | The patch will have the same name as its source file unless you |
|
1438 | The patch will have the same name as its source file unless you | |
1439 | give it a new one with --name. |
|
1439 | give it a new one with --name. | |
1440 |
|
1440 | |||
1441 | You can register an existing patch inside the patch directory |
|
1441 | You can register an existing patch inside the patch directory | |
1442 | with the --existing flag. |
|
1442 | with the --existing flag. | |
1443 |
|
1443 | |||
1444 | With --force, an existing patch of the same name will be overwritten. |
|
1444 | With --force, an existing patch of the same name will be overwritten. | |
1445 |
|
1445 | |||
1446 | An existing changeset may be placed under mq control with --rev |
|
1446 | An existing changeset may be placed under mq control with --rev | |
1447 | (e.g. qimport --rev tip -n patch will place tip under mq control). |
|
1447 | (e.g. qimport --rev tip -n patch will place tip under mq control). | |
1448 | With --git, patches imported with --rev will use the git diff |
|
1448 | With --git, patches imported with --rev will use the git diff | |
1449 | format. |
|
1449 | format. | |
1450 | """ |
|
1450 | """ | |
1451 | q = repo.mq |
|
1451 | q = repo.mq | |
1452 | q.qimport(repo, filename, patchname=opts['name'], |
|
1452 | q.qimport(repo, filename, patchname=opts['name'], | |
1453 | existing=opts['existing'], force=opts['force'], rev=opts['rev'], |
|
1453 | existing=opts['existing'], force=opts['force'], rev=opts['rev'], | |
1454 | git=opts['git']) |
|
1454 | git=opts['git']) | |
1455 | q.save_dirty() |
|
1455 | q.save_dirty() | |
1456 | return 0 |
|
1456 | return 0 | |
1457 |
|
1457 | |||
1458 | def init(ui, repo, **opts): |
|
1458 | def init(ui, repo, **opts): | |
1459 | """init a new queue repository |
|
1459 | """init a new queue repository | |
1460 |
|
1460 | |||
1461 | The queue repository is unversioned by default. If -c is |
|
1461 | The queue repository is unversioned by default. If -c is | |
1462 | specified, qinit will create a separate nested repository |
|
1462 | specified, qinit will create a separate nested repository | |
1463 | for patches. Use qcommit to commit changes to this queue |
|
1463 | for patches. Use qcommit to commit changes to this queue | |
1464 | repository.""" |
|
1464 | repository.""" | |
1465 | q = repo.mq |
|
1465 | q = repo.mq | |
1466 | r = q.init(repo, create=opts['create_repo']) |
|
1466 | r = q.init(repo, create=opts['create_repo']) | |
1467 | q.save_dirty() |
|
1467 | q.save_dirty() | |
1468 | if r: |
|
1468 | if r: | |
1469 | fp = r.wopener('.hgignore', 'w') |
|
1469 | fp = r.wopener('.hgignore', 'w') | |
1470 | print >> fp, 'syntax: glob' |
|
1470 | print >> fp, 'syntax: glob' | |
1471 | print >> fp, 'status' |
|
1471 | print >> fp, 'status' | |
1472 | print >> fp, 'guards' |
|
1472 | print >> fp, 'guards' | |
1473 | fp.close() |
|
1473 | fp.close() | |
1474 | r.wopener('series', 'w').close() |
|
1474 | r.wopener('series', 'w').close() | |
1475 | r.add(['.hgignore', 'series']) |
|
1475 | r.add(['.hgignore', 'series']) | |
1476 | return 0 |
|
1476 | return 0 | |
1477 |
|
1477 | |||
1478 | def clone(ui, source, dest=None, **opts): |
|
1478 | def clone(ui, source, dest=None, **opts): | |
1479 | '''clone main and patch repository at same time |
|
1479 | '''clone main and patch repository at same time | |
1480 |
|
1480 | |||
1481 | If source is local, destination will have no patches applied. If |
|
1481 | If source is local, destination will have no patches applied. If | |
1482 | source is remote, this command can not check if patches are |
|
1482 | source is remote, this command can not check if patches are | |
1483 | applied in source, so cannot guarantee that patches are not |
|
1483 | applied in source, so cannot guarantee that patches are not | |
1484 | applied in destination. If you clone remote repository, be sure |
|
1484 | applied in destination. If you clone remote repository, be sure | |
1485 | before that it has no patches applied. |
|
1485 | before that it has no patches applied. | |
1486 |
|
1486 | |||
1487 | Source patch repository is looked for in <src>/.hg/patches by |
|
1487 | Source patch repository is looked for in <src>/.hg/patches by | |
1488 | default. Use -p <url> to change. |
|
1488 | default. Use -p <url> to change. | |
1489 | ''' |
|
1489 | ''' | |
1490 | commands.setremoteconfig(ui, opts) |
|
1490 | commands.setremoteconfig(ui, opts) | |
1491 | if dest is None: |
|
1491 | if dest is None: | |
1492 | dest = hg.defaultdest(source) |
|
1492 | dest = hg.defaultdest(source) | |
1493 | sr = hg.repository(ui, ui.expandpath(source)) |
|
1493 | sr = hg.repository(ui, ui.expandpath(source)) | |
1494 | qbase, destrev = None, None |
|
1494 | qbase, destrev = None, None | |
1495 | if sr.local(): |
|
1495 | if sr.local(): | |
1496 | reposetup(ui, sr) |
|
1496 | reposetup(ui, sr) | |
1497 | if sr.mq.applied: |
|
1497 | if sr.mq.applied: | |
1498 | qbase = revlog.bin(sr.mq.applied[0].rev) |
|
1498 | qbase = revlog.bin(sr.mq.applied[0].rev) | |
1499 | if not hg.islocal(dest): |
|
1499 | if not hg.islocal(dest): | |
1500 | destrev = sr.parents(qbase)[0] |
|
1500 | destrev = sr.parents(qbase)[0] | |
1501 | ui.note(_('cloning main repo\n')) |
|
1501 | ui.note(_('cloning main repo\n')) | |
1502 | sr, dr = hg.clone(ui, sr, dest, |
|
1502 | sr, dr = hg.clone(ui, sr, dest, | |
1503 | pull=opts['pull'], |
|
1503 | pull=opts['pull'], | |
1504 | rev=destrev, |
|
1504 | rev=destrev, | |
1505 | update=False, |
|
1505 | update=False, | |
1506 | stream=opts['uncompressed']) |
|
1506 | stream=opts['uncompressed']) | |
1507 | ui.note(_('cloning patch repo\n')) |
|
1507 | ui.note(_('cloning patch repo\n')) | |
1508 | spr, dpr = hg.clone(ui, opts['patches'] or (sr.url() + '/.hg/patches'), |
|
1508 | spr, dpr = hg.clone(ui, opts['patches'] or (sr.url() + '/.hg/patches'), | |
1509 | dr.url() + '/.hg/patches', |
|
1509 | dr.url() + '/.hg/patches', | |
1510 | pull=opts['pull'], |
|
1510 | pull=opts['pull'], | |
1511 | update=not opts['noupdate'], |
|
1511 | update=not opts['noupdate'], | |
1512 | stream=opts['uncompressed']) |
|
1512 | stream=opts['uncompressed']) | |
1513 | if dr.local(): |
|
1513 | if dr.local(): | |
1514 | if qbase: |
|
1514 | if qbase: | |
1515 | ui.note(_('stripping applied patches from destination repo\n')) |
|
1515 | ui.note(_('stripping applied patches from destination repo\n')) | |
1516 | reposetup(ui, dr) |
|
1516 | reposetup(ui, dr) | |
1517 | dr.mq.strip(dr, qbase, update=False, backup=None) |
|
1517 | dr.mq.strip(dr, qbase, update=False, backup=None) | |
1518 | if not opts['noupdate']: |
|
1518 | if not opts['noupdate']: | |
1519 | ui.note(_('updating destination repo\n')) |
|
1519 | ui.note(_('updating destination repo\n')) | |
1520 | hg.update(dr, dr.changelog.tip()) |
|
1520 | hg.update(dr, dr.changelog.tip()) | |
1521 |
|
1521 | |||
1522 | def commit(ui, repo, *pats, **opts): |
|
1522 | def commit(ui, repo, *pats, **opts): | |
1523 | """commit changes in the queue repository""" |
|
1523 | """commit changes in the queue repository""" | |
1524 | q = repo.mq |
|
1524 | q = repo.mq | |
1525 | r = q.qrepo() |
|
1525 | r = q.qrepo() | |
1526 | if not r: raise util.Abort('no queue repository') |
|
1526 | if not r: raise util.Abort('no queue repository') | |
1527 | commands.commit(r.ui, r, *pats, **opts) |
|
1527 | commands.commit(r.ui, r, *pats, **opts) | |
1528 |
|
1528 | |||
1529 | def series(ui, repo, **opts): |
|
1529 | def series(ui, repo, **opts): | |
1530 | """print the entire series file""" |
|
1530 | """print the entire series file""" | |
1531 | repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) |
|
1531 | repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) | |
1532 | return 0 |
|
1532 | return 0 | |
1533 |
|
1533 | |||
1534 | def top(ui, repo, **opts): |
|
1534 | def top(ui, repo, **opts): | |
1535 | """print the name of the current patch""" |
|
1535 | """print the name of the current patch""" | |
1536 | q = repo.mq |
|
1536 | q = repo.mq | |
1537 | t = len(q.applied) |
|
1537 | t = len(q.applied) | |
1538 | if t: |
|
1538 | if t: | |
1539 | return q.qseries(repo, start=t-1, length=1, status='A', |
|
1539 | return q.qseries(repo, start=t-1, length=1, status='A', | |
1540 | summary=opts.get('summary')) |
|
1540 | summary=opts.get('summary')) | |
1541 | else: |
|
1541 | else: | |
1542 | ui.write("No patches applied\n") |
|
1542 | ui.write("No patches applied\n") | |
1543 | return 1 |
|
1543 | return 1 | |
1544 |
|
1544 | |||
1545 | def next(ui, repo, **opts): |
|
1545 | def next(ui, repo, **opts): | |
1546 | """print the name of the next patch""" |
|
1546 | """print the name of the next patch""" | |
1547 | q = repo.mq |
|
1547 | q = repo.mq | |
1548 | end = q.series_end() |
|
1548 | end = q.series_end() | |
1549 | if end == len(q.series): |
|
1549 | if end == len(q.series): | |
1550 | ui.write("All patches applied\n") |
|
1550 | ui.write("All patches applied\n") | |
1551 | return 1 |
|
1551 | return 1 | |
1552 | return q.qseries(repo, start=end, length=1, summary=opts.get('summary')) |
|
1552 | return q.qseries(repo, start=end, length=1, summary=opts.get('summary')) | |
1553 |
|
1553 | |||
1554 | def prev(ui, repo, **opts): |
|
1554 | def prev(ui, repo, **opts): | |
1555 | """print the name of the previous patch""" |
|
1555 | """print the name of the previous patch""" | |
1556 | q = repo.mq |
|
1556 | q = repo.mq | |
1557 | l = len(q.applied) |
|
1557 | l = len(q.applied) | |
1558 | if l == 1: |
|
1558 | if l == 1: | |
1559 | ui.write("Only one patch applied\n") |
|
1559 | ui.write("Only one patch applied\n") | |
1560 | return 1 |
|
1560 | return 1 | |
1561 | if not l: |
|
1561 | if not l: | |
1562 | ui.write("No patches applied\n") |
|
1562 | ui.write("No patches applied\n") | |
1563 | return 1 |
|
1563 | return 1 | |
1564 | return q.qseries(repo, start=l-2, length=1, status='A', |
|
1564 | return q.qseries(repo, start=l-2, length=1, status='A', | |
1565 | summary=opts.get('summary')) |
|
1565 | summary=opts.get('summary')) | |
1566 |
|
1566 | |||
1567 | def new(ui, repo, patch, **opts): |
|
1567 | def new(ui, repo, patch, **opts): | |
1568 | """create a new patch |
|
1568 | """create a new patch | |
1569 |
|
1569 | |||
1570 | qnew creates a new patch on top of the currently-applied patch |
|
1570 | qnew creates a new patch on top of the currently-applied patch | |
1571 | (if any). It will refuse to run if there are any outstanding |
|
1571 | (if any). It will refuse to run if there are any outstanding | |
1572 | changes unless -f is specified, in which case the patch will |
|
1572 | changes unless -f is specified, in which case the patch will | |
1573 | be initialised with them. |
|
1573 | be initialised with them. | |
1574 |
|
1574 | |||
1575 | -e, -m or -l set the patch header as well as the commit message. |
|
1575 | -e, -m or -l set the patch header as well as the commit message. | |
1576 | If none is specified, the patch header is empty and the |
|
1576 | If none is specified, the patch header is empty and the | |
1577 | commit message is 'New patch: PATCH'""" |
|
1577 | commit message is 'New patch: PATCH'""" | |
1578 | q = repo.mq |
|
1578 | q = repo.mq | |
1579 | message = commands.logmessage(opts) |
|
1579 | message = commands.logmessage(opts) | |
1580 | if opts['edit']: |
|
1580 | if opts['edit']: | |
1581 | message = ui.edit(message, ui.username()) |
|
1581 | message = ui.edit(message, ui.username()) | |
1582 | q.new(repo, patch, msg=message, force=opts['force']) |
|
1582 | q.new(repo, patch, msg=message, force=opts['force']) | |
1583 | q.save_dirty() |
|
1583 | q.save_dirty() | |
1584 | return 0 |
|
1584 | return 0 | |
1585 |
|
1585 | |||
1586 | def refresh(ui, repo, *pats, **opts): |
|
1586 | def refresh(ui, repo, *pats, **opts): | |
1587 | """update the current patch |
|
1587 | """update the current patch | |
1588 |
|
1588 | |||
1589 | If any file patterns are provided, the refreshed patch will contain only |
|
1589 | If any file patterns are provided, the refreshed patch will contain only | |
1590 | the modifications that match those patterns; the remaining modifications |
|
1590 | the modifications that match those patterns; the remaining modifications | |
1591 | will remain in the working directory. |
|
1591 | will remain in the working directory. | |
|
1592 | ||||
|
1593 | hg add/remove/copy/rename work as usual, though you might want to use | |||
|
1594 | git-style patches (--git or [diff] git=1) to track copies and renames. | |||
1592 | """ |
|
1595 | """ | |
1593 | q = repo.mq |
|
1596 | q = repo.mq | |
1594 | message = commands.logmessage(opts) |
|
1597 | message = commands.logmessage(opts) | |
1595 | if opts['edit']: |
|
1598 | if opts['edit']: | |
1596 | if message: |
|
1599 | if message: | |
1597 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1600 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) | |
1598 | patch = q.applied[-1].name |
|
1601 | patch = q.applied[-1].name | |
1599 | (message, comment, user, date, hasdiff) = q.readheaders(patch) |
|
1602 | (message, comment, user, date, hasdiff) = q.readheaders(patch) | |
1600 | message = ui.edit('\n'.join(message), user or ui.username()) |
|
1603 | message = ui.edit('\n'.join(message), user or ui.username()) | |
1601 | ret = q.refresh(repo, pats, msg=message, **opts) |
|
1604 | ret = q.refresh(repo, pats, msg=message, **opts) | |
1602 | q.save_dirty() |
|
1605 | q.save_dirty() | |
1603 | return ret |
|
1606 | return ret | |
1604 |
|
1607 | |||
1605 | def diff(ui, repo, *pats, **opts): |
|
1608 | def diff(ui, repo, *pats, **opts): | |
1606 | """diff of the current patch""" |
|
1609 | """diff of the current patch""" | |
1607 | repo.mq.diff(repo, pats, opts) |
|
1610 | repo.mq.diff(repo, pats, opts) | |
1608 | return 0 |
|
1611 | return 0 | |
1609 |
|
1612 | |||
1610 | def fold(ui, repo, *files, **opts): |
|
1613 | def fold(ui, repo, *files, **opts): | |
1611 | """fold the named patches into the current patch |
|
1614 | """fold the named patches into the current patch | |
1612 |
|
1615 | |||
1613 | Patches must not yet be applied. Each patch will be successively |
|
1616 | Patches must not yet be applied. Each patch will be successively | |
1614 | applied to the current patch in the order given. If all the |
|
1617 | applied to the current patch in the order given. If all the | |
1615 | patches apply successfully, the current patch will be refreshed |
|
1618 | patches apply successfully, the current patch will be refreshed | |
1616 | with the new cumulative patch, and the folded patches will |
|
1619 | with the new cumulative patch, and the folded patches will | |
1617 | be deleted. With -k/--keep, the folded patch files will not |
|
1620 | be deleted. With -k/--keep, the folded patch files will not | |
1618 | be removed afterwards. |
|
1621 | be removed afterwards. | |
1619 |
|
1622 | |||
1620 | The header for each folded patch will be concatenated with |
|
1623 | The header for each folded patch will be concatenated with | |
1621 | the current patch header, separated by a line of '* * *'.""" |
|
1624 | the current patch header, separated by a line of '* * *'.""" | |
1622 |
|
1625 | |||
1623 | q = repo.mq |
|
1626 | q = repo.mq | |
1624 |
|
1627 | |||
1625 | if not files: |
|
1628 | if not files: | |
1626 | raise util.Abort(_('qfold requires at least one patch name')) |
|
1629 | raise util.Abort(_('qfold requires at least one patch name')) | |
1627 | if not q.check_toppatch(repo): |
|
1630 | if not q.check_toppatch(repo): | |
1628 | raise util.Abort(_('No patches applied')) |
|
1631 | raise util.Abort(_('No patches applied')) | |
1629 |
|
1632 | |||
1630 | message = commands.logmessage(opts) |
|
1633 | message = commands.logmessage(opts) | |
1631 | if opts['edit']: |
|
1634 | if opts['edit']: | |
1632 | if message: |
|
1635 | if message: | |
1633 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1636 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) | |
1634 |
|
1637 | |||
1635 | parent = q.lookup('qtip') |
|
1638 | parent = q.lookup('qtip') | |
1636 | patches = [] |
|
1639 | patches = [] | |
1637 | messages = [] |
|
1640 | messages = [] | |
1638 | for f in files: |
|
1641 | for f in files: | |
1639 | p = q.lookup(f) |
|
1642 | p = q.lookup(f) | |
1640 | if p in patches or p == parent: |
|
1643 | if p in patches or p == parent: | |
1641 | ui.warn(_('Skipping already folded patch %s') % p) |
|
1644 | ui.warn(_('Skipping already folded patch %s') % p) | |
1642 | if q.isapplied(p): |
|
1645 | if q.isapplied(p): | |
1643 | raise util.Abort(_('qfold cannot fold already applied patch %s') % p) |
|
1646 | raise util.Abort(_('qfold cannot fold already applied patch %s') % p) | |
1644 | patches.append(p) |
|
1647 | patches.append(p) | |
1645 |
|
1648 | |||
1646 | for p in patches: |
|
1649 | for p in patches: | |
1647 | if not message: |
|
1650 | if not message: | |
1648 | messages.append(q.readheaders(p)[0]) |
|
1651 | messages.append(q.readheaders(p)[0]) | |
1649 | pf = q.join(p) |
|
1652 | pf = q.join(p) | |
1650 | (patchsuccess, files, fuzz) = q.patch(repo, pf) |
|
1653 | (patchsuccess, files, fuzz) = q.patch(repo, pf) | |
1651 | if not patchsuccess: |
|
1654 | if not patchsuccess: | |
1652 | raise util.Abort(_('Error folding patch %s') % p) |
|
1655 | raise util.Abort(_('Error folding patch %s') % p) | |
1653 | patch.updatedir(ui, repo, files) |
|
1656 | patch.updatedir(ui, repo, files) | |
1654 |
|
1657 | |||
1655 | if not message: |
|
1658 | if not message: | |
1656 | message, comments, user = q.readheaders(parent)[0:3] |
|
1659 | message, comments, user = q.readheaders(parent)[0:3] | |
1657 | for msg in messages: |
|
1660 | for msg in messages: | |
1658 | message.append('* * *') |
|
1661 | message.append('* * *') | |
1659 | message.extend(msg) |
|
1662 | message.extend(msg) | |
1660 | message = '\n'.join(message) |
|
1663 | message = '\n'.join(message) | |
1661 |
|
1664 | |||
1662 | if opts['edit']: |
|
1665 | if opts['edit']: | |
1663 | message = ui.edit(message, user or ui.username()) |
|
1666 | message = ui.edit(message, user or ui.username()) | |
1664 |
|
1667 | |||
1665 | q.refresh(repo, msg=message) |
|
1668 | q.refresh(repo, msg=message) | |
1666 | q.delete(repo, patches, opts) |
|
1669 | q.delete(repo, patches, opts) | |
1667 | q.save_dirty() |
|
1670 | q.save_dirty() | |
1668 |
|
1671 | |||
1669 | def guard(ui, repo, *args, **opts): |
|
1672 | def guard(ui, repo, *args, **opts): | |
1670 | '''set or print guards for a patch |
|
1673 | '''set or print guards for a patch | |
1671 |
|
1674 | |||
1672 | Guards control whether a patch can be pushed. A patch with no |
|
1675 | Guards control whether a patch can be pushed. A patch with no | |
1673 | guards is always pushed. A patch with a positive guard ("+foo") is |
|
1676 | guards is always pushed. A patch with a positive guard ("+foo") is | |
1674 | pushed only if the qselect command has activated it. A patch with |
|
1677 | pushed only if the qselect command has activated it. A patch with | |
1675 | a negative guard ("-foo") is never pushed if the qselect command |
|
1678 | a negative guard ("-foo") is never pushed if the qselect command | |
1676 | has activated it. |
|
1679 | has activated it. | |
1677 |
|
1680 | |||
1678 | With no arguments, print the currently active guards. |
|
1681 | With no arguments, print the currently active guards. | |
1679 | With arguments, set guards for the named patch. |
|
1682 | With arguments, set guards for the named patch. | |
1680 |
|
1683 | |||
1681 | To set a negative guard "-foo" on topmost patch ("--" is needed so |
|
1684 | To set a negative guard "-foo" on topmost patch ("--" is needed so | |
1682 | hg will not interpret "-foo" as an option): |
|
1685 | hg will not interpret "-foo" as an option): | |
1683 | hg qguard -- -foo |
|
1686 | hg qguard -- -foo | |
1684 |
|
1687 | |||
1685 | To set guards on another patch: |
|
1688 | To set guards on another patch: | |
1686 | hg qguard other.patch +2.6.17 -stable |
|
1689 | hg qguard other.patch +2.6.17 -stable | |
1687 | ''' |
|
1690 | ''' | |
1688 | def status(idx): |
|
1691 | def status(idx): | |
1689 | guards = q.series_guards[idx] or ['unguarded'] |
|
1692 | guards = q.series_guards[idx] or ['unguarded'] | |
1690 | ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards))) |
|
1693 | ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards))) | |
1691 | q = repo.mq |
|
1694 | q = repo.mq | |
1692 | patch = None |
|
1695 | patch = None | |
1693 | args = list(args) |
|
1696 | args = list(args) | |
1694 | if opts['list']: |
|
1697 | if opts['list']: | |
1695 | if args or opts['none']: |
|
1698 | if args or opts['none']: | |
1696 | raise util.Abort(_('cannot mix -l/--list with options or arguments')) |
|
1699 | raise util.Abort(_('cannot mix -l/--list with options or arguments')) | |
1697 | for i in xrange(len(q.series)): |
|
1700 | for i in xrange(len(q.series)): | |
1698 | status(i) |
|
1701 | status(i) | |
1699 | return |
|
1702 | return | |
1700 | if not args or args[0][0:1] in '-+': |
|
1703 | if not args or args[0][0:1] in '-+': | |
1701 | if not q.applied: |
|
1704 | if not q.applied: | |
1702 | raise util.Abort(_('no patches applied')) |
|
1705 | raise util.Abort(_('no patches applied')) | |
1703 | patch = q.applied[-1].name |
|
1706 | patch = q.applied[-1].name | |
1704 | if patch is None and args[0][0:1] not in '-+': |
|
1707 | if patch is None and args[0][0:1] not in '-+': | |
1705 | patch = args.pop(0) |
|
1708 | patch = args.pop(0) | |
1706 | if patch is None: |
|
1709 | if patch is None: | |
1707 | raise util.Abort(_('no patch to work with')) |
|
1710 | raise util.Abort(_('no patch to work with')) | |
1708 | if args or opts['none']: |
|
1711 | if args or opts['none']: | |
1709 | q.set_guards(q.find_series(patch), args) |
|
1712 | q.set_guards(q.find_series(patch), args) | |
1710 | q.save_dirty() |
|
1713 | q.save_dirty() | |
1711 | else: |
|
1714 | else: | |
1712 | status(q.series.index(q.lookup(patch))) |
|
1715 | status(q.series.index(q.lookup(patch))) | |
1713 |
|
1716 | |||
1714 | def header(ui, repo, patch=None): |
|
1717 | def header(ui, repo, patch=None): | |
1715 | """Print the header of the topmost or specified patch""" |
|
1718 | """Print the header of the topmost or specified patch""" | |
1716 | q = repo.mq |
|
1719 | q = repo.mq | |
1717 |
|
1720 | |||
1718 | if patch: |
|
1721 | if patch: | |
1719 | patch = q.lookup(patch) |
|
1722 | patch = q.lookup(patch) | |
1720 | else: |
|
1723 | else: | |
1721 | if not q.applied: |
|
1724 | if not q.applied: | |
1722 | ui.write('No patches applied\n') |
|
1725 | ui.write('No patches applied\n') | |
1723 | return 1 |
|
1726 | return 1 | |
1724 | patch = q.lookup('qtip') |
|
1727 | patch = q.lookup('qtip') | |
1725 | message = repo.mq.readheaders(patch)[0] |
|
1728 | message = repo.mq.readheaders(patch)[0] | |
1726 |
|
1729 | |||
1727 | ui.write('\n'.join(message) + '\n') |
|
1730 | ui.write('\n'.join(message) + '\n') | |
1728 |
|
1731 | |||
1729 | def lastsavename(path): |
|
1732 | def lastsavename(path): | |
1730 | (directory, base) = os.path.split(path) |
|
1733 | (directory, base) = os.path.split(path) | |
1731 | names = os.listdir(directory) |
|
1734 | names = os.listdir(directory) | |
1732 | namere = re.compile("%s.([0-9]+)" % base) |
|
1735 | namere = re.compile("%s.([0-9]+)" % base) | |
1733 | maxindex = None |
|
1736 | maxindex = None | |
1734 | maxname = None |
|
1737 | maxname = None | |
1735 | for f in names: |
|
1738 | for f in names: | |
1736 | m = namere.match(f) |
|
1739 | m = namere.match(f) | |
1737 | if m: |
|
1740 | if m: | |
1738 | index = int(m.group(1)) |
|
1741 | index = int(m.group(1)) | |
1739 | if maxindex == None or index > maxindex: |
|
1742 | if maxindex == None or index > maxindex: | |
1740 | maxindex = index |
|
1743 | maxindex = index | |
1741 | maxname = f |
|
1744 | maxname = f | |
1742 | if maxname: |
|
1745 | if maxname: | |
1743 | return (os.path.join(directory, maxname), maxindex) |
|
1746 | return (os.path.join(directory, maxname), maxindex) | |
1744 | return (None, None) |
|
1747 | return (None, None) | |
1745 |
|
1748 | |||
1746 | def savename(path): |
|
1749 | def savename(path): | |
1747 | (last, index) = lastsavename(path) |
|
1750 | (last, index) = lastsavename(path) | |
1748 | if last is None: |
|
1751 | if last is None: | |
1749 | index = 0 |
|
1752 | index = 0 | |
1750 | newpath = path + ".%d" % (index + 1) |
|
1753 | newpath = path + ".%d" % (index + 1) | |
1751 | return newpath |
|
1754 | return newpath | |
1752 |
|
1755 | |||
1753 | def push(ui, repo, patch=None, **opts): |
|
1756 | def push(ui, repo, patch=None, **opts): | |
1754 | """push the next patch onto the stack""" |
|
1757 | """push the next patch onto the stack""" | |
1755 | q = repo.mq |
|
1758 | q = repo.mq | |
1756 | mergeq = None |
|
1759 | mergeq = None | |
1757 |
|
1760 | |||
1758 | if opts['all']: |
|
1761 | if opts['all']: | |
1759 | if not q.series: |
|
1762 | if not q.series: | |
1760 | raise util.Abort(_('no patches in series')) |
|
1763 | raise util.Abort(_('no patches in series')) | |
1761 | patch = q.series[-1] |
|
1764 | patch = q.series[-1] | |
1762 | if opts['merge']: |
|
1765 | if opts['merge']: | |
1763 | if opts['name']: |
|
1766 | if opts['name']: | |
1764 | newpath = opts['name'] |
|
1767 | newpath = opts['name'] | |
1765 | else: |
|
1768 | else: | |
1766 | newpath, i = lastsavename(q.path) |
|
1769 | newpath, i = lastsavename(q.path) | |
1767 | if not newpath: |
|
1770 | if not newpath: | |
1768 | ui.warn("no saved queues found, please use -n\n") |
|
1771 | ui.warn("no saved queues found, please use -n\n") | |
1769 | return 1 |
|
1772 | return 1 | |
1770 | mergeq = queue(ui, repo.join(""), newpath) |
|
1773 | mergeq = queue(ui, repo.join(""), newpath) | |
1771 | ui.warn("merging with queue at: %s\n" % mergeq.path) |
|
1774 | ui.warn("merging with queue at: %s\n" % mergeq.path) | |
1772 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
|
1775 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], | |
1773 | mergeq=mergeq) |
|
1776 | mergeq=mergeq) | |
1774 | q.save_dirty() |
|
1777 | q.save_dirty() | |
1775 | return ret |
|
1778 | return ret | |
1776 |
|
1779 | |||
1777 | def pop(ui, repo, patch=None, **opts): |
|
1780 | def pop(ui, repo, patch=None, **opts): | |
1778 | """pop the current patch off the stack""" |
|
1781 | """pop the current patch off the stack""" | |
1779 | localupdate = True |
|
1782 | localupdate = True | |
1780 | if opts['name']: |
|
1783 | if opts['name']: | |
1781 | q = queue(ui, repo.join(""), repo.join(opts['name'])) |
|
1784 | q = queue(ui, repo.join(""), repo.join(opts['name'])) | |
1782 | ui.warn('using patch queue: %s\n' % q.path) |
|
1785 | ui.warn('using patch queue: %s\n' % q.path) | |
1783 | localupdate = False |
|
1786 | localupdate = False | |
1784 | else: |
|
1787 | else: | |
1785 | q = repo.mq |
|
1788 | q = repo.mq | |
1786 | q.pop(repo, patch, force=opts['force'], update=localupdate, all=opts['all']) |
|
1789 | q.pop(repo, patch, force=opts['force'], update=localupdate, all=opts['all']) | |
1787 | q.save_dirty() |
|
1790 | q.save_dirty() | |
1788 | return 0 |
|
1791 | return 0 | |
1789 |
|
1792 | |||
1790 | def rename(ui, repo, patch, name=None, **opts): |
|
1793 | def rename(ui, repo, patch, name=None, **opts): | |
1791 | """rename a patch |
|
1794 | """rename a patch | |
1792 |
|
1795 | |||
1793 | With one argument, renames the current patch to PATCH1. |
|
1796 | With one argument, renames the current patch to PATCH1. | |
1794 | With two arguments, renames PATCH1 to PATCH2.""" |
|
1797 | With two arguments, renames PATCH1 to PATCH2.""" | |
1795 |
|
1798 | |||
1796 | q = repo.mq |
|
1799 | q = repo.mq | |
1797 |
|
1800 | |||
1798 | if not name: |
|
1801 | if not name: | |
1799 | name = patch |
|
1802 | name = patch | |
1800 | patch = None |
|
1803 | patch = None | |
1801 |
|
1804 | |||
1802 | if patch: |
|
1805 | if patch: | |
1803 | patch = q.lookup(patch) |
|
1806 | patch = q.lookup(patch) | |
1804 | else: |
|
1807 | else: | |
1805 | if not q.applied: |
|
1808 | if not q.applied: | |
1806 | ui.write(_('No patches applied\n')) |
|
1809 | ui.write(_('No patches applied\n')) | |
1807 | return |
|
1810 | return | |
1808 | patch = q.lookup('qtip') |
|
1811 | patch = q.lookup('qtip') | |
1809 | absdest = q.join(name) |
|
1812 | absdest = q.join(name) | |
1810 | if os.path.isdir(absdest): |
|
1813 | if os.path.isdir(absdest): | |
1811 | name = normname(os.path.join(name, os.path.basename(patch))) |
|
1814 | name = normname(os.path.join(name, os.path.basename(patch))) | |
1812 | absdest = q.join(name) |
|
1815 | absdest = q.join(name) | |
1813 | if os.path.exists(absdest): |
|
1816 | if os.path.exists(absdest): | |
1814 | raise util.Abort(_('%s already exists') % absdest) |
|
1817 | raise util.Abort(_('%s already exists') % absdest) | |
1815 |
|
1818 | |||
1816 | if name in q.series: |
|
1819 | if name in q.series: | |
1817 | raise util.Abort(_('A patch named %s already exists in the series file') % name) |
|
1820 | raise util.Abort(_('A patch named %s already exists in the series file') % name) | |
1818 |
|
1821 | |||
1819 | if ui.verbose: |
|
1822 | if ui.verbose: | |
1820 | ui.write('Renaming %s to %s\n' % (patch, name)) |
|
1823 | ui.write('Renaming %s to %s\n' % (patch, name)) | |
1821 | i = q.find_series(patch) |
|
1824 | i = q.find_series(patch) | |
1822 | guards = q.guard_re.findall(q.full_series[i]) |
|
1825 | guards = q.guard_re.findall(q.full_series[i]) | |
1823 | q.full_series[i] = name + ''.join([' #' + g for g in guards]) |
|
1826 | q.full_series[i] = name + ''.join([' #' + g for g in guards]) | |
1824 | q.parse_series() |
|
1827 | q.parse_series() | |
1825 | q.series_dirty = 1 |
|
1828 | q.series_dirty = 1 | |
1826 |
|
1829 | |||
1827 | info = q.isapplied(patch) |
|
1830 | info = q.isapplied(patch) | |
1828 | if info: |
|
1831 | if info: | |
1829 | q.applied[info[0]] = statusentry(info[1], name) |
|
1832 | q.applied[info[0]] = statusentry(info[1], name) | |
1830 | q.applied_dirty = 1 |
|
1833 | q.applied_dirty = 1 | |
1831 |
|
1834 | |||
1832 | util.rename(q.join(patch), absdest) |
|
1835 | util.rename(q.join(patch), absdest) | |
1833 | r = q.qrepo() |
|
1836 | r = q.qrepo() | |
1834 | if r: |
|
1837 | if r: | |
1835 | wlock = r.wlock() |
|
1838 | wlock = r.wlock() | |
1836 | if r.dirstate.state(name) == 'r': |
|
1839 | if r.dirstate.state(name) == 'r': | |
1837 | r.undelete([name], wlock) |
|
1840 | r.undelete([name], wlock) | |
1838 | r.copy(patch, name, wlock) |
|
1841 | r.copy(patch, name, wlock) | |
1839 | r.remove([patch], False, wlock) |
|
1842 | r.remove([patch], False, wlock) | |
1840 |
|
1843 | |||
1841 | q.save_dirty() |
|
1844 | q.save_dirty() | |
1842 |
|
1845 | |||
1843 | def restore(ui, repo, rev, **opts): |
|
1846 | def restore(ui, repo, rev, **opts): | |
1844 | """restore the queue state saved by a rev""" |
|
1847 | """restore the queue state saved by a rev""" | |
1845 | rev = repo.lookup(rev) |
|
1848 | rev = repo.lookup(rev) | |
1846 | q = repo.mq |
|
1849 | q = repo.mq | |
1847 | q.restore(repo, rev, delete=opts['delete'], |
|
1850 | q.restore(repo, rev, delete=opts['delete'], | |
1848 | qupdate=opts['update']) |
|
1851 | qupdate=opts['update']) | |
1849 | q.save_dirty() |
|
1852 | q.save_dirty() | |
1850 | return 0 |
|
1853 | return 0 | |
1851 |
|
1854 | |||
1852 | def save(ui, repo, **opts): |
|
1855 | def save(ui, repo, **opts): | |
1853 | """save current queue state""" |
|
1856 | """save current queue state""" | |
1854 | q = repo.mq |
|
1857 | q = repo.mq | |
1855 | message = commands.logmessage(opts) |
|
1858 | message = commands.logmessage(opts) | |
1856 | ret = q.save(repo, msg=message) |
|
1859 | ret = q.save(repo, msg=message) | |
1857 | if ret: |
|
1860 | if ret: | |
1858 | return ret |
|
1861 | return ret | |
1859 | q.save_dirty() |
|
1862 | q.save_dirty() | |
1860 | if opts['copy']: |
|
1863 | if opts['copy']: | |
1861 | path = q.path |
|
1864 | path = q.path | |
1862 | if opts['name']: |
|
1865 | if opts['name']: | |
1863 | newpath = os.path.join(q.basepath, opts['name']) |
|
1866 | newpath = os.path.join(q.basepath, opts['name']) | |
1864 | if os.path.exists(newpath): |
|
1867 | if os.path.exists(newpath): | |
1865 | if not os.path.isdir(newpath): |
|
1868 | if not os.path.isdir(newpath): | |
1866 | raise util.Abort(_('destination %s exists and is not ' |
|
1869 | raise util.Abort(_('destination %s exists and is not ' | |
1867 | 'a directory') % newpath) |
|
1870 | 'a directory') % newpath) | |
1868 | if not opts['force']: |
|
1871 | if not opts['force']: | |
1869 | raise util.Abort(_('destination %s exists, ' |
|
1872 | raise util.Abort(_('destination %s exists, ' | |
1870 | 'use -f to force') % newpath) |
|
1873 | 'use -f to force') % newpath) | |
1871 | else: |
|
1874 | else: | |
1872 | newpath = savename(path) |
|
1875 | newpath = savename(path) | |
1873 | ui.warn("copy %s to %s\n" % (path, newpath)) |
|
1876 | ui.warn("copy %s to %s\n" % (path, newpath)) | |
1874 | util.copyfiles(path, newpath) |
|
1877 | util.copyfiles(path, newpath) | |
1875 | if opts['empty']: |
|
1878 | if opts['empty']: | |
1876 | try: |
|
1879 | try: | |
1877 | os.unlink(q.join(q.status_path)) |
|
1880 | os.unlink(q.join(q.status_path)) | |
1878 | except: |
|
1881 | except: | |
1879 | pass |
|
1882 | pass | |
1880 | return 0 |
|
1883 | return 0 | |
1881 |
|
1884 | |||
1882 | def strip(ui, repo, rev, **opts): |
|
1885 | def strip(ui, repo, rev, **opts): | |
1883 | """strip a revision and all later revs on the same branch""" |
|
1886 | """strip a revision and all later revs on the same branch""" | |
1884 | rev = repo.lookup(rev) |
|
1887 | rev = repo.lookup(rev) | |
1885 | backup = 'all' |
|
1888 | backup = 'all' | |
1886 | if opts['backup']: |
|
1889 | if opts['backup']: | |
1887 | backup = 'strip' |
|
1890 | backup = 'strip' | |
1888 | elif opts['nobackup']: |
|
1891 | elif opts['nobackup']: | |
1889 | backup = 'none' |
|
1892 | backup = 'none' | |
1890 | update = repo.dirstate.parents()[0] != revlog.nullid |
|
1893 | update = repo.dirstate.parents()[0] != revlog.nullid | |
1891 | repo.mq.strip(repo, rev, backup=backup, update=update) |
|
1894 | repo.mq.strip(repo, rev, backup=backup, update=update) | |
1892 | return 0 |
|
1895 | return 0 | |
1893 |
|
1896 | |||
1894 | def select(ui, repo, *args, **opts): |
|
1897 | def select(ui, repo, *args, **opts): | |
1895 | '''set or print guarded patches to push |
|
1898 | '''set or print guarded patches to push | |
1896 |
|
1899 | |||
1897 | Use the qguard command to set or print guards on patch, then use |
|
1900 | Use the qguard command to set or print guards on patch, then use | |
1898 | qselect to tell mq which guards to use. A patch will be pushed if it |
|
1901 | qselect to tell mq which guards to use. A patch will be pushed if it | |
1899 | has no guards or any positive guards match the currently selected guard, |
|
1902 | has no guards or any positive guards match the currently selected guard, | |
1900 | but will not be pushed if any negative guards match the current guard. |
|
1903 | but will not be pushed if any negative guards match the current guard. | |
1901 | For example: |
|
1904 | For example: | |
1902 |
|
1905 | |||
1903 | qguard foo.patch -stable (negative guard) |
|
1906 | qguard foo.patch -stable (negative guard) | |
1904 | qguard bar.patch +stable (positive guard) |
|
1907 | qguard bar.patch +stable (positive guard) | |
1905 | qselect stable |
|
1908 | qselect stable | |
1906 |
|
1909 | |||
1907 | This activates the "stable" guard. mq will skip foo.patch (because |
|
1910 | This activates the "stable" guard. mq will skip foo.patch (because | |
1908 | it has a negative match) but push bar.patch (because it |
|
1911 | it has a negative match) but push bar.patch (because it | |
1909 | has a positive match). |
|
1912 | has a positive match). | |
1910 |
|
1913 | |||
1911 | With no arguments, prints the currently active guards. |
|
1914 | With no arguments, prints the currently active guards. | |
1912 | With one argument, sets the active guard. |
|
1915 | With one argument, sets the active guard. | |
1913 |
|
1916 | |||
1914 | Use -n/--none to deactivate guards (no other arguments needed). |
|
1917 | Use -n/--none to deactivate guards (no other arguments needed). | |
1915 | When no guards are active, patches with positive guards are skipped |
|
1918 | When no guards are active, patches with positive guards are skipped | |
1916 | and patches with negative guards are pushed. |
|
1919 | and patches with negative guards are pushed. | |
1917 |
|
1920 | |||
1918 | qselect can change the guards on applied patches. It does not pop |
|
1921 | qselect can change the guards on applied patches. It does not pop | |
1919 | guarded patches by default. Use --pop to pop back to the last applied |
|
1922 | guarded patches by default. Use --pop to pop back to the last applied | |
1920 | patch that is not guarded. Use --reapply (which implies --pop) to push |
|
1923 | patch that is not guarded. Use --reapply (which implies --pop) to push | |
1921 | back to the current patch afterwards, but skip guarded patches. |
|
1924 | back to the current patch afterwards, but skip guarded patches. | |
1922 |
|
1925 | |||
1923 | Use -s/--series to print a list of all guards in the series file (no |
|
1926 | Use -s/--series to print a list of all guards in the series file (no | |
1924 | other arguments needed). Use -v for more information.''' |
|
1927 | other arguments needed). Use -v for more information.''' | |
1925 |
|
1928 | |||
1926 | q = repo.mq |
|
1929 | q = repo.mq | |
1927 | guards = q.active() |
|
1930 | guards = q.active() | |
1928 | if args or opts['none']: |
|
1931 | if args or opts['none']: | |
1929 | old_unapplied = q.unapplied(repo) |
|
1932 | old_unapplied = q.unapplied(repo) | |
1930 | old_guarded = [i for i in xrange(len(q.applied)) if |
|
1933 | old_guarded = [i for i in xrange(len(q.applied)) if | |
1931 | not q.pushable(i)[0]] |
|
1934 | not q.pushable(i)[0]] | |
1932 | q.set_active(args) |
|
1935 | q.set_active(args) | |
1933 | q.save_dirty() |
|
1936 | q.save_dirty() | |
1934 | if not args: |
|
1937 | if not args: | |
1935 | ui.status(_('guards deactivated\n')) |
|
1938 | ui.status(_('guards deactivated\n')) | |
1936 | if not opts['pop'] and not opts['reapply']: |
|
1939 | if not opts['pop'] and not opts['reapply']: | |
1937 | unapplied = q.unapplied(repo) |
|
1940 | unapplied = q.unapplied(repo) | |
1938 | guarded = [i for i in xrange(len(q.applied)) |
|
1941 | guarded = [i for i in xrange(len(q.applied)) | |
1939 | if not q.pushable(i)[0]] |
|
1942 | if not q.pushable(i)[0]] | |
1940 | if len(unapplied) != len(old_unapplied): |
|
1943 | if len(unapplied) != len(old_unapplied): | |
1941 | ui.status(_('number of unguarded, unapplied patches has ' |
|
1944 | ui.status(_('number of unguarded, unapplied patches has ' | |
1942 | 'changed from %d to %d\n') % |
|
1945 | 'changed from %d to %d\n') % | |
1943 | (len(old_unapplied), len(unapplied))) |
|
1946 | (len(old_unapplied), len(unapplied))) | |
1944 | if len(guarded) != len(old_guarded): |
|
1947 | if len(guarded) != len(old_guarded): | |
1945 | ui.status(_('number of guarded, applied patches has changed ' |
|
1948 | ui.status(_('number of guarded, applied patches has changed ' | |
1946 | 'from %d to %d\n') % |
|
1949 | 'from %d to %d\n') % | |
1947 | (len(old_guarded), len(guarded))) |
|
1950 | (len(old_guarded), len(guarded))) | |
1948 | elif opts['series']: |
|
1951 | elif opts['series']: | |
1949 | guards = {} |
|
1952 | guards = {} | |
1950 | noguards = 0 |
|
1953 | noguards = 0 | |
1951 | for gs in q.series_guards: |
|
1954 | for gs in q.series_guards: | |
1952 | if not gs: |
|
1955 | if not gs: | |
1953 | noguards += 1 |
|
1956 | noguards += 1 | |
1954 | for g in gs: |
|
1957 | for g in gs: | |
1955 | guards.setdefault(g, 0) |
|
1958 | guards.setdefault(g, 0) | |
1956 | guards[g] += 1 |
|
1959 | guards[g] += 1 | |
1957 | if ui.verbose: |
|
1960 | if ui.verbose: | |
1958 | guards['NONE'] = noguards |
|
1961 | guards['NONE'] = noguards | |
1959 | guards = guards.items() |
|
1962 | guards = guards.items() | |
1960 | guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:])) |
|
1963 | guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:])) | |
1961 | if guards: |
|
1964 | if guards: | |
1962 | ui.note(_('guards in series file:\n')) |
|
1965 | ui.note(_('guards in series file:\n')) | |
1963 | for guard, count in guards: |
|
1966 | for guard, count in guards: | |
1964 | ui.note('%2d ' % count) |
|
1967 | ui.note('%2d ' % count) | |
1965 | ui.write(guard, '\n') |
|
1968 | ui.write(guard, '\n') | |
1966 | else: |
|
1969 | else: | |
1967 | ui.note(_('no guards in series file\n')) |
|
1970 | ui.note(_('no guards in series file\n')) | |
1968 | else: |
|
1971 | else: | |
1969 | if guards: |
|
1972 | if guards: | |
1970 | ui.note(_('active guards:\n')) |
|
1973 | ui.note(_('active guards:\n')) | |
1971 | for g in guards: |
|
1974 | for g in guards: | |
1972 | ui.write(g, '\n') |
|
1975 | ui.write(g, '\n') | |
1973 | else: |
|
1976 | else: | |
1974 | ui.write(_('no active guards\n')) |
|
1977 | ui.write(_('no active guards\n')) | |
1975 | reapply = opts['reapply'] and q.applied and q.appliedname(-1) |
|
1978 | reapply = opts['reapply'] and q.applied and q.appliedname(-1) | |
1976 | popped = False |
|
1979 | popped = False | |
1977 | if opts['pop'] or opts['reapply']: |
|
1980 | if opts['pop'] or opts['reapply']: | |
1978 | for i in xrange(len(q.applied)): |
|
1981 | for i in xrange(len(q.applied)): | |
1979 | pushable, reason = q.pushable(i) |
|
1982 | pushable, reason = q.pushable(i) | |
1980 | if not pushable: |
|
1983 | if not pushable: | |
1981 | ui.status(_('popping guarded patches\n')) |
|
1984 | ui.status(_('popping guarded patches\n')) | |
1982 | popped = True |
|
1985 | popped = True | |
1983 | if i == 0: |
|
1986 | if i == 0: | |
1984 | q.pop(repo, all=True) |
|
1987 | q.pop(repo, all=True) | |
1985 | else: |
|
1988 | else: | |
1986 | q.pop(repo, i-1) |
|
1989 | q.pop(repo, i-1) | |
1987 | break |
|
1990 | break | |
1988 | if popped: |
|
1991 | if popped: | |
1989 | try: |
|
1992 | try: | |
1990 | if reapply: |
|
1993 | if reapply: | |
1991 | ui.status(_('reapplying unguarded patches\n')) |
|
1994 | ui.status(_('reapplying unguarded patches\n')) | |
1992 | q.push(repo, reapply) |
|
1995 | q.push(repo, reapply) | |
1993 | finally: |
|
1996 | finally: | |
1994 | q.save_dirty() |
|
1997 | q.save_dirty() | |
1995 |
|
1998 | |||
1996 | def reposetup(ui, repo): |
|
1999 | def reposetup(ui, repo): | |
1997 | class mqrepo(repo.__class__): |
|
2000 | class mqrepo(repo.__class__): | |
1998 | def abort_if_wdir_patched(self, errmsg, force=False): |
|
2001 | def abort_if_wdir_patched(self, errmsg, force=False): | |
1999 | if self.mq.applied and not force: |
|
2002 | if self.mq.applied and not force: | |
2000 | parent = revlog.hex(self.dirstate.parents()[0]) |
|
2003 | parent = revlog.hex(self.dirstate.parents()[0]) | |
2001 | if parent in [s.rev for s in self.mq.applied]: |
|
2004 | if parent in [s.rev for s in self.mq.applied]: | |
2002 | raise util.Abort(errmsg) |
|
2005 | raise util.Abort(errmsg) | |
2003 |
|
2006 | |||
2004 | def commit(self, *args, **opts): |
|
2007 | def commit(self, *args, **opts): | |
2005 | if len(args) >= 6: |
|
2008 | if len(args) >= 6: | |
2006 | force = args[5] |
|
2009 | force = args[5] | |
2007 | else: |
|
2010 | else: | |
2008 | force = opts.get('force') |
|
2011 | force = opts.get('force') | |
2009 | self.abort_if_wdir_patched( |
|
2012 | self.abort_if_wdir_patched( | |
2010 | _('cannot commit over an applied mq patch'), |
|
2013 | _('cannot commit over an applied mq patch'), | |
2011 | force) |
|
2014 | force) | |
2012 |
|
2015 | |||
2013 | return super(mqrepo, self).commit(*args, **opts) |
|
2016 | return super(mqrepo, self).commit(*args, **opts) | |
2014 |
|
2017 | |||
2015 | def push(self, remote, force=False, revs=None): |
|
2018 | def push(self, remote, force=False, revs=None): | |
2016 | if self.mq.applied and not force and not revs: |
|
2019 | if self.mq.applied and not force and not revs: | |
2017 | raise util.Abort(_('source has mq patches applied')) |
|
2020 | raise util.Abort(_('source has mq patches applied')) | |
2018 | return super(mqrepo, self).push(remote, force, revs) |
|
2021 | return super(mqrepo, self).push(remote, force, revs) | |
2019 |
|
2022 | |||
2020 | def tags(self): |
|
2023 | def tags(self): | |
2021 | if self.tagscache: |
|
2024 | if self.tagscache: | |
2022 | return self.tagscache |
|
2025 | return self.tagscache | |
2023 |
|
2026 | |||
2024 | tagscache = super(mqrepo, self).tags() |
|
2027 | tagscache = super(mqrepo, self).tags() | |
2025 |
|
2028 | |||
2026 | q = self.mq |
|
2029 | q = self.mq | |
2027 | if not q.applied: |
|
2030 | if not q.applied: | |
2028 | return tagscache |
|
2031 | return tagscache | |
2029 |
|
2032 | |||
2030 | mqtags = [(patch.rev, patch.name) for patch in q.applied] |
|
2033 | mqtags = [(patch.rev, patch.name) for patch in q.applied] | |
2031 | mqtags.append((mqtags[-1][0], 'qtip')) |
|
2034 | mqtags.append((mqtags[-1][0], 'qtip')) | |
2032 | mqtags.append((mqtags[0][0], 'qbase')) |
|
2035 | mqtags.append((mqtags[0][0], 'qbase')) | |
2033 | for patch in mqtags: |
|
2036 | for patch in mqtags: | |
2034 | if patch[1] in tagscache: |
|
2037 | if patch[1] in tagscache: | |
2035 | self.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1]) |
|
2038 | self.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1]) | |
2036 | else: |
|
2039 | else: | |
2037 | tagscache[patch[1]] = revlog.bin(patch[0]) |
|
2040 | tagscache[patch[1]] = revlog.bin(patch[0]) | |
2038 |
|
2041 | |||
2039 | return tagscache |
|
2042 | return tagscache | |
2040 |
|
2043 | |||
2041 | def _branchtags(self): |
|
2044 | def _branchtags(self): | |
2042 | q = self.mq |
|
2045 | q = self.mq | |
2043 | if not q.applied: |
|
2046 | if not q.applied: | |
2044 | return super(mqrepo, self)._branchtags() |
|
2047 | return super(mqrepo, self)._branchtags() | |
2045 |
|
2048 | |||
2046 | self.branchcache = {} # avoid recursion in changectx |
|
2049 | self.branchcache = {} # avoid recursion in changectx | |
2047 | cl = self.changelog |
|
2050 | cl = self.changelog | |
2048 | partial, last, lrev = self._readbranchcache() |
|
2051 | partial, last, lrev = self._readbranchcache() | |
2049 |
|
2052 | |||
2050 | qbase = cl.rev(revlog.bin(q.applied[0].rev)) |
|
2053 | qbase = cl.rev(revlog.bin(q.applied[0].rev)) | |
2051 | start = lrev + 1 |
|
2054 | start = lrev + 1 | |
2052 | if start < qbase: |
|
2055 | if start < qbase: | |
2053 | # update the cache (excluding the patches) and save it |
|
2056 | # update the cache (excluding the patches) and save it | |
2054 | self._updatebranchcache(partial, lrev+1, qbase) |
|
2057 | self._updatebranchcache(partial, lrev+1, qbase) | |
2055 | self._writebranchcache(partial, cl.node(qbase-1), qbase-1) |
|
2058 | self._writebranchcache(partial, cl.node(qbase-1), qbase-1) | |
2056 | start = qbase |
|
2059 | start = qbase | |
2057 | # if start = qbase, the cache is as updated as it should be. |
|
2060 | # if start = qbase, the cache is as updated as it should be. | |
2058 | # if start > qbase, the cache includes (part of) the patches. |
|
2061 | # if start > qbase, the cache includes (part of) the patches. | |
2059 | # we might as well use it, but we won't save it. |
|
2062 | # we might as well use it, but we won't save it. | |
2060 |
|
2063 | |||
2061 | # update the cache up to the tip |
|
2064 | # update the cache up to the tip | |
2062 | self._updatebranchcache(partial, start, cl.count()) |
|
2065 | self._updatebranchcache(partial, start, cl.count()) | |
2063 |
|
2066 | |||
2064 | return partial |
|
2067 | return partial | |
2065 |
|
2068 | |||
2066 | if repo.local(): |
|
2069 | if repo.local(): | |
2067 | repo.__class__ = mqrepo |
|
2070 | repo.__class__ = mqrepo | |
2068 | repo.mq = queue(ui, repo.join("")) |
|
2071 | repo.mq = queue(ui, repo.join("")) | |
2069 |
|
2072 | |||
2070 | seriesopts = [('s', 'summary', None, _('print first line of patch header'))] |
|
2073 | seriesopts = [('s', 'summary', None, _('print first line of patch header'))] | |
2071 |
|
2074 | |||
2072 | cmdtable = { |
|
2075 | cmdtable = { | |
2073 | "qapplied": (applied, [] + seriesopts, 'hg qapplied [-s] [PATCH]'), |
|
2076 | "qapplied": (applied, [] + seriesopts, 'hg qapplied [-s] [PATCH]'), | |
2074 | "qclone": (clone, |
|
2077 | "qclone": (clone, | |
2075 | [('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2078 | [('', 'pull', None, _('use pull protocol to copy metadata')), | |
2076 | ('U', 'noupdate', None, _('do not update the new working directories')), |
|
2079 | ('U', 'noupdate', None, _('do not update the new working directories')), | |
2077 | ('', 'uncompressed', None, |
|
2080 | ('', 'uncompressed', None, | |
2078 | _('use uncompressed transfer (fast over LAN)')), |
|
2081 | _('use uncompressed transfer (fast over LAN)')), | |
2079 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2082 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2080 | ('p', 'patches', '', _('location of source patch repo')), |
|
2083 | ('p', 'patches', '', _('location of source patch repo')), | |
2081 | ('', 'remotecmd', '', |
|
2084 | ('', 'remotecmd', '', | |
2082 | _('specify hg command to run on the remote side'))], |
|
2085 | _('specify hg command to run on the remote side'))], | |
2083 | 'hg qclone [OPTION]... SOURCE [DEST]'), |
|
2086 | 'hg qclone [OPTION]... SOURCE [DEST]'), | |
2084 | "qcommit|qci": |
|
2087 | "qcommit|qci": | |
2085 | (commit, |
|
2088 | (commit, | |
2086 | commands.table["^commit|ci"][1], |
|
2089 | commands.table["^commit|ci"][1], | |
2087 | 'hg qcommit [OPTION]... [FILE]...'), |
|
2090 | 'hg qcommit [OPTION]... [FILE]...'), | |
2088 | "^qdiff": (diff, |
|
2091 | "^qdiff": (diff, | |
2089 | [('g', 'git', None, _('use git extended diff format')), |
|
2092 | [('g', 'git', None, _('use git extended diff format')), | |
2090 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2093 | ('I', 'include', [], _('include names matching the given patterns')), | |
2091 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2094 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2092 | 'hg qdiff [-I] [-X] [FILE]...'), |
|
2095 | 'hg qdiff [-I] [-X] [FILE]...'), | |
2093 | "qdelete|qremove|qrm": |
|
2096 | "qdelete|qremove|qrm": | |
2094 | (delete, |
|
2097 | (delete, | |
2095 | [('k', 'keep', None, _('keep patch file')), |
|
2098 | [('k', 'keep', None, _('keep patch file')), | |
2096 | ('r', 'rev', [], _('stop managing a revision'))], |
|
2099 | ('r', 'rev', [], _('stop managing a revision'))], | |
2097 | 'hg qdelete [-k] [-r REV]... PATCH...'), |
|
2100 | 'hg qdelete [-k] [-r REV]... PATCH...'), | |
2098 | 'qfold': |
|
2101 | 'qfold': | |
2099 | (fold, |
|
2102 | (fold, | |
2100 | [('e', 'edit', None, _('edit patch header')), |
|
2103 | [('e', 'edit', None, _('edit patch header')), | |
2101 | ('k', 'keep', None, _('keep folded patch files')) |
|
2104 | ('k', 'keep', None, _('keep folded patch files')) | |
2102 | ] + commands.commitopts, |
|
2105 | ] + commands.commitopts, | |
2103 | 'hg qfold [-e] [-m <text>] [-l <file] PATCH...'), |
|
2106 | 'hg qfold [-e] [-m <text>] [-l <file] PATCH...'), | |
2104 | 'qguard': (guard, [('l', 'list', None, _('list all patches and guards')), |
|
2107 | 'qguard': (guard, [('l', 'list', None, _('list all patches and guards')), | |
2105 | ('n', 'none', None, _('drop all guards'))], |
|
2108 | ('n', 'none', None, _('drop all guards'))], | |
2106 | 'hg qguard [PATCH] [+GUARD...] [-GUARD...]'), |
|
2109 | 'hg qguard [PATCH] [+GUARD...] [-GUARD...]'), | |
2107 | 'qheader': (header, [], |
|
2110 | 'qheader': (header, [], | |
2108 | _('hg qheader [PATCH]')), |
|
2111 | _('hg qheader [PATCH]')), | |
2109 | "^qimport": |
|
2112 | "^qimport": | |
2110 | (qimport, |
|
2113 | (qimport, | |
2111 | [('e', 'existing', None, 'import file in patch dir'), |
|
2114 | [('e', 'existing', None, 'import file in patch dir'), | |
2112 | ('n', 'name', '', 'patch file name'), |
|
2115 | ('n', 'name', '', 'patch file name'), | |
2113 | ('f', 'force', None, 'overwrite existing files'), |
|
2116 | ('f', 'force', None, 'overwrite existing files'), | |
2114 | ('r', 'rev', [], 'place existing revisions under mq control'), |
|
2117 | ('r', 'rev', [], 'place existing revisions under mq control'), | |
2115 | ('g', 'git', None, _('use git extended diff format'))], |
|
2118 | ('g', 'git', None, _('use git extended diff format'))], | |
2116 | 'hg qimport [-e] [-n NAME] [-f] [-g] [-r REV]... FILE...'), |
|
2119 | 'hg qimport [-e] [-n NAME] [-f] [-g] [-r REV]... FILE...'), | |
2117 | "^qinit": |
|
2120 | "^qinit": | |
2118 | (init, |
|
2121 | (init, | |
2119 | [('c', 'create-repo', None, 'create queue repository')], |
|
2122 | [('c', 'create-repo', None, 'create queue repository')], | |
2120 | 'hg qinit [-c]'), |
|
2123 | 'hg qinit [-c]'), | |
2121 | "qnew": |
|
2124 | "qnew": | |
2122 | (new, |
|
2125 | (new, | |
2123 | [('e', 'edit', None, _('edit commit message')), |
|
2126 | [('e', 'edit', None, _('edit commit message')), | |
2124 | ('f', 'force', None, _('import uncommitted changes into patch')) |
|
2127 | ('f', 'force', None, _('import uncommitted changes into patch')) | |
2125 | ] + commands.commitopts, |
|
2128 | ] + commands.commitopts, | |
2126 | 'hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH'), |
|
2129 | 'hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH'), | |
2127 | "qnext": (next, [] + seriesopts, 'hg qnext [-s]'), |
|
2130 | "qnext": (next, [] + seriesopts, 'hg qnext [-s]'), | |
2128 | "qprev": (prev, [] + seriesopts, 'hg qprev [-s]'), |
|
2131 | "qprev": (prev, [] + seriesopts, 'hg qprev [-s]'), | |
2129 | "^qpop": |
|
2132 | "^qpop": | |
2130 | (pop, |
|
2133 | (pop, | |
2131 | [('a', 'all', None, 'pop all patches'), |
|
2134 | [('a', 'all', None, 'pop all patches'), | |
2132 | ('n', 'name', '', 'queue name to pop'), |
|
2135 | ('n', 'name', '', 'queue name to pop'), | |
2133 | ('f', 'force', None, 'forget any local changes')], |
|
2136 | ('f', 'force', None, 'forget any local changes')], | |
2134 | 'hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]'), |
|
2137 | 'hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]'), | |
2135 | "^qpush": |
|
2138 | "^qpush": | |
2136 | (push, |
|
2139 | (push, | |
2137 | [('f', 'force', None, 'apply if the patch has rejects'), |
|
2140 | [('f', 'force', None, 'apply if the patch has rejects'), | |
2138 | ('l', 'list', None, 'list patch name in commit text'), |
|
2141 | ('l', 'list', None, 'list patch name in commit text'), | |
2139 | ('a', 'all', None, 'apply all patches'), |
|
2142 | ('a', 'all', None, 'apply all patches'), | |
2140 | ('m', 'merge', None, 'merge from another queue'), |
|
2143 | ('m', 'merge', None, 'merge from another queue'), | |
2141 | ('n', 'name', '', 'merge queue name')], |
|
2144 | ('n', 'name', '', 'merge queue name')], | |
2142 | 'hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]'), |
|
2145 | 'hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]'), | |
2143 | "^qrefresh": |
|
2146 | "^qrefresh": | |
2144 | (refresh, |
|
2147 | (refresh, | |
2145 | [('e', 'edit', None, _('edit commit message')), |
|
2148 | [('e', 'edit', None, _('edit commit message')), | |
2146 | ('g', 'git', None, _('use git extended diff format')), |
|
2149 | ('g', 'git', None, _('use git extended diff format')), | |
2147 | ('s', 'short', None, 'refresh only files already in the patch'), |
|
2150 | ('s', 'short', None, 'refresh only files already in the patch'), | |
2148 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2151 | ('I', 'include', [], _('include names matching the given patterns')), | |
2149 | ('X', 'exclude', [], _('exclude names matching the given patterns')) |
|
2152 | ('X', 'exclude', [], _('exclude names matching the given patterns')) | |
2150 | ] + commands.commitopts, |
|
2153 | ] + commands.commitopts, | |
2151 | 'hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] FILES...'), |
|
2154 | 'hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] FILES...'), | |
2152 | 'qrename|qmv': |
|
2155 | 'qrename|qmv': | |
2153 | (rename, [], 'hg qrename PATCH1 [PATCH2]'), |
|
2156 | (rename, [], 'hg qrename PATCH1 [PATCH2]'), | |
2154 | "qrestore": |
|
2157 | "qrestore": | |
2155 | (restore, |
|
2158 | (restore, | |
2156 | [('d', 'delete', None, 'delete save entry'), |
|
2159 | [('d', 'delete', None, 'delete save entry'), | |
2157 | ('u', 'update', None, 'update queue working dir')], |
|
2160 | ('u', 'update', None, 'update queue working dir')], | |
2158 | 'hg qrestore [-d] [-u] REV'), |
|
2161 | 'hg qrestore [-d] [-u] REV'), | |
2159 | "qsave": |
|
2162 | "qsave": | |
2160 | (save, |
|
2163 | (save, | |
2161 | [('c', 'copy', None, 'copy patch directory'), |
|
2164 | [('c', 'copy', None, 'copy patch directory'), | |
2162 | ('n', 'name', '', 'copy directory name'), |
|
2165 | ('n', 'name', '', 'copy directory name'), | |
2163 | ('e', 'empty', None, 'clear queue status file'), |
|
2166 | ('e', 'empty', None, 'clear queue status file'), | |
2164 | ('f', 'force', None, 'force copy')] + commands.commitopts, |
|
2167 | ('f', 'force', None, 'force copy')] + commands.commitopts, | |
2165 | 'hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'), |
|
2168 | 'hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'), | |
2166 | "qselect": (select, |
|
2169 | "qselect": (select, | |
2167 | [('n', 'none', None, _('disable all guards')), |
|
2170 | [('n', 'none', None, _('disable all guards')), | |
2168 | ('s', 'series', None, _('list all guards in series file')), |
|
2171 | ('s', 'series', None, _('list all guards in series file')), | |
2169 | ('', 'pop', None, |
|
2172 | ('', 'pop', None, | |
2170 | _('pop to before first guarded applied patch')), |
|
2173 | _('pop to before first guarded applied patch')), | |
2171 | ('', 'reapply', None, _('pop, then reapply patches'))], |
|
2174 | ('', 'reapply', None, _('pop, then reapply patches'))], | |
2172 | 'hg qselect [OPTION...] [GUARD...]'), |
|
2175 | 'hg qselect [OPTION...] [GUARD...]'), | |
2173 | "qseries": |
|
2176 | "qseries": | |
2174 | (series, |
|
2177 | (series, | |
2175 | [('m', 'missing', None, 'print patches not in series')] + seriesopts, |
|
2178 | [('m', 'missing', None, 'print patches not in series')] + seriesopts, | |
2176 | 'hg qseries [-ms]'), |
|
2179 | 'hg qseries [-ms]'), | |
2177 | "^strip": |
|
2180 | "^strip": | |
2178 | (strip, |
|
2181 | (strip, | |
2179 | [('f', 'force', None, 'force multi-head removal'), |
|
2182 | [('f', 'force', None, 'force multi-head removal'), | |
2180 | ('b', 'backup', None, 'bundle unrelated changesets'), |
|
2183 | ('b', 'backup', None, 'bundle unrelated changesets'), | |
2181 | ('n', 'nobackup', None, 'no backups')], |
|
2184 | ('n', 'nobackup', None, 'no backups')], | |
2182 | 'hg strip [-f] [-b] [-n] REV'), |
|
2185 | 'hg strip [-f] [-b] [-n] REV'), | |
2183 | "qtop": (top, [] + seriesopts, 'hg qtop [-s]'), |
|
2186 | "qtop": (top, [] + seriesopts, 'hg qtop [-s]'), | |
2184 | "qunapplied": (unapplied, [] + seriesopts, 'hg qunapplied [-s] [PATCH]'), |
|
2187 | "qunapplied": (unapplied, [] + seriesopts, 'hg qunapplied [-s] [PATCH]'), | |
2185 | } |
|
2188 | } |
General Comments 0
You need to be logged in to leave comments.
Login now