Subject: [PATCH 8/10] Move the username matching inside the loop

From: Jonas Fonseca <[email-masked]>
Date: Sat, 4 Jun 2005 16:42:42 +0200

By handling -u in the commit parsing loop no extra git-cat-file call is
necessary. Keep the line-based matching scheme so that it is still possible
to restrict searches by using prefixing the search string with either
'author' or 'committer' (e.g. -u'author.*miciah').

This change also magically removes trailing empty lines from commit logs.

Signed-off-by: Jonas Fonseca <[email-masked]>
---

 cg-log |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/cg-log b/cg-log
--- a/cg-log
+++ b/cg-log
@@ -184,6 +184,10 @@ print_commit_log() {
 				parents[${#parents[@]}]="$rest"
 				;;
 			"")
+				if [ "$user" ]; then
+					echo -e "author $author\ncommitter $committer" \
+						| grep -qi "$user" || return
+				fi
 				echo ${colheader}commit ${commit%:*} $coldefault
 				echo ${colheader}tree $tree $coldefault
 
@@ -223,9 +227,9 @@ $revls | $revsort | while read time comm
 		[ "$parent" ] || diff_ops=--root
 		[ "$(git-diff-tree -r $diff_ops $commit $parent "$@")" ] || continue
 	fi
-	if [ "$user" ]; then
-		git-cat-file commit $commit | grep -e '^author ' -e '^committer ' | grep -qi "$user" || continue
+	log="$(print_commit_log $commit)"
+	if [ "$log" ]; then
+		echo "$log"
+		echo
 	fi
-	print_commit_log $commit
-	echo
 done | pager
-- 
Jonas Fonseca