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 <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Dec 9, 2019 at 12:52 UTC
2866fd284c57d729d486ed93a7fc118f78e765cb
1 file changed
+16
-15
builtin/name-rev.c
+16
-15
@@ -107,12 +107,26 @@ copy_data:
107
108
static void name_rev(struct commit *start_commit,
109
const char *tip_name, timestamp_t taggerdate,
110
- int from_tag)
110
+ int from_tag, int deref)
111
{
112
struct prio_queue queue;
113
struct commit *commit;
114
struct commit **parents_to_queue = NULL;
115
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
+ }
130
131
memset(&queue, 0, sizeof(queue)); /* Use the prio_queue as LIFO */
132
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
323
if (taggerdate == TIME_MAX)
324
taggerdate = commit->date;
325
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);
327
}
328
return 0;
329
}