rebase: clean up some warnings and memory leaks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
diff --git a/src/rebase.c b/src/rebase.c
index a27ecab..91e3d90 100644
--- a/src/rebase.c
+++ b/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;
diff --git a/tests/rebase/setup.c b/tests/rebase/setup.c
index 1756414..e72075a 100644
--- a/tests/rebase/setup.c
+++ b/tests/rebase/setup.c
@@ -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));