unpack-trees: oneway_merge to update submodules
[gitweb.git] / builtin / am.c
index 02853b3e05bfef638963dbfe91a7eccf3d40b9e6..06b824518fbdfd883e1905eaafdb0001b87f91a0 100644 (file)
@@ -708,6 +708,7 @@ static int split_mail_mbox(struct am_state *state, const char **paths,
 {
        struct child_process cp = CHILD_PROCESS_INIT;
        struct strbuf last = STRBUF_INIT;
+       int ret;
 
        cp.git_cmd = 1;
        argv_array_push(&cp.args, "mailsplit");
@@ -721,13 +722,16 @@ static int split_mail_mbox(struct am_state *state, const char **paths,
        argv_array_push(&cp.args, "--");
        argv_array_pushv(&cp.args, paths);
 
-       if (capture_command(&cp, &last, 8))
-               return -1;
+       ret = capture_command(&cp, &last, 8);
+       if (ret)
+               goto exit;
 
        state->cur = 1;
        state->last = strtol(last.buf, NULL, 10);
 
-       return 0;
+exit:
+       strbuf_release(&last);
+       return ret ? -1 : 0;
 }
 
 /**
@@ -1433,7 +1437,7 @@ static void write_index_patch(const struct am_state *state)
        if (!get_oid_tree("HEAD", &head))
                tree = lookup_tree(&head);
        else
-               tree = lookup_tree(&empty_tree_oid);
+               tree = lookup_tree(the_hash_algo->empty_tree);
 
        fp = xfopen(am_path(state, "patch"), "w");
        init_revisions(&rev_info, NULL);