@matheusbsbs / matheus-bagliano / commits / 28f9af5d25
Fork 0

git-submodule summary: code framework

These patches teach git-submodule a new subcommand 'summary' to show commit summary of checked out submodules between a given super project commit (defaults to HEAD) and working tree (or index, when --cached is given). This patch just introduces the framework to find submodules which have summary to show. A submodule will have summary if it falls into these cases: - type 'M': modified and checked out (1) - type 'A': added and checked out (2) - type 'D': deleted - type 'T': typechanged (blob <-> submodule) Notes: 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ping Yin committed Mar 11, 2008 at 21:52 UTC 28f9af5d25ec04288d8c501058d83ac76c8be6f4
1 file changed +56 -5
git-submodule.sh
+56 -5
@@ -4,7 +4,7 @@
4 #
5 # Copyright (c) 2007 Lars Hjemli
6
7 -USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'
7 +USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update|summary [<commit>]] [--] [<path>...]'
8 OPTIONS_SPEC=
9 . git-sh-setup
10 require_work_tree
@@ -320,7 +320,58 @@ set_name_rev () {
320 ) )
321 test -z "$revname" || revname=" ($revname)"
322 }
323 +#
324 +# Show commit summary for submodules in index or working tree
325 +#
326 +# If '--cached' is given, show summary between index and given commit,
327 +# or between working tree and given commit
328 +#
329 +# $@ = [commit (default 'HEAD'),] requested paths (default all)
330 +#
331 +cmd_summary() {
332 + # parse $args after "submodule ... summary".
333 + while test $# -ne 0
334 + do
335 + case "$1" in
336 + --cached)
337 + cached="$1"
338 + ;;
339 + --)
340 + shift
341 + break
342 + ;;
343 + -*)
344 + usage
345 + ;;
346 + *)
347 + break
348 + ;;
349 + esac
350 + shift
351 + done
352
353 + if rev=$(git rev-parse --verify "$1^0" 2>/dev/null)
354 + then
355 + head=$rev
356 + shift
357 + else
358 + head=HEAD
359 + fi
360 +
361 + cd_to_toplevel
362 + # Get modified modules cared by user
363 + modules=$(git diff-index $cached --raw $head -- "$@" |
364 + grep -e '^:160000' -e '^:[0-7]* 160000' |
365 + while read mod_src mod_dst sha1_src sha1_dst status name
366 + do
367 + # Always show modules deleted or type-changed (blob<->module)
368 + test $status = D -o $status = T && echo "$name" && continue
369 + # Also show added or modified modules which are checked out
370 + GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
371 + echo "$name"
372 + done
373 + )
374 +}
375 #
376 # List all submodules, prefixed with:
377 # - submodule not initialized
@@ -391,7 +442,7 @@ cmd_status()
442 while test $# != 0 && test -z "$command"
443 do
444 case "$1" in
394 - add | init | update | status)
445 + add | init | update | status | summary)
446 command=$1
447 ;;
448 -q|--quiet)
@@ -406,7 +457,7 @@ do
457 branch="$2"; shift
458 ;;
459 --cached)
409 - cached=1
460 + cached="$1"
461 ;;
462 --)
463 break
@@ -430,8 +481,8 @@ then
481 usage
482 fi
483
433 -# "--cached" is accepted only by "status"
434 -if test -n "$cached" && test "$command" != status
484 +# "--cached" is accepted only by "status" and "summary"
485 +if test -n "$cached" && test "$command" != status -a "$command" != summary
486 then
487 usage
488 fi