summaryrefslogtreecommitdiffstats
path: root/src/tools/git-external-diff
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
commit46651ce6fe013220ed397add242004d764fc0153 (patch)
tree6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/tools/git-external-diff
parentInitial commit. (diff)
downloadpostgresql-14-46651ce6fe013220ed397add242004d764fc0153.tar.xz
postgresql-14-46651ce6fe013220ed397add242004d764fc0153.zip
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/git-external-diff')
-rw-r--r--src/tools/git-external-diff59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/tools/git-external-diff b/src/tools/git-external-diff
new file mode 100644
index 0000000..39ddd01
--- /dev/null
+++ b/src/tools/git-external-diff
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# This script is used to produce git context diffs
+
+# Supplied parameters:
+# $1 $2 $3 $4 $5 $6 $7
+# path old-file old-hash old-mode new-file new-hash new-mode
+# 'path' is the git-tree-relative path of the file being diff'ed
+
+=comment
+
+This info is copied from the old wiki page on Working with git:
+
+Context diffs with Git
+
+Copy git-external-diff into libexec/git-core/ of your git installation
+and configure git to use that wrapper with:
+
+ git config [--global] diff.external git-external-diff
+
+--global makes the configuration global for your user - otherwise it is
+just configured for the current repository.
+
+For every command which displays diffs in some way you can use the
+parameter "--[no-]-ext-diff" to enable respectively disable using the
+external diff command.
+
+For the git diff command --ext-diff is enabled by default - for any
+other command like git log -p or git format-patch it is not!
+
+This method should work on all platforms supported by git.
+
+If you do not want to configure the external wrapper permanently or you
+want to overwrite it you can also invoke git like:
+
+ export GIT_EXTERNAL_DIFF=git-external-diff
+ git diff --[no-]ext-diff
+
+Alternatively, configure a git alias in ~/.gitconfig or .git/config:
+
+ [alias]
+ cdiff = !GIT_EXTERNAL_DIFF=git-context-diff git diff
+=cut
+
+old_hash="$3"
+new_hash=$(git hash-object "$5")
+
+# no change?
+[ "$old_hash" = "$new_hash" ] && exit 0
+
+[ "$DIFF_OPTS" = "" ] && DIFF_OPTS='-pcd'
+
+echo "diff --git a/$1 b/$1"
+echo "new file mode $7"
+echo "index ${old_hash:0:7}..${new_hash:0:7}"
+
+diff --label a/"$1" --label b/"$1" $DIFF_OPTS "$2" "$5"
+
+exit 0