cmdutil: move -M / --reuse-message handling to cmdutil.logmessage

Summary:
This just moves `-M / --reuse-message` handling from the `commit` command
to a lower layer, making it more reusable.

Reviewed By: xavierd

Differential Revision: D17168992

fbshipit-source-id: 4fe7e93ceae45eff281214dcff03ef3f9ee0c898
This commit is contained in:
Jun Wu 2019-09-04 16:58:40 -07:00 committed by Facebook Github Bot
parent fd071d2076
commit 15f97d7f53
2 changed files with 13 additions and 12 deletions

View File

@ -857,6 +857,19 @@ def bailifchanged(repo, merge=True, hint=None):
def logmessage(repo, opts):
""" get the log message according to -m and -l option """
ui = repo.ui
# Allow the commit message from another commit to be reused.
reuserev = opts.get("reuse_message")
if reuserev:
incompatibleopts = ["message", "logfile"]
currentinvaliopts = [opt for opt in incompatibleopts if opts.get(opt)]
if currentinvaliopts:
raise error.Abort(
_("--reuse-message and --%s are mutually exclusive")
% (currentinvaliopts[0])
)
opts["message"] = scmutil.revsingle(repo, reuserev).description()
message = opts.get("message")
logfile = opts.get("logfile")

View File

@ -1714,18 +1714,6 @@ def _docommit(ui, repo, *pats, **opts):
opts = pycompat.byteskwargs(opts)
# Allow the commit message from another commit to be reused.
reuserev = opts.get("reuse_message")
if reuserev:
incompatibleopts = ["message", "logfile"]
currentinvaliopts = [opt for opt in incompatibleopts if opts.get(opt)]
if currentinvaliopts:
raise error.Abort(
_("--reuse-message and --%s are mutually exclusive")
% (currentinvaliopts[0])
)
opts["message"] = scmutil.revsingle(repo, reuserev).description()
cmdutil.checkunfinished(repo, commit=True)
branch = repo[None].branch()