commit.c: Remove backward goto in read_craft_line()
Bad graft data is noticed in several places in read_graft_line(), and in each case we go back to the first site of detection. It in general is a better style to have an exception handling out of line from the main codepath and make error codepath jump forward. Signed-off-by: Ralf Thielow <ralf.thielow@googlemail.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ralf Thielow committed
Dec 1, 2010 at 20:15 UTC
df5d43be1f721b0ede37097b815463ceb43b0449
1 file changed
+7
-6
commit.c
+7
-6
@@ -137,12 +137,8 @@ struct commit_graft *read_graft_line(char *buf, int len)
137
buf[--len] = '\0';
138
if (buf[0] == '#' || buf[0] == '\0')
139
return NULL;
140
- if ((len + 1) % 41) {
141
- bad_graft_data:
142
- error("bad graft data: %s", buf);
143
- free(graft);
144
- return NULL;
145
- }
140
+ if ((len + 1) % 41)
141
+ goto bad_graft_data;
142
i = (len + 1) / 41 - 1;
143
graft = xmalloc(sizeof(*graft) + 20 * i);
144
graft->nr_parent = i;
@@ -155,6 +151,11 @@ struct commit_graft *read_graft_line(char *buf, int len)
151
goto bad_graft_data;
152
}
153
return graft;
154
+
155
+bad_graft_data:
156
+ error("bad graft data: %s", buf);
157
+ free(graft);
158
+ return NULL;
159
}
160
161
static int read_graft_file(const char *graft_file)