Skip to content

Commit dd432a6

Browse files
szedergitster
authored andcommitted
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>
1 parent dd090a8 commit dd432a6

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

builtin/name-rev.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,19 @@ static void name_rev(struct commit *commit,
111111
struct commit_list *parents;
112112
int parent_number = 1;
113113

114-
parse_commit(commit);
115-
116-
if (commit->date < cutoff)
117-
return;
118-
119114
if (!create_or_update_name(commit, tip_name, taggerdate, generation,
120115
distance, from_tag))
121116
return;
122117

123118
for (parents = commit->parents;
124119
parents;
125120
parents = parents->next, parent_number++) {
121+
struct commit *parent = parents->item;
122+
123+
parse_commit(parent);
124+
if (parent->date < cutoff)
125+
continue;
126+
126127
if (parent_number > 1) {
127128
size_t len;
128129
char *new_name;
@@ -135,11 +136,11 @@ static void name_rev(struct commit *commit,
135136
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
136137
parent_number);
137138

138-
name_rev(parents->item, new_name, taggerdate, 0,
139+
name_rev(parent, new_name, taggerdate, 0,
139140
distance + MERGE_TRAVERSAL_WEIGHT,
140141
from_tag);
141142
} else {
142-
name_rev(parents->item, tip_name, taggerdate,
143+
name_rev(parent, tip_name, taggerdate,
143144
generation + 1, distance + 1,
144145
from_tag);
145146
}
@@ -273,16 +274,18 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
273274
if (o && o->type == OBJ_COMMIT) {
274275
struct commit *commit = (struct commit *)o;
275276
int from_tag = starts_with(path, "refs/tags/");
276-
const char *tip_name;
277277

278278
if (taggerdate == TIME_MAX)
279279
taggerdate = commit->date;
280280
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+
}
286289
}
287290
return 0;
288291
}

0 commit comments

Comments
 (0)