Skip to content

Commit 2866fd2

Browse files
szedergitster
authored andcommitted
name-rev: cleanup name_ref()
Earlier patches in this series moved a couple of conditions from the recursive name_rev() function into its caller name_ref(), for no other reason than to make eliminating the recursion a bit easier to follow. Since the previous patch name_rev() is not recursive anymore, so let's move all those conditions back into name_rev(). Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49f7a2f commit 2866fd2

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

builtin/name-rev.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,26 @@ static struct rev_name *create_or_update_name(struct commit *commit,
107107

108108
static void name_rev(struct commit *start_commit,
109109
const char *tip_name, timestamp_t taggerdate,
110-
int from_tag)
110+
int from_tag, int deref)
111111
{
112112
struct prio_queue queue;
113113
struct commit *commit;
114114
struct commit **parents_to_queue = NULL;
115115
size_t parents_to_queue_nr, parents_to_queue_alloc = 0;
116+
char *to_free = NULL;
117+
118+
parse_commit(start_commit);
119+
if (start_commit->date < cutoff)
120+
return;
121+
122+
if (deref)
123+
tip_name = to_free = xstrfmt("%s^0", tip_name);
124+
125+
if (!create_or_update_name(start_commit, tip_name, taggerdate, 0, 0,
126+
from_tag)) {
127+
free(to_free);
128+
return;
129+
}
116130

117131
memset(&queue, 0, sizeof(queue)); /* Use the prio_queue as LIFO */
118132
prio_queue_put(&queue, start_commit);
@@ -309,20 +323,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
309323
if (taggerdate == TIME_MAX)
310324
taggerdate = commit->date;
311325
path = name_ref_abbrev(path, can_abbreviate_output);
312-
if (commit->date >= cutoff) {
313-
const char *tip_name;
314-
char *to_free = NULL;
315-
if (deref)
316-
tip_name = to_free = xstrfmt("%s^0", path);
317-
else
318-
tip_name = xstrdup(path);
319-
if (create_or_update_name(commit, tip_name, taggerdate,
320-
0, 0, from_tag))
321-
name_rev(commit, tip_name, taggerdate,
322-
from_tag);
323-
else
324-
free(to_free);
325-
}
326+
name_rev(commit, xstrdup(path), taggerdate, from_tag, deref);
326327
}
327328
return 0;
328329
}

0 commit comments

Comments
 (0)