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