mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f026c7563a
commit
a763126b5c
@ -122,7 +122,12 @@ static void add_commit_info(struct commit *commit, void *util,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct commit_reflog {
|
struct commit_reflog {
|
||||||
int flag, recno;
|
int recno;
|
||||||
|
enum selector_type {
|
||||||
|
SELECTOR_NONE,
|
||||||
|
SELECTOR_INDEX,
|
||||||
|
SELECTOR_DATE
|
||||||
|
} selector;
|
||||||
struct complete_reflogs *reflogs;
|
struct complete_reflogs *reflogs;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -146,6 +151,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
|
|||||||
struct complete_reflogs *reflogs;
|
struct complete_reflogs *reflogs;
|
||||||
char *branch, *at = strchr(name, '@');
|
char *branch, *at = strchr(name, '@');
|
||||||
struct commit_reflog *commit_reflog;
|
struct commit_reflog *commit_reflog;
|
||||||
|
enum selector_type selector = SELECTOR_NONE;
|
||||||
|
|
||||||
if (commit->object.flags & UNINTERESTING)
|
if (commit->object.flags & UNINTERESTING)
|
||||||
die ("Cannot walk reflogs for %s", name);
|
die ("Cannot walk reflogs for %s", name);
|
||||||
@ -158,7 +164,10 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
|
|||||||
if (*ep != '}') {
|
if (*ep != '}') {
|
||||||
recno = -1;
|
recno = -1;
|
||||||
timestamp = approxidate(at + 2);
|
timestamp = approxidate(at + 2);
|
||||||
|
selector = SELECTOR_DATE;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
selector = SELECTOR_INDEX;
|
||||||
} else
|
} else
|
||||||
recno = 0;
|
recno = 0;
|
||||||
|
|
||||||
@ -196,7 +205,6 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
|
|||||||
|
|
||||||
commit_reflog = xcalloc(sizeof(struct commit_reflog), 1);
|
commit_reflog = xcalloc(sizeof(struct commit_reflog), 1);
|
||||||
if (recno < 0) {
|
if (recno < 0) {
|
||||||
commit_reflog->flag = 1;
|
|
||||||
commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
|
commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
|
||||||
if (commit_reflog->recno < 0) {
|
if (commit_reflog->recno < 0) {
|
||||||
free(branch);
|
free(branch);
|
||||||
@ -205,6 +213,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
commit_reflog->recno = reflogs->nr - recno - 1;
|
commit_reflog->recno = reflogs->nr - recno - 1;
|
||||||
|
commit_reflog->selector = selector;
|
||||||
commit_reflog->reflogs = reflogs;
|
commit_reflog->reflogs = reflogs;
|
||||||
|
|
||||||
add_commit_info(commit, commit_reflog, &info->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);
|
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];
|
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
|
||||||
strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
|
strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user