git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: Jef Driesen <jefdriesen@hotmail.com>
Cc: Jeff King <peff@peff.net>, Nanako Shiraishi <nanako3@lavabit.com>,
	<git@vger.kernel.org>
Subject: [RFC PATCH 1/5] reflog-walk: refactor the branch@{num} formatting
Date: Mon, 12 Oct 2009 23:06:03 +0200	[thread overview]
Message-ID: <1c524798bde29912429d400f0c48591acadad6d7.1255380039.git.trast@student.ethz.ch> (raw)
In-Reply-To: <cover.1255380039.git.trast@student.ethz.ch>

We'll use the same output in an upcoming commit, so refactor its
formatting (which was duplicated anyway) into a separate function.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 reflog-walk.c |   56 ++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/reflog-walk.c b/reflog-walk.c
index 5623ea6..9478dbc 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -241,36 +241,48 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
 	commit->object.flags &= ~(ADDED | SEEN | SHOWN);
 }
 
-void show_reflog_message(struct reflog_walk_info *info, int oneline,
+void get_reflog_selector(struct strbuf *sb,
+			 struct reflog_walk_info *reflog_info,
+			 enum date_mode dmode)
+{
+	struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
+	struct reflog_info *info;
+
+	if (!commit_reflog)
+		return;
+
+	strbuf_addf(sb, "%s@{", commit_reflog->reflogs->ref);
+	if (commit_reflog->flag || dmode) {
+		info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
+		strbuf_addf(sb, "%s", show_date(info->timestamp,
+						info->tz,
+						dmode));
+	} else {
+		strbuf_addf(sb, "%d", commit_reflog->reflogs->nr
+			    - 2 - commit_reflog->recno);
+	}
+
+	strbuf_addch(sb, '}');
+}
+
+void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
 	enum date_mode dmode)
 {
-	if (info && info->last_commit_reflog) {
-		struct commit_reflog *commit_reflog = info->last_commit_reflog;
+	if (reflog_info && reflog_info->last_commit_reflog) {
+		struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
 		struct reflog_info *info;
+		struct strbuf selector = STRBUF_INIT;
 
 		info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
+		get_reflog_selector(&selector, reflog_info, dmode);
 		if (oneline) {
-			printf("%s@{", commit_reflog->reflogs->ref);
-			if (commit_reflog->flag || dmode)
-				printf("%s", show_date(info->timestamp,
-						       info->tz,
-						       dmode));
-			else
-				printf("%d", commit_reflog->reflogs->nr
-				       - 2 - commit_reflog->recno);
-			printf("}: %s", info->message);
+			printf("%s: %s", selector.buf, info->message);
 		}
 		else {
-			printf("Reflog: %s@{", commit_reflog->reflogs->ref);
-			if (commit_reflog->flag || dmode)
-				printf("%s", show_date(info->timestamp,
-							info->tz,
-							dmode));
-			else
-				printf("%d", commit_reflog->reflogs->nr
-				       - 2 - commit_reflog->recno);
-			printf("} (%s)\nReflog message: %s",
-			       info->email, info->message);
+			printf("Reflog: %s (%s)\nReflog message: %s",
+			       selector.buf, info->email, info->message);
 		}
+
+		strbuf_release(&selector);
 	}
 }
-- 
1.6.5.64.g01287

  reply	other threads:[~2009-10-12 21:14 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-12 15:47 git stash list with more than 10 items? Jef Driesen
2009-10-12 17:52 ` Jeff King
2009-10-12 19:37   ` [PATCH] git-stash documentation: mention default options for 'list' Miklos Vajna
2009-10-12 19:39     ` Jeff King
2009-10-12 21:06   ` [RFC PATCH 0/5] Pretty formats for reflog data Thomas Rast
2009-10-12 21:06     ` Thomas Rast [this message]
2009-10-12 21:06     ` [RFC PATCH 2/5] Introduce new pretty formats %g and %G for reflog information Thomas Rast
2009-10-14  4:59       ` Jeff King
2009-10-14  9:58         ` Thomas Rast
2009-10-14  9:13       ` Junio C Hamano
2009-10-12 21:06     ` [RFC PATCH 3/5] stash: Use new %g/%G formats instead of sed Thomas Rast
2009-10-14  5:00       ` Jeff King
2009-10-12 21:06     ` [RFC PATCH 4/5] stash list: drop the default limit of 10 stashes Thomas Rast
2009-10-14  5:02       ` Jeff King
2009-10-12 21:06     ` [RFC PATCH 5/5] stash: change built-in ref to 'stash' instead of 'refs/stash' Thomas Rast
2009-10-14  5:06       ` Jeff King
2009-10-15 22:41         ` [PATCH v2 0/5] Pretty formats for reflog data Thomas Rast
2009-10-15 22:41           ` [PATCH v2 1/5] Refactor pretty_print_commit arguments into a struct Thomas Rast
2009-10-15 22:41           ` [PATCH v2 2/5] reflog-walk: refactor the branch@{num} formatting Thomas Rast
2009-10-15 22:41           ` [PATCH v2 3/5] Introduce new pretty formats %g[sdD] for reflog information Thomas Rast
2009-10-16  5:32             ` Jeff King
2009-10-16  8:50               ` Thomas Rast
2009-10-16 14:20               ` [PATCH v3 0/5] Pretty formats for reflog data Thomas Rast
2009-10-16 14:20                 ` [PATCH v3 1/5] Refactor pretty_print_commit arguments into a struct Thomas Rast
2009-10-17 17:05                   ` Junio C Hamano
2009-10-18 18:51                     ` Thomas Rast
2009-10-18 22:47                       ` Junio C Hamano
2009-10-19 15:48                         ` [PATCH v4 0/5] Pretty formats for reflog data Thomas Rast
2009-10-19 15:48                           ` [PATCH v4 1/5] Refactor pretty_print_commit arguments into a struct Thomas Rast
2009-10-19 15:48                           ` [PATCH v4 2/5] reflog-walk: refactor the branch@{num} formatting Thomas Rast
2009-10-19 15:48                           ` [PATCH v4 3/5] Introduce new pretty formats %g[sdD] for reflog information Thomas Rast
2009-10-19 15:48                           ` [PATCH v4 4/5] stash list: use new %g formats instead of sed Thomas Rast
2009-10-19 15:48                           ` [PATCH v4 5/5] stash list: drop the default limit of 10 stashes Thomas Rast
2009-10-16 14:20                 ` [PATCH v3 2/5] reflog-walk: refactor the branch@{num} formatting Thomas Rast
2009-10-16 14:20                 ` [PATCH v3 3/5] Introduce new pretty formats %g[sdD] for reflog information Thomas Rast
2009-10-17 14:48                   ` [PATCH v3.1 " Thomas Rast
2009-10-17 15:06                     ` Jakub Narebski
2009-10-18  7:18                     ` Jeff King
2009-10-18 10:34                       ` Nanako Shiraishi
2009-10-16 14:20                 ` [PATCH v3 4/5] stash list: use new %g formats instead of sed Thomas Rast
2009-10-16 14:20                 ` [PATCH v3 5/5] stash list: drop the default limit of 10 stashes Thomas Rast
2009-10-17  0:50                 ` [PATCH v3 0/5] Pretty formats for reflog data Junio C Hamano
2009-10-17  1:18                 ` Jeff King
2009-10-15 22:41           ` [PATCH v2 4/5] stash list: use new %g formats instead of sed Thomas Rast
2009-10-15 22:41           ` [PATCH v2 5/5] stash list: drop the default limit of 10 stashes Thomas Rast
2009-10-16  5:20           ` [PATCH v2 0/5] Pretty formats for reflog data Jeff King
2009-10-16  9:00             ` Jakub Narebski
2009-10-12 21:37     ` [RFC PATCH " Jeff King
2009-10-12 21:52       ` Thomas Rast

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=1c524798bde29912429d400f0c48591acadad6d7.1255380039.git.trast@student.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=git@vger.kernel.org \
    --cc=jefdriesen@hotmail.com \
    --cc=nanako3@lavabit.com \
    --cc=peff@peff.net \
    /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).