@matheusbsbs / matheus-bagliano / commits / 72b103fec7
Fork 0

reflog-walk: refactor the branch@{num} formatting

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Oct 19, 2009 at 17:48 UTC 72b103fec7af967d295410c2fd3899bc6e8386e2
1 file changed +32 -22
reflog-walk.c
+32 -22
@@ -241,36 +241,46 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
241 commit->object.flags &= ~(ADDED | SEEN | SHOWN);
242 }
243
244 -void show_reflog_message(struct reflog_walk_info *info, int oneline,
244 +void get_reflog_selector(struct strbuf *sb,
245 + struct reflog_walk_info *reflog_info,
246 + enum date_mode dmode)
247 +{
248 + struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
249 + struct reflog_info *info;
250 +
251 + if (!commit_reflog)
252 + return;
253 +
254 + strbuf_addf(sb, "%s@{", commit_reflog->reflogs->ref);
255 + if (commit_reflog->flag || dmode) {
256 + info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
257 + strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
258 + } else {
259 + strbuf_addf(sb, "%d", commit_reflog->reflogs->nr
260 + - 2 - commit_reflog->recno);
261 + }
262 +
263 + strbuf_addch(sb, '}');
264 +}
265 +
266 +void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
267 enum date_mode dmode)
268 {
247 - if (info && info->last_commit_reflog) {
248 - struct commit_reflog *commit_reflog = info->last_commit_reflog;
269 + if (reflog_info && reflog_info->last_commit_reflog) {
270 + struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
271 struct reflog_info *info;
272 + struct strbuf selector = STRBUF_INIT;
273
274 info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
275 + get_reflog_selector(&selector, reflog_info, dmode);
276 if (oneline) {
253 - printf("%s@{", commit_reflog->reflogs->ref);
254 - if (commit_reflog->flag || dmode)
255 - printf("%s", show_date(info->timestamp,
256 - info->tz,
257 - dmode));
258 - else
259 - printf("%d", commit_reflog->reflogs->nr
260 - - 2 - commit_reflog->recno);
261 - printf("}: %s", info->message);
277 + printf("%s: %s", selector.buf, info->message);
278 }
279 else {
264 - printf("Reflog: %s@{", commit_reflog->reflogs->ref);
265 - if (commit_reflog->flag || dmode)
266 - printf("%s", show_date(info->timestamp,
267 - info->tz,
268 - dmode));
269 - else
270 - printf("%d", commit_reflog->reflogs->nr
271 - - 2 - commit_reflog->recno);
272 - printf("} (%s)\nReflog message: %s",
273 - info->email, info->message);
280 + printf("Reflog: %s (%s)\nReflog message: %s",
281 + selector.buf, info->email, info->message);
282 }
283 +
284 + strbuf_release(&selector);
285 }
286 }