name-rev: restructure creating/updating 'struct rev_name' instances
At the beginning of the recursive name_rev() function it creates a new 'struct rev_name' instance for each previously unvisited commit or, if this visit results in better name for an already visited commit, then updates the 'struct rev_name' instance attached to the commit, or returns early. Restructure this so it's caller creates or updates the 'struct rev_name' instance associated with the commit to be passed as parameter, 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. This change also plugs the memory leak that was temporarily unplugged in the earlier "name-rev: pull out deref handling from the recursion" patch in this series. 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
dd432a6ecf
commit
3a52150301
@ -111,14 +111,12 @@ static void name_rev(struct commit *commit,
|
|||||||
struct commit_list *parents;
|
struct commit_list *parents;
|
||||||
int parent_number = 1;
|
int parent_number = 1;
|
||||||
|
|
||||||
if (!create_or_update_name(commit, tip_name, taggerdate, generation,
|
|
||||||
distance, from_tag))
|
|
||||||
return;
|
|
||||||
|
|
||||||
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;
|
struct commit *parent = parents->item;
|
||||||
|
const char *new_name;
|
||||||
|
int new_generation, new_distance;
|
||||||
|
|
||||||
parse_commit(parent);
|
parse_commit(parent);
|
||||||
if (parent->date < cutoff)
|
if (parent->date < cutoff)
|
||||||
@ -126,7 +124,6 @@ static void name_rev(struct commit *commit,
|
|||||||
|
|
||||||
if (parent_number > 1) {
|
if (parent_number > 1) {
|
||||||
size_t len;
|
size_t len;
|
||||||
char *new_name;
|
|
||||||
|
|
||||||
strip_suffix(tip_name, "^0", &len);
|
strip_suffix(tip_name, "^0", &len);
|
||||||
if (generation > 0)
|
if (generation > 0)
|
||||||
@ -135,15 +132,19 @@ static void name_rev(struct commit *commit,
|
|||||||
else
|
else
|
||||||
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
|
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
|
||||||
parent_number);
|
parent_number);
|
||||||
|
new_generation = 0;
|
||||||
name_rev(parent, new_name, taggerdate, 0,
|
new_distance = distance + MERGE_TRAVERSAL_WEIGHT;
|
||||||
distance + MERGE_TRAVERSAL_WEIGHT,
|
|
||||||
from_tag);
|
|
||||||
} else {
|
} else {
|
||||||
name_rev(parent, tip_name, taggerdate,
|
new_name = tip_name;
|
||||||
generation + 1, distance + 1,
|
new_generation = generation + 1;
|
||||||
from_tag);
|
new_distance = distance + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (create_or_update_name(parent, new_name, taggerdate,
|
||||||
|
new_generation, new_distance,
|
||||||
|
from_tag))
|
||||||
|
name_rev(parent, new_name, taggerdate,
|
||||||
|
new_generation, new_distance, from_tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,11 +281,17 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
|
|||||||
path = name_ref_abbrev(path, can_abbreviate_output);
|
path = name_ref_abbrev(path, can_abbreviate_output);
|
||||||
if (commit->date >= cutoff) {
|
if (commit->date >= cutoff) {
|
||||||
const char *tip_name;
|
const char *tip_name;
|
||||||
|
char *to_free = NULL;
|
||||||
if (deref)
|
if (deref)
|
||||||
tip_name = xstrfmt("%s^0", path);
|
tip_name = to_free = xstrfmt("%s^0", path);
|
||||||
else
|
else
|
||||||
tip_name = xstrdup(path);
|
tip_name = xstrdup(path);
|
||||||
name_rev(commit, tip_name, taggerdate, 0, 0, from_tag);
|
if (create_or_update_name(commit, tip_name, taggerdate,
|
||||||
|
0, 0, from_tag))
|
||||||
|
name_rev(commit, tip_name, taggerdate, 0, 0,
|
||||||
|
from_tag);
|
||||||
|
else
|
||||||
|
free(to_free);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user