name-rev: rewrite create_or_update_name()
This code was moved straight out of name_rev(). As such, we inherited the "goto" to jump from an if into an else-if. We also inherited the fact that "nothing to do -- return NULL" is handled last. Rewrite the function to first handle the "nothing to do" case. Then we can handle the conditional allocation early before going on to populate the struct. No need for goto-ing. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin Ågren committed
Feb 5, 2020 at 18:19 UTC
3e2feb0d64c994d343b42a62bd521fb5d6bdfe02
1 file changed
+12
-12
builtin/name-rev.c
+12
-12
@@ -88,21 +88,21 @@ static struct rev_name *create_or_update_name(struct commit *commit,
88
{
89
struct rev_name *name = get_commit_rev_name(commit);
90
91
+ if (name && !is_better_name(name, taggerdate, distance, from_tag))
92
+ return NULL;
93
+
94
if (name == NULL) {
95
name = xmalloc(sizeof(*name));
96
set_commit_rev_name(commit, name);
94
- goto copy_data;
95
- } else if (is_better_name(name, taggerdate, distance, from_tag)) {
96
-copy_data:
97
- name->tip_name = tip_name;
98
- name->taggerdate = taggerdate;
99
- name->generation = generation;
100
- name->distance = distance;
101
- name->from_tag = from_tag;
102
-
103
- return name;
104
- } else
105
- return NULL;
97
+ }
98
+
99
+ name->tip_name = tip_name;
100
+ name->taggerdate = taggerdate;
101
+ name->generation = generation;
102
+ name->distance = distance;
103
+ name->from_tag = from_tag;
104
+
105
+ return name;
106
}
107
108
static void name_rev(struct commit *start_commit,