mirror of
https://github.com/git/git.git
synced 2026-02-18 21:59:08 +00:00
Merge branch 'jk/maint-reflog-walk-count-vs-time' (early part) into next
"git log -g --format='%gd: %gs' refs/stash" (or worse yet, the same
command line with refs/stash@{0}) was affected by log.date=iso settings
and failed to show stash@{0}, stash@{1},... in the output. Clarify the
DWIM rules to give the most precedence to how the starting point is
specified (i.e. stash@{0} vs stash@{now}), and then use the presense
of "--date=<format>" command line option as the secondary clue to decide
whether reflog entries are shown with numbers or timestamps.
By Jeff King
* 'jk/maint-reflog-walk-count-vs-time' (early part):
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
This commit is contained in:
@@ -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) {
|
||||
|
||||
1
commit.h
1
commit.h
@@ -84,6 +84,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;
|
||||
|
||||
@@ -652,6 +652,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;
|
||||
|
||||
4
pretty.c
4
pretty.c
@@ -1009,7 +1009,9 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
|
||||
if (c->pretty_ctx->reflog_info)
|
||||
get_reflog_selector(sb,
|
||||
c->pretty_ctx->reflog_info,
|
||||
c->pretty_ctx->date_mode,
|
||||
c->pretty_ctx->date_mode_explicit ?
|
||||
c->pretty_ctx->date_mode :
|
||||
DATE_NORMAL,
|
||||
(placeholder[1] == 'd'));
|
||||
return 2;
|
||||
case 's': /* reflog message */
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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 && dmode)) {
|
||||
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
|
||||
strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
|
||||
} else {
|
||||
|
||||
@@ -64,6 +64,14 @@ test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
cat >expect <<'EOF'
|
||||
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@{1112911993 -0700} (C O Mitter <committer@example.com>)
|
||||
Reflog message: commit (initial): one
|
||||
@@ -82,6 +90,51 @@ test_expect_success 'using --date= shows reflog date (oneline)' '
|
||||
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
|
||||
'
|
||||
|
||||
: >expect
|
||||
test_expect_success 'empty reflog file' '
|
||||
git branch empty &&
|
||||
|
||||
Reference in New Issue
Block a user