Download:
child 142:0c326ee38ba2
parent 140:b39b7473c873
141:66e31ac77c94
Anton Shestakov <av6@dwimlabs.net>, Thu, 22 Dec 2016 13:41:34 +0800
.hgrc: have a committemplate and use it in .hgeditor for showing diff

2 файлов изменено, 24 вставок(+), 11 удалений(-) [+]
.hgeditor file | annotate | diff | comparison | revisions
.hgrc file | annotate | diff | comparison | revisions
--- a/.hgeditor Thu Dec 22 13:40:29 2016 +0800
+++ b/.hgeditor Thu Dec 22 13:41:34 2016 +0800
@@ -1,8 +1,4 @@
#!/bin/sh
-#
-# This is an example of using HGEDITOR to create of diff to review the
-# changes while commiting.
-
HGTMP=""
cleanup_exit() {
@@ -19,13 +15,13 @@
exit 1
fi
-(
- grep '^HG: \(changed\|added\|removed\)' "$1" | cut -d ' ' -f 3- | while read changed; do
- "$HG" diff "$changed" >> "$HGTMP/diff"
- done
-)
-
-cat "$1" > "$HGTMP/msg"
+LINE=$(fgrep 'HG: --- 8< ---' -nm1 "$1" | cut -d: -f1)
+if [ -n "$LINE" ]; then
+ head -n "$(( LINE - 1 ))" "$1" > "$HGTMP/msg"
+ tail -n +"$(( LINE + 1 ))" "$1" | sed -e 's/^HG: //g' > "$HGTMP/diff"
+else
+ cat "$1" > "$HGTMP/msg"
+fi
MD5=$(which md5sum 2>/dev/null) || \
MD5=$(which md5 2>/dev/null)
--- a/.hgrc Thu Dec 22 13:40:29 2016 +0800
+++ b/.hgrc Thu Dec 22 13:41:34 2016 +0800
@@ -43,3 +43,20 @@
changeset.public = green
changeset.secret = red
+
+[committemplate]
+changeset = {desc}\n\n
+ HG: Enter commit message. Lines beginning with 'HG:' are removed.
+ HG: {extramsg}
+ HG: --
+ HG: user: {author}\n{ifeq(p2rev, "-1", "",
+ "HG: branch merge\n")
+ }HG: branch '{branch}'\n{if(activebookmark,
+ "HG: bookmark '{activebookmark}'\n") }{subrepos %
+ "HG: subrepo {subrepo}\n" }{file_adds %
+ "HG: added {file}\n" }{file_mods %
+ "HG: changed {file}\n" }{file_dels %
+ "HG: removed {file}\n" }{if(files, "",
+ "HG: no files changed\n")
+ }HG: --- 8< ---
+ {splitlines(diff()) % 'HG: {line}\n'}