]> git.ipfire.org Git - thirdparty/git.git/commitdiff
name-rev: rewrite create_or_update_name()
authorMartin Ågren <martin.agren@gmail.com>
Wed, 5 Feb 2020 17:19:22 +0000 (18:19 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Feb 2020 18:23:42 +0000 (10:23 -0800)
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>
builtin/name-rev.c

index 6b9e8c850b03c618ac11af30d4dac73f8aa51a6b..c2239ac3f76e84c3fef1b5abf686e5a382b95194 100644 (file)
@@ -88,21 +88,21 @@ static struct rev_name *create_or_update_name(struct commit *commit,
 {
        struct rev_name *name = get_commit_rev_name(commit);
 
+       if (name && !is_better_name(name, taggerdate, distance, from_tag))
+               return NULL;
+
        if (name == NULL) {
                name = xmalloc(sizeof(*name));
                set_commit_rev_name(commit, name);
-               goto copy_data;
-       } else if (is_better_name(name, taggerdate, distance, from_tag)) {
-copy_data:
-               name->tip_name = tip_name;
-               name->taggerdate = taggerdate;
-               name->generation = generation;
-               name->distance = distance;
-               name->from_tag = from_tag;
-
-               return name;
-       } else
-               return NULL;
+       }
+
+       name->tip_name = tip_name;
+       name->taggerdate = taggerdate;
+       name->generation = generation;
+       name->distance = distance;
+       name->from_tag = from_tag;
+
+       return name;
 }
 
 static void name_rev(struct commit *start_commit,