MCPcopy Index your code
hub / github.com/git/git / append_squash_message

Function append_squash_message

sequencer.c:2002–2058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2000}
2001
2002static int append_squash_message(struct strbuf *buf, const char *body,
2003 enum todo_command command, struct replay_opts *opts,
2004 unsigned flag)
2005{
2006 struct replay_ctx *ctx = opts->ctx;
2007 const char *fixup_msg;
2008 size_t commented_len = 0, fixup_off;
2009 /*
2010 * amend is non-interactive and not normally used with fixup!
2011 * or squash! commits, so only comment out those subjects when
2012 * squashing commit messages.
2013 */
2014 if (starts_with(body, "amend!") ||
2015 ((command == TODO_SQUASH || seen_squash(ctx)) &&
2016 (starts_with(body, "squash!") || starts_with(body, "fixup!"))))
2017 commented_len = commit_subject_length(body);
2018
2019 strbuf_addf(buf, "\n%s ", comment_line_str);
2020 strbuf_addf(buf, _(nth_commit_msg_fmt),
2021 ++ctx->current_fixup_count + 1);
2022 strbuf_addstr(buf, "\n\n");
2023 strbuf_add_commented_lines(buf, body, commented_len, comment_line_str);
2024 /* buf->buf may be reallocated so store an offset into the buffer */
2025 fixup_off = buf->len;
2026 strbuf_addstr(buf, body + commented_len);
2027
2028 /* fixup -C after squash behaves like squash */
2029 if (is_fixup_flag(command, flag) && !seen_squash(ctx)) {
2030 /*
2031 * We're replacing the commit message so we need to
2032 * append any trailers if the user requested
2033 * '--signoff' or '--trailer'.
2034 */
2035 if (opts->signoff)
2036 append_signoff(buf, 0, 0);
2037
2038 if (opts->trailer_args.nr)
2039 amend_strbuf_with_trailers(buf, &opts->trailer_args);
2040
2041 if ((command == TODO_FIXUP) &&
2042 (flag & TODO_REPLACE_FIXUP_MSG) &&
2043 (file_exists(rebase_path_fixup_msg()) ||
2044 !file_exists(rebase_path_squash_msg()))) {
2045 fixup_msg = skip_blank_lines(buf->buf + fixup_off);
2046 if (write_message(fixup_msg, strlen(fixup_msg),
2047 rebase_path_fixup_msg(), 0) < 0)
2048 return error(_("cannot write '%s'"),
2049 rebase_path_fixup_msg());
2050 } else {
2051 unlink(rebase_path_fixup_msg());
2052 }
2053 } else {
2054 unlink(rebase_path_fixup_msg());
2055 }
2056
2057 return 0;
2058}
2059

Callers 1

update_squash_messagesFunction · 0.85

Calls 13

starts_withFunction · 0.85
seen_squashFunction · 0.85
commit_subject_lengthFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_addstrFunction · 0.85
is_fixup_flagFunction · 0.85
append_signoffFunction · 0.85
file_existsFunction · 0.85
skip_blank_linesFunction · 0.85
write_messageFunction · 0.85

Tested by

no test coverage detected