@matheusbsbs / matheus-bagliano / commits / dd432a6ecf
Fork 0

name-rev: restructure parsing commits and applying date cutoff

At the beginning of the recursive name_rev() function it parses the commit it got as parameter, and returns early if the commit is older than a cutoff limit. Restructure this so the caller parses the commit and checks its date, and doesn't invoke name_rev() if the commit to be passed as parameter is older than the cutoff, i.e. both name_ref() before calling name_rev() and name_rev() itself as it iterates over the parent commits. This makes eliminating the recursion a bit easier to follow, and the condition moved to name_ref() will be moved back to name_rev() after the recursion is eliminated. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Nov 12, 2019 at 11:38 UTC dd432a6ecf022b40760dd04fe4e94fdfcb1b270d
1 file changed +16 -13
builtin/name-rev.c
+16 -13
@@ -111,11 +111,6 @@ static void name_rev(struct commit *commit,
111 struct commit_list *parents;
112 int parent_number = 1;
113
114 - parse_commit(commit);
115 -
116 - if (commit->date < cutoff)
117 - return;
118 -
114 if (!create_or_update_name(commit, tip_name, taggerdate, generation,
115 distance, from_tag))
116 return;
@@ -123,6 +118,12 @@ static void name_rev(struct commit *commit,
118 for (parents = commit->parents;
119 parents;
120 parents = parents->next, parent_number++) {
121 + struct commit *parent = parents->item;
122 +
123 + parse_commit(parent);
124 + if (parent->date < cutoff)
125 + continue;
126 +
127 if (parent_number > 1) {
128 size_t len;
129 char *new_name;
@@ -135,11 +136,11 @@ static void name_rev(struct commit *commit,
136 new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
137 parent_number);
138
138 - name_rev(parents->item, new_name, taggerdate, 0,
139 + name_rev(parent, new_name, taggerdate, 0,
140 distance + MERGE_TRAVERSAL_WEIGHT,
141 from_tag);
142 } else {
142 - name_rev(parents->item, tip_name, taggerdate,
143 + name_rev(parent, tip_name, taggerdate,
144 generation + 1, distance + 1,
145 from_tag);
146 }
@@ -273,16 +274,18 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
274 if (o && o->type == OBJ_COMMIT) {
275 struct commit *commit = (struct commit *)o;
276 int from_tag = starts_with(path, "refs/tags/");
276 - const char *tip_name;
277
278 if (taggerdate == TIME_MAX)
279 taggerdate = commit->date;
280 path = name_ref_abbrev(path, can_abbreviate_output);
281 - if (deref)
282 - tip_name = xstrfmt("%s^0", path);
283 - else
284 - tip_name = xstrdup(path);
285 - name_rev(commit, tip_name, taggerdate, 0, 0, from_tag);
281 + if (commit->date >= cutoff) {
282 + const char *tip_name;
283 + if (deref)
284 + tip_name = xstrfmt("%s^0", path);
285 + else
286 + tip_name = xstrdup(path);
287 + name_rev(commit, tip_name, taggerdate, 0, 0, from_tag);
288 + }
289 }
290 return 0;
291 }