}
  
        tree = parse_tree_indirect(oid);
-       prime_cache_tree(the_repository->index, tree);
+       prime_cache_tree(the_repository, the_repository->index, tree);
  
 -      if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0)
 +      if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) {
                ret = error(_("could not write index"));
 -      free((void *)desc.buffer);
 -
 -      if (ret)
 -              return ret;
 +              goto leave_reset_head;
 +      }
  
        reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
        strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
                struct string_list merge_rr = STRING_LIST_INIT_DUP;
  
                options.action = "skip";
 +              set_reflog_action(&options);
  
-               rerere_clear(&merge_rr);
+               rerere_clear(the_repository, &merge_rr);
                string_list_clear(&merge_rr, 1);
  
 -              if (reset_head(NULL, "reset", NULL, 0, NULL, NULL) < 0)
 +              if (reset_head(NULL, "reset", NULL, RESET_HEAD_HARD,
 +                             NULL, NULL) < 0)
                        die(_("could not discard worktree changes"));
-               remove_branch_state();
++              remove_branch_state(the_repository);
                if (read_basic_state(&options))
                        exit(1);
                goto run_rebase;
        case ACTION_ABORT: {
                struct string_list merge_rr = STRING_LIST_INIT_DUP;
                options.action = "abort";
 +              set_reflog_action(&options);
  
-               rerere_clear(&merge_rr);
+               rerere_clear(the_repository, &merge_rr);
                string_list_clear(&merge_rr, 1);
  
                if (read_basic_state(&options))
                        exit(1);
                if (reset_head(&options.orig_head, "reset",
 -                             options.head_name, 0, NULL, NULL) < 0)
 +                             options.head_name, RESET_HEAD_HARD,
 +                             NULL, NULL) < 0)
                        die(_("could not move back to %s"),
                            oid_to_hex(&options.orig_head));
-               remove_branch_state();
++              remove_branch_state(the_repository);
                ret = finish_rebase(&options);
                goto cleanup;
        }
 
  {
        struct lock_file index_lock = LOCK_INIT;
        int index_fd = hold_locked_index(&index_lock, 0);
-       if (read_index(&the_index) < 0) {
 -      if (read_index_preload(r->index, NULL, 0) < 0) {
++      if (read_index(r->index) < 0) {
                rollback_lock_file(&index_lock);
                return error(_("git %s: failed to read the index"),
                        _(action_name(opts)));
                goto leave_merge;
        }
  
-                     git_path_merge_head(the_repository), 0);
-       write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
 +      write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
++                    git_path_merge_head(r), 0);
++      write_message("no-ff", 5, git_path_merge_mode(r), 0);
 +
        for (j = bases; j; j = j->next)
                commit_list_insert(j->item, &reversed);
        free_commit_list(bases);
  
        if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head))
                return -1;
 -;
 +
-       if (require_clean_work_tree("rebase", "", 1, 1))
+       if (require_clean_work_tree(r, "rebase", "", 1, 1))
                return -1;
  
-       return sequencer_continue(opts);
+       return sequencer_continue(r, opts);
  }
  
  struct subject2item_entry {
 
  
  #define SUMMARY_INITIAL_COMMIT   (1 << 0)
  #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)
- void print_commit_summary(const char *prefix, const struct object_id *oid,
+ void print_commit_summary(struct repository *repo,
+                         const char *prefix,
+                         const struct object_id *oid,
                          unsigned int flags);
 +
 +int read_author_script(const char *path, char **name, char **email, char **date,
 +                     int allow_missing);
  #endif
  
  void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
 
        struct stat st;
        struct object_id oid;
  
-       if (!stat(git_path_merge_head(the_repository), &st)) {
+       if (!stat(git_path_merge_head(r), &st)) {
 +              wt_status_check_rebase(NULL, state);
                state->merge_in_progress = 1;
        } else if (wt_status_check_rebase(NULL, state)) {
                ;               /* all set */