builtin/am: fold am_signoff() into am_append_signoff()
There are no more direct calls to am_signoff(), so we can fold its logic in am_append_signoff(). (This is done in a separate commit rather than in the previous one, to make it easier to revert this specific change if additional calls are ever introduced.) Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Giuseppe Bilotta committed
Apr 15, 2017 at 16:41 UTC
0fb3c4fc9a20cc3d7869d46bb8a774e4038fc62c
1 file changed
+15
-18
builtin/am.c
+15
-18
@@ -1181,42 +1181,39 @@ static void NORETURN die_user_resolve(const struct am_state *state)
1181
exit(128);
1182
}
1183
1184
-static void am_signoff(struct strbuf *sb)
1184
+/**
1185
+ * Appends signoff to the "msg" field of the am_state.
1186
+ */
1187
+static void am_append_signoff(struct am_state *state)
1188
{
1189
char *cp;
1190
struct strbuf mine = STRBUF_INIT;
1191
+ struct strbuf sb = STRBUF_INIT;
1192
1189
- /* Does it end with our own sign-off? */
1193
+ strbuf_attach(&sb, state->msg, state->msg_len, state->msg_len);
1194
+
1195
+ /* our sign-off */
1196
strbuf_addf(&mine, "\n%s%s\n",
1197
sign_off_header,
1198
fmt_name(getenv("GIT_COMMITTER_NAME"),
1199
getenv("GIT_COMMITTER_EMAIL")));
1194
- if (mine.len < sb->len &&
1195
- !strcmp(mine.buf, sb->buf + sb->len - mine.len))
1200
+
1201
+ /* Does sb end with it already? */
1202
+ if (mine.len < sb.len &&
1203
+ !strcmp(mine.buf, sb.buf + sb.len - mine.len))
1204
goto exit; /* no need to duplicate */
1205
1206
/* Does it have any Signed-off-by: in the text */
1199
- for (cp = sb->buf;
1207
+ for (cp = sb.buf;
1208
cp && *cp && (cp = strstr(cp, sign_off_header)) != NULL;
1209
cp = strchr(cp, '\n')) {
1202
- if (sb->buf == cp || cp[-1] == '\n')
1210
+ if (sb.buf == cp || cp[-1] == '\n')
1211
break;
1212
}
1213
1206
- strbuf_addstr(sb, mine.buf + !!cp);
1214
+ strbuf_addstr(&sb, mine.buf + !!cp);
1215
exit:
1216
strbuf_release(&mine);
1209
-}
1210
-
1211
-/**
1212
- * Appends signoff to the "msg" field of the am_state.
1213
- */
1214
-static void am_append_signoff(struct am_state *state)
1215
-{
1216
- struct strbuf sb = STRBUF_INIT;
1217
-
1218
- strbuf_attach(&sb, state->msg, state->msg_len, state->msg_len);
1219
- am_signoff(&sb);
1217
state->msg = strbuf_detach(&sb, &state->msg_len);
1218
}
1219