Skip to content

Commit

Permalink
Merge branch 'jk/maint-reflog-walk-count-vs-time' into maint
Browse files Browse the repository at this point in the history
Gives a better DWIM behaviour for --pretty=format:%gd, "stash list", and
"log -g", depending on how the starting point ("master" vs "master@{0}" vs
"master@{now}") and date formatting options (e.g. "--date=iso") are given
on the command line.

By Jeff King (4) and Junio C Hamano (1)
* jk/maint-reflog-walk-count-vs-time:
  reflog-walk: tell explicit --date=default from not having --date at all
  reflog-walk: always make HEAD@{0} show indexed selectors
  reflog-walk: clean up "flag" field of commit_reflog struct
  log: respect date_mode_explicit with --format:%gd
  t1411: add more selector index/date tests
  • Loading branch information
gitster committed May 14, 2012
2 parents badabc0 + 55ccf85 commit adc3a81
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 16 deletions.
1 change: 1 addition & 0 deletions builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static void show_commit(struct commit *commit, void *data)
struct pretty_print_context ctx = {0};
ctx.abbrev = revs->abbrev;
ctx.date_mode = revs->date_mode;
ctx.date_mode_explicit = revs->date_mode_explicit;
ctx.fmt = revs->commit_format;
pretty_print_commit(&ctx, commit, &buf);
if (revs->graph) {
Expand Down
1 change: 1 addition & 0 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct pretty_print_context {
const char *after_subject;
int preserve_subject;
enum date_mode date_mode;
unsigned date_mode_explicit:1;
int need_8bit_cte;
int show_notes;
struct reflog_walk_info *reflog_info;
Expand Down
8 changes: 4 additions & 4 deletions log-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,9 @@ void show_log(struct rev_info *opt)
* graph info here.
*/
show_reflog_message(opt->reflog_info,
opt->commit_format == CMIT_FMT_ONELINE,
opt->date_mode_explicit ?
opt->date_mode :
DATE_NORMAL);
opt->commit_format == CMIT_FMT_ONELINE,
opt->date_mode,
opt->date_mode_explicit);
if (opt->commit_format == CMIT_FMT_ONELINE)
return;
}
Expand All @@ -652,6 +651,7 @@ void show_log(struct rev_info *opt)
if (ctx.need_8bit_cte >= 0)
ctx.need_8bit_cte = has_non_ascii(opt->add_signoff);
ctx.date_mode = opt->date_mode;
ctx.date_mode_explicit = opt->date_mode_explicit;
ctx.abbrev = opt->diffopt.abbrev;
ctx.after_subject = extra_headers;
ctx.preserve_subject = opt->preserve_subject;
Expand Down
1 change: 1 addition & 0 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
get_reflog_selector(sb,
c->pretty_ctx->reflog_info,
c->pretty_ctx->date_mode,
c->pretty_ctx->date_mode_explicit,
(placeholder[1] == 'd'));
return 2;
case 's': /* reflog message */
Expand Down
22 changes: 16 additions & 6 deletions reflog-walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ static void add_commit_info(struct commit *commit, void *util,
}

struct commit_reflog {
int flag, recno;
int recno;
enum selector_type {
SELECTOR_NONE,
SELECTOR_INDEX,
SELECTOR_DATE
} selector;
struct complete_reflogs *reflogs;
};

Expand All @@ -150,6 +155,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
struct complete_reflogs *reflogs;
char *branch, *at = strchr(name, '@');
struct commit_reflog *commit_reflog;
enum selector_type selector = SELECTOR_NONE;

if (commit->object.flags & UNINTERESTING)
die ("Cannot walk reflogs for %s", name);
Expand All @@ -162,7 +168,10 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
if (*ep != '}') {
recno = -1;
timestamp = approxidate(at + 2);
selector = SELECTOR_DATE;
}
else
selector = SELECTOR_INDEX;
} else
recno = 0;

Expand Down Expand Up @@ -200,7 +209,6 @@ int add_reflog_for_walk(struct reflog_walk_info *info,

commit_reflog = xcalloc(sizeof(struct commit_reflog), 1);
if (recno < 0) {
commit_reflog->flag = 1;
commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
if (commit_reflog->recno < 0) {
free(branch);
Expand All @@ -209,6 +217,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
}
} else
commit_reflog->recno = reflogs->nr - recno - 1;
commit_reflog->selector = selector;
commit_reflog->reflogs = reflogs;

add_commit_info(commit, commit_reflog, &info->reflogs);
Expand Down Expand Up @@ -247,7 +256,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)

void get_reflog_selector(struct strbuf *sb,
struct reflog_walk_info *reflog_info,
enum date_mode dmode,
enum date_mode dmode, int force_date,
int shorten)
{
struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
Expand All @@ -267,7 +276,8 @@ void get_reflog_selector(struct strbuf *sb,
}

strbuf_addf(sb, "%s@{", printed_ref);
if (commit_reflog->flag || dmode) {
if (commit_reflog->selector == SELECTOR_DATE ||
(commit_reflog->selector == SELECTOR_NONE && force_date)) {
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
} else {
Expand Down Expand Up @@ -308,15 +318,15 @@ const char *get_reflog_ident(struct reflog_walk_info *reflog_info)
}

void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
enum date_mode dmode)
enum date_mode dmode, int force_date)
{
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, 0);
get_reflog_selector(&selector, reflog_info, dmode, force_date, 0);
if (oneline) {
printf("%s: %s", selector.buf, info->message);
}
Expand Down
4 changes: 2 additions & 2 deletions reflog-walk.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ extern int add_reflog_for_walk(struct reflog_walk_info *info,
extern void fake_reflog_parent(struct reflog_walk_info *info,
struct commit *commit);
extern void show_reflog_message(struct reflog_walk_info *info, int,
enum date_mode);
enum date_mode, int force_date);
extern void get_reflog_message(struct strbuf *sb,
struct reflog_walk_info *reflog_info);
extern const char *get_reflog_ident(struct reflog_walk_info *reflog_info);
extern void get_reflog_selector(struct strbuf *sb,
struct reflog_walk_info *reflog_info,
enum date_mode dmode,
enum date_mode dmode, int force_date,
int shorten);

#endif
61 changes: 57 additions & 4 deletions t/t1411-reflog-show.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,73 @@ test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
'

cat >expect <<'EOF'
Reflog: HEAD@{1112911993 -0700} (C O Mitter <committer@example.com>)
HEAD@{Thu Apr 7 15:13:13 2005 -0700}
EOF
test_expect_success 'using @{now} syntax shows reflog date (format=%gd)' '
git log -g -1 --format=%gd HEAD@{now} >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
Reflog message: commit (initial): one
EOF
test_expect_success 'using --date= shows reflog date (multiline)' '
git log -g -1 --date=raw >tmp &&
git log -g -1 --date=default >tmp &&
grep ^Reflog <tmp >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
e46513e HEAD@{1112911993 -0700}: commit (initial): one
e46513e HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
EOF
test_expect_success 'using --date= shows reflog date (oneline)' '
git log -g -1 --oneline --date=raw >actual &&
git log -g -1 --oneline --date=default >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
HEAD@{1112911993 -0700}
EOF
test_expect_success 'using --date= shows reflog date (format=%gd)' '
git log -g -1 --format=%gd --date=raw >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
Reflog message: commit (initial): one
EOF
test_expect_success 'log.date does not invoke "--date" magic (multiline)' '
test_config log.date raw &&
git log -g -1 >tmp &&
grep ^Reflog <tmp >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
e46513e HEAD@{0}: commit (initial): one
EOF
test_expect_success 'log.date does not invoke "--date" magic (oneline)' '
test_config log.date raw &&
git log -g -1 --oneline >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
HEAD@{0}
EOF
test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
test_config log.date raw &&
git log -g -1 --format=%gd >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
HEAD@{0}
EOF
test_expect_success '--date magic does not override explicit @{0} syntax' '
git log -g -1 --format=%gd --date=raw HEAD@{0} >actual &&
test_cmp expect actual
'

Expand Down

0 comments on commit adc3a81

Please sign in to comment.