On 12/31/2016 10:41 PM, Sean Farley wrote:
# HG changeset patch
# User Sean Farley <s...@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,

--
Pierre-Yves David
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to