* [cogito PATCH] Add "-c" (colorize) option to cg-diff
@ 2005-05-20 14:58 Catalin Marinas
0 siblings, 0 replies; only message in thread
From: Catalin Marinas @ 2005-05-20 14:58 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 134 bytes --]
An option I found quite useful in quilt. I just copied the
corresponding code from quilt (released under GPLv2) to cg-diff.
Catalin
[-- Attachment #2: patch-color-diff --]
[-- Type: text/plain, Size: 3131 bytes --]
Add "-c" (colorize) option to cg-diff
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Index: cg-diff
===================================================================
--- ca5fef50fb68a3afbb35e1a48ac622f7a964f021/cg-diff (mode:100755)
+++ uncommitted/cg-diff (mode:100755)
@@ -14,6 +14,8 @@
# -p instead of one ID denotes a parent commit to the specified ID
# (which must not be a tree, obviously).
#
+# -c colorizes the diff output
+#
# Outputs a diff converting the first tree to the second one.
. ${COGITO_LIB}cg-Xlib
@@ -22,7 +24,17 @@
id1=" "
id2=" "
parent=
+opt_color=
+setup_colors()
+{
+ local C=diff_hdr=32:diff_add=36:diff_mod=35:diff_rem=35:diff_hunk=33:diff_ctx=35:diff_cctx=33:patch_offs=33:patch_fuzz=35:patch_fail=31:clear=00
+ [ -n "$COGITO_COLORS" ] && C="$C:$COGITO_COLORS"
+
+ C=${C//=/=\'$'\e'[}
+ C=color_${C//:/m\'; color_}m\'
+ eval $C
+}
# FIXME: The commandline parsing is awful.
@@ -31,6 +43,12 @@
parent=1
fi
+if [ "$1" = "-c" ]; then
+ shift
+ opt_color=1
+ setup_colors
+fi
+
if [ "$1" = "-r" ]; then
shift
id1=$(echo "$1": | cut -d : -f 1)
@@ -44,6 +62,32 @@
shift
fi
+colorize() {
+ if [ "$opt_color" ]; then
+ /usr/bin/gawk '
+ { if (/^(Index:|\-\-\-|\+\+\+|\*\*\*) /)
+ print "'$color_diff_hdr'" $0 "'$color_clear'"
+ else if (/^\+/)
+ print "'$color_diff_add'" $0 "'$color_clear'"
+ else if (/^-/)
+ print "'$color_diff_rem'" $0 "'$color_clear'"
+ else if (/^!/)
+ print "'$color_diff_mod'" $0 "'$color_clear'"
+ else if (/^@@ \-[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@/)
+ print gensub(/^(@@[^@]*@@)([ \t]*)(.*)/,
+ "'$color_diff_hunk'" "\\1" "'$color_clear'" \
+ "\\2" \
+ "'$color_diff_ctx'" "\\3" "'$color_clear'", "")
+ else if (/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/)
+ print "'$color_diff_cctx'" $0 "'$color_clear'"
+ else
+ print
+ }'
+ else
+ cat
+ fi
+}
+
if [ "$parent" ]; then
id2="$id1"
id1=$(parent-id "$id2" | head -n 1)
@@ -71,7 +115,7 @@
# FIXME: Update ret based on what did we match. And take "$@"
# to account after all.
ret=
- git-diff-cache -r -z $tree | xargs -0 ${COGITO_LIB}cg-Xdiffdo "$tree" uncommitted "$filter"
+ git-diff-cache -r -z $tree | xargs -0 ${COGITO_LIB}cg-Xdiffdo "$tree" uncommitted "$filter" | colorize
[ "$filter" ] && rm $filter
@@ -85,7 +129,7 @@
[ "$id1" = "$id2" ] && die "trying to diff $id1 against itself"
-git-diff-tree -r -z $id1 $id2 | xargs -0 ${COGITO_LIB}cg-Xdiffdo $id1 $id2 "$filter"
+git-diff-tree -r -z $id1 $id2 | xargs -0 ${COGITO_LIB}cg-Xdiffdo $id1 $id2 "$filter" | colorize
[ "$filter" ] && rm $filter
exit 0
Index: cg-help
===================================================================
--- ca5fef50fb68a3afbb35e1a48ac622f7a964f021/cg-help (mode:100755)
+++ uncommitted/cg-help (mode:100755)
@@ -26,7 +26,7 @@
cg-cancel
cg-clone [-s] SOURCE_LOC [DESTDIR]
cg-commit [-m"Commit message"]... [-e | -E] [FILE]... < log message
- cg-diff [-p] [-r FROM_ID[:TO_ID]] [FILE]...
+ cg-diff [-p] [-c] [-r FROM_ID[:TO_ID]] [FILE]...
cg-export DEST [TREE_ID]
cg-help [COMMAND]
cg-init
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-05-20 14:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-20 14:58 [cogito PATCH] Add "-c" (colorize) option to cg-diff Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox