Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit a763126

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f026c75 commit a763126

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

reflog-walk.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ static void add_commit_info(struct commit *commit, void *util,
122122
}
123123

124124
struct commit_reflog {
125-
int flag, recno;
125+
int recno;
126+
enum selector_type {
127+
SELECTOR_NONE,
128+
SELECTOR_INDEX,
129+
SELECTOR_DATE
130+
} selector;
126131
struct complete_reflogs *reflogs;
127132
};
128133

@@ -146,6 +151,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
146151
struct complete_reflogs *reflogs;
147152
char *branch, *at = strchr(name, '@');
148153
struct commit_reflog *commit_reflog;
154+
enum selector_type selector = SELECTOR_NONE;
149155

150156
if (commit->object.flags & UNINTERESTING)
151157
die ("Cannot walk reflogs for %s", name);
@@ -158,7 +164,10 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
158164
if (*ep != '}') {
159165
recno = -1;
160166
timestamp = approxidate(at + 2);
167+
selector = SELECTOR_DATE;
161168
}
169+
else
170+
selector = SELECTOR_INDEX;
162171
} else
163172
recno = 0;
164173

@@ -196,7 +205,6 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
196205

197206
commit_reflog = xcalloc(sizeof(struct commit_reflog), 1);
198207
if (recno < 0) {
199-
commit_reflog->flag = 1;
200208
commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
201209
if (commit_reflog->recno < 0) {
202210
free(branch);
@@ -205,6 +213,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
205213
}
206214
} else
207215
commit_reflog->recno = reflogs->nr - recno - 1;
216+
commit_reflog->selector = selector;
208217
commit_reflog->reflogs = reflogs;
209218

210219
add_commit_info(commit, commit_reflog, &info->reflogs);
@@ -263,7 +272,7 @@ void get_reflog_selector(struct strbuf *sb,
263272
}
264273

265274
strbuf_addf(sb, "%s@{", printed_ref);
266-
if (commit_reflog->flag || dmode) {
275+
if (commit_reflog->selector == SELECTOR_DATE || dmode) {
267276
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
268277
strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
269278
} else {

0 commit comments

Comments
 (0)