##// END OF EJS Templates
commit: move commit editor to cmdutil, pass as function
Matt Mackall -
r8407:223000a6 default
parent child Browse files
Show More
@@ -124,10 +124,11 b" def fetch(ui, repo, source='default', **"
124 message = (cmdutil.logmessage(opts) or
124 message = (cmdutil.logmessage(opts) or
125 (_('Automated merge with %s') %
125 (_('Automated merge with %s') %
126 url.removeauth(other.url())))
126 url.removeauth(other.url())))
127 force_editor = opts.get('force_editor') or opts.get('edit')
127 editor = cmdutil.commiteditor
128 n = repo.commit(mod + add + rem, message,
128 if opts.get('force_editor') or opts.get('edit'):
129 opts['user'], opts['date'], force=True,
129 editor = cmdutil.commitforceeditor
130 force_editor=force_editor)
130 n = repo.commit(mod + add + rem, message, opts['user'],
131 opts['date'], force=True, editor=editor)
131 ui.status(_('new changeset %d:%s merges remote changes '
132 ui.status(_('new changeset %d:%s merges remote changes '
132 'with local\n') % (repo.changelog.rev(n),
133 'with local\n') % (repo.changelog.rev(n),
133 short(n)))
134 short(n)))
@@ -450,8 +450,7 b' def reposetup(ui, repo):'
450 return kwt.wread(filename, data)
450 return kwt.wread(filename, data)
451
451
452 def commit(self, files=None, text='', user=None, date=None,
452 def commit(self, files=None, text='', user=None, date=None,
453 match=None, force=False, force_editor=False,
453 match=None, force=False, editor=None, extra={}):
454 extra={}, empty_ok=False):
455 wlock = lock = None
454 wlock = lock = None
456 _p1 = _p2 = None
455 _p1 = _p2 = None
457 try:
456 try:
@@ -473,8 +472,7 b' def reposetup(ui, repo):'
473 _p2 = hex(_p2)
472 _p2 = hex(_p2)
474
473
475 n = super(kwrepo, self).commit(files, text, user, date, match,
474 n = super(kwrepo, self).commit(files, text, user, date, match,
476 force, force_editor,
475 force, editor, extra)
477 extra, empty_ok)
478
476
479 # restore commit hooks
477 # restore commit hooks
480 for name, cmd in commithooks.iteritems():
478 for name, cmd in commithooks.iteritems():
@@ -1221,3 +1221,40 b' def commit(ui, repo, commitfunc, pats, o'
1221 return commitfunc(ui, repo, message, m, opts)
1221 return commitfunc(ui, repo, message, m, opts)
1222 except ValueError, inst:
1222 except ValueError, inst:
1223 raise util.Abort(str(inst))
1223 raise util.Abort(str(inst))
1224
1225 def commiteditor(repo, ctx, added, updated, removed):
1226 if ctx.description():
1227 return ctx.description()
1228 return commitforceeditor(repo, ctx, added, updated, removed)
1229
1230 def commitforceeditor(repo, ctx, added, updated, removed):
1231 edittext = []
1232 if ctx.description():
1233 edittext.append(ctx.description())
1234 edittext.append("")
1235 edittext.append("") # Empty line between message and comments.
1236 edittext.append(_("HG: Enter commit message."
1237 " Lines beginning with 'HG:' are removed."))
1238 edittext.append("HG: --")
1239 edittext.append(_("HG: user: %s") % ctx.user())
1240 if ctx.p2():
1241 edittext.append(_("HG: branch merge"))
1242 if ctx.branch():
1243 edittext.append(_("HG: branch '%s'")
1244 % encoding.tolocal(ctx.branch()))
1245 edittext.extend([_("HG: added %s") % f for f in added])
1246 edittext.extend([_("HG: changed %s") % f for f in updated])
1247 edittext.extend([_("HG: removed %s") % f for f in removed])
1248 if not added and not updated and not removed:
1249 edittext.append(_("HG: no files changed"))
1250 edittext.append("")
1251 # run editor in the repository root
1252 olddir = os.getcwd()
1253 os.chdir(repo.root)
1254 text = repo.ui.edit("\n".join(edittext), ctx.user())
1255 os.chdir(olddir)
1256
1257 if not text.strip():
1258 raise util.Abort(_("empty commit message"))
1259
1260 return text
@@ -642,10 +642,13 b' def commit(ui, repo, *pats, **opts):'
642 extra = {}
642 extra = {}
643 if opts.get('close_branch'):
643 if opts.get('close_branch'):
644 extra['close'] = 1
644 extra['close'] = 1
645 e = cmdutil.commiteditor
646 if opts.get('force_editor'):
647 e = cmdutil.commitforceeditor
648
645 def commitfunc(ui, repo, message, match, opts):
649 def commitfunc(ui, repo, message, match, opts):
646 return repo.commit(match.files(), message, opts.get('user'),
650 return repo.commit(match.files(), message, opts.get('user'),
647 opts.get('date'), match, force_editor=opts.get('force_editor'),
651 opts.get('date'), match, editor=e, extra=extra)
648 extra=extra)
649
652
650 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
653 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
651 if not node:
654 if not node:
@@ -1741,7 +1744,8 b' def import_(ui, repo, patch1, *patches, '
1741 files = patch.updatedir(ui, repo, files, similarity=sim/100.)
1744 files = patch.updatedir(ui, repo, files, similarity=sim/100.)
1742 if not opts.get('no_commit'):
1745 if not opts.get('no_commit'):
1743 n = repo.commit(files, message, opts.get('user') or user,
1746 n = repo.commit(files, message, opts.get('user') or user,
1744 opts.get('date') or date)
1747 opts.get('date') or date,
1748 editor=cmdutil.commiteditor)
1745 if opts.get('exact'):
1749 if opts.get('exact'):
1746 if hex(n) != nodeid:
1750 if hex(n) != nodeid:
1747 repo.rollback()
1751 repo.rollback()
@@ -768,7 +768,7 b' class localrepository(repo.repository):'
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
@@ -811,7 +811,7 b' class localrepository(repo.repository):'
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
@@ -824,11 +824,9 b' class localrepository(repo.repository):'
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)
829
828
830 def _commitctx(self, ctx, force=False, force_editor=False, empty_ok=False,
829 def _commitctx(self, ctx, force=False, editor=None, working=True):
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
@@ -895,39 +893,12 b' class localrepository(repo.repository):'
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()
General Comments 0
You need to be logged in to leave comments. Login now