git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonas Fonseca <fonseca@diku.dk>
To: Petr Baudis <pasky@ucw.cz>
Cc: git@vger.kernel.org
Subject: [PATCH 10/10] Add -s option to show log summary
Date: Sat, 4 Jun 2005 16:43:34 +0200	[thread overview]
Message-ID: <20050604144334.GN12615@diku.dk> (raw)
In-Reply-To: <20050604143831.GD12615@diku.dk>

When passing -s to cg-log each log entry is summarized in one line. The line
carries info about commit date, author, first log line and the commit id. It
will look something like the following (with only:

  2005-05-20 11:46 Linus Torvalds   sparse cleanup   e99d59ff0bff349ef20...

The result ends up being 130 chars wide however the commit id is placed so
that it can easily be hidden if line wrapping in the pager is enabled.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---

 cg-Xlib |    4 +++-
 cg-log  |   53 ++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/cg-Xlib b/cg-Xlib
--- a/cg-Xlib
+++ b/cg-Xlib
@@ -47,10 +47,12 @@ mktemp () {
 
 showdate () {
 	date="$1"
+	format="$2"
+	[ "$format" ] || format=-R
 	sec=${date[0]}; tz=${date[1]}
 	dtz=${tz/+/}
 	lsec=$(expr $dtz / 100 \* 3600 + $dtz % 100 \* 60 + $sec)
-	pdate="$(date -Rud "1970-01-01 UTC + $lsec sec" 2>/dev/null)"
+	pdate="$(date -ud "1970-01-01 UTC + $lsec sec" "$format" 2>/dev/null)"
 
 	echo "${pdate/+0000/$tz}"
 }
diff --git a/cg-log b/cg-log
--- a/cg-log
+++ b/cg-log
@@ -14,15 +14,21 @@
 # cg-log then displays only changes in those files.
 #
 # -c::
-#	Add color to the output. Currently, the colors are:
-#	- `author`:	'cyan'
-#	- `committer`:	'magenta'
-#	- `header`:	'green'
-#	- `files`:	'blue'
-#	- `signoff`:	'yellow'
+#	Colorize to the output. When getting log summary the `date` is
+#	colored 'green', the `author` is colored 'cyan', the `commit ID`
+#	is colored 'blue' and the special line trimming character (~) is
+#	colored 'magenta'. +
+#	+
+#	When getting the full log the colors are:
+#		- `author`:	'cyan'
+#		- `committer`:	'magenta'
+#		- `header`:	'green'
+#		- `files`:	'blue'
+#		- `signoff`:	'yellow'
 #
 # -f::
-#	List affected files.
+#	List affected files. This option does not make sense when using
+#	`-s` to get a log summary.
 #
 # -r FROM_ID[:TO_ID]::
 #	Limit the log information to a set of revisions using either
@@ -36,6 +42,12 @@
 #	End the log listing at the merge base of the -r arguments
 #	(defaulting to master and origin).
 #
+# -s::
+#	Show a one line summary for each log entry. The summary contains
+#	information about the commit date, the author, the first line
+#	of the commit log and the commit ID. Long author and commit log
+#	titles are trimmed but marked with an ending tilde (~).
+#
 # -uUSERNAME::
 #	List only commits where author or committer contains 'USERNAME'.
 #	The search for 'USERNAME' is case-insensitive.
@@ -55,7 +67,7 @@
 #
 #	$ cg-log -r releasetag-0.9:releasetag-0.10
 
-USAGE="cg-log [-c] [-f] [m] [-uUSERNAME] [-r FROM_ID[:TO_ID] FILE..."
+USAGE="cg-log [-c] [-f] [-m] [-s] [-uUSERNAME] [-r FROM_ID[:TO_ID] FILE..."
 
 . ${COGITO_LIB}cg-Xlib
 # Try to fix the annoying "Broken pipe" output. May not help, but apparently
@@ -71,6 +83,7 @@ coldefault=
 list_files=
 log_start=
 log_end=
+summary=
 user=
 mergebase=
 files=()
@@ -107,6 +120,9 @@ while [ "$1" ]; do
 	-m)
 		mergebase=1
 		;;
+	-s)
+		summary=1
+		;;
 	*)
 		files=("$@")
 		break
@@ -196,6 +212,8 @@ print_commit_log() {
 					echo -e "author $author\ncommitter $committer" \
 						| grep -qi "$user" || return
 				fi
+				[ "$summary" ] && continue
+
 				echo ${colheader}commit ${commit%:*} $coldefault
 				echo ${colheader}tree $tree $coldefault
 
@@ -222,6 +240,23 @@ print_commit_log() {
 					s/./    &/
 				'
 				;;
+			*)
+				# Print summary
+				author="${author% <*}"
+				date=(${committer#*> })
+				date="$(showdate $date '+%F %H:%M')"
+				title="$key $rest"
+				if [ "${#title}" -gt 51 ]; then
+					title="${title:0:50}$colcommitter~"
+				fi
+				if [ "${#author}" -gt 20 ]; then
+					author="${author:0:19}$colcommitter~"
+				fi
+
+				printf "$colheader$date $colauthor%-20s $coldefault%-51s $colfiles${commit%:*}$coldefault\n" \
+					"$author" "$title"
+				return
+				;;
 			esac
 		done
 }
@@ -232,6 +267,6 @@ $revls | $revsort | while read time comm
 	log="$(print_commit_log $commit)"
 	if [ "$log" ]; then
 		echo "$log"
-		echo
+		[ "$summary" ] || echo
 	fi
 done | pager
-- 
Jonas Fonseca

      parent reply	other threads:[~2005-06-04 14:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-04 14:38 [PATCHSET] cg-log cleanups and enhancements Jonas Fonseca
2005-06-04 14:39 ` [PATCH 1/10] Cleanup conversion to human readable date Jonas Fonseca
2005-06-04 14:39 ` [PATCH 2/10] Separate handling of tree and parent in commit headers Jonas Fonseca
2005-06-04 14:40 ` [PATCH 3/10] Separate handling of author and committer " Jonas Fonseca
2005-06-04 14:40 ` [PATCH 4/10] First parse all commit header entries then print them Jonas Fonseca
2005-06-04 14:41 ` [PATCH 5/10] Move printing of the commit info line inside the loop Jonas Fonseca
2005-06-04 14:41 ` [PATCH 6/10] Remove the catch all rule Jonas Fonseca
2005-06-04 14:42 ` [PATCH 7/10] Move log printing to separate function Jonas Fonseca
2005-06-04 14:42 ` [PATCH 8/10] Move the username matching inside the loop Jonas Fonseca
2005-06-04 14:43 ` [PATCH 9/10] Move file " Jonas Fonseca
2005-06-04 14:43 ` Jonas Fonseca [this message]

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=20050604144334.GN12615@diku.dk \
    --to=fonseca@diku.dk \
    --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).