Subject: [PATCH Cogito] cg-diff: add -s option to summarize (diffstat) changes

From: Jonas Fonseca <[email-masked]>
Date: Sun, 2 Oct 2005 12:14:20 +0200

Pipes the diff output through git-apply --stat --summary.

Signed-off-by: Jonas Fonseca <[email-masked]>

---
commit 20282cdd610ecef03c8c97853bc0749ef3ab32b3
tree 6dd04a780217d116c44c1f78c5e831fc40a32df9
parent b41f8cafc556233613412ff3545e3507202b666a
author Jonas Fonseca <[email-masked]> Thu, 29 Sep 2005 15:09:42 +0200
committer Jonas Fonseca <[email-masked]> Thu, 29 Sep 2005 15:09:42 +0200

 cg-diff |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/cg-diff b/cg-diff
--- a/cg-diff
+++ b/cg-diff
@@ -17,6 +17,11 @@
 #	Instead of one ID denotes a parent commit to the specified ID
 #	(which must not be a tree, obviously).
 #
+# -s::
+#	Summarize the diff by showing a histogram for removed and added
+#	lines (similar to the output of diffstat(1)) and information
+#	about added and renamed files and mode changes.
+#
 # -r FROM_ID[:TO_ID]::
 #	Specify the revisions to diff using either '-r rev1:rev2' or
 #	'-r rev1 -r rev2'. If no revision is specified, the current
@@ -41,7 +46,7 @@
 #	to before invoking $PAGER. It defaults to $LESS concatenated
 #	with the `R` flag to allow displaying of colorized output.
 
-USAGE="cg-diff [-c] [-m] [-p] [-r FROM_ID[:TO_ID]] [FILE]..."
+USAGE="cg-diff [-c] [-m] [-s] [-p] [-r FROM_ID[:TO_ID]] [FILE]..."
 
 . ${COGITO_LIB}cg-Xlib || exit 1
 
@@ -65,7 +70,12 @@ setup_colors()
 
 colorize()
 {
-	if [ "$opt_color" ]; then
+	if [ "$opt_summary" ]; then
+		# Add an empty line so the diffstat indentation won't
+		# get messed up
+		echo
+		git-apply --summary --stat
+	elif [ "$opt_color" ]; then
 		gawk '
 		{ if (/^(diff --git) /)
 		    print "'$coldiffhdr'" $0 "'$coldefault'"
@@ -96,6 +106,7 @@ id2=" "
 parent=
 opt_color=
 mergebase=
+opt_summary=
 
 while optparse; do
 	if optparse -c; then
@@ -103,6 +114,8 @@ while optparse; do
 		setup_colors
 	elif optparse -p; then
 		parent=1
+	elif optparse -s; then
+		opt_summary=1
 	elif optparse -r=; then
 		if echo "$OPTARG" | fgrep -q '..'; then
 			id2=${OPTARG#*..}

-- 
Jonas Fonseca