Skip to content

Commit 0fb3c4f

Browse files
Oblomovgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b7cc705 commit 0fb3c4f

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

builtin/am.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,42 +1181,39 @@ static void NORETURN die_user_resolve(const struct am_state *state)
11811181
exit(128);
11821182
}
11831183

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)
11851188
{
11861189
char *cp;
11871190
struct strbuf mine = STRBUF_INIT;
1191+
struct strbuf sb = STRBUF_INIT;
11881192

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 */
11901196
strbuf_addf(&mine, "\n%s%s\n",
11911197
sign_off_header,
11921198
fmt_name(getenv("GIT_COMMITTER_NAME"),
11931199
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))
11961204
goto exit; /* no need to duplicate */
11971205

11981206
/* Does it have any Signed-off-by: in the text */
1199-
for (cp = sb->buf;
1207+
for (cp = sb.buf;
12001208
cp && *cp && (cp = strstr(cp, sign_off_header)) != NULL;
12011209
cp = strchr(cp, '\n')) {
1202-
if (sb->buf == cp || cp[-1] == '\n')
1210+
if (sb.buf == cp || cp[-1] == '\n')
12031211
break;
12041212
}
12051213

1206-
strbuf_addstr(sb, mine.buf + !!cp);
1214+
strbuf_addstr(&sb, mine.buf + !!cp);
12071215
exit:
12081216
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);
12201217
state->msg = strbuf_detach(&sb, &state->msg_len);
12211218
}
12221219

0 commit comments

Comments
 (0)