<div dir="ltr"><div class="gmail_quote">On Sun, Apr 4, 2010 at 1:03 AM, Mads Kiilerich <span dir="ltr"><<a href="mailto:mads@kiilerich.com">mads@kiilerich.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Itamar Ravid wrote, On 04/03/2010 05:17 PM:<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# HG changeset patch<br>
# User Itamar Ravid<<a href="mailto:iravid@iravid.com" target="_blank">iravid@iravid.com</a>><br>
# Date 1270307531 -10800<br>
# Node ID 2272a05026eb11f2d52067606729df6d86f18627<br>
# Parent cd0c49bdbfd9edab18c3656d8a8a0bd27a9aa82a<br>
Abstract the functionality of calling an editor into the 'edit' function to prevent<br>
users from having to mess with the code responsible for generating the temporary<br>
commit message and diff files.<br>
<br>
</blockquote>
<br></div>
I don't know where it is documented, but the first line of the commit message is special by convention supported by Mercurial. IIRC it should be a summary of the change, no more than 80 characters, and preferable prefixed with (in this case) "hgeditor:".<br>
<br>
[crew: Should the exact guideline (whatever it is) be added to ContributingChanges? (Perhaps together with some advice of content and language)]<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
diff -r cd0c49bdbfd9 -r 2272a05026eb hgeditor<br>
--- a/hgeditor Thu Apr 01 17:51:59 2010 -0500<br>
+++ b/hgeditor Sat Apr 03 18:12:11 2010 +0300<br>
@@ -3,19 +3,22 @@<br>
# This is an example of using HGEDITOR to create of diff to review the<br>
# changes while commiting.<br>
<br>
-# If you want to pass your favourite editor some other parameters<br>
-# only for Mercurial, modify this:<br>
-case "${EDITOR}" in<br>
- "")<br>
- EDITOR="vi"<br>
- ;;<br>
- emacs)<br>
- EDITOR="$EDITOR -nw"<br>
- ;;<br>
- gvim|vim)<br>
- EDITOR="$EDITOR -f -o"<br>
- ;;<br>
-esac<br>
+# Edit a file, optionally opening another one as reference within the editor.<br>
+# If you want to pass your favourite editor some other parameters only for Mercurial,<br>
+# modify the 'case' statement within this function.<br>
+edit() {<br>
+ case "${EDITOR}" in<br>
+ "")<br>
+ vi "$1" "$2"<br>
+ ;;<br>
+ emacs)<br>
+ emacs -nw "$1" "$2"<br>
+ ;;<br>
<br>
</blockquote>
<br></div>
vi and emacs will now be called with an empty 2nd parameter in some cases (such as "hg qref -e"). vi will fail and emacs will complain. </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">The old behavior was that other values of $EDITOR could be used (such as vi) - that should be preserved.</div><div class="im"><br></div></blockquote><div><br></div><div>That's true - I've overlooked those cases :-) Perhaps something like the suggestion below could be better?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
HGTMP=""<br>
@@ -45,9 +48,9 @@<br>
MD5=$(which md5 2>/dev/null)<br>
[ -x "${MD5}" ]&& CHECKSUM=`${MD5} "$HGTMP/msg"`<br>
if [ -s "$HGTMP/diff" ]; then<br>
- $EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $?<br>
+ edit "$HGTMP/msg" "$HGTMP/diff" || exit $?<br>
else<br>
- $EDITOR "$HGTMP/msg" || exit $?<br>
+ edit "$HGTMP/msg" || exit $?<br>
fi<br>
[ -x "${MD5}" ]&& (echo "$CHECKSUM" | ${MD5} -c>/dev/null 2>&1&& exit 13)<br>
<br>
</blockquote>
<br></div>
It seems like this refactoring isn't a good idea.<br>
<br>
Perhaps there is no simple way to achieve what you want, so perhaps it isn't a good idea to include it in Mercurial?<br>
<br>
Or perhaps do it in a different hackish way: Define a "vim" function which handles the second argument in this special way and calls out to the binary.<br><font color="#888888">
<br>
/Mads<br></font></blockquote><div><br></div><div>edit() {</div><div> case "${EDITOR}" in</div><div> "")</div><div> EDITOR="vi"</div><div> ;;</div><div> emacs)</div>
<div> EDITOR="$EDITOR -nw"</div><div> ;;</div><div> gvim|vim)</div><div> # Note special case when opening two files below</div><div> EDITOR="$EDITOR"</div>
<div> ;;</div><div> esac</div><div><br></div><div> if [ -z "$2" ]; then</div><div> "$EDITOR" "$1"</div><div> else</div><div> if [ $EDITOR = "vim" -o $EDITOR = "gvim" ]; then</div>
<div> # Handle irregular arg-ordering when calling g/vim</div><div> "$EDITOR" "+e $2" "+set buftype=help" "+split $1"</div><div> else</div><div> "$EDITOR" "$1" "$2"</div>
<div> fi</div><div> fi</div><div>}</div><div> </div></div>This, I believe, handles the problems discussed while still containing the edit logic within the function. What do you think?<div><br></div><div>Regarding the commit message convention, I'll resubmit the patchbomb with a proper one once we iron out the code issues.</div>
</div>