diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-10-18 09:41:20 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-10-18 11:17:08 +0200 |
commit | 284816093ee733490d2129031cb2634b0ac61f6d (patch) | |
tree | 6b2a62eb422d73be945c823f9d0dde0bb9eff005 | |
parent | ca2d34a8445bfa34e6184fa0315b6185cce0f834 (diff) | |
download | libgit2-284816093ee733490d2129031cb2634b0ac61f6d.tar.gz |
stash: refactor code that prepares commit messages
-rw-r--r-- | src/stash.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/stash.c b/src/stash.c index d619045fc..4a13d0530 100644 --- a/src/stash.c +++ b/src/stash.c @@ -437,36 +437,33 @@ cleanup: return error; } -static int prepare_worktree_commit_message( - git_buf* msg, - const char *user_message) +static int prepare_worktree_commit_message(git_buf *out, const char *user_message) { git_buf buf = GIT_BUF_INIT; - int error; - - if ((error = git_buf_set(&buf, git_buf_cstr(msg), git_buf_len(msg))) < 0) - return error; - - git_buf_clear(msg); + int error = 0; - if (!user_message) - git_buf_printf(msg, "WIP on %s", git_buf_cstr(&buf)); - else { + if (!user_message) { + git_buf_printf(&buf, "WIP on %s", git_buf_cstr(out)); + } else { const char *colon; - if ((colon = strchr(git_buf_cstr(&buf), ':')) == NULL) + if ((colon = strchr(git_buf_cstr(out), ':')) == NULL) goto cleanup; - git_buf_puts(msg, "On "); - git_buf_put(msg, git_buf_cstr(&buf), colon - buf.ptr); - git_buf_printf(msg, ": %s\n", user_message); + git_buf_puts(&buf, "On "); + git_buf_put(&buf, git_buf_cstr(out), colon - out->ptr); + git_buf_printf(&buf, ": %s\n", user_message); } - error = (git_buf_oom(msg) || git_buf_oom(&buf)) ? -1 : 0; + if (git_buf_oom(&buf)) { + error = -1; + goto cleanup; + } + + git_buf_swap(out, &buf); cleanup: git_buf_dispose(&buf); - return error; } |