[PATCH] allow cg-log to display commit entries for particular files/directories
From: Nicolas Pitre <hidden>
Date: 2016-06-15 22:41:55
This patch allows for one or more paths to be specified with the effect of restricting the log to commits that affected those files or files under given directories. This is not perfect as some merge commits might or might not be listed. But usually they're not really interesting in the context of this feature. It is otherwise pretty simple and effective until a better tool is available. For example: cg-log arch/arm/kernel/ will show all commits that affected files under arch/arm/kernel/ starting from the head branch. Signed-off-by: Nicolas Pitre <redacted>
--- k/cg-log
+++ l/cg-log@@ -14,6 +14,9 @@ # # Takes an id resolving to a commit to start from (HEAD by default), # or id1:id2 representing an (id1;id2] range of commits to show. +# +# May also take one or more files and/or directories to reduce the +# log to commits modifying those files/directories only. . cg-Xlib
@@ -33,14 +36,16 @@ else coldefault= fi -if echo "$1" | grep -q ':'; then - id1=$(commit-id $(echo "$1" | cut -d : -f 1)) || exit 1 - id2=$(commit-id $(echo "$1" | cut -d : -f 2)) || exit 1 +id="$1"; [ -a "$1" ] && id="" || shift + +if echo "$id" | grep -q ':'; then + id1=$(commit-id $(echo "$id" | cut -d : -f 1)) || exit 1 + id2=$(commit-id $(echo "$id" | cut -d : -f 2)) || exit 1 revls="rev-tree $id2 ^$id1" revsort="sort -rn" revfmt="rev-tree" else - id1="$(commit-id $1)" || exit 1 + id1="$(commit-id $id)" || exit 1 revls="rev-list $id1" || exit 1 revsort="cat" revfmt="rev-list"
@@ -48,6 +53,10 @@ fi $revls | $revsort | while read time commit parents; do [ "$revfmt" = "rev-list" ] && commit="$time" + if [ $# -ne 0 ]; then + parent=$(cat-file commit $commit | sed -n '2s/parent //p;2Q') + [ "$parent" ] && [ "$(diff-tree -r $commit $parent "$@")" ] || continue + fi echo $colheader""commit ${commit%:*} $coldefault; cat-file commit $commit | \ while read key rest; do