chiark / gitweb /
Add contrib/stg-whatchanged: look at what would be changed by refreshing.
authorYann Dirson <ydirson@altern.org>
Fri, 2 Mar 2007 21:34:28 +0000 (21:34 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 2 Mar 2007 21:34:28 +0000 (21:34 +0000)
This script outputs a "metadiff" (diff of diffs, ie. diff between 2
versions of a single patch).  This is somewhat a proof of concept, and some
work is indeed needed in the way to present the results.  Consider
filtering the output at least through colordiff.

I have 2 uses for this script:
- when simply editing a patch, provides a 3rd way to check what I've done
  before refreshing (in addition to "stg diff" and "stg diff -r //bottom")
- most usefully, when resolving conflicts caused by a push, to ease
  checking of the merge result.

Signed-off-by: Yann Dirson <ydirson@altern.org>
contrib/stg-whatchanged [new file with mode: 0755]

diff --git a/contrib/stg-whatchanged b/contrib/stg-whatchanged
new file mode 100755 (executable)
index 0000000..f80d0a1
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+set -e
+
+# stg-whatchanged - show a metadiff for the patch being modified,
+# especially when resolving a merge.
+
+# Copyright (c) 2006-2007 Yann Dirson <ydirson@altern.org>
+# Subject to the GNU GPL, version 2.
+
+# FIXME:
+# - should only exclude hunk headers differing only in line offsets
+# - diff coloring should show changes in context lines differently than
+#   changes in contents
+# - filter on ^index lines is a bit wide
+# - we should be able to ask diff to force a new hunk on "^@@ " to better
+#   handle them
+# - we should always show the hunk header for any changes within a hunk
+
+# default to unified diff
+if [ "$#" = 0 ]; then
+    set -- -u
+fi
+
+# Merges via "push" leave top=bottom so we must look at old patch
+# in this case (unlike, eg., "pick --fold")
+patchdir="$(git-rev-parse --git-dir)/patches/$(stg branch)/$(stg top)"
+if [ $(cat "$patchdir/bottom") = $(cat "$patchdir/top") ];
+then
+    current_cmd="stg show //top.old"
+else
+    current_cmd="stg show"
+fi
+
+colordiff "$@" \
+    -I '^index [0-9a-b]*..[0-9a-b]*' \
+    -I '^@@ .* @@' \
+    <($current_cmd) <(stg diff -r//bottom) | less -RFX