* [PATCH v3 1/4] git-submodule summary: code framework
@ 2008-03-07 18:27 Ping Yin
2008-03-07 18:27 ` [PATCH v3 2/4] git-submodule summary: show commit summary Ping Yin
0 siblings, 1 reply; 6+ messages in thread
From: Ping Yin @ 2008-03-07 18:27 UTC (permalink / raw)
To: gitster; +Cc: git, Ping Yin
Following patches will teach git-submodule a new subcommand 'summary' to
show commit summary of user-cared (i.e. checked out) submodules between
a given super project commit (default to HEAD) and working tree
(or index, switched by --cached).
This patch just introduces the framework and find submodules which has
summary to show. A submodule will have summary if it fits into any one of
following cases.
- type 'M': modified and checked out (1)
- type 'A': added and checked out (2)
- type 'D': deleted
- type 'T': typechanged (blob <-> submodule)
Note:
1. There may be modified but not checked out cases. In the case of a
merge conflict, even if the submodule is not checked out, there may
be still a diff between index and HEAD on the submodule entry
(i.e. modified). The summary will not be show for such a submodule.
2. A similar explanation applies to the added but not checked out case.
Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
git-submodule.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index a6aaf40..0a48f57 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
@@ -320,7 +320,58 @@ set_name_rev () {
) )
test -z "$revname" || revname=" ($revname)"
}
+#
+# Show commit summary for submodules in index or working tree
+#
+# If '--cached' is given, show summary between index and given commit,
+# or between working tree and given commit
+#
+# $@ = [commit (default 'HEAD'),] requested paths (default all)
+#
+cmd_summary() {
+ # parse $args after "submodule ... summary".
+ while test $# -ne 0
+ do
+ case "$1" in
+ --cached)
+ cached="$1"
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ usage
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+ done
+ if rev=$(git rev-parse --verify "$1^0" 2>/dev/null)
+ then
+ head=$rev
+ shift
+ else
+ head=HEAD
+ fi
+
+ cd_to_toplevel
+ # Get modified modules cared by user
+ modules=$(git diff-index $cached --raw $head -- "$@" |
+ grep -e '^:160000' -e '^:[0-7]* 160000' |
+ while read mod_src mod_dst sha1_src sha1_dst status name
+ do
+ # Always show modules deleted or type-changed (blob<->module)
+ test $status = D -o $status = T && echo "$name" && continue
+ # Also show added or modified modules which are checked out
+ GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
+ echo "$name"
+ done
+ )
+}
#
# List all submodules, prefixed with:
# - submodule not initialized
@@ -391,7 +442,7 @@ cmd_status()
while test $# != 0 && test -z "$command"
do
case "$1" in
- add | init | update | status)
+ add | init | update | status | summary)
command=$1
;;
-q|--quiet)
@@ -406,7 +457,7 @@ do
branch="$2"; shift
;;
--cached)
- cached=1
+ cached="$1"
;;
--)
break
@@ -430,8 +481,8 @@ then
usage
fi
-# "--cached" is accepted only by "status"
-if test -n "$cached" && test "$command" != status
+# "--cached" is accepted only by "status" and "summary"
+if test -n "$cached" && test "$command" != status -a "$command" != summary
then
usage
fi
--
1.5.4.3.347.g5314c
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/4] git-submodule summary: show commit summary
2008-03-07 18:27 [PATCH v3 1/4] git-submodule summary: code framework Ping Yin
@ 2008-03-07 18:27 ` Ping Yin
2008-03-07 18:27 ` [PATCH v3 3/4] git-submodule summary: limit summary size Ping Yin
0 siblings, 1 reply; 6+ messages in thread
From: Ping Yin @ 2008-03-07 18:27 UTC (permalink / raw)
To: gitster; +Cc: git, Ping Yin
This patch does the hard work to show submodule commit summary.
For a modified submodule, a series of commits will be shown with
the following command
git log --pretty='format:%m %s' --left-right \
--first-parent sha1_src...sha1_dst
where the src sha1 is from the given super project commit and the
dst sha1 is from the index or working tree (switched by --cached).
For a deleted, added, or typechanged (blob<->submodule) submodule,
only one single newest commit from the existing end (for example,
src end for submodule deleted or type changed from submodule to blob)
will be shown.
If the src/dst sha1 for a submodule is missing in the submodule
directory, a warning will be issued except in two cases where the
submodule directory is deleted (type 'D') or typechanged to blob
(one case of type 'T').
In the title line for a submodule, the src/dst sha1 and the number
of commits (--first-parent) between the two sha1s will be shown.
The following example demonstrates most cases.
Example: commit summary for modified submodules sm1-sm5.
--------------------------------------------
$ git submodule summary
* sm1 354cd45...3f751e5 (4):
< one line message for C
< one line message for B
> one line message for D
> one line message for E
* sm2 5c8bfb5...000000 (3):
< one line message for F
* sm3 354cd45...3f751e5:
Warn: sm3 doesn't contain commit 354cd45
* sm4 354cd34(submodule)-> 235efa(blob) (1):
< one line message for G
* sm5 354cd34(blob)-> 235efa(submodule) (5):
> one line message for H
--------------------------------------------
Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
git-submodule.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 0a48f57..1751ab2 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -371,6 +371,94 @@ cmd_summary() {
echo "$name"
done
)
+
+ test -n "$modules" &&
+ git diff-index $cached --raw $head -- $modules |
+ grep -e '^:160000' -e '^:[0-7]* 160000' |
+ cut -c2- |
+ while read mod_src mod_dst sha1_src sha1_dst status name
+ do
+ if test -z "$cached" &&
+ test $sha1_dst = 0000000000000000000000000000000000000000
+ then
+ sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD) || continue
+ fi
+ missing_src=
+ missing_dst=
+
+ test $mod_src = 160000 &&
+ ! GIT_DIR="$name/.git" git-rev-parse --verify $sha1_src^0 >/dev/null 2>&1 &&
+ missing_src=t
+
+ test $mod_dst = 160000 &&
+ ! GIT_DIR="$name/.git" git-rev-parse --verify $sha1_dst^0 >/dev/null 2>&1 &&
+ missing_dst=t
+
+ total_commits=
+ case "$missing_src,$missing_dst" in
+ t,)
+ errmsg=" Warn: $name doesn't contain commit $sha1_src"
+ ;;
+ ,t)
+ errmsg=" Warn: $name doesn't contain commit $sha1_dst"
+ ;;
+ t,t)
+ errmsg=" Warn: $name doesn't contain commits $sha1_src and $sha1_dst"
+ ;;
+ *)
+ errmsg=
+ total_commits=$(
+ if test $mod_src = 160000 -a $mod_dst = 160000
+ then
+ range="$sha1_src...$sha1_dst"
+ elif test $mod_src = 160000
+ then
+ range=$sha1_src
+ else
+ range=$sha1_dst
+ fi
+ GIT_DIR="$name/.git" \
+ git log --pretty=oneline --first-parent $range | wc -l
+ )
+ total_commits=" ($total_commits)"
+ ;;
+ esac
+
+ sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
+ sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
+ if test $status = T
+ then
+ if test $mod_dst = 160000
+ then
+ echo "* $name $sha1_abbr_src(blob)->$sha1_abbr_dst(submodule)$total_commits:"
+ else
+ echo "* $name $sha1_abbr_src(submodule)->$sha1_abbr_dst(blob)$total_commits:"
+ fi
+ else
+ echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
+ fi
+ if test -n "$errmsg"
+ then
+ # 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
+ if test $mod_src = 160000 -a $mod_dst = 160000
+ then
+ GIT_DIR="$name/.git" \
+ git log --pretty='format: %m %s' \
+ --left-right --first-parent $sha1_src...$sha1_dst
+ elif test $mod_dst = 160000
+ then
+ GIT_DIR="$name/.git" \
+ git log --pretty='format: > %h %s' -1 $sha1_dst
+ else
+ GIT_DIR="$name/.git" \
+ git log --pretty='format: < %h %s' -1 $sha1_src
+ fi
+ fi
+ echo
+ done
}
#
# List all submodules, prefixed with:
--
1.5.4.3.347.g5314c
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 3/4] git-submodule summary: limit summary size
2008-03-07 18:27 ` [PATCH v3 2/4] git-submodule summary: show commit summary Ping Yin
@ 2008-03-07 18:27 ` Ping Yin
2008-03-07 18:27 ` [PATCH v3 4/4] git-submodule summary: documentation Ping Yin
0 siblings, 1 reply; 6+ messages in thread
From: Ping Yin @ 2008-03-07 18:27 UTC (permalink / raw)
To: gitster; +Cc: git, Ping Yin
This patch teaches git-submodule an option '--summary-limit|-n <number>'
to limit number of commits in total for the summary of each submodule in
the modified case (only a single commit is shown in other cases).
Number 0 will disable summary and minus number means unlimted (the default).
Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
git-submodule.sh | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 1751ab2..d0a0205 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 <n>] [<commit>]] \
+[--] [<path>...]"
OPTIONS_SPEC=
. git-sh-setup
require_work_tree
@@ -329,6 +331,8 @@ set_name_rev () {
# $@ = [commit (default 'HEAD'),] requested paths (default all)
#
cmd_summary() {
+ summary_limit=-1
+
# parse $args after "submodule ... summary".
while test $# -ne 0
do
@@ -336,6 +340,15 @@ cmd_summary() {
--cached)
cached="$1"
;;
+ -n|--summary-limit)
+ if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
+ then
+ :
+ else
+ usage
+ fi
+ shift
+ ;;
--)
shift
break
@@ -350,6 +363,8 @@ cmd_summary() {
shift
done
+ test $summary_limit = 0 && return
+
if rev=$(git rev-parse --verify "$1^0" 2>/dev/null)
then
head=$rev
@@ -445,8 +460,10 @@ cmd_summary() {
else
if test $mod_src = 160000 -a $mod_dst = 160000
then
+ limit=
+ test $summary_limit -gt 0 && limit="-$summary_limit"
GIT_DIR="$name/.git" \
- git log --pretty='format: %m %s' \
+ git log $limit --pretty='format: %m %s' \
--left-right --first-parent $sha1_src...$sha1_dst
elif test $mod_dst = 160000
then
--
1.5.4.3.347.g5314c
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 4/4] git-submodule summary: documentation
2008-03-07 18:27 ` [PATCH v3 3/4] git-submodule summary: limit summary size Ping Yin
@ 2008-03-07 18:27 ` Ping Yin
2008-03-08 9:37 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: Ping Yin @ 2008-03-07 18:27 UTC (permalink / raw)
To: gitster; +Cc: git, Ping Yin
Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
Documentation/git-submodule.txt | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index e818e6e..4fbc182 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -12,6 +12,7 @@ SYNOPSIS
'git-submodule' [--quiet] add [-b branch] [--] <repository> [<path>]
'git-submodule' [--quiet] status [--cached] [--] [<path>...]
'git-submodule' [--quiet] [init|update] [--] [<path>...]
+'git-submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]
COMMANDS
@@ -46,6 +47,12 @@ update::
checkout the commit specified in the index of the containing repository.
This will make the submodules HEAD be detached.
+summary::
+ Show commit summary between given commit (default to HEAD) and
+ working tree/index. For a submodule in question, a series of commits
+ between src sha1 and dst sha1 will be shown where src sha1 is from the
+ given super project commit and dst sha1 is from the index or working
+ tree (switched by --cached).
OPTIONS
-------
@@ -56,9 +63,18 @@ OPTIONS
Branch of repository to add as submodule.
--cached::
- Display the SHA-1 stored in the index, not the SHA-1 of the currently
- checked out submodule commit. This option is only valid for the
- status command.
+ This option is only valid for commands status and summary.
+ When combined with status, display the SHA-1 stored in the index,
+ not the SHA-1 of the currently checked out submodule commit. When
+ combined with summary, switch dst comparison side from working
+ tree to index.
+
+-n, --summary-limit::
+ This option is only valid for the summary command.
+ Limit the summary size (number of commits shown in total).
+ Number 0 will disable summary and minus number means unlimted
+ (the default). This limit only applies to modified submodules. The
+ size is always limited to 1 for added/deleted/typechanged submodules.
<path>::
Path to submodule(s). When specified this will restrict the command
--
1.5.4.3.347.g5314c
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 4/4] git-submodule summary: documentation
2008-03-07 18:27 ` [PATCH v3 4/4] git-submodule summary: documentation Ping Yin
@ 2008-03-08 9:37 ` Junio C Hamano
2008-03-09 13:12 ` Ping Yin
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2008-03-08 9:37 UTC (permalink / raw)
To: Ping Yin; +Cc: git
I've replaced the previous series in 'pu' with this series and queued in
'pu', but with a few wording fixes.
I didn't closely look at the script itself yet. I thinkthe series is
getting closer to a mergeable shape, but it needs tests.
Documentation/git-submodule.txt | 17 +++++++----------
1 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 4fbc182..e96bf36 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -48,11 +48,10 @@ update::
This will make the submodules HEAD be detached.
summary::
- Show commit summary between given commit (default to HEAD) and
+ Show commit summary between the given commit (defaults to HEAD) and
working tree/index. For a submodule in question, a series of commits
- between src sha1 and dst sha1 will be shown where src sha1 is from the
- given super project commit and dst sha1 is from the index or working
- tree (switched by --cached).
+ in the submodule between the given super project commit and the
+ index or working tree (switched by --cached) are shown.
OPTIONS
-------
@@ -63,16 +62,14 @@ OPTIONS
Branch of repository to add as submodule.
--cached::
- This option is only valid for commands status and summary.
- When combined with status, display the SHA-1 stored in the index,
- not the SHA-1 of the currently checked out submodule commit. When
- combined with summary, switch dst comparison side from working
- tree to index.
+ This option is only valid for status and summary commands. These
+ commands typically use the commit found in the submodule HEAD, but
+ with this option, the commit stored in the index is used instead.
-n, --summary-limit::
This option is only valid for the summary command.
Limit the summary size (number of commits shown in total).
- Number 0 will disable summary and minus number means unlimted
+ Giving 0 will disable the summary; a negative number means unlimted
(the default). This limit only applies to modified submodules. The
size is always limited to 1 for added/deleted/typechanged submodules.
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 4/4] git-submodule summary: documentation
2008-03-08 9:37 ` Junio C Hamano
@ 2008-03-09 13:12 ` Ping Yin
0 siblings, 0 replies; 6+ messages in thread
From: Ping Yin @ 2008-03-09 13:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Sat, Mar 8, 2008 at 5:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
> I've replaced the previous series in 'pu' with this series and queued in
> 'pu', but with a few wording fixes.
>
> I didn't closely look at the script itself yet. I thinkthe series is
> getting closer to a mergeable shape, but it needs tests.
I will send my tests tommorrow
>
>
>
>
--
Ping Yin
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-03-09 13:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-07 18:27 [PATCH v3 1/4] git-submodule summary: code framework Ping Yin
2008-03-07 18:27 ` [PATCH v3 2/4] git-submodule summary: show commit summary Ping Yin
2008-03-07 18:27 ` [PATCH v3 3/4] git-submodule summary: limit summary size Ping Yin
2008-03-07 18:27 ` [PATCH v3 4/4] git-submodule summary: documentation Ping Yin
2008-03-08 9:37 ` Junio C Hamano
2008-03-09 13:12 ` Ping Yin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).