[PATCH 2 of 3] commit: add a -M/--reuse-message option to copy a commit message from a
Tony Tung
tonytung at fb.com
Fri May 15 17:54:36 CDT 2015
# HG changeset patch
# User Tony Tung <tonytung at fb.com>
# Date 1429655274 25200
# Tue Apr 21 15:27:54 2015 -0700
# Node ID dc122dd80665762d8febe2db1a08ce00a63d5ab8
# Parent 18cadf9d058931ef00e5272d15cb5cf2ebc3a248
commit: add a -M/--reuse-message option to copy a commit message from a
revspec
One way to split up a diff that includes a refactor involves resetting to
the ancestor, and then committing the refactor first. When committing the
main change, it's helpful to be able to reuse the commit message from the
earlier commit that includes both the refactor and the new functionality.
This makes it easy to grab the commit message.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -285,11 +285,15 @@
""" get the log message according to -m and -l option """
message = opts.get('message')
logfile = opts.get('logfile')
-
- if message and logfile:
- raise util.Abort(_('options --message and --logfile are mutually '
- 'exclusive'))
- if not message and logfile:
+ revspec = opts.get('reuse_message')
+
+ # calculate how many are set. if more than one are set, we need to abort.
+ num_set = len([x for x in [message, logfile, revspec] if x])
+
+ if num_set > 1:
+ raise util.Abort(_('options --message, --logfile, and --reuse-message '
+ 'are mutually exclusive'))
+ if logfile:
try:
if logfile == '-':
message = ui.fin.read()
@@ -298,6 +302,18 @@
except IOError, inst:
raise util.Abort(_("can't read commit message '%s': %s") %
(logfile, inst.strerror))
+
+ if revspec:
+ revs = repo.revs(revspec)
+
+ if len(revs) > 1:
+ raise util.Abort(_("revspec %s refers to more than one revision") %
+ revspec)
+
+ ctx = context.changectx(repo, revs.first())
+
+ message = ctx.description()
+
return message
def mergeeditform(ctxorbool, baseformname):
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -93,6 +93,8 @@
_('use text as commit message'), _('TEXT')),
('l', 'logfile', '',
_('read commit message from file'), _('FILE')),
+ ('M', 'reuse-message', '',
+ _('use message from REVSPEC'), _('REVSPEC')),
]
commitopts2 = [
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -614,3 +614,41 @@
$ hg co --clean tip
abort: path contains illegal component: HG8B6C~2/hgrc (glob)
[255]
+
+setup for -M/--reuse-message tests
+
+ $ rm -rf .hg
+ $ hg init
+ $ echo 'c1' > file
+ $ hg commit -Aqm "commit 1
+ > message"
+ $ hg log --template '{desc}\n' .
+ commit 1
+ message
+ $ echo 'c2' >> file
+ $ hg commit -m "commit 2
+ > second line"
+ $ echo 'c3' >> file
+
+attempt to select more than one rev when using -M/--reuse-message
+
+ $ hg commit -M 0..1
+ abort: revspec 0..1 refers to more than one revision
+ [255]
+
+attempt to use -M/--reuse-message along with -m
+
+ $ hg commit -M 0 -m "another message!"
+ abort: options --message, --logfile, and --reuse-message are mutually exclusive
+ [255]
+
+successful -M/--reuse-message
+
+ $ hg commit -M 0
+ $ hg log --template '{desc}\n'
+ commit 1
+ message
+ commit 2
+ second line
+ commit 1
+ message
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -202,7 +202,7 @@
add: include, exclude, subrepos, dry-run
annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude, template
clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
- commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos
+ commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, reuse-message, date, user, subrepos
diff: rev, change, text, git, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, root, include, exclude, subrepos
export: output, switch-parent, rev, text, git, nodates
forget: include, exclude
@@ -218,7 +218,7 @@
update: clean, check, date, rev, tool
addremove: similarity, subrepos, include, exclude, dry-run
archive: no-decode, prefix, rev, type, subrepos, include, exclude
- backout: merge, commit, parent, rev, edit, tool, include, exclude, message, logfile, date, user
+ backout: merge, commit, parent, rev, edit, tool, include, exclude, message, logfile, reuse-message, date, user
bisect: reset, good, bad, skip, extend, command, noupdate
bookmarks: force, rev, delete, rename, inactive, template
branch: force, clean
@@ -268,7 +268,7 @@
heads: rev, topo, active, closed, style, template
help: extension, command, keyword
identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure
- import: strip, base, edit, force, no-commit, bypass, partial, exact, prefix, import-branch, message, logfile, date, user, similarity
+ import: strip, base, edit, force, no-commit, bypass, partial, exact, prefix, import-branch, message, logfile, reuse-message, date, user, similarity
incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
locate: rev, print0, fullpath, include, exclude
manifest: rev, all, template
diff --git a/tests/test-mq-qrefresh-interactive.t b/tests/test-mq-qrefresh-interactive.t
--- a/tests/test-mq-qrefresh-interactive.t
+++ b/tests/test-mq-qrefresh-interactive.t
@@ -31,18 +31,19 @@
options ([+] can be repeated):
- -e --edit invoke editor on commit messages
- -g --git use git extended diff format
- -s --short refresh only files already in the patch and
- specified files
- -U --currentuser add/update author field in patch with current user
- -u --user USER add/update author field in patch with given user
- -D --currentdate add/update date field in patch with current date
- -d --date DATE add/update date field in patch with given date
- -I --include PATTERN [+] include names matching the given patterns
- -X --exclude PATTERN [+] exclude names matching the given patterns
- -m --message TEXT use text as commit message
- -l --logfile FILE read commit message from file
+ -e --edit invoke editor on commit messages
+ -g --git use git extended diff format
+ -s --short refresh only files already in the patch and
+ specified files
+ -U --currentuser add/update author field in patch with current user
+ -u --user USER add/update author field in patch with given user
+ -D --currentdate add/update date field in patch with current date
+ -d --date DATE add/update date field in patch with given date
+ -I --include PATTERN [+] include names matching the given patterns
+ -X --exclude PATTERN [+] exclude names matching the given patterns
+ -m --message TEXT use text as commit message
+ -l --logfile FILE read commit message from file
+ -M --reuse-message REVSPEC use message from REVSPEC
(some details hidden, use --verbose to show complete help)
@@ -73,19 +74,20 @@
options ([+] can be repeated):
- -e --edit invoke editor on commit messages
- -g --git use git extended diff format
- -s --short refresh only files already in the patch and
- specified files
- -U --currentuser add/update author field in patch with current user
- -u --user USER add/update author field in patch with given user
- -D --currentdate add/update date field in patch with current date
- -d --date DATE add/update date field in patch with given date
- -I --include PATTERN [+] include names matching the given patterns
- -X --exclude PATTERN [+] exclude names matching the given patterns
- -m --message TEXT use text as commit message
- -l --logfile FILE read commit message from file
- -i --interactive interactively select changes to refresh
+ -e --edit invoke editor on commit messages
+ -g --git use git extended diff format
+ -s --short refresh only files already in the patch and
+ specified files
+ -U --currentuser add/update author field in patch with current user
+ -u --user USER add/update author field in patch with given user
+ -D --currentdate add/update date field in patch with current date
+ -d --date DATE add/update date field in patch with given date
+ -I --include PATTERN [+] include names matching the given patterns
+ -X --exclude PATTERN [+] exclude names matching the given patterns
+ -m --message TEXT use text as commit message
+ -l --logfile FILE read commit message from file
+ -M --reuse-message REVSPEC use message from REVSPEC
+ -i --interactive interactively select changes to refresh
(some details hidden, use --verbose to show complete help)
diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t
--- a/tests/test-qrecord.t
+++ b/tests/test-qrecord.t
@@ -56,23 +56,24 @@
options ([+] can be repeated):
- -A --addremove mark new/missing files as added/removed before
- committing
- --close-branch mark a branch as closed, hiding it from the branch
- list
- --amend amend the parent of the working directory
- -s --secret use the secret phase for committing
- -e --edit invoke editor on commit messages
- -I --include PATTERN [+] include names matching the given patterns
- -X --exclude PATTERN [+] exclude names matching the given patterns
- -m --message TEXT use text as commit message
- -l --logfile FILE read commit message from file
- -d --date DATE record the specified date as commit date
- -u --user USER record the specified user as committer
- -S --subrepos recurse into subrepositories
- -w --ignore-all-space ignore white space when comparing lines
- -b --ignore-space-change ignore changes in the amount of white space
- -B --ignore-blank-lines ignore changes whose lines are all blank
+ -A --addremove mark new/missing files as added/removed before
+ committing
+ --close-branch mark a branch as closed, hiding it from the branch
+ list
+ --amend amend the parent of the working directory
+ -s --secret use the secret phase for committing
+ -e --edit invoke editor on commit messages
+ -I --include PATTERN [+] include names matching the given patterns
+ -X --exclude PATTERN [+] exclude names matching the given patterns
+ -m --message TEXT use text as commit message
+ -l --logfile FILE read commit message from file
+ -M --reuse-message REVSPEC use message from REVSPEC
+ -d --date DATE record the specified date as commit date
+ -u --user USER record the specified user as committer
+ -S --subrepos recurse into subrepositories
+ -w --ignore-all-space ignore white space when comparing lines
+ -b --ignore-space-change ignore changes in the amount of white space
+ -B --ignore-blank-lines ignore changes whose lines are all blank
(some details hidden, use --verbose to show complete help)
@@ -133,20 +134,21 @@
options ([+] can be repeated):
- -e --edit invoke editor on commit messages
- -g --git use git extended diff format
- -U --currentuser add "From: <current user>" to patch
- -u --user USER add "From: <USER>" to patch
- -D --currentdate add "Date: <current date>" to patch
- -d --date DATE add "Date: <DATE>" to patch
- -I --include PATTERN [+] include names matching the given patterns
- -X --exclude PATTERN [+] exclude names matching the given patterns
- -m --message TEXT use text as commit message
- -l --logfile FILE read commit message from file
- -w --ignore-all-space ignore white space when comparing lines
- -b --ignore-space-change ignore changes in the amount of white space
- -B --ignore-blank-lines ignore changes whose lines are all blank
- --mq operate on patch repository
+ -e --edit invoke editor on commit messages
+ -g --git use git extended diff format
+ -U --currentuser add "From: <current user>" to patch
+ -u --user USER add "From: <USER>" to patch
+ -D --currentdate add "Date: <current date>" to patch
+ -d --date DATE add "Date: <DATE>" to patch
+ -I --include PATTERN [+] include names matching the given patterns
+ -X --exclude PATTERN [+] exclude names matching the given patterns
+ -m --message TEXT use text as commit message
+ -l --logfile FILE read commit message from file
+ -M --reuse-message REVSPEC use message from REVSPEC
+ -w --ignore-all-space ignore white space when comparing lines
+ -b --ignore-space-change ignore changes in the amount of white space
+ -B --ignore-blank-lines ignore changes whose lines are all blank
+ --mq operate on patch repository
(some details hidden, use --verbose to show complete help)
diff --git a/tests/test-record.t b/tests/test-record.t
--- a/tests/test-record.t
+++ b/tests/test-record.t
@@ -43,23 +43,24 @@
options ([+] can be repeated):
- -A --addremove mark new/missing files as added/removed before
- committing
- --close-branch mark a branch as closed, hiding it from the branch
- list
- --amend amend the parent of the working directory
- -s --secret use the secret phase for committing
- -e --edit invoke editor on commit messages
- -I --include PATTERN [+] include names matching the given patterns
- -X --exclude PATTERN [+] exclude names matching the given patterns
- -m --message TEXT use text as commit message
- -l --logfile FILE read commit message from file
- -d --date DATE record the specified date as commit date
- -u --user USER record the specified user as committer
- -S --subrepos recurse into subrepositories
- -w --ignore-all-space ignore white space when comparing lines
- -b --ignore-space-change ignore changes in the amount of white space
- -B --ignore-blank-lines ignore changes whose lines are all blank
+ -A --addremove mark new/missing files as added/removed before
+ committing
+ --close-branch mark a branch as closed, hiding it from the branch
+ list
+ --amend amend the parent of the working directory
+ -s --secret use the secret phase for committing
+ -e --edit invoke editor on commit messages
+ -I --include PATTERN [+] include names matching the given patterns
+ -X --exclude PATTERN [+] exclude names matching the given patterns
+ -m --message TEXT use text as commit message
+ -l --logfile FILE read commit message from file
+ -M --reuse-message REVSPEC use message from REVSPEC
+ -d --date DATE record the specified date as commit date
+ -u --user USER record the specified user as committer
+ -S --subrepos recurse into subrepositories
+ -w --ignore-all-space ignore white space when comparing lines
+ -b --ignore-space-change ignore changes in the amount of white space
+ -B --ignore-blank-lines ignore changes whose lines are all blank
(some details hidden, use --verbose to show complete help)
More information about the Mercurial-devel
mailing list