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