Thread (16 messages) flat view 16 messages, 3 authors, 2016-06-15
STALE3721d

[PATCH v2 3/3] git-submodule: New subcommand 'summary' (3) - limit summary size

From: Ping Yin <hidden>
Date: 2016-06-15 22:44:18
Subsystem: the rest · Maintainer: Linus Torvalds

This patches teaches git-submodule an option '--summary-limit|-n <number>'
to limit number of commits for the summary. Number 0 will disable summary
and minus number will not limit the summary size.

For beauty and clarification, the last commit for each section (backward
and forward) will always be shown disregarding the given limit. So actual
summary size may be greater than the given limit.

In the same super project of these patch series, 'git submodule -n 2
summary sm1' and 'git submodule -n 3 summary sm1' will show the same.

---------------------------------------
 $ git submodule -n 2 summary sm1
 # Submodules modifiled: sm1
 #
 # * sm1 354cd45...3f751e5:
 #   <one line message for C
 #   <one line message for B
 #   >... (1 more)
 #   >one line message for E
 #
---------------------------------------

Signed-off-by: Ping Yin <redacted>
---
 git-submodule.sh |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 8322771..64f1f5c 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -4,7 +4,9 @@
 #
 # Copyright (c) 2007 Lars Hjemli
 
-USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update|summary [<commit>]] [--] [<path>...]'
+USAGE="[--quiet] [--cached] \
+[add <repo> [-b branch]|status|init|update|summary [-n|--summary-limit <number>] [<commit>]] \
+[--] [<path>...]"
 OPTIONS_SPEC=
 . git-sh-setup
 require_work_tree
@@ -330,6 +332,8 @@ set_name_rev () {
 #
 cmd_summary()
 {
+	summary_limit=-1
+
 	# parse $args after "submodule ... summary".
 	while test $# -ne 0
 	do
@@ -337,6 +341,14 @@ cmd_summary()
 		--cached)
 			cached=1
 			;;
+		-n|--summary-limit)
+			if test -z "$2" || echo "$2" | grep --quiet -v '^-\?[0-9]\+$'
+			then
+				usage
+			fi
+			summary_limit="$2"
+			shift
+			;;
 		--)
 			shift
 			break
@@ -351,6 +363,8 @@ cmd_summary()
 		shift
 	done
 
+	test $summary_limit = 0 && return
+
 	cache_option=${cached:+--cached}
 
 	if rev=$(git rev-parse --verify "$1^0" 2>/dev/null)
@@ -443,8 +457,44 @@ cmd_summary()
 			# Don't give error msg for modification whose dst is not submodule, i.e. deleted or changed to blob
 			test $mod_dst = 160000 && echo "$errmsg"
 		else
-			test -n "$left" && echo "$left"
-			test -n "$right" && echo "$right"
+			lc0=0
+			rc0=0
+			test -n "$left" && lc0=$(echo "$left" | wc -l)
+			test -n "$right" && rc0=$(echo "$right" | wc -l)
+
+			if (( $summary_limit < 0 ))
+			then
+				lc=$lc0
+				rc=$rc0
+			elif (( $lc0 < $summary_limit ))
+			then
+				lc=$lc0
+				rc=$(($summary_limit-$lc))
+			else
+				lc=$summary_limit
+				rc=1
+			fi
+
+			if (( $rc > $rc0 ))
+			then
+				rc=$rc0
+			fi
+
+			if test -n "$left"
+			then
+				skip=$(($lc0-$lc))
+				echo "$left" | head -$(($lc-1))
+				test $skip != 0 && echo "  <... ($skip more)"
+				echo "$left" | tail -1
+			fi
+
+			if test -n "$right"
+			then
+				skip=$(($rc0-$rc))
+				echo "$right" | head -$(($rc-1))
+				test $skip != 0 && echo "  >... ($skip more)"
+				echo "$right" | tail -1
+			fi
 		fi
 		echo
 	done | sed -e 's/^/# /'
-- 
1.5.4.3.347.g5314c
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help