git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] allow cg-log to display commit entries for particular files/directories
@ 2005-04-29  3:27 Nicolas Pitre
  0 siblings, 0 replies; only message in thread
From: Nicolas Pitre @ 2005-04-29  3:27 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-04-29  3:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-29  3:27 [PATCH] allow cg-log to display commit entries for particular files/directories Nicolas Pitre

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).