]> git.ipfire.org Git - thirdparty/git.git/commitdiff
name-rev: drop name_rev()'s 'generation' and 'distance' parameters
authorSZEDER Gábor <szeder.dev@gmail.com>
Tue, 12 Nov 2019 10:38:19 +0000 (11:38 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2019 21:29:04 +0000 (13:29 -0800)
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>
builtin/name-rev.c

index 6416c49f67a9853eb8065b7cae54f562d145e60c..fc61d6fa71447803a9afc0a07a35327e31c4ba50 100644 (file)
@@ -106,8 +106,9 @@ copy_data:
 
 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;
 
@@ -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)
@@ -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);
        }
 }
 
@@ -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);