Patchwork cmdutil: add special string that ignores rest of text

login
register
mail settings
Submitter Sean Farley
Date Dec. 31, 2016, 9:41 p.m.
Message ID <bd762c3d68423f7fa9e5.1483220501@1.0.0.127.in-addr.arpa>
Download mbox | patch
Permalink /patch/18060/
State Changes Requested
Headers show

Comments

Sean Farley - Dec. 31, 2016, 9:41 p.m.
# HG changeset patch
# User Sean Farley <sean@farley.io>
# Date 1483220196 21600
#      Sat Dec 31 15:36:36 2016 -0600
# Node ID bd762c3d68423f7fa9e5e2b97425ed7108e0b8fc
# Parent  69459fdf3b1b06e4add68d4dbd36a585d818f3b1
cmdutil: add special string that ignores rest of text

Similar to git, we add a special string: "HG: ------------------------
>8 ------------------------" that means anything below it is ignored in
a commit message.

This is helpful for integrating with third-party tools that display the
Ryan McElroy - Jan. 3, 2017, 11:40 p.m.
On Sat, Dec 31, 2016 at 9:41 PM, Sean Farley <sean@farley.io> wrote:

> # HG changeset patch
> # User Sean Farley <sean@farley.io>
> # Date 1483220196 21600
> #      Sat Dec 31 15:36:36 2016 -0600
> # Node ID bd762c3d68423f7fa9e5e2b97425ed7108e0b8fc
> # Parent  69459fdf3b1b06e4add68d4dbd36a585d818f3b1
> cmdutil: add special string that ignores rest of text
>
> Similar to git, we add a special string: "HG: ------------------------
> >8 ------------------------" that means anything below it is ignored in
> a commit message.
>
> This is helpful for integrating with third-party tools that display the
> diff in the editor buffer.
>

+1 on the feature, but this probably deserves a test
Pierre-Yves David - Jan. 4, 2017, 3:43 p.m.
On 12/31/2016 10:41 PM, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean@farley.io>
> # Date 1483220196 21600
> #      Sat Dec 31 15:36:36 2016 -0600
> # Node ID bd762c3d68423f7fa9e5e2b97425ed7108e0b8fc
> # Parent  69459fdf3b1b06e4add68d4dbd36a585d818f3b1
> cmdutil: add special string that ignores rest of text
>
> Similar to git, we add a special string: "HG: ------------------------
>> 8 ------------------------" that means anything below it is ignored in
> a commit message.
>
> This is helpful for integrating with third-party tools that display the
> diff in the editor buffer.

That seems a useful feature thanks for poking at this, but I agree with 
Ryan that having a test would be better. In addition, how do we expect 
people do dicover this exist, your patch introduce the feature but not 
usage or documentation about it is added ?

> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -2753,10 +2753,18 @@ def commitforceeditor(repo, ctx, subs, f
>      repo.dirstate.write(tr)
>      pending = tr and tr.writepending() and repo.root
>
>      editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
>                          editform=editform, pending=pending)
> +
> +    # strip away anything below this special string (used for editors that want
> +    # to display the diff)
> +    linebelow = "^HG: ------------------------ >8 ------------------------"

Small code feedback as we are at it:

  * Should we also fix the line ending? ($ as final char of the string)

  * moving the constant as "_linebelow" (or whatever better name) at the 
module level would make is accessible to extensions. That a simple move 
that can prove useful in the feature.

> +    stripbelow = re.search(linebelow, editortext, flags=re.MULTILINE)
> +    if stripbelow:
> +        editortext = editortext[:stripbelow.start()]
> +
>      text = re.sub("(?m)^HG:.*(\n|$)", "", editortext)
>      os.chdir(olddir)
>
>      if finishdesc:
>          text = finishdesc(text)

Cheers,
Sean Farley - Jan. 4, 2017, 9:22 p.m.
Pierre-Yves David <pierre-yves.david@ens-lyon.org> writes:

> On 12/31/2016 10:41 PM, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean@farley.io>
>> # Date 1483220196 21600
>> #      Sat Dec 31 15:36:36 2016 -0600
>> # Node ID bd762c3d68423f7fa9e5e2b97425ed7108e0b8fc
>> # Parent  69459fdf3b1b06e4add68d4dbd36a585d818f3b1
>> cmdutil: add special string that ignores rest of text
>>
>> Similar to git, we add a special string: "HG: ------------------------
>>> 8 ------------------------" that means anything below it is ignored in
>> a commit message.
>>
>> This is helpful for integrating with third-party tools that display the
>> diff in the editor buffer.
>
> That seems a useful feature thanks for poking at this, but I agree with 
> Ryan that having a test would be better. In addition, how do we expect 
> people do dicover this exist, your patch introduce the feature but not 
> usage or documentation about it is added ?

Yeah, my idea was to make this "experimental" but I have no problems
adding it to the docs. Will do in V2.

>> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
>> --- a/mercurial/cmdutil.py
>> +++ b/mercurial/cmdutil.py
>> @@ -2753,10 +2753,18 @@ def commitforceeditor(repo, ctx, subs, f
>>      repo.dirstate.write(tr)
>>      pending = tr and tr.writepending() and repo.root
>>
>>      editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
>>                          editform=editform, pending=pending)
>> +
>> +    # strip away anything below this special string (used for editors that want
>> +    # to display the diff)
>> +    linebelow = "^HG: ------------------------ >8 ------------------------"
>
> Small code feedback as we are at it:
>
>   * Should we also fix the line ending? ($ as final char of the string)

Ah, good catch!

>   * moving the constant as "_linebelow" (or whatever better name) at the 
> module level would make is accessible to extensions. That a simple move 
> that can prove useful in the feature.

That's a good point. Will do in V2.

Patch

diff in the editor buffer.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2753,10 +2753,18 @@  def commitforceeditor(repo, ctx, subs, f
     repo.dirstate.write(tr)
     pending = tr and tr.writepending() and repo.root
 
     editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
                         editform=editform, pending=pending)
+
+    # strip away anything below this special string (used for editors that want
+    # to display the diff)
+    linebelow = "^HG: ------------------------ >8 ------------------------"
+    stripbelow = re.search(linebelow, editortext, flags=re.MULTILINE)
+    if stripbelow:
+        editortext = editortext[:stripbelow.start()]
+
     text = re.sub("(?m)^HG:.*(\n|$)", "", editortext)
     os.chdir(olddir)
 
     if finishdesc:
         text = finishdesc(text)