[RFC] reflog: show committer date in verbose mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



By default, reflog won't show committer date and for some cases won't
show commit log either. It will be helpful to show them all by passing
a more complicated pretty formatter to `git reflog` like this:

    $ git reflog show \
      --pretty="%Cred%h%Creset %gd: %gs%n  >> %Cblue%ci (%cr)%Creset: %s"

It will be nice to add this pretty formatter automatically when run
`git reflog` in verbose mode. Also add new flag "verbose" to rev_info.

Signed-off-by: Jiang Xin <worldhello.net@xxxxxxxxx>
---
 builtin/log.c | 31 +++++++++++++++++++++++++++++++
 revision.c    |  1 +
 revision.h    |  1 +
 3 files changed, 33 insertions(+)

diff --git a/builtin/log.c b/builtin/log.c
index dd3f10..fd213 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -615,6 +615,37 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
 	rev.use_terminator = 1;
 	rev.always_show_header = 1;
 	cmd_log_init_finish(argc, argv, prefix, &rev, &opt);
+	if (rev.verbose && !rev.pretty_given) {
+		struct strbuf formatter = STRBUF_INIT;
+		rev.verbose_header = 1;
+		rev.pretty_given = 1;
+		strbuf_addf(&formatter, "%s%%h%s %%gd: %%gs%%n",
+			    diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
+			    diff_get_color_opt(&rev.diffopt, DIFF_RESET));
+		switch (rev.verbose) {
+		case 1:
+			strbuf_addf(&formatter, "    >> %s%%ci%s (%s%%cr%s)",
+				    diff_get_color_opt(&rev.diffopt, DIFF_METAINFO),
+				    diff_get_color_opt(&rev.diffopt, DIFF_RESET),
+				    diff_get_color_opt(&rev.diffopt, DIFF_METAINFO),
+				    diff_get_color_opt(&rev.diffopt, DIFF_RESET));
+			strbuf_addstr(&formatter, ": %s");
+			break;
+		default:
+			strbuf_addf(&formatter, "    >> %s%%cD%s (%s%%cr%s)",
+				    diff_get_color_opt(&rev.diffopt, DIFF_METAINFO),
+				    diff_get_color_opt(&rev.diffopt, DIFF_RESET),
+				    diff_get_color_opt(&rev.diffopt, DIFF_METAINFO),
+				    diff_get_color_opt(&rev.diffopt, DIFF_RESET));
+			strbuf_addf(&formatter, ", by %s%%an%s",
+				    diff_get_color_opt(&rev.diffopt, DIFF_METAINFO),
+				    diff_get_color_opt(&rev.diffopt, DIFF_RESET));
+			strbuf_addstr(&formatter, ": %s");
+			break;
+		}
+		get_commit_format(formatter.buf, &rev);
+		strbuf_release(&formatter);
+	}
 
 	return cmd_log_walk(&rev);
 }
diff --git a/revision.c b/revision.c
index 518cd..f7483 100644
--- a/revision.c
+++ b/revision.c
@@ -1514,6 +1514,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->combine_merges = 1;
 	} else if (!strcmp(arg, "-v")) {
 		revs->verbose_header = 1;
+		revs->verbose++;
 	} else if (!strcmp(arg, "--pretty")) {
 		revs->verbose_header = 1;
 		revs->pretty_given = 1;
diff --git a/revision.h b/revision.h
index a313a..032ec 100644
--- a/revision.h
+++ b/revision.h
@@ -119,6 +119,7 @@ struct rev_info {
 			show_notes_given:1,
 			show_signature:1,
 			pretty_given:1,
+			verbose:4,
 			abbrev_commit:1,
 			abbrev_commit_given:1,
 			use_terminator:1,
-- 
1.8.3.466.g52d8e0f

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]