@matheusbsbs / matheus-bagliano / commits / 1cb639e6b0
Fork 0

git-submodule summary: show commit summary

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' \ --first-parent sha1_src...sha1_dst where the sha1_src is from the given super project commit and the sha1_dst 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 commits 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ping Yin committed Mar 11, 2008 at 21:52 UTC 1cb639e6b02d8740cd2d4516a34822b43660babc
1 file changed +102
git-submodule.sh
+102
@@ -371,6 +371,108 @@ cmd_summary() {
371 echo "$name"
372 done
373 )
374 +
375 + test -n "$modules" &&
376 + git diff-index $cached --raw $head -- $modules |
377 + grep -e '^:160000' -e '^:[0-7]* 160000' |
378 + cut -c2- |
379 + while read mod_src mod_dst sha1_src sha1_dst status name
380 + do
381 + if test -z "$cached" &&
382 + test $sha1_dst = 0000000000000000000000000000000000000000
383 + then
384 + case "$mod_dst" in
385 + 160000)
386 + sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
387 + ;;
388 + 100644 | 100755 | 120000)
389 + sha1_dst=$(git hash-object $name)
390 + ;;
391 + 000000)
392 + ;; # removed
393 + *)
394 + # unexpected type
395 + echo >&2 "unexpected mode $mod_dst"
396 + continue ;;
397 + esac
398 + fi
399 + missing_src=
400 + missing_dst=
401 +
402 + test $mod_src = 160000 &&
403 + ! GIT_DIR="$name/.git" git-rev-parse --verify $sha1_src^0 >/dev/null 2>&1 &&
404 + missing_src=t
405 +
406 + test $mod_dst = 160000 &&
407 + ! GIT_DIR="$name/.git" git-rev-parse --verify $sha1_dst^0 >/dev/null 2>&1 &&
408 + missing_dst=t
409 +
410 + total_commits=
411 + case "$missing_src,$missing_dst" in
412 + t,)
413 + errmsg=" Warn: $name doesn't contain commit $sha1_src"
414 + ;;
415 + ,t)
416 + errmsg=" Warn: $name doesn't contain commit $sha1_dst"
417 + ;;
418 + t,t)
419 + errmsg=" Warn: $name doesn't contain commits $sha1_src and $sha1_dst"
420 + ;;
421 + *)
422 + errmsg=
423 + total_commits=$(
424 + if test $mod_src = 160000 -a $mod_dst = 160000
425 + then
426 + range="$sha1_src...$sha1_dst"
427 + elif test $mod_src = 160000
428 + then
429 + range=$sha1_src
430 + else
431 + range=$sha1_dst
432 + fi
433 + GIT_DIR="$name/.git" \
434 + git log --pretty=oneline --first-parent $range | wc -l
435 + )
436 + total_commits=" ($total_commits)"
437 + ;;
438 + esac
439 +
440 + sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
441 + sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
442 + if test $status = T
443 + then
444 + if test $mod_dst = 160000
445 + then
446 + echo "* $name $sha1_abbr_src(blob)->$sha1_abbr_dst(submodule)$total_commits:"
447 + else
448 + echo "* $name $sha1_abbr_src(submodule)->$sha1_abbr_dst(blob)$total_commits:"
449 + fi
450 + else
451 + echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
452 + fi
453 + if test -n "$errmsg"
454 + then
455 + # Don't give error msg for modification whose dst is not submodule
456 + # i.e. deleted or changed to blob
457 + test $mod_dst = 160000 && echo "$errmsg"
458 + else
459 + if test $mod_src = 160000 -a $mod_dst = 160000
460 + then
461 + GIT_DIR="$name/.git" \
462 + git log --pretty='format: %m %s' \
463 + --first-parent $sha1_src...$sha1_dst
464 + elif test $mod_dst = 160000
465 + then
466 + GIT_DIR="$name/.git" \
467 + git log --pretty='format: > %s' -1 $sha1_dst
468 + else
469 + GIT_DIR="$name/.git" \
470 + git log --pretty='format: < %s' -1 $sha1_src
471 + fi
472 + echo
473 + fi
474 + echo
475 + done
476 }
477 #
478 # List all submodules, prefixed with: