mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-03 21:35:32 +00:00
rebase: clean up some warnings and memory leaks
This commit is contained in:
parent
e69737d760
commit
796b03bd49
40
src/rebase.c
40
src/rebase.c
@ -33,7 +33,7 @@
|
||||
|
||||
#define MSGNUM_FILE "msgnum"
|
||||
#define END_FILE "end"
|
||||
#define CMT_FILE_FMT "cmt.%d"
|
||||
#define CMT_FILE_FMT "cmt.%" PRIuZ
|
||||
#define CURRENT_FILE "current"
|
||||
#define REWRITTEN_FILE "rewritten"
|
||||
|
||||
@ -109,7 +109,10 @@ done:
|
||||
return 0;
|
||||
}
|
||||
|
||||
GIT_INLINE(int) rebase_readfile(git_buf *out, git_buf *state_path, const char *filename)
|
||||
GIT_INLINE(int) rebase_readfile(
|
||||
git_buf *out,
|
||||
git_buf *state_path,
|
||||
const char *filename)
|
||||
{
|
||||
size_t state_path_len = state_path->size;
|
||||
int error;
|
||||
@ -131,7 +134,7 @@ GIT_INLINE(int) rebase_readint(
|
||||
size_t *out, git_buf *asc_out, git_buf *state_path, const char *filename)
|
||||
{
|
||||
int32_t num;
|
||||
char *eol;
|
||||
const char *eol;
|
||||
int error = 0;
|
||||
|
||||
if ((error = rebase_readfile(asc_out, state_path, filename)) < 0)
|
||||
@ -166,7 +169,7 @@ GIT_INLINE(int) rebase_readoid(
|
||||
static int rebase_open_merge(git_rebase *rebase)
|
||||
{
|
||||
git_buf state_path = GIT_BUF_INIT, buf = GIT_BUF_INIT, cmt = GIT_BUF_INIT;
|
||||
git_oid current_id = {0};
|
||||
git_oid current_id = {{0}};
|
||||
git_rebase_operation *operation;
|
||||
size_t i, msgnum = 0, end;
|
||||
int error;
|
||||
@ -667,14 +670,12 @@ done:
|
||||
return error;
|
||||
}
|
||||
|
||||
static int normalize_checkout_opts(
|
||||
static void normalize_checkout_opts(
|
||||
git_rebase *rebase,
|
||||
git_commit *current_commit,
|
||||
git_checkout_options *checkout_opts,
|
||||
const git_checkout_options *given_checkout_opts)
|
||||
{
|
||||
git_commit *current_commit = NULL;
|
||||
int error = 0;
|
||||
|
||||
if (given_checkout_opts != NULL)
|
||||
memcpy(checkout_opts, given_checkout_opts, sizeof(git_checkout_options));
|
||||
else {
|
||||
@ -691,25 +692,11 @@ static int normalize_checkout_opts(
|
||||
if (!checkout_opts->our_label)
|
||||
checkout_opts->our_label = rebase->onto_name;
|
||||
|
||||
if (!checkout_opts->their_label) {
|
||||
git_rebase_operation *operation =
|
||||
git_array_get(rebase->operations, rebase->current);
|
||||
|
||||
if ((error = git_commit_lookup(
|
||||
¤t_commit, rebase->repo, &operation->id)) < 0)
|
||||
goto done;
|
||||
|
||||
checkout_opts->their_label =
|
||||
git__strdup(git_commit_summary(current_commit));
|
||||
GITERR_CHECK_ALLOC(checkout_opts->their_label);
|
||||
}
|
||||
if (!checkout_opts->their_label)
|
||||
checkout_opts->their_label = git_commit_summary(current_commit);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
|
||||
done:
|
||||
git_commit_free(current_commit);
|
||||
return error;
|
||||
}
|
||||
|
||||
GIT_INLINE(int) rebase_movenext(git_rebase *rebase)
|
||||
@ -768,8 +755,9 @@ static int rebase_next_merge(
|
||||
(error = rebase_setupfile(rebase, CURRENT_FILE, -1, "%.*s\n", GIT_OID_HEXSZ, current_idstr)) < 0)
|
||||
goto done;
|
||||
|
||||
if ((error = normalize_checkout_opts(rebase, &checkout_opts, given_checkout_opts)) < 0 ||
|
||||
(error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, NULL)) < 0 ||
|
||||
normalize_checkout_opts(rebase, current_commit, &checkout_opts, given_checkout_opts);
|
||||
|
||||
if ((error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, NULL)) < 0 ||
|
||||
(error = git_merge__check_result(rebase->repo, index)) < 0 ||
|
||||
(error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0)
|
||||
goto done;
|
||||
|
||||
@ -40,6 +40,7 @@ void test_rebase_setup__blocked_when_in_progress(void)
|
||||
cl_git_pass(git_merge_head_from_ref(&upstream_head, repo, upstream_ref));
|
||||
|
||||
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, signature, NULL));
|
||||
git_rebase_free(rebase);
|
||||
|
||||
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user