[PATCH 5 of 9] localrepo: add "editor" argument to "tag()"
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Mon May 5 12:33:05 UTC 2014
# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1399292800 -32400
# Mon May 05 21:26:40 2014 +0900
# Branch stable
# Node ID 9152874122c6ff967387d38081aa87f5ed677654
# Parent e4659ade0bed4e6f9fef51839b101479852c4863
localrepo: add "editor" argument to "tag()"
Before this patch, "localrepository.tag()" doesn't take "editor"
argument, and this prevents callers from passing "editor" argument to
"localrepository.commit()" invoked internally.
This patch adds "editor" argument to "localrepository.tag()" (and
"_tag()", too), and makes "commands.tag()" invoke it with "editor"
argument.
This patch also omits explicit "localrepository.savecommitmesssage()"
invocation, because "localrepository.commit()" will invoke specified
"editor" and save edited commit message into ".hg/last-message.txt"
automatically.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5684,15 +5684,18 @@
date = util.parsedate(date)
if opts.get('edit'):
- message = ui.edit(message, ui.username())
- repo.savecommitmessage(message)
+ def editor(repo, ctx, subs):
+ return ui.edit(ctx.description() + "\n", ctx.user())
+ else:
+ editor = False
# don't allow tagging the null rev
if (not opts.get('remove') and
scmutil.revsingle(repo, rev_).rev() == nullrev):
raise util.Abort(_("cannot tag null revision"))
- repo.tag(names, r, message, opts.get('local'), opts.get('user'), date)
+ repo.tag(names, r, message, opts.get('local'), opts.get('user'), date,
+ editor=editor)
finally:
release(lock, wlock)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -479,7 +479,8 @@
return hook.hook(self.ui, self, name, throw, **args)
@unfilteredmethod
- def _tag(self, names, node, message, local, user, date, extra={}):
+ def _tag(self, names, node, message, local, user, date, extra={},
+ editor=False):
if isinstance(names, str):
names = (names,)
@@ -539,14 +540,15 @@
self[None].add(['.hgtags'])
m = matchmod.exact(self.root, '', ['.hgtags'])
- tagnode = self.commit(message, user, date, extra=extra, match=m)
+ tagnode = self.commit(message, user, date, extra=extra, match=m,
+ editor=editor)
for name in names:
self.hook('tag', node=hex(node), tag=name, local=local)
return tagnode
- def tag(self, names, node, message, local, user, date):
+ def tag(self, names, node, message, local, user, date, editor=False):
'''tag a revision with one or more symbolic names.
names is a list of strings or, when adding a single tag, names may be a
@@ -574,7 +576,7 @@
'(please commit .hgtags manually)'))
self.tags() # instantiate the cache
- self._tag(names, node, message, local, user, date)
+ self._tag(names, node, message, local, user, date, editor=editor)
@filteredpropertycache
def _tagscache(self):
diff --git a/tests/test-tag.t b/tests/test-tag.t
--- a/tests/test-tag.t
+++ b/tests/test-tag.t
@@ -225,8 +225,11 @@
at first, test saving last-message.txt
+(test that editor is not invoked before transaction starting)
+
$ cat > .hg/hgrc << '__EOF__'
> [hooks]
+ > # this failure occurs before editor invocation
> pretag.test-saving-lastmessage = false
> __EOF__
$ rm -f .hg/last-message.txt
@@ -234,12 +237,37 @@
abort: pretag.test-saving-lastmessage hook exited with status 1
[255]
$ cat .hg/last-message.txt
+ cat: .hg/last-message.txt: No such file or directory
+ [1]
+
+(test that editor is invoked and commit message is saved into
+"last-message.txt")
+
+ $ cat >> .hg/hgrc << '__EOF__'
+ > [hooks]
+ > pretag.test-saving-lastmessage =
+ > # this failure occurs after editor invocation
+ > pretxncommit.unexpectedabort = false
+ > __EOF__
+
+ $ rm -f .hg/last-message.txt
+ $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg tag custom-tag -e
+ transaction abort!
+ rollback completed
+ note: commit message saved in .hg/last-message.txt
+ abort: pretxncommit.unexpectedabort hook exited with status 1
+ [255]
+ $ cat .hg/last-message.txt
custom tag message
second line
- $ cat > .hg/hgrc << '__EOF__'
+
+ $ cat >> .hg/hgrc << '__EOF__'
> [hooks]
- > pretag.test-saving-lastmessage =
+ > pretxncommit.unexpectedabort =
> __EOF__
+ $ hg status .hgtags
+ M .hgtags
+ $ hg revert --no-backup -q .hgtags
then, test custom commit message itself
More information about the Mercurial-devel
mailing list