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>
This commit is contained in:

committed by
Junio C Hamano

parent
dd090a8a37
commit
dd432a6ecf
@ -111,11 +111,6 @@ static void name_rev(struct commit *commit,
|
|||||||
struct commit_list *parents;
|
struct commit_list *parents;
|
||||||
int parent_number = 1;
|
int parent_number = 1;
|
||||||
|
|
||||||
parse_commit(commit);
|
|
||||||
|
|
||||||
if (commit->date < cutoff)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!create_or_update_name(commit, tip_name, taggerdate, generation,
|
if (!create_or_update_name(commit, tip_name, taggerdate, generation,
|
||||||
distance, from_tag))
|
distance, from_tag))
|
||||||
return;
|
return;
|
||||||
@ -123,6 +118,12 @@ static void name_rev(struct commit *commit,
|
|||||||
for (parents = commit->parents;
|
for (parents = commit->parents;
|
||||||
parents;
|
parents;
|
||||||
parents = parents->next, parent_number++) {
|
parents = parents->next, parent_number++) {
|
||||||
|
struct commit *parent = parents->item;
|
||||||
|
|
||||||
|
parse_commit(parent);
|
||||||
|
if (parent->date < cutoff)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (parent_number > 1) {
|
if (parent_number > 1) {
|
||||||
size_t len;
|
size_t len;
|
||||||
char *new_name;
|
char *new_name;
|
||||||
@ -135,11 +136,11 @@ static void name_rev(struct commit *commit,
|
|||||||
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
|
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
|
||||||
parent_number);
|
parent_number);
|
||||||
|
|
||||||
name_rev(parents->item, new_name, taggerdate, 0,
|
name_rev(parent, new_name, taggerdate, 0,
|
||||||
distance + MERGE_TRAVERSAL_WEIGHT,
|
distance + MERGE_TRAVERSAL_WEIGHT,
|
||||||
from_tag);
|
from_tag);
|
||||||
} else {
|
} else {
|
||||||
name_rev(parents->item, tip_name, taggerdate,
|
name_rev(parent, tip_name, taggerdate,
|
||||||
generation + 1, distance + 1,
|
generation + 1, distance + 1,
|
||||||
from_tag);
|
from_tag);
|
||||||
}
|
}
|
||||||
@ -273,16 +274,18 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
|
|||||||
if (o && o->type == OBJ_COMMIT) {
|
if (o && o->type == OBJ_COMMIT) {
|
||||||
struct commit *commit = (struct commit *)o;
|
struct commit *commit = (struct commit *)o;
|
||||||
int from_tag = starts_with(path, "refs/tags/");
|
int from_tag = starts_with(path, "refs/tags/");
|
||||||
const char *tip_name;
|
|
||||||
|
|
||||||
if (taggerdate == TIME_MAX)
|
if (taggerdate == TIME_MAX)
|
||||||
taggerdate = commit->date;
|
taggerdate = commit->date;
|
||||||
path = name_ref_abbrev(path, can_abbreviate_output);
|
path = name_ref_abbrev(path, can_abbreviate_output);
|
||||||
if (deref)
|
if (commit->date >= cutoff) {
|
||||||
tip_name = xstrfmt("%s^0", path);
|
const char *tip_name;
|
||||||
else
|
if (deref)
|
||||||
tip_name = xstrdup(path);
|
tip_name = xstrfmt("%s^0", path);
|
||||||
name_rev(commit, tip_name, taggerdate, 0, 0, from_tag);
|
else
|
||||||
|
tip_name = xstrdup(path);
|
||||||
|
name_rev(commit, tip_name, taggerdate, 0, 0, from_tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user