Using vimdiff to view single diffs
hg cat <filename> | vim - -c ":vert diffsplit <filename>" -c "map q :qa!<CR>";
Using bash to save as a command:
hgdiff() { hg cat $1 | vim - -c ":vert diffsplit $1" -c "map q :qa!<CR>"; }
Then just use hgdiff <filename> to invoke, and q from within vim to quit.
ErikTerpstra added:
If you want the new version on the right side, try this instead:
hgdiff() { vimdiff -c 'map q :qa!<CR>' <(hg cat "$1") "$1"; }
ErnieRael added:
A bash script, I call it hgdiff, like hg diff for -r -c options
Get rid of the <space> before the "#!"
#!/bin/bash usage() { echo "${0##*/} ([-c REV] | [-r REV1 [-r REV2]]) FILE" >&2 echo " with -c, older REV on the left" >&2 echo " with -r, REV1 on the left. If no REV2, right side modifiable" >&2 exit 1 } hgrevtmp() { local tmpf=$(mktemp --tmpdir hgTmpRev$1.XXXXXXXXXX) hg cat -r $1 "$2" >> "$tmpf" if [ $? != 0 ]; then return 1; fi chmod a-w "$tmpf" echo "$tmpf" } declare -a rev declare -a change nRev=0 nChange=0 declare TEMP TEMP=$(getopt "hr:c:" "$@") if [ $? != 0 ]; then usage; fi eval set -- "$TEMP" while true do case "$1" in -r) rev[nRev++]=$2; shift 2;; -c) change[nChange]=$2; shift 2;; -h) usage;; --) shift; break;; *) echo Internal Error; exit 1;; esac done # echo rev: ${rev[*]} # echo change: ${change[*]} # echo remain: $# $* if [[ $# != 1 ]]; then echo "exactly one FILE can be specified, not $#" someError=true fi if [[ $nRev > 0 && $nChange > 0 ]]; then echo "can only specify one of -c and -r" someError=true fi if [[ $nRev > 2 ]]; then echo "at most two -r can be specified, not $nRev" someError=true fi if [[ $nChange > 1 ]]; then echo "only one -c can be specified, not $nChange" someError=true fi if [ "$someError" = true ]; then usage; fi deleteTemps() { #echo delete: $tmpf1 $tmpf2 rm -f "$tmpf1" "$tmpf2" } # bail if an error and delete the temps set -e trap deleteTemps ERR # convert rev to version number in local repository convertToRev() { hg log -r $1 --template '{rev}' } toPrevRev() { if [ $1 == 0 ]; then echo "null" return; fi # get the array of parents for the rev local parents=($(hg log -r $1 --template '{parents}')) if [ $? != 0 ]; then return 1; fi # Note: parents without "[i]" is first item in array if [ -z "$parents" ]; then echo $(($1 - 1)) else convertToRev $parents fi } repo_file=$1 noMod="set nomodifiable" chg=${change[0]} if [ -n "$chg" ]; then # diff given rev against previous rev chg=$(convertToRev $chg) # subtract one from change number to get previous tmpf1=$(hgrevtmp $(toPrevRev $chg) "$repo_file") tmpf2=$(hgrevtmp $chg "$repo_file") f2=$tmpf2 f2Mod=$noMod else if [ $nRev == 0 ]; then tmpf1=$(hgrevtmp tip "$repo_file") f2=$repo_file else rev=$(convertToRev ${rev[0]}) tmpf1=$(hgrevtmp $rev "$repo_file") if [ $nRev == 1 ]; then f2=$repo_file else rev=$(convertToRev ${rev[1]}) tmpf2=$(hgrevtmp $rev "$repo_file") f2=$tmpf2 f2Mod=$noMod fi fi fi ( gvim --nofork -d -c ":set columns=170" \ $(cygpath -m "$tmpf1") \ -c "set nomodifiable" \ $(cygpath -m "$f2") \ -c "wincmd w" \ -c "$f2Mod" \ -c "wincmd =" \ -c "map q :qa<CR>" deleteTemps ) &