Skip to content

Instantly share code, notes, and snippets.

@unux
Created July 18, 2013 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unux/6030952 to your computer and use it in GitHub Desktop.
Save unux/6030952 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Give yourself a split view of your changes when you're committing
#
# If you patch hgext/record.py you can even show the changes you're
# cherry picking.
#
# Usage:
# HGEDITOR=~/bin/hg_ci_editor.sh hg ci ...
# HGEDITOR=~/bin/hg_ci_editor.sh hg record ...
#
readonly HG_CI_FILE=$1
readonly DIFF_FILE=".hg/record-backups/hg_record.diff"
DIFF_CMD="hg diff --nodates"
if [ -r "$(hg root)/$DIFF_FILE" ]; then
DIFF_CMD="cat $DIFF_FILE"
fi
vim $HG_CI_FILE \
--cmd ":autocmd BufRead $HG_CI_FILE :autocmd BufWinLeave $HG_CI_FILE :qall"\
-c "set cmdheight=2" \
-c ":vnew" \
-c ":read !$DIFF_CMD" \
-c "set filetype=diff readonly" \
-c "set buftype=nofile bufhidden=hide noswapfile" \
-c ":wincmd t"
-c "set cmdheight=1" \
status=$?
exit $status
# NOTE: this patch is against mercurial 2.2.3
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -586,6 +586,12 @@
try:
ui.debug('applying patch\n')
ui.debug(fp.getvalue())
+ record_patch_filename = os.path.join(backupdir, 'hg_record.diff')
+ try:
+ rp = open(record_patch_filename, 'wb')
+ rp.write(fp.getvalue())
+ finally:
+ rp.close()
patch.internalpatch(ui, repo, fp, 1, eolmode=None)
except patch.PatchError, err:
raise util.Abort(str(err))
@@ -621,6 +627,8 @@
# writing it.
shutil.copystat(tmpname, repo.wjoin(realname))
os.unlink(tmpname)
+ if dopatch:
+ os.unlink(record_patch_filename)
if tobackup:
os.rmdir(backupdir)
except OSError:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment