git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Pitre <nico@cam.org>
To: Petr Baudis <pasky@ucw.cz>
Cc: git@vger.kernel.org
Subject: [PATCH] allow cg-log to display commit entries for particular files/directories
Date: Thu, 28 Apr 2005 23:27:02 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.62.0504282308200.14033@localhost.localdomain> (raw)

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

                 reply	other threads:[~2005-04-29  3:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.62.0504282308200.14033@localhost.localdomain \
    --to=nico@cam.org \
    --cc=git@vger.kernel.org \
    --cc=pasky@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).