From b1f5d8f24c7f9b2598bf7c5fec56ac4bc51901bb Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Fri, 17 Sep 2021 08:27:56 +1000 Subject: [PATCH 1/1] initial --- git-differ | 20 +++++++++++++++++ git-review | 40 +++++++++++++++++++++++++++++++++ git-show-i | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100755 git-differ create mode 100755 git-review create mode 100755 git-show-i diff --git a/git-differ b/git-differ new file mode 100755 index 0000000..6fcf790 --- /dev/null +++ b/git-differ @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Assumes a lot about invocation: +# commit1 commit2 -- path + +EXT="${4##*.}" + +case "$EXT" in + png|jpg|bmp) + F1=$(mktemp --suffix=$EXT) + git cat-file -p $1:$4 > $F1 + F2=$(mktemp --suffix=$EXT) + git cat-file -p $2:$4 > $F2 + montage $F1 $F2 -tile 2x1 -geometry +5+5 -border 2 png:- | display - + rm -f $F1 $F2 + ;; + *) + git meld $* + ;; +esac diff --git a/git-review b/git-review new file mode 100755 index 0000000..c671cd9 --- /dev/null +++ b/git-review @@ -0,0 +1,40 @@ +#!/bin/zsh +# +# Review commits based on the branch graph +# + +N=1 +if [ $# = 1 ] ; then + if [ -e $1 ] ; then + FOCUS=$1 + else + N=$1 + fi +elif [ $# = 2 ] ; then + N=$1 + FOCUS=$2 +fi +FMT='--pretty=format:%h %d %s' + +GRAPH="$(git log --graph --full-history "$FMT" --all $FOCUS )" + +PROJECT="$(git rev-parse --show-toplevel| sed 's/.*\///')" + +X=$(echo "$GRAPH" | iselect -t "$PROJECT" -n git-review -p $N -P -K -k/ -kp ) + +[ -z "$X" ] && exit 0 +X=( ${(s[:])X} ) +N=$X[1] +K=$X[2] +X=$X[3] +if [ "$K" = / ] ; then + read "x?Search: " + N=${"$(echo "$GRAPH" | grep -nF "$x")"%%:*} +elif [ "$K" = "p" ] ; then + # previous commit + Z=${"$(git rev-parse ${X}~1)"[1,7]} + [ -z "$Z" ] || N=${"$(echo "$GRAPH" | grep -nF "$Z")"%%:*} +else + FOCUS=$FOCUS git-show-i $X~1 $X +fi +exec $0 $N $FOCUS diff --git a/git-show-i b/git-show-i new file mode 100755 index 0000000..088b35c --- /dev/null +++ b/git-show-i @@ -0,0 +1,65 @@ +#!/bin/zsh +# +# Show differences between $1 and $2 with selection + +TMP=/tmp/git-show-i-$$ +mkdir -p $TMP +function cleanup() { + rm -rf $TMP + trap "" 0 + exit +} +trap "cleanup" 0 2 15 + +git diff --no-prefix $* 2>/dev/null | \ + csplit -z -b %04d -f $TMP/hunk# - "/^diff --git/" "{*}" > /dev/null + +if [ ! -f $TMP/hunk#0000 ] ; then + read 'x?Push enter' + exit 0 +fi + +LIST=( ${(f)"$(head -qn1 $TMP/* 2>/dev/null | awk '{print "" $3;}')"} ) + +if [ -z "$LIST" ] ; then + read 'x?Nothing to show. Push enter' + exit 0 +fi + +# translate a given selection index, if for a submodule, into the +# commit ids for the submodule +function submodule_delta() { + # Determine which diff-hunk is selected + HUNK="$(grep -lF "diff --git $1 " $TMP/* )" + # If the hunk ends with "+Subproject commit ", then it's a sub project + tail -n 2 $HUNK | grep "^.Subproject commit " | sed 's/.* //' +} + +PROJECT="$(git rev-parse --show-toplevel| sed 's/.*\///')" +if [ -n "$FOCUS" ] ; then + # point at the focused item + LAST=${$(echo "${(F)LIST}" | grep -nF "$FOCUS")%%:*} +fi +[ -z "$LAST" ] && LAST=1 +while true ; do + X="$(iselect -f -n "git-show-i" -K -t "$PROJECT: commit $1" -p $LAST \ + $LIST "Done" )" + [ -z "$X" ] && break + LAST=${$(echo "${(F)LIST}" | grep -nF "${X#*:}")%%:*} + #read "x?$LAST $X" + case "${X%%:*}" in + RETURN|KEY_RIGHT) + [ "${X#*:}" = Done ] && exit 0 + # If the selection is a sub module, then use git-show-i + # recursively for the submodule versions + SUBS=( $(submodule_delta "${X#*:}" ) ) + if [ -z "$SUBS" ] ; then + #git meld $* -- "${X#*:}" + git-differ $* -- "${X#*:}" + else + ( cd ${X#*:} ; $0 $SUBS ) + fi + continue + ;; + esac +done -- 2.39.2