Add the diffcol.sh file to the contrib directory
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 20 Oct 2006 20:48:30 +0000 (21:48 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 20 Oct 2006 20:48:30 +0000 (21:48 +0100)
This script is a pager for colourifying the diff output. Copied from Quilt.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
MANIFEST.in
contrib/diffcol.sh [new file with mode: 0755]
examples/stgitrc
setup.py

index 4ebca0e..5668fdf 100644 (file)
@@ -3,3 +3,4 @@ include stg-prof
 include templates/*.tmpl
 include examples/*.tmpl
 include examples/stgitrc
+include contrib/diffcol.sh
diff --git a/contrib/diffcol.sh b/contrib/diffcol.sh
new file mode 100755 (executable)
index 0000000..ea9109d
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# Code copied from Quilt (http://savannah.nongnu.org/projects/quilt)
+#
+# Copyright 2006 - the Quilt authors
+#
+#  This script is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2 as
+#  published by the Free Software Foundation.
+
+setup_colors()
+{
+       local C="diffhdr=1;36:diffhdradd=1;32:diffadd=32:diffhdrmod=1;35:diffmod=35:diffhdrrem=1;31:diffrem=31:diffhunk=36:diffctx=34:diffcctx=33:default=0"
+       [ -n "$DIFF_COLORS" ] && C="$C:$DIFF_COLORS"
+
+       C=${C//=/=\'$'\e'[}
+       C=col${C//:/m\'; col}m\'
+       #coldefault=$(tput op)
+       eval $C
+}
+
+setup_colors
+
+gawk '{
+       if (/^(Index:|diff --git) /)
+               print "'$coldiffhdr'" $0 "'$coldefault'"
+       else if (/^======*$/)
+               print "'$coldiffhdr'" $0 "'$coldefault'"
+       else if (/^\+\+\+/)
+               print "'$coldiffhdradd'" $0 "'$coldefault'"
+       else if (/^\*\*\*/)
+               print "'$coldiffhdrmod'" $0 "'$coldefault'"
+       else if (/^---/)
+               print "'$coldiffhdrrem'" $0 "'$coldefault'"
+       else if (/^(\+|new( file)? mode )/)
+               print "'$coldiffadd'" $0 "'$coldefault'"
+       else if (/^(-|(deleted file|old) mode )/)
+               print "'$coldiffrem'" $0 "'$coldefault'"
+       else if (/^!/)
+               print "'$coldiffmod'" $0 "'$coldefault'"
+       else if (/^@@ \-[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@/)
+               print gensub(/^(@@[^@]*@@)([ \t]*)(.*)/,
+                       "'$coldiffhunk'" "\\1" "'$coldefault'" \
+                       "\\2" \
+                       "'$coldiffctx'" "\\3" "'$coldefault'", "")
+       else if (/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/)
+               print "'$coldiffcctx'" $0 "'$coldefault'"
+       else {
+               print
+       }
+}' $1 | less -R -S
index cd22e97..28e1879 100644 (file)
@@ -25,7 +25,7 @@ smtpserver: localhost:25
 #editor: /usr/bin/vi
 
 # this value overrides the default PAGER environment variable
-#pager: less -S
+#pager: ~/share/stgit/contrib/diffcol.sh
 
 # The three-way merge tool. Note that the 'output' file contains the
 # same data as 'branch1'. This is useful for tools that do not take an
index 7888f29..7c043b8 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -18,5 +18,6 @@ setup(name = 'stgit',
       data_files = [('share/stgit/templates', glob.glob('templates/*.tmpl')),
                     ('share/stgit/examples', glob.glob('examples/*.tmpl')),
                     ('share/stgit/examples', ['examples/stgitrc']),
+                    ('share/stgit/contrib', ['contrib/diffcol.sh']),
                     ('share/doc/stgit', glob.glob('doc/*.txt'))]
       )