304 if format and format.startswith("tag") and subject: |
304 if format and format.startswith("tag") and subject: |
305 message.insert(0, "") |
305 message.insert(0, "") |
306 message.insert(0, subject) |
306 message.insert(0, subject) |
307 return (message, comments, user, date, diffstart > 1) |
307 return (message, comments, user, date, diffstart > 1) |
308 |
308 |
|
309 def removeundo(self, repo): |
|
310 undo = repo.sjoin('undo') |
|
311 if not os.path.exists(undo): |
|
312 return |
|
313 try: |
|
314 os.unlink(undo) |
|
315 except OSError, inst: |
|
316 self.ui.warn('error removing undo: %s\n' % str(inst)) |
|
317 |
309 def printdiff(self, repo, node1, node2=None, files=None, |
318 def printdiff(self, repo, node1, node2=None, files=None, |
310 fp=None, changes=None, opts={}): |
319 fp=None, changes=None, opts={}): |
311 fns, matchfn, anypats = cmdutil.matchpats(repo, files, opts) |
320 fns, matchfn, anypats = cmdutil.matchpats(repo, files, opts) |
312 |
321 |
313 patch.diff(repo, node1, node2, fns, match=matchfn, |
322 patch.diff(repo, node1, node2, fns, match=matchfn, |
347 if comments: |
356 if comments: |
348 comments = "\n".join(comments) + '\n\n' |
357 comments = "\n".join(comments) + '\n\n' |
349 patchf.write(comments) |
358 patchf.write(comments) |
350 self.printdiff(repo, head, n, fp=patchf) |
359 self.printdiff(repo, head, n, fp=patchf) |
351 patchf.close() |
360 patchf.close() |
|
361 self.removeundo(repo) |
352 return (0, n) |
362 return (0, n) |
353 |
363 |
354 def qparents(self, repo, rev=None): |
364 def qparents(self, repo, rev=None): |
355 if rev is None: |
365 if rev is None: |
356 (p1, p2) = repo.dirstate.parents() |
366 (p1, p2) = repo.dirstate.parents() |
379 # the first patch in the queue is never a merge patch |
389 # the first patch in the queue is never a merge patch |
380 # |
390 # |
381 pname = ".hg.patches.merge.marker" |
391 pname = ".hg.patches.merge.marker" |
382 n = repo.commit(None, '[mq]: merge marker', user=None, force=1, |
392 n = repo.commit(None, '[mq]: merge marker', user=None, force=1, |
383 wlock=wlock) |
393 wlock=wlock) |
|
394 self.removeundo(repo) |
384 self.applied.append(statusentry(revlog.hex(n), pname)) |
395 self.applied.append(statusentry(revlog.hex(n), pname)) |
385 self.applied_dirty = 1 |
396 self.applied_dirty = 1 |
386 |
397 |
387 head = self.qparents(repo) |
398 head = self.qparents(repo) |
388 |
399 |
486 if fuzz and strict: |
497 if fuzz and strict: |
487 self.ui.warn("fuzz found when applying patch, stopping\n") |
498 self.ui.warn("fuzz found when applying patch, stopping\n") |
488 err = 1 |
499 err = 1 |
489 break |
500 break |
490 tr.close() |
501 tr.close() |
|
502 self.removeundo(repo) |
491 return (err, n) |
503 return (err, n) |
492 |
504 |
493 def delete(self, repo, patches, opts): |
505 def delete(self, repo, patches, opts): |
494 realpatches = [] |
506 realpatches = [] |
495 for patch in patches: |
507 for patch in patches: |
584 wlock = None |
596 wlock = None |
585 r = self.qrepo() |
597 r = self.qrepo() |
586 if r: r.add([patch]) |
598 if r: r.add([patch]) |
587 if commitfiles: |
599 if commitfiles: |
588 self.refresh(repo, short=True) |
600 self.refresh(repo, short=True) |
|
601 self.removeundo(repo) |
589 |
602 |
590 def strip(self, repo, rev, update=True, backup="all", wlock=None): |
603 def strip(self, repo, rev, update=True, backup="all", wlock=None): |
591 def limitheads(chlog, stop): |
604 def limitheads(chlog, stop): |
592 """return the list of all nodes that have no children""" |
605 """return the list of all nodes that have no children""" |
593 p = {} |
606 p = {} |
707 stripall(revnum) |
720 stripall(revnum) |
708 |
721 |
709 change = chlog.read(rev) |
722 change = chlog.read(rev) |
710 chlog.strip(revnum, revnum) |
723 chlog.strip(revnum, revnum) |
711 repo.manifest.strip(repo.manifest.rev(change[0]), revnum) |
724 repo.manifest.strip(repo.manifest.rev(change[0]), revnum) |
|
725 self.removeundo(repo) |
712 if saveheads: |
726 if saveheads: |
713 self.ui.status("adding branch\n") |
727 self.ui.status("adding branch\n") |
714 commands.unbundle(self.ui, repo, "file:%s" % chgrpfile, |
728 commands.unbundle(self.ui, repo, "file:%s" % chgrpfile, |
715 update=False) |
729 update=False) |
716 if backup != "strip": |
730 if backup != "strip": |
1084 self.strip(repo, top, update=False, backup='strip', wlock=wlock) |
1098 self.strip(repo, top, update=False, backup='strip', wlock=wlock) |
1085 n = repo.commit(filelist, message, changes[1], match=matchfn, |
1099 n = repo.commit(filelist, message, changes[1], match=matchfn, |
1086 force=1, wlock=wlock) |
1100 force=1, wlock=wlock) |
1087 self.applied[-1] = statusentry(revlog.hex(n), patchfn) |
1101 self.applied[-1] = statusentry(revlog.hex(n), patchfn) |
1088 self.applied_dirty = 1 |
1102 self.applied_dirty = 1 |
|
1103 self.removeundo(repo) |
1089 else: |
1104 else: |
1090 self.printdiff(repo, patchparent, fp=patchf) |
1105 self.printdiff(repo, patchparent, fp=patchf) |
1091 patchf.close() |
1106 patchf.close() |
1092 added = repo.status()[1] |
1107 added = repo.status()[1] |
1093 for a in added: |
1108 for a in added: |
1266 if not n: |
1281 if not n: |
1267 self.ui.warn("repo commit failed\n") |
1282 self.ui.warn("repo commit failed\n") |
1268 return 1 |
1283 return 1 |
1269 self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line')) |
1284 self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line')) |
1270 self.applied_dirty = 1 |
1285 self.applied_dirty = 1 |
|
1286 self.removeundo(undo) |
1271 |
1287 |
1272 def full_series_end(self): |
1288 def full_series_end(self): |
1273 if len(self.applied) > 0: |
1289 if len(self.applied) > 0: |
1274 p = self.applied[-1].name |
1290 p = self.applied[-1].name |
1275 end = self.find_series(p) |
1291 end = self.find_series(p) |