Skip to content

Commit 72b103f

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd2e794 commit 72b103f

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

reflog-walk.c

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -241,36 +241,46 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
241241
commit->object.flags &= ~(ADDED | SEEN | SHOWN);
242242
}
243243

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,
245267
enum date_mode dmode)
246268
{
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;
249271
struct reflog_info *info;
272+
struct strbuf selector = STRBUF_INIT;
250273

251274
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
275+
get_reflog_selector(&selector, reflog_info, dmode);
252276
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);
262278
}
263279
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);
274282
}
283+
284+
strbuf_release(&selector);
275285
}
276286
}

0 commit comments

Comments
 (0)