git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] allow cg-log to display commit entries for particular files/directories

From
Nicolas Pitre <nico@cam.org>
Date
Apr 29, 2005, 03:27 UTC
Message-ID
<Pine.LNX.4.62.0504282308200.14033@localhost.localdomain>

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 <nico@cam.org>

--- 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
Message 1 of 1 in “allow cg-log to display commit entries for particular files/directories”
  1. allow cg-log to display commit entries for particular files/directoriesNicolas Pitre, Apr 29, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.