From a763126b5c0120057908e939a0ff7cc95f899f69 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 4 May 2012 01:26:26 -0400 Subject: reflog-walk: clean up "flag" field of commit_reflog struct When we prepare to walk a reflog, we parse the specification and pull some information from it, such as which reflog to look in (e.g., HEAD), and where to start (e.g., HEAD@{10} or HEAD@{yesterday}). The resulting struct has a "recno" field to show where in the reflog we are starting. It also has a "flag" field; if true, it means the recno field came from parsing a date like HEAD@{yesterday}. There are two problems with this: 1. "flag" is an absolutely terrible name, as it conveys nothing about the meaning 2. you can tell "HEAD" from "HEAD@{yesterday}", but you can't differentiate "HEAD" from "HEAD{0}" This patch converts the flag into a tri-state (and gives it a better name!). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- reflog-walk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'reflog-walk.c') diff --git a/reflog-walk.c b/reflog-walk.c index 5d81d39a52..80bffb0a00 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -122,7 +122,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; }; @@ -146,6 +151,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); @@ -158,7 +164,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; @@ -196,7 +205,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); @@ -205,6 +213,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); @@ -263,7 +272,7 @@ void get_reflog_selector(struct strbuf *sb, } strbuf_addf(sb, "%s@{", printed_ref); - if (commit_reflog->flag || dmode) { + if (commit_reflog->selector == SELECTOR_DATE || dmode) { info = &commit_reflog->reflogs->items[commit_reflog->recno+1]; strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode)); } else { -- cgit v1.2.3 From 794151e9b595ddc2700c0801caabfd27be763e12 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 4 May 2012 01:27:25 -0400 Subject: reflog-walk: always make HEAD@{0} show indexed selectors When we are showing reflog selectors during a walk, we infer from context whether the user wanted to see the index in each selector, or the reflog date. The current rules are: 1. if the user asked for an explicit date format in the output, show the date 2. if the user asked for ref@{now}, show the date 3. if neither is true, show the index However, if we see "ref@{0}", that should be a strong clue that the user wants to see the counted version. In fact, it should be much stronger than the date format in (1). The user may have been setting the date format to use in another part of the output (e.g., in --format="%gd (%ad)", they may have wanted to influence the author date). This patch flips the rules to: 1. if the user asked for ref@{0}, always show the index 2. if the user asked for ref@{now}, always show the date 3. otherwise, we have just "ref"; show them counted by default, but respect the presence of "--date" as a clue that the user wanted them date-based Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- reflog-walk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'reflog-walk.c') diff --git a/reflog-walk.c b/reflog-walk.c index 80bffb0a00..b84e80f2ca 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -272,7 +272,8 @@ void get_reflog_selector(struct strbuf *sb, } strbuf_addf(sb, "%s@{", printed_ref); - if (commit_reflog->selector == SELECTOR_DATE || 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 { -- cgit v1.2.3 From 55ccf85a524f6a2d8cb5582d80a2927ff11dfb64 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 7 May 2012 14:11:32 -0700 Subject: reflog-walk: tell explicit --date=default from not having --date at all Introduction of opt->date_mode_explicit was a step in the right direction, but lost that crucial bit at the very end of the callchain, and the callee could not tell an explicitly specified "I want *date* but in default format" from the built-in default value passed when there was no --date specified. Signed-off-by: Junio C Hamano --- reflog-walk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'reflog-walk.c') diff --git a/reflog-walk.c b/reflog-walk.c index b84e80f2ca..0c904fb2d1 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -252,7 +252,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; @@ -273,7 +273,7 @@ void get_reflog_selector(struct strbuf *sb, strbuf_addf(sb, "%s@{", printed_ref); if (commit_reflog->selector == SELECTOR_DATE || - (commit_reflog->selector == SELECTOR_NONE && dmode)) { + (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 { @@ -302,7 +302,7 @@ void get_reflog_message(struct strbuf *sb, } 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; @@ -310,7 +310,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); } -- cgit v1.2.3