make `view diff on commit` a feature that is easy to use

Katsunori Fujiwara flying.foozy at gmail.com
Fri Nov 14 09:19:02 UTC 2014


2014-11-14 17:25 GMT+09:00 anatoly techtonik <techtonik at gmail.com>:
> On Fri, Nov 14, 2014 at 4:12 AM, Katsunori Fujiwara
> <flying.foozy at gmail.com> wrote:
>> 2014-11-05 5:50 GMT+09:00 anatoly techtonik <techtonik at gmail.com>:
>>
>>> I always do `hg diff` before `hg ci` (sometimes also `hg sum/st`),
>>> which is very clumsy, so I went to see if something is already
>>> available.
>>>
>>> vim-only
>>> https://stackoverflow.com/questions/8009333/vim-show-diff-on-commit-in-mercurial
>>> http://mercurial.selenic.com/wiki/DiffsInCommitMessageInVIM
>>>
>>> bash-only
>>> http://mercurial.selenic.com/wiki/hgeditor
>>>
>>>
>>> I've tried to bring my own solution with temporary file, but the
>>> diff with prepended HG: loses syntax highlighting. So, to make
>>> this feature more useful, maybe these two things are possible
>>> to implement:
>>>
>>> 1. remove all lines after HG: block, i.e.
>>> -HG: Enter commit message.  Lines beginning with 'HG:' are removed.
>>> -HG: Leave message empty to abort commit.
>>> +HG: Enter commit message.  Lines beginning with 'HG:' and any text
>>> +HG: after are removed. Leave message empty to abort commit.
>>>
>>> 2. hg commit -v  to show diff
>>>     hg commit -vv to show diff + diffstat
>>> (grabbed the idea from SO comment above)
>>
>> Would customization by "[committemplate]" configuration help you ?
>>
>>     http://www.selenic.com/mercurial/hgrc.5.html#committemplate
>>
>> Combination of "[committemplate]" and the template
>> function "diff()" allows you to show "diff" of the newly added
>> revision in your favorite style.
>
> My favorite style is to show diffs without HG: prefix on each line, which is
> impossible with committemplate too.

"[committemplate] changeset" should show diff without
leading "HG: " by just writing "{diff()}", because:

  - "diff()" is normal template function (not specific for
    templating of "[committemplate]")

  - leading "HG: " of each line isn't automatically added for
    templating of "[committemplate] changeset"

On the other hand, when you want to add leading "HG: " to diff
output, you should write configuration like below:

    changeset = HG: this line should be ignored
        {splitlines(diff()) % 'HG: {line}\n'}

In "[committemplate]" configuration, adding/omitting
leading "HG: " of each lines is responsiblity of users.

-- 
----------------------------------------------------------------------
FUJIWARA Katsunori(flying.foozy at gmail.com)



More information about the Mercurial mailing list