Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 8407:223000a687b0
commit: move commit editor to cmdutil, pass as function
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 14 May 2009 13:20:40 -0500 |
parents | 7cbf8fcd2453 |
children | 1d11d985c179 |
comparison
equal
deleted
inserted
replaced
8406:6ad1f72bdf34 | 8407:223000a687b0 |
---|---|
766 changelist.append(fname) | 766 changelist.append(fname) |
767 | 767 |
768 return fparent1 | 768 return fparent1 |
769 | 769 |
770 def commit(self, files=None, text="", user=None, date=None, match=None, | 770 def commit(self, files=None, text="", user=None, date=None, match=None, |
771 force=False, force_editor=False, extra={}, empty_ok=False): | 771 force=False, editor=False, extra={}): |
772 wlock = lock = None | 772 wlock = lock = None |
773 if extra.get("close"): | 773 if extra.get("close"): |
774 force = True | 774 force = True |
775 if files: | 775 if files: |
776 files = list(set(files)) | 776 files = list(set(files)) |
809 if f in ms and ms[f] == 'u': | 809 if f in ms and ms[f] == 'u': |
810 raise util.Abort(_("unresolved merge conflicts " | 810 raise util.Abort(_("unresolved merge conflicts " |
811 "(see hg resolve)")) | 811 "(see hg resolve)")) |
812 wctx = context.workingctx(self, (p1, p2), text, user, date, | 812 wctx = context.workingctx(self, (p1, p2), text, user, date, |
813 extra, changes) | 813 extra, changes) |
814 r = self._commitctx(wctx, force, force_editor, empty_ok, True) | 814 r = self._commitctx(wctx, force, editor, True) |
815 ms.reset() | 815 ms.reset() |
816 return r | 816 return r |
817 | 817 |
818 finally: | 818 finally: |
819 wlock.release() | 819 wlock.release() |
822 """Add a new revision to current repository. | 822 """Add a new revision to current repository. |
823 | 823 |
824 Revision information is passed in the context.memctx argument. | 824 Revision information is passed in the context.memctx argument. |
825 commitctx() does not touch the working directory. | 825 commitctx() does not touch the working directory. |
826 """ | 826 """ |
827 return self._commitctx(ctx, force=True, force_editor=False, | 827 return self._commitctx(ctx, force=True, editor=None, working=False) |
828 empty_ok=True, working=False) | 828 |
829 | 829 def _commitctx(self, ctx, force=False, editor=None, working=True): |
830 def _commitctx(self, ctx, force=False, force_editor=False, empty_ok=False, | |
831 working=True): | |
832 lock = self.lock() | 830 lock = self.lock() |
833 tr = None | 831 tr = None |
834 valid = 0 # don't save the dirstate if this isn't set | 832 valid = 0 # don't save the dirstate if this isn't set |
835 try: | 833 try: |
836 commit = sorted(ctx.modified() + ctx.added()) | 834 commit = sorted(ctx.modified() + ctx.added()) |
893 del m1[f] | 891 del m1[f] |
894 removed1.append(f) | 892 removed1.append(f) |
895 mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0], | 893 mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0], |
896 (new, removed1)) | 894 (new, removed1)) |
897 | 895 |
898 # add changeset | 896 if editor: |
899 if (not empty_ok and not text) or force_editor: | 897 text = editor(self, ctx, added, updated, removed) |
900 edittext = [] | |
901 if text: | |
902 edittext.append(text) | |
903 edittext.append("") | |
904 edittext.append("") # Empty line between message and comments. | |
905 edittext.append(_("HG: Enter commit message." | |
906 " Lines beginning with 'HG:' are removed.")) | |
907 edittext.append("HG: --") | |
908 edittext.append(_("HG: user: %s") % user) | |
909 if p2 != nullid: | |
910 edittext.append(_("HG: branch merge")) | |
911 if branchname: | |
912 edittext.append(_("HG: branch '%s'") | |
913 % encoding.tolocal(branchname)) | |
914 edittext.extend([_("HG: added %s") % f for f in added]) | |
915 edittext.extend([_("HG: changed %s") % f for f in updated]) | |
916 edittext.extend([_("HG: removed %s") % f for f in removed]) | |
917 if not added and not updated and not removed: | |
918 edittext.append(_("HG: no files changed")) | |
919 edittext.append("") | |
920 # run editor in the repository root | |
921 olddir = os.getcwd() | |
922 os.chdir(self.root) | |
923 text = self.ui.edit("\n".join(edittext), user) | |
924 os.chdir(olddir) | |
925 | 898 |
926 lines = [line.rstrip() for line in text.rstrip().splitlines()] | 899 lines = [line.rstrip() for line in text.rstrip().splitlines()] |
927 while lines and not lines[0]: | 900 while lines and not lines[0]: |
928 del lines[0] | 901 del lines[0] |
929 if not lines and working: | |
930 raise util.Abort(_("empty commit message")) | |
931 text = '\n'.join(lines) | 902 text = '\n'.join(lines) |
932 | 903 |
933 self.changelog.delayupdate() | 904 self.changelog.delayupdate() |
934 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2, | 905 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2, |
935 user, ctx.date(), extra) | 906 user, ctx.date(), extra) |