Skip to content

Commit

Permalink
name-rev: drop name_rev()'s 'generation' and 'distance' parameters
Browse files Browse the repository at this point in the history
Following the previous patches in this series we can get the values of
name_rev()'s 'generation' and 'distance' parameters from the 'stuct
rev_name' associated with the commit as well.

Let's simplify the function's signature and remove these two
unnecessary parameters.

Note that at this point we could do the same with the 'tip_name',
'taggerdate' and 'from_tag' parameters as well, but those parameters
will be necessary later, after the recursion is eliminated.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
szeder authored and gitster committed Dec 6, 2019
1 parent 3a52150 commit 8c5724c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions builtin/name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ static struct rev_name *create_or_update_name(struct commit *commit,

static void name_rev(struct commit *commit,
const char *tip_name, timestamp_t taggerdate,
int generation, int distance, int from_tag)
int from_tag)
{
struct rev_name *name = get_commit_rev_name(commit);
struct commit_list *parents;
int parent_number = 1;

Expand All @@ -116,7 +117,7 @@ static void name_rev(struct commit *commit,
parents = parents->next, parent_number++) {
struct commit *parent = parents->item;
const char *new_name;
int new_generation, new_distance;
int generation, distance;

parse_commit(parent);
if (parent->date < cutoff)
Expand All @@ -126,25 +127,25 @@ static void name_rev(struct commit *commit,
size_t len;

strip_suffix(tip_name, "^0", &len);
if (generation > 0)
if (name->generation > 0)
new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
generation, parent_number);
name->generation,
parent_number);
else
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
parent_number);
new_generation = 0;
new_distance = distance + MERGE_TRAVERSAL_WEIGHT;
generation = 0;
distance = name->distance + MERGE_TRAVERSAL_WEIGHT;
} else {
new_name = tip_name;
new_generation = generation + 1;
new_distance = distance + 1;
generation = name->generation + 1;
distance = name->distance + 1;
}

if (create_or_update_name(parent, new_name, taggerdate,
new_generation, new_distance,
generation, distance,
from_tag))
name_rev(parent, new_name, taggerdate,
new_generation, new_distance, from_tag);
name_rev(parent, new_name, taggerdate, from_tag);
}
}

Expand Down Expand Up @@ -288,7 +289,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
tip_name = xstrdup(path);
if (create_or_update_name(commit, tip_name, taggerdate,
0, 0, from_tag))
name_rev(commit, tip_name, taggerdate, 0, 0,
name_rev(commit, tip_name, taggerdate,
from_tag);
else
free(to_free);
Expand Down

0 comments on commit 8c5724c

Please sign in to comment.