Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'jk/maint-reflog-walk-count-vs-time'

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...
commit d318a3997a76155795f28ffefb52158c0c4133ab 2 parents 65029d8 + 55ccf85
Junio C Hamano authored May 11, 2012
1  builtin/rev-list.c
@@ -109,6 +109,7 @@ static void show_commit(struct commit *commit, void *data)
109 109
 		struct pretty_print_context ctx = {0};
110 110
 		ctx.abbrev = revs->abbrev;
111 111
 		ctx.date_mode = revs->date_mode;
  112
+		ctx.date_mode_explicit = revs->date_mode_explicit;
112 113
 		ctx.fmt = revs->commit_format;
113 114
 		pretty_print_commit(&ctx, commit, &buf);
114 115
 		if (revs->graph) {
1  commit.h
@@ -84,6 +84,7 @@ struct pretty_print_context {
84 84
 	const char *after_subject;
85 85
 	int preserve_subject;
86 86
 	enum date_mode date_mode;
  87
+	unsigned date_mode_explicit:1;
87 88
 	int need_8bit_cte;
88 89
 	int show_notes;
89 90
 	struct reflog_walk_info *reflog_info;
8  log-tree.c
@@ -629,10 +629,9 @@ void show_log(struct rev_info *opt)
629 629
 			 * graph info here.
630 630
 			 */
631 631
 			show_reflog_message(opt->reflog_info,
632  
-				    opt->commit_format == CMIT_FMT_ONELINE,
633  
-				    opt->date_mode_explicit ?
634  
-					opt->date_mode :
635  
-					DATE_NORMAL);
  632
+					    opt->commit_format == CMIT_FMT_ONELINE,
  633
+					    opt->date_mode,
  634
+					    opt->date_mode_explicit);
636 635
 			if (opt->commit_format == CMIT_FMT_ONELINE)
637 636
 				return;
638 637
 		}
@@ -652,6 +651,7 @@ void show_log(struct rev_info *opt)
652 651
 	if (ctx.need_8bit_cte >= 0)
653 652
 		ctx.need_8bit_cte = has_non_ascii(opt->add_signoff);
654 653
 	ctx.date_mode = opt->date_mode;
  654
+	ctx.date_mode_explicit = opt->date_mode_explicit;
655 655
 	ctx.abbrev = opt->diffopt.abbrev;
656 656
 	ctx.after_subject = extra_headers;
657 657
 	ctx.preserve_subject = opt->preserve_subject;
1  pretty.c
@@ -1010,6 +1010,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
1010 1010
 				get_reflog_selector(sb,
1011 1011
 						    c->pretty_ctx->reflog_info,
1012 1012
 						    c->pretty_ctx->date_mode,
  1013
+						    c->pretty_ctx->date_mode_explicit,
1013 1014
 						    (placeholder[1] == 'd'));
1014 1015
 			return 2;
1015 1016
 		case 's':	/* reflog message */
22  reflog-walk.c
@@ -126,7 +126,12 @@ static void add_commit_info(struct commit *commit, void *util,
126 126
 }
127 127
 
128 128
 struct commit_reflog {
129  
-	int flag, recno;
  129
+	int recno;
  130
+	enum selector_type {
  131
+		SELECTOR_NONE,
  132
+		SELECTOR_INDEX,
  133
+		SELECTOR_DATE
  134
+	} selector;
130 135
 	struct complete_reflogs *reflogs;
131 136
 };
132 137
 
@@ -150,6 +155,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
150 155
 	struct complete_reflogs *reflogs;
151 156
 	char *branch, *at = strchr(name, '@');
152 157
 	struct commit_reflog *commit_reflog;
  158
+	enum selector_type selector = SELECTOR_NONE;
153 159
 
154 160
 	if (commit->object.flags & UNINTERESTING)
155 161
 		die ("Cannot walk reflogs for %s", name);
@@ -162,7 +168,10 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
162 168
 		if (*ep != '}') {
163 169
 			recno = -1;
164 170
 			timestamp = approxidate(at + 2);
  171
+			selector = SELECTOR_DATE;
165 172
 		}
  173
+		else
  174
+			selector = SELECTOR_INDEX;
166 175
 	} else
167 176
 		recno = 0;
168 177
 
@@ -200,7 +209,6 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
200 209
 
201 210
 	commit_reflog = xcalloc(sizeof(struct commit_reflog), 1);
202 211
 	if (recno < 0) {
203  
-		commit_reflog->flag = 1;
204 212
 		commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
205 213
 		if (commit_reflog->recno < 0) {
206 214
 			free(branch);
@@ -209,6 +217,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
209 217
 		}
210 218
 	} else
211 219
 		commit_reflog->recno = reflogs->nr - recno - 1;
  220
+	commit_reflog->selector = selector;
212 221
 	commit_reflog->reflogs = reflogs;
213 222
 
214 223
 	add_commit_info(commit, commit_reflog, &info->reflogs);
@@ -247,7 +256,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
247 256
 
248 257
 void get_reflog_selector(struct strbuf *sb,
249 258
 			 struct reflog_walk_info *reflog_info,
250  
-			 enum date_mode dmode,
  259
+			 enum date_mode dmode, int force_date,
251 260
 			 int shorten)
252 261
 {
253 262
 	struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
@@ -267,7 +276,8 @@ void get_reflog_selector(struct strbuf *sb,
267 276
 	}
268 277
 
269 278
 	strbuf_addf(sb, "%s@{", printed_ref);
270  
-	if (commit_reflog->flag || dmode) {
  279
+	if (commit_reflog->selector == SELECTOR_DATE ||
  280
+	    (commit_reflog->selector == SELECTOR_NONE && force_date)) {
271 281
 		info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
272 282
 		strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
273 283
 	} else {
@@ -308,7 +318,7 @@ const char *get_reflog_ident(struct reflog_walk_info *reflog_info)
308 318
 }
309 319
 
310 320
 void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
311  
-	enum date_mode dmode)
  321
+			 enum date_mode dmode, int force_date)
312 322
 {
313 323
 	if (reflog_info && reflog_info->last_commit_reflog) {
314 324
 		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,
316 326
 		struct strbuf selector = STRBUF_INIT;
317 327
 
318 328
 		info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
319  
-		get_reflog_selector(&selector, reflog_info, dmode, 0);
  329
+		get_reflog_selector(&selector, reflog_info, dmode, force_date, 0);
320 330
 		if (oneline) {
321 331
 			printf("%s: %s", selector.buf, info->message);
322 332
 		}
4  reflog-walk.h
@@ -11,13 +11,13 @@ extern int add_reflog_for_walk(struct reflog_walk_info *info,
11 11
 extern void fake_reflog_parent(struct reflog_walk_info *info,
12 12
 		struct commit *commit);
13 13
 extern void show_reflog_message(struct reflog_walk_info *info, int,
14  
-		enum date_mode);
  14
+				enum date_mode, int force_date);
15 15
 extern void get_reflog_message(struct strbuf *sb,
16 16
 		struct reflog_walk_info *reflog_info);
17 17
 extern const char *get_reflog_ident(struct reflog_walk_info *reflog_info);
18 18
 extern void get_reflog_selector(struct strbuf *sb,
19 19
 		struct reflog_walk_info *reflog_info,
20  
-		enum date_mode dmode,
  20
+		enum date_mode dmode, int force_date,
21 21
 		int shorten);
22 22
 
23 23
 #endif
61  t/t1411-reflog-show.sh
@@ -65,20 +65,73 @@ test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
65 65
 '
66 66
 
67 67
 cat >expect <<'EOF'
68  
-Reflog: HEAD@{1112911993 -0700} (C O Mitter <committer@example.com>)
  68
+HEAD@{Thu Apr 7 15:13:13 2005 -0700}
  69
+EOF
  70
+test_expect_success 'using @{now} syntax shows reflog date (format=%gd)' '
  71
+	git log -g -1 --format=%gd HEAD@{now} >actual &&
  72
+	test_cmp expect actual
  73
+'
  74
+
  75
+cat >expect <<'EOF'
  76
+Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
69 77
 Reflog message: commit (initial): one
70 78
 EOF
71 79
 test_expect_success 'using --date= shows reflog date (multiline)' '
72  
-	git log -g -1 --date=raw >tmp &&
  80
+	git log -g -1 --date=default >tmp &&
73 81
 	grep ^Reflog <tmp >actual &&
74 82
 	test_cmp expect actual
75 83
 '
76 84
 
77 85
 cat >expect <<'EOF'
78  
-e46513e HEAD@{1112911993 -0700}: commit (initial): one
  86
+e46513e HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
79 87
 EOF
80 88
 test_expect_success 'using --date= shows reflog date (oneline)' '
81  
-	git log -g -1 --oneline --date=raw >actual &&
  89
+	git log -g -1 --oneline --date=default >actual &&
  90
+	test_cmp expect actual
  91
+'
  92
+
  93
+cat >expect <<'EOF'
  94
+HEAD@{1112911993 -0700}
  95
+EOF
  96
+test_expect_success 'using --date= shows reflog date (format=%gd)' '
  97
+	git log -g -1 --format=%gd --date=raw >actual &&
  98
+	test_cmp expect actual
  99
+'
  100
+
  101
+cat >expect <<'EOF'
  102
+Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
  103
+Reflog message: commit (initial): one
  104
+EOF
  105
+test_expect_success 'log.date does not invoke "--date" magic (multiline)' '
  106
+	test_config log.date raw &&
  107
+	git log -g -1 >tmp &&
  108
+	grep ^Reflog <tmp >actual &&
  109
+	test_cmp expect actual
  110
+'
  111
+
  112
+cat >expect <<'EOF'
  113
+e46513e HEAD@{0}: commit (initial): one
  114
+EOF
  115
+test_expect_success 'log.date does not invoke "--date" magic (oneline)' '
  116
+	test_config log.date raw &&
  117
+	git log -g -1 --oneline >actual &&
  118
+	test_cmp expect actual
  119
+'
  120
+
  121
+cat >expect <<'EOF'
  122
+HEAD@{0}
  123
+EOF
  124
+test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
  125
+	test_config log.date raw &&
  126
+	git log -g -1 --format=%gd >actual &&
  127
+	test_cmp expect actual
  128
+'
  129
+
  130
+cat >expect <<'EOF'
  131
+HEAD@{0}
  132
+EOF
  133
+test_expect_success '--date magic does not override explicit @{0} syntax' '
  134
+	git log -g -1 --format=%gd --date=raw HEAD@{0} >actual &&
82 135
 	test_cmp expect actual
83 136
 '
84 137
 

0 notes on commit d318a39

Please sign in to comment.
Something went wrong with that request. Please try again.