638 if (name in self._reserved or name.startswith('.hg') |
638 if (name in self._reserved or name.startswith('.hg') |
639 or name.startswith('.mq')): |
639 or name.startswith('.mq')): |
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 """ |
647 msg = opts.get('msg') |
647 msg = opts.get('msg') |
648 force = opts.get('force') |
648 force = opts.get('force') |
649 user = opts.get('user') |
649 user = opts.get('user') |
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 |
659 def badfn(f, msg): |
659 def badfn(f, msg): |
660 raise util.Abort('%s: %s' % (f, msg)) |
660 raise util.Abort('%s: %s' % (f, msg)) |
663 else: |
663 else: |
664 m, a, r, d = self.check_localchanges(repo, force) |
664 m, a, r, d = self.check_localchanges(repo, force) |
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 |
704 |
720 |
705 def strip(self, repo, rev, update=True, backup="all", force=None): |
721 def strip(self, repo, rev, update=True, backup="all", force=None): |