@matheusbsbs / matheus-bagliano / commits / 8c5724c585
Fork 0

name-rev: drop name_rev()'s 'generation' and 'distance' parameters

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>

SZEDER Gábor committed Nov 12, 2019 at 11:38 UTC 8c5724c585791662ec5701719e8665a2db5517fd
1 file changed +13 -12
builtin/name-rev.c
+13 -12
@@ -106,8 +106,9 @@ copy_data:
106
107 static void name_rev(struct commit *commit,
108 const char *tip_name, timestamp_t taggerdate,
109 - int generation, int distance, int from_tag)
109 + int from_tag)
110 {
111 + struct rev_name *name = get_commit_rev_name(commit);
112 struct commit_list *parents;
113 int parent_number = 1;
114
@@ -116,7 +117,7 @@ static void name_rev(struct commit *commit,
117 parents = parents->next, parent_number++) {
118 struct commit *parent = parents->item;
119 const char *new_name;
119 - int new_generation, new_distance;
120 + int generation, distance;
121
122 parse_commit(parent);
123 if (parent->date < cutoff)
@@ -126,25 +127,25 @@ static void name_rev(struct commit *commit,
127 size_t len;
128
129 strip_suffix(tip_name, "^0", &len);
129 - if (generation > 0)
130 + if (name->generation > 0)
131 new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
131 - generation, parent_number);
132 + name->generation,
133 + parent_number);
134 else
135 new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
136 parent_number);
135 - new_generation = 0;
136 - new_distance = distance + MERGE_TRAVERSAL_WEIGHT;
137 + generation = 0;
138 + distance = name->distance + MERGE_TRAVERSAL_WEIGHT;
139 } else {
140 new_name = tip_name;
139 - new_generation = generation + 1;
140 - new_distance = distance + 1;
141 + generation = name->generation + 1;
142 + distance = name->distance + 1;
143 }
144
145 if (create_or_update_name(parent, new_name, taggerdate,
144 - new_generation, new_distance,
146 + generation, distance,
147 from_tag))
146 - name_rev(parent, new_name, taggerdate,
147 - new_generation, new_distance, from_tag);
148 + name_rev(parent, new_name, taggerdate, from_tag);
149 }
150 }
151
@@ -288,7 +289,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
289 tip_name = xstrdup(path);
290 if (create_or_update_name(commit, tip_name, taggerdate,
291 0, 0, from_tag))
291 - name_rev(commit, tip_name, taggerdate, 0, 0,
292 + name_rev(commit, tip_name, taggerdate,
293 from_tag);
294 else
295 free(to_free);