Skip to content

Commit 3e2feb0

Browse files
Martin Ågrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0654dc commit 3e2feb0

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

builtin/name-rev.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ static struct rev_name *create_or_update_name(struct commit *commit,
8888
{
8989
struct rev_name *name = get_commit_rev_name(commit);
9090

91+
if (name && !is_better_name(name, taggerdate, distance, from_tag))
92+
return NULL;
93+
9194
if (name == NULL) {
9295
name = xmalloc(sizeof(*name));
9396
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;
106106
}
107107

108108
static void name_rev(struct commit *start_commit,

0 commit comments

Comments
 (0)