[PATCH] cmdutil: show diffs in commit message with ui.verbosecommit option
Jordi Gutiérrez Hermoso
jordigh at octave.org
Wed Jan 15 20:21:40 CST 2014
On Sat, 2014-01-11 at 15:20 -0600, Martin Geisler wrote:
> Jordi Gutiérrez Hermoso <jordigh at octave.org> writes:
> > # HG changeset patch
> > # User Jordi Gutiérrez Hermoso <jordigh at octave.org>
> > # Date 1373469596 14400
> > # Wed Jul 10 11:19:56 2013 -0400
> > # Node ID b40695568db84a43b24cffb4c32583a759d96b09
> > # Parent 01bdccfeb9d98ae85388d06c9c694b946f346edf
> > cmdutil: show diffs in commit message with ui.verbosecommit option
> I know people have been asking for this, but I've never really
> understood why: I simply run 'hg diff' in another terminal or take a
> peek in TortoiseHg.
It would be convenient to be able to look at the diff as one is
writing a commit message about it. Indeed, since lines beginning with
HG: are ignored, it is even possible to even annotate the diff inline
in the commit message. It seems useful to me.
Another use case is as a final reminder of what's about to be
committed if using hg (c)record. In that case, you want to see what
you're about to commit, "hg diff" or thg will be no help. I thought
this patch helped with the case of (c)record, but testing it again, I
see that it doesn't. I'll fix this.
> > The following adds an option, ui.verbosecommit, which displays the
> > entire diff about to be committed in the text editor window,
> If this goes in, then I suggest using a more descriptive name than
> ui.verbosecommit. Maybe ui.commitmsgdiff so that the scope of the
> setting is more well-defined.
Originally I was hoping for other kinds of output besides the diff,
hence the generic name. I have forgotten what those other things were,
so I'll revert to your specific option name.
> > prefixed with "HG:". This is useful as a final reminder of what's
> > about to be committed while writing the commit message.
> > diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> > --- a/mercurial/cmdutil.py
> > +++ b/mercurial/cmdutil.py
> > @@ -1864,6 +1864,12 @@
> > edittext.extend([_("HG: added %s") % f for f in added])
> > edittext.extend([_("HG: changed %s") % f for f in modified])
> > edittext.extend([_("HG: removed %s") % f for f in removed])
> > + if repo.ui.config("ui","verbosecommit"):
> > + edittext.append("HG: ")
> > + diff = ctx.diff()
> > + for f in diff:
> > + for l in f.split("\n"):
> > + edittext.extend([_("HG: %s") % l])
> You should probably either use
> for l in f.split("\n"):
> edittext.append(_("HG: %s") % l)
> edittext.extend([_("HG: %s") % l for l in f.split("\n")])
> That is, either append single lines or extend the list with all lines in
> one go.
I'll make this change.
- Jordi G. H.
More information about the Mercurial-devel