Merge branch 'jk/maint-reflog-walk-count-vs-time' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 14 May 2012 18:46:16 +0000 (11:46 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 May 2012 18:46:16 +0000 (11:46 -0700)
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

builtin/rev-list.c
commit.h
log-tree.c
pretty.c
reflog-walk.c
reflog-walk.h
t/t1411-reflog-show.sh
index 4c4d404afc7321a222d3dc136b570ada3d3c2317..ff5a38372d76cc50167a8f7e7862a67cc9d419ea 100644 (file)
@@ -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) {
index 154c0e34ff7d2dbaddcfb66b74d26697ffba6381..205eea3382161672ae2206a3d858eb2075fcb0a2 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -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;
index 44f02683722c5b9181f94f1a6380f8ad191eb08f..376d97317674dfe6dcffec3772c899c4fc96f82f 100644 (file)
@@ -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;
                }
@@ -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;
index f2dee308b887efc9a23ee1b2dcda9119f23cc9a4..02a0a2bb43570fec656c4152454fa67743111a2c 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -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 */
index 86d18843f52046d87741bffa9f865ec973a2ae73..b2fbdb2392f80a531d5f9a21630a036d45c0a827 100644 (file)
@@ -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);
@@ -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;
@@ -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 {
@@ -308,7 +318,7 @@ 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;
@@ -316,7 +326,7 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
                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);
                }
index afb1ae3fde93a5c61def211be56b0554a25dd45e..50265f51c56431025b665abf34ac29fdce3d302b 100644 (file)
@@ -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
index caa687b5b46cea65ed16c70c29cc11e9e8b771f1..9a105fe21f0da2851fc0f2aae4ff10e2417c9842 100755 (executable)
@@ -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
 '