* [PATCH] git-submodule: New subcommand 'summary' (1) - code framework
2007-12-31 17:35 [PATCH] git-submodule: New subcommand 'summary' Ping Yin
@ 2007-12-31 17:35 ` Ping Yin
2007-12-31 17:35 ` [PATCH] git-submodule: New subcommand 'summary' (2) - hard work Ping Yin
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Ping Yin @ 2007-12-31 17:35 UTC (permalink / raw)
To: git; +Cc: Ping Yin
Following patches teach git-submodule a new subcommand 'summary' to show
commit summary of user-cared (i.e. checked out) submodules since a given
commit (default HEAD) of super project.
For a submodule in question, a series of commits will be shown as the path
from the src commit to the dst commit, where the src commit is from the given
super project commit, and the dst commit is from the index or working tree
(switched by --cached).
Following is an example of the output
# Submodules modifiled: sm1 sm2 sm3
#
# * sm1 354cd45...3f751e5:
# <one line message for C
# <one line message for B
# >one line message for D
# >one line message for E
#
# * sm2 5c8bfb5...000000:
# <one line message for F
#
# * sm3 354cd45...3f751e5:
# Warn: sm3 doesn't contain commit 354cd45
#
This superproject shown above has modified/deleted submodules sm1 to sm3.
sm1 has commit C as src (given commit or HEAD) and commit E as dst (index
or working tree) as following picture shows.
--A-->B-->C (in src:354cd45)
\
-->D-->E (in dst:3f751e5)
The 'Submodules modified' section for sm1 shows how to change sm1 from
src commit C to dst commit E: firstly backward (<) to commit A from
commit C via commit B, and then forward (>) to commit E via commit D.
Illustration for output of deleted sm2 is similar.
If the src/dst commit for a submodule is not found in the work tree (say
the submodule respository in the work tree), a warning will be issued.
sm3 falls into this case.
This patch just gives the framework. It just finds the submodules to be
shown as follows.
# Submodules modifiled: sm1 sm2 sm3
#
Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
git-submodule.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index ad9fe62..0e81484 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -4,7 +4,7 @@
#
# Copyright (c) 2007 Lars Hjemli
-USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'
+USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update|summary <commit>] [--] [<path>...]'
OPTIONS_SPEC=
. git-sh-setup
require_work_tree
@@ -255,7 +255,46 @@ set_name_rev () {
) )
test -z "$revname" || revname=" ($revname)"
}
+#
+# Show commit summary for submodules in index or working tree relative to the given commit
+#
+# If '--cached' is given, show summary between index and given commit,
+# or between working tree and given commit
+#
+# @ = [head counting commits from (default 'HEAD'),] requested paths (default to all)
+#
+modules_summary()
+{
+ cache_option=${cached:+--cached}
+
+ if rev=$(git rev-parse --verify "$1^0" 2>/dev/null)
+ then
+ head=$rev
+ shift
+ else
+ head=HEAD
+ fi
+ cwd=$(pwd)
+ cd_to_toplevel
+
+ # get modified modules which have been checked out (i.e. cared by user)
+ modules=$(git diff $cache_option --raw $head -- "$@" |
+ grep '^:160000\|:000000 160000' |
+ while read mod_src mod_dst sha1_src sha1_dst status name
+ do
+ test $status=D && echo "$name" && continue
+ GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
+ echo "$name"
+ done
+ )
+
+ # TODO: quote module names containing space or tab
+ test -n "$modules" &&
+ echo "# Submodules modified: "$modules &&
+ echo "#"
+ cd "$cwd"
+}
#
# List all submodules, prefixed with:
# - submodule not initialized
@@ -305,6 +344,9 @@ do
update)
update=1
;;
+ summary)
+ summary=1
+ ;;
status)
status=1
;;
@@ -345,17 +387,20 @@ case "$add,$branch" in
;;
esac
-case "$add,$init,$update,$status,$cached" in
-1,,,,)
+case "$add,$init,$update,$summary,$status,$cached" in
+1,,,,,)
module_add "$@"
;;
-,1,,,)
+,1,,,,)
modules_init "$@"
;;
-,,1,,)
+,,1,,,)
modules_update "$@"
;;
-,,,*,*)
+,,,1,,*)
+ modules_summary "$@"
+ ;;
+,,,,*,*)
modules_list "$@"
;;
*)
--
1.5.4.rc2.9.gf5146-dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] git-submodule: New subcommand 'summary' (3) - limit summary size
2007-12-31 17:35 [PATCH] git-submodule: New subcommand 'summary' Ping Yin
2007-12-31 17:35 ` [PATCH] git-submodule: New subcommand 'summary' (1) - code framework Ping Yin
2007-12-31 17:35 ` [PATCH] git-submodule: New subcommand 'summary' (2) - hard work Ping Yin
@ 2007-12-31 17:35 ` Ping Yin
2008-01-08 12:20 ` [PATCH] git-submodule: New subcommand 'summary' Ping Yin
3 siblings, 0 replies; 6+ messages in thread
From: Ping Yin @ 2007-12-31 17:35 UTC (permalink / raw)
To: git; +Cc: Ping Yin
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' and
'git submodule -n 3' will both show
# Submodules modifiled: sm1 sm2 sm3
#
# * sm1 354cd45...3f751e5:
# <one line message for C
# <one line message for B
# >... (1 more)
# >one line message for E
#
# * sm2 5c8bfb5...000000:
# <one line message for F
#
# * sm3 354cd45...3f751e5:
# Warn: sm3 doesn't contain commit 354cd45
#
Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
git-submodule.sh | 40 +++++++++++++++++++++++++++++++++++++---
1 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index cccb539..58d0243 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -4,7 +4,8 @@
#
# Copyright (c) 2007 Lars Hjemli
-USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update|summary <commit>] [--] [<path>...]'
+USAGE="[--quiet] [--cached] [-n|--summary-limit <number>] \
+[add <repo> [-b branch]|status|init|update|summary <commit>] [--] [<path>...]"
OPTIONS_SPEC=
. git-sh-setup
require_work_tree
@@ -16,6 +17,7 @@ update=
status=
quiet=
cached=
+summary_limit=
#
# print stuff on stdout unless -q was specified
@@ -265,6 +267,10 @@ set_name_rev () {
#
modules_summary()
{
+ summary_limit=${summary_limit:-1000000}
+ summary_limit=$((summary_limit<0?1000000:summary_limit))
+ test $summary_limit = 0 && return
+
cache_option=${cached:+--cached}
if rev=$(git rev-parse --verify "$1^0" 2>/dev/null)
@@ -352,8 +358,29 @@ modules_summary()
then
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)
+ lc=$((lc0<summary_limit?lc0:summary_limit))
+ rc=$((summary_limit>lc?summary_limit-lc:1))
+ rc=$((rc<rc0?rc:rc0))
+
+ 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
) | sed 's/^/# /'
@@ -430,6 +457,13 @@ do
--cached)
cached=1
;;
+ -n|--summary-limit)
+ if [ -z "$2" ]; then
+ usage
+ fi
+ summary_limit="$2"
+ shift
+ ;;
--)
break
;;
--
1.5.4.rc2.9.gf5146-dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread