summaryrefslogtreecommitdiff
path: root/builtin/name-rev.c
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder.dev@gmail.com>2019-11-12 10:38:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-12-06 21:29:04 (GMT)
commit3a521503019de7ca0c550c3861619bb8881c388c (patch)
treee3195bafd13fdac1c8251a553af70a32bd694c12 /builtin/name-rev.c
parentdd432a6ecf022b40760dd04fe4e94fdfcb1b270d (diff)
downloadgit-3a521503019de7ca0c550c3861619bb8881c388c.zip
git-3a521503019de7ca0c550c3861619bb8881c388c.tar.gz
git-3a521503019de7ca0c550c3861619bb8881c388c.tar.bz2
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>
Diffstat (limited to 'builtin/name-rev.c')
-rw-r--r--builtin/name-rev.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 5041227..6416c49 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -111,14 +111,12 @@ static void name_rev(struct commit *commit,
struct commit_list *parents;
int parent_number = 1;
- if (!create_or_update_name(commit, tip_name, taggerdate, generation,
- distance, from_tag))
- return;
-
for (parents = commit->parents;
parents;
parents = parents->next, parent_number++) {
struct commit *parent = parents->item;
+ const char *new_name;
+ int new_generation, new_distance;
parse_commit(parent);
if (parent->date < cutoff)
@@ -126,7 +124,6 @@ static void name_rev(struct commit *commit,
if (parent_number > 1) {
size_t len;
- char *new_name;
strip_suffix(tip_name, "^0", &len);
if (generation > 0)
@@ -135,15 +132,19 @@ static void name_rev(struct commit *commit,
else
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
parent_number);
-
- name_rev(parent, new_name, taggerdate, 0,
- distance + MERGE_TRAVERSAL_WEIGHT,
- from_tag);
+ new_generation = 0;
+ new_distance = distance + MERGE_TRAVERSAL_WEIGHT;
} else {
- name_rev(parent, tip_name, taggerdate,
- generation + 1, distance + 1,
- from_tag);
+ new_name = tip_name;
+ new_generation = generation + 1;
+ 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);
if (commit->date >= cutoff) {
const char *tip_name;
+ char *to_free = NULL;
if (deref)
- tip_name = xstrfmt("%s^0", path);
+ tip_name = to_free = xstrfmt("%s^0", path);
else
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;