##// END OF EJS Templates
mq: heavy rearrangement of qnew to make it recover reliably from errors....
Brendan Cully -
r7162:ce10a2f2 default
parent child Browse files
Show More
@@ -640,7 +640,7 b' class queue:'
640 raise util.Abort(_('"%s" cannot be used as the name of a patch')
640 raise util.Abort(_('"%s" cannot be used as the name of a patch')
641 % name)
641 % name)
642
642
643 def new(self, repo, patch, *pats, **opts):
643 def new(self, repo, patchfn, *pats, **opts):
644 """options:
644 """options:
645 msg: a string or a no-argument function returning a string
645 msg: a string or a no-argument function returning a string
646 """
646 """
@@ -650,9 +650,9 b' class queue:'
650 date = opts.get('date')
650 date = opts.get('date')
651 if date:
651 if date:
652 date = util.parsedate(date)
652 date = util.parsedate(date)
653 self.check_reserved_name(patch)
653 self.check_reserved_name(patchfn)
654 if os.path.exists(self.join(patch)):
654 if os.path.exists(self.join(patchfn)):
655 raise util.Abort(_('patch "%s" already exists') % patch)
655 raise util.Abort(_('patch "%s" already exists') % patchfn)
656 if opts.get('include') or opts.get('exclude') or pats:
656 if opts.get('include') or opts.get('exclude') or pats:
657 match = cmdutil.match(repo, pats, opts)
657 match = cmdutil.match(repo, pats, opts)
658 # detect missing files in pats
658 # detect missing files in pats
@@ -665,39 +665,55 b' class queue:'
665 match = cmdutil.match(repo, m + a + r)
665 match = cmdutil.match(repo, m + a + r)
666 commitfiles = m + a + r
666 commitfiles = m + a + r
667 self.check_toppatch(repo)
667 self.check_toppatch(repo)
668 insert = self.full_series_end()
668 wlock = repo.wlock()
669 wlock = repo.wlock()
669 try:
670 try:
670 insert = self.full_series_end()
671 # if patch file write fails, abort early
671 if callable(msg):
672 p = self.opener(patchfn, "w")
672 msg = msg()
673 try:
673 commitmsg = msg and msg or ("[mq]: %s" % patch)
674 if date:
674 n = repo.commit(commitfiles, commitmsg, user, date, match=match, force=True)
675 p.write("# HG changeset patch\n")
675 if n == None:
676 if user:
676 raise util.Abort(_("repo commit failed"))
677 p.write("# User " + user + "\n")
677 self.full_series[insert:insert] = [patch]
678 p.write("# Date %d %d\n\n" % date)
678 self.applied.append(statusentry(revlog.hex(n), patch))
679 elif user:
679 self.parse_series()
680 p.write("From: " + user + "\n\n")
680 self.series_dirty = 1
681
681 self.applied_dirty = 1
682 if callable(msg):
682 p = self.opener(patch, "w")
683 msg = msg()
683 if date:
684 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
684 p.write("# HG changeset patch\n")
685 n = repo.commit(commitfiles, commitmsg, user, date, match=match, force=True)
685 if user:
686 if n == None:
686 p.write("# User " + user + "\n")
687 raise util.Abort(_("repo commit failed"))
687 p.write("# Date %d %d\n" % date)
688 try:
688 p.write("\n")
689 self.full_series[insert:insert] = [patchfn]
689 elif user:
690 self.applied.append(statusentry(revlog.hex(n), patchfn))
690 p.write("From: " + user + "\n")
691 self.parse_series()
691 p.write("\n")
692 self.series_dirty = 1
692 if msg:
693 self.applied_dirty = 1
693 msg = msg + "\n"
694 if msg:
694 p.write(msg)
695 msg = msg + "\n"
695 p.close()
696 p.write(msg)
696 wlock = None
697 if commitfiles:
697 r = self.qrepo()
698 diffopts = self.diffopts()
698 if r: r.add([patch])
699 if opts.get('git'): diffopts.git = True
699 if commitfiles:
700 parent = self.qparents(repo, n)
700 self.refresh(repo, short=True, git=opts.get('git'))
701 patch.diff(repo, node1=parent, node2=n, fp=p,
702 match=match, opts=diffopts)
703 p.close()
704 wlock = None
705 r = self.qrepo()
706 if r: r.add([patchfn])
707 except:
708 repo.rollback()
709 raise
710 except Exception, inst:
711 patchpath = self.join(patchfn)
712 try:
713 os.unlink(patchpath)
714 except:
715 self.ui.warn(_('error unlinking %s\n') % patchpath)
716 raise
701 self.removeundo(repo)
717 self.removeundo(repo)
702 finally:
718 finally:
703 del wlock
719 del wlock
General Comments 0
You need to be logged in to leave comments. Login now