Merge branch 'nd/style-opening-brace'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2019 21:49:52 +0000 (13:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2019 21:49:52 +0000 (13:49 -0800)
Code clean-up.

* nd/style-opening-brace:
style: the opening '{' of a function is in a separate line

1  2 
bisect.c
builtin/push.c
convert.c
diff.c
git.c
sequencer.c
userdiff.c
diff --combined bisect.c
index 4c1b80bff666455f63ea6afa60992a3dc6f4b657,bd140cde36d499d604b87bf005dbad985f79f12e..6bf521138a590496a7b3fa7c2515ac53f815a1e3
+++ b/bisect.c
@@@ -558,7 -558,8 +558,8 @@@ struct commit_list *filter_skipped(stru
   * is increased by one between each call, but that should not matter
   * for this application.
   */
- static unsigned get_prn(unsigned count) {
+ static unsigned get_prn(unsigned count)
+ {
        count = count * 1103515245 + 12345;
        return (count/65536) % PRN_MODULO;
  }
@@@ -626,15 -627,14 +627,15 @@@ static struct commit_list *managed_skip
        return skip_away(list, count);
  }
  
 -static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
 +static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
 +                           const char *prefix,
                             const char *bad_format, const char *good_format,
                             int read_paths)
  {
        struct argv_array rev_argv = ARGV_ARRAY_INIT;
        int i;
  
 -      repo_init_revisions(the_repository, revs, prefix);
 +      repo_init_revisions(r, revs, prefix);
        revs->abbrev = 0;
        revs->commit_format = CMIT_FMT_UNSPECIFIED;
  
@@@ -724,25 -724,23 +725,25 @@@ static int bisect_checkout(const struc
        return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
  }
  
 -static struct commit *get_commit_reference(const struct object_id *oid)
 +static struct commit *get_commit_reference(struct repository *r,
 +                                         const struct object_id *oid)
  {
 -      struct commit *r = lookup_commit_reference(the_repository, oid);
 -      if (!r)
 +      struct commit *c = lookup_commit_reference(r, oid);
 +      if (!c)
                die(_("Not a valid commit name %s"), oid_to_hex(oid));
 -      return r;
 +      return c;
  }
  
 -static struct commit **get_bad_and_good_commits(int *rev_nr)
 +static struct commit **get_bad_and_good_commits(struct repository *r,
 +                                              int *rev_nr)
  {
        struct commit **rev;
        int i, n = 0;
  
        ALLOC_ARRAY(rev, 1 + good_revs.nr);
 -      rev[n++] = get_commit_reference(current_bad_oid);
 +      rev[n++] = get_commit_reference(r, current_bad_oid);
        for (i = 0; i < good_revs.nr; i++)
 -              rev[n++] = get_commit_reference(good_revs.oid + i);
 +              rev[n++] = get_commit_reference(r, good_revs.oid + i);
        *rev_nr = n;
  
        return rev;
@@@ -826,13 -824,12 +827,13 @@@ static void check_merge_bases(int rev_n
        free_commit_list(result);
  }
  
 -static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
 +static int check_ancestors(struct repository *r, int rev_nr,
 +                         struct commit **rev, const char *prefix)
  {
        struct rev_info revs;
        int res;
  
 -      bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
 +      bisect_rev_setup(r, &revs, prefix, "^%s", "%s", 0);
  
        bisect_common(&revs);
        res = (revs.commits != NULL);
   * If a merge base must be tested by the user, its source code will be
   * checked out to be tested by the user and we will exit.
   */
 -static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
 +static void check_good_are_ancestors_of_bad(struct repository *r,
 +                                          const char *prefix,
 +                                          int no_checkout)
  {
        char *filename = git_pathdup("BISECT_ANCESTORS_OK");
        struct stat st;
                goto done;
  
        /* Check if all good revs are ancestor of the bad rev. */
 -      rev = get_bad_and_good_commits(&rev_nr);
 -      if (check_ancestors(rev_nr, rev, prefix))
 +      rev = get_bad_and_good_commits(r, &rev_nr);
 +      if (check_ancestors(r, rev_nr, rev, prefix))
                check_merge_bases(rev_nr, rev, no_checkout);
        free(rev);
  
  /*
   * This does "git diff-tree --pretty COMMIT" without one fork+exec.
   */
 -static void show_diff_tree(const char *prefix, struct commit *commit)
 +static void show_diff_tree(struct repository *r,
 +                         const char *prefix,
 +                         struct commit *commit)
  {
        struct rev_info opt;
  
        /* diff-tree init */
 -      repo_init_revisions(the_repository, &opt, prefix);
 +      repo_init_revisions(r, &opt, prefix);
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
        opt.abbrev = 0;
        opt.diff = 1;
@@@ -953,7 -946,7 +954,7 @@@ void read_bisect_terms(const char **rea
   * If no_checkout is non-zero, the bisection process does not
   * checkout the trial commit but instead simply updates BISECT_HEAD.
   */
 -int bisect_next_all(const char *prefix, int no_checkout)
 +int bisect_next_all(struct repository *r, const char *prefix, int no_checkout)
  {
        struct rev_info revs;
        struct commit_list *tried;
        if (read_bisect_refs())
                die(_("reading bisect refs failed"));
  
 -      check_good_are_ancestors_of_bad(prefix, no_checkout);
 +      check_good_are_ancestors_of_bad(r, prefix, no_checkout);
  
 -      bisect_rev_setup(&revs, prefix, "%s", "^%s", 1);
 +      bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
        revs.limited = 1;
  
        bisect_common(&revs);
                exit_if_skipped_commits(tried, current_bad_oid);
                printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
                        term_bad);
 -              show_diff_tree(prefix, revs.commits->item);
 +              show_diff_tree(r, prefix, revs.commits->item);
                /* This means the bisection process succeeded. */
                exit(10);
        }
diff --combined builtin/push.c
index ee1e8420271d93620de98f74a7a515151a69cb23,759812d1d5de5d22a2f26bef776c13b88af2d325..021dd3b1e48979086de68a434d4eddbbeb074df3
@@@ -143,7 -143,9 +143,9 @@@ static int push_url_of_remote(struct re
        return remote->url_nr;
  }
  
- static NORETURN int die_push_simple(struct branch *branch, struct remote *remote) {
+ static NORETURN int die_push_simple(struct branch *branch,
+                                   struct remote *remote)
+ {
        /*
         * There's no point in using shorten_unambiguous_ref here,
         * as the ambiguity would be on the remote side, not what
@@@ -355,8 -357,7 +357,8 @@@ static int push_with_options(struct tra
  
        if (verbosity > 0)
                fprintf(stderr, _("Pushing to %s\n"), transport->url);
 -      err = transport_push(transport, rs, flags, &reject_reasons);
 +      err = transport_push(the_repository, transport,
 +                           rs, flags, &reject_reasons);
        if (err != 0) {
                fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
                error(_("failed to push some refs to '%s'"), transport->url);
diff --combined convert.c
index 5f60c11ce038d8057f82b75bcfb03737160b79c2,bc40f01eb47a9ca13a596cadb12ce288e922f8fd..0d89ae7c2302a4bff3a6fdcb4a7015a81eeb8025
+++ b/convert.c
@@@ -705,7 -705,7 +705,7 @@@ static int filter_buffer_or_fd(int in, 
  }
  
  static int apply_single_file_filter(const char *path, const char *src, size_t len, int fd,
 -                        struct strbuf *dst, const char *cmd)
 +                                  struct strbuf *dst, const char *cmd)
  {
        /*
         * Create a pipeline to have the command filter the buffer's
@@@ -778,7 -778,8 +778,8 @@@ static int start_multi_file_filter_fn(s
  
  static void handle_filter_error(const struct strbuf *filter_status,
                                struct cmd2process *entry,
-                               const unsigned int wanted_capability) {
+                               const unsigned int wanted_capability)
+ {
        if (!strcmp(filter_status->buf, "error"))
                ; /* The filter signaled a problem with the file. */
        else if (!strcmp(filter_status->buf, "abort") && wanted_capability) {
@@@ -1091,7 -1092,7 +1092,7 @@@ static int count_ident(const char *cp, 
  }
  
  static int ident_to_git(const char *path, const char *src, size_t len,
 -                        struct strbuf *buf, int ident)
 +                      struct strbuf *buf, int ident)
  {
        char *dst, *dollar;
  
  }
  
  static int ident_to_worktree(const char *path, const char *src, size_t len,
 -                             struct strbuf *buf, int ident)
 +                           struct strbuf *buf, int ident)
  {
        struct object_id oid;
        char *to_free = NULL, *dollar, *spc;
diff --combined diff.c
index f1e901a5fc3f4d4bd61fd1ce0ed69bb261424c15,b5f573cf7ae5909b119d7affb049c366308a6d5e..1b5f27636061feb0ecf273f257c5e080c5ff7481
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -291,7 -291,7 +291,7 @@@ static int parse_color_moved(const cha
                return error(_("color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed-zebra', 'plain'"));
  }
  
 -static int parse_color_moved_ws(const char *arg)
 +static unsigned parse_color_moved_ws(const char *arg)
  {
        int ret = 0;
        struct string_list l = STRING_LIST_INIT_DUP;
                        ret |= XDF_IGNORE_WHITESPACE;
                else if (!strcmp(sb.buf, "allow-indentation-change"))
                        ret |= COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE;
 -              else
 -                      error(_("ignoring unknown color-moved-ws mode '%s'"), sb.buf);
 +              else {
 +                      ret |= COLOR_MOVED_WS_ERROR;
 +                      error(_("unknown color-moved-ws mode '%s', possible values are 'ignore-space-change', 'ignore-space-at-eol', 'ignore-all-space', 'allow-indentation-change'"), sb.buf);
 +              }
  
                strbuf_release(&sb);
        }
  
        if ((ret & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) &&
 -          (ret & XDF_WHITESPACE_FLAGS))
 -              die(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
 +          (ret & XDF_WHITESPACE_FLAGS)) {
 +              error(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
 +              ret |= COLOR_MOVED_WS_ERROR;
 +      }
  
        string_list_clear(&l, 0);
  
@@@ -345,8 -341,8 +345,8 @@@ int git_diff_ui_config(const char *var
                return 0;
        }
        if (!strcmp(var, "diff.colormovedws")) {
 -              int cm = parse_color_moved_ws(value);
 -              if (cm < 0)
 +              unsigned cm = parse_color_moved_ws(value);
 +              if (cm & COLOR_MOVED_WS_ERROR)
                        return -1;
                diff_color_moved_ws_default = cm;
                return 0;
@@@ -1641,7 -1637,8 +1641,8 @@@ static void emit_hunk_header(struct emi
        strbuf_release(&msgbuf);
  }
  
- static struct diff_tempfile *claim_diff_tempfile(void) {
+ static struct diff_tempfile *claim_diff_tempfile(void)
+ {
        int i;
        for (i = 0; i < ARRAY_SIZE(diff_temp); i++)
                if (!diff_temp[i].name)
@@@ -3317,14 -3314,14 +3318,14 @@@ void diff_set_mnemonic_prefix(struct di
                options->b_prefix = b;
  }
  
 -struct userdiff_driver *get_textconv(struct index_state *istate,
 +struct userdiff_driver *get_textconv(struct repository *r,
                                     struct diff_filespec *one)
  {
        if (!DIFF_FILE_VALID(one))
                return NULL;
  
 -      diff_filespec_load_driver(one, istate);
 -      return userdiff_get_textconv(one->driver);
 +      diff_filespec_load_driver(one, r->index);
 +      return userdiff_get_textconv(r, one->driver);
  }
  
  static void builtin_diff(const char *name_a,
        }
  
        if (o->flags.allow_textconv) {
 -              textconv_one = get_textconv(o->repo->index, one);
 -              textconv_two = get_textconv(o->repo->index, two);
 +              textconv_one = get_textconv(o->repo, one);
 +              textconv_two = get_textconv(o->repo, two);
        }
  
        /* Never use a non-valid filename anywhere if at all possible */
@@@ -4823,7 -4820,8 +4824,8 @@@ static int parse_diff_filter_opt(const 
        return 0;
  }
  
- static void enable_patch_output(int *fmt) {
+ static void enable_patch_output(int *fmt)
+ {
        *fmt &= ~DIFF_FORMAT_NO_OUTPUT;
        *fmt |= DIFF_FORMAT_PATCH;
  }
@@@ -5038,13 -5036,10 +5040,13 @@@ int diff_opt_parse(struct diff_options 
        else if (skip_prefix(arg, "--color-moved=", &arg)) {
                int cm = parse_color_moved(arg);
                if (cm < 0)
 -                      die("bad --color-moved argument: %s", arg);
 +                      return error("bad --color-moved argument: %s", arg);
                options->color_moved = cm;
        } else if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
 -              options->color_moved_ws_handling = parse_color_moved_ws(arg);
 +              unsigned cm = parse_color_moved_ws(arg);
 +              if (cm & COLOR_MOVED_WS_ERROR)
 +                      return -1;
 +              options->color_moved_ws_handling = cm;
        } else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
@@@ -6441,7 -6436,7 +6443,7 @@@ int textconv_object(struct repository *
  
        df = alloc_filespec(path);
        fill_filespec(df, oid, oid_valid, mode);
 -      textconv = get_textconv(r->index, df);
 +      textconv = get_textconv(r, df);
        if (!textconv) {
                free_filespec(df);
                return 0;
diff --combined git.c
index 4d53a3d50da0c699ca83babdf12122532c3eafe9,d69beaf3b0383ed271a0751e4f9e6eccf3fb5cce..0ce0e13f0f4879ae4608bd61d3a6a1f55ef7892e
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -98,7 -98,8 +98,8 @@@ static int list_cmds(const char *spec
        return 0;
  }
  
- static void commit_pager_choice(void) {
+ static void commit_pager_choice(void)
+ {
        switch (use_pager) {
        case 0:
                setenv("GIT_PAGER", "cat", 1);
@@@ -338,27 -339,27 +339,27 @@@ static int handle_alias(int *argcp, con
                        if (ret >= 0)   /* normal exit */
                                exit(ret);
  
 -                      die_errno("while expanding alias '%s': '%s'",
 -                          alias_command, alias_string + 1);
 +                      die_errno(_("while expanding alias '%s': '%s'"),
 +                                alias_command, alias_string + 1);
                }
                count = split_cmdline(alias_string, &new_argv);
                if (count < 0)
 -                      die("Bad alias.%s string: %s", alias_command,
 -                          split_cmdline_strerror(count));
 +                      die(_("bad alias.%s string: %s"), alias_command,
 +                          _(split_cmdline_strerror(count)));
                option_count = handle_options(&new_argv, &count, &envchanged);
                if (envchanged)
 -                      die("alias '%s' changes environment variables.\n"
 -                               "You can use '!git' in the alias to do this",
 -                               alias_command);
 +                      die(_("alias '%s' changes environment variables.\n"
 +                            "You can use '!git' in the alias to do this"),
 +                          alias_command);
                memmove(new_argv - option_count, new_argv,
                                count * sizeof(char *));
                new_argv -= option_count;
  
                if (count < 1)
 -                      die("empty alias for %s", alias_command);
 +                      die(_("empty alias for %s"), alias_command);
  
                if (!strcmp(alias_command, new_argv[0]))
 -                      die("recursive alias: %s", alias_command);
 +                      die(_("recursive alias: %s"), alias_command);
  
                trace_argv_printf(new_argv,
                                  "trace: alias expansion: %s =>",
@@@ -409,7 -410,7 +410,7 @@@ static int run_builtin(struct cmd_struc
  
        if (!help && get_super_prefix()) {
                if (!(p->option & SUPPORT_SUPER_PREFIX))
 -                      die("%s doesn't support --super-prefix", p->cmd);
 +                      die(_("%s doesn't support --super-prefix"), p->cmd);
        }
  
        if (!help && p->option & NEED_WORK_TREE)
  
        /* Check for ENOSPC and EIO errors.. */
        if (fflush(stdout))
 -              die_errno("write failure on standard output");
 +              die_errno(_("write failure on standard output"));
        if (ferror(stdout))
 -              die("unknown write failure on standard output");
 +              die(_("unknown write failure on standard output"));
        if (fclose(stdout))
 -              die_errno("close failed on standard output");
 +              die_errno(_("close failed on standard output"));
        return 0;
  }
  
@@@ -654,7 -655,7 +655,7 @@@ static void execv_dashed_external(cons
        int status;
  
        if (get_super_prefix())
 -              die("%s doesn't support --super-prefix", argv[0]);
 +              die(_("%s doesn't support --super-prefix"), argv[0]);
  
        if (use_pager == -1 && !is_builtin(argv[0]))
                use_pager = check_pager_config(argv[0]);
@@@ -766,7 -767,7 +767,7 @@@ int cmd_main(int argc, const char **arg
        if (skip_prefix(cmd, "git-", &cmd)) {
                argv[0] = cmd;
                handle_builtin(argc, argv);
 -              die("cannot handle %s as a builtin", cmd);
 +              die(_("cannot handle %s as a builtin"), cmd);
        }
  
        /* Look for flags.. */
        } else {
                /* The user didn't specify a command; give them help */
                commit_pager_choice();
 -              printf("usage: %s\n\n", git_usage_string);
 +              printf(_("usage: %s\n\n"), git_usage_string);
                list_common_cmds_help();
                printf("\n%s\n", _(git_more_info_string));
                exit(1);
diff --combined sequencer.c
index b68bca0bef927f0ebb2d8762f658946be7107fcb,55b609a7f44c950c967a6b264c8ed45ff8c80a92..4f1cb5e38fe77171cbcb7c070a1b5557d0bdcd6a
@@@ -356,8 -356,7 +356,8 @@@ static void free_message(struct commit 
        unuse_commit_buffer(commit, msg->message);
  }
  
 -static void print_advice(int show_hint, struct replay_opts *opts)
 +static void print_advice(struct repository *r, int show_hint,
 +                       struct replay_opts *opts)
  {
        char *msg = getenv("GIT_CHERRY_PICK_HELP");
  
                 * (typically rebase --interactive) wants to take care
                 * of the commit itself so remove CHERRY_PICK_HEAD
                 */
 -              unlink(git_path_cherry_pick_head(the_repository));
 +              unlink(git_path_cherry_pick_head(r));
                return;
        }
  
@@@ -441,14 -440,14 +441,14 @@@ static int read_oneliner(struct strbuf 
        return 1;
  }
  
 -static struct tree *empty_tree(void)
 +static struct tree *empty_tree(struct repository *r)
  {
 -      return lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
 +      return lookup_tree(r, the_hash_algo->empty_tree);
  }
  
 -static int error_dirty_index(struct replay_opts *opts)
 +static int error_dirty_index(struct index_state *istate, struct replay_opts *opts)
  {
 -      if (read_cache_unmerged())
 +      if (read_index_unmerged(istate))
                return error_resolve_conflict(_(action_name(opts)));
  
        error(_("your local changes would be overwritten by %s."),
@@@ -473,18 -472,15 +473,18 @@@ static void update_abort_safety_file(vo
                write_file(git_path_abort_safety_file(), "%s", "");
  }
  
 -static int fast_forward_to(const struct object_id *to, const struct object_id *from,
 -                      int unborn, struct replay_opts *opts)
 +static int fast_forward_to(struct repository *r,
 +                         const struct object_id *to,
 +                         const struct object_id *from,
 +                         int unborn,
 +                         struct replay_opts *opts)
  {
        struct ref_transaction *transaction;
        struct strbuf sb = STRBUF_INIT;
        struct strbuf err = STRBUF_INIT;
  
 -      read_index(&the_index);
 -      if (checkout_fast_forward(the_repository, from, to, 1))
 +      read_index(r->index);
 +      if (checkout_fast_forward(r, from, to, 1))
                return -1; /* the callee should have complained already */
  
        strbuf_addf(&sb, _("%s: fast-forward"), _(action_name(opts)));
        return 0;
  }
  
 -void append_conflicts_hint(struct strbuf *msgbuf)
 +void append_conflicts_hint(struct index_state *istate,
 +                         struct strbuf *msgbuf)
  {
        int i;
  
        strbuf_addch(msgbuf, '\n');
        strbuf_commented_addf(msgbuf, "Conflicts:\n");
 -      for (i = 0; i < active_nr;) {
 -              const struct cache_entry *ce = active_cache[i++];
 +      for (i = 0; i < istate->cache_nr;) {
 +              const struct cache_entry *ce = istate->cache[i++];
                if (ce_stage(ce)) {
                        strbuf_commented_addf(msgbuf, "\t%s\n", ce->name);
 -                      while (i < active_nr && !strcmp(ce->name,
 -                                                      active_cache[i]->name))
 +                      while (i < istate->cache_nr &&
 +                             !strcmp(ce->name, istate->cache[i]->name))
                                i++;
                }
        }
  }
  
 -static int do_recursive_merge(struct commit *base, struct commit *next,
 +static int do_recursive_merge(struct repository *r,
 +                            struct commit *base, struct commit *next,
                              const char *base_label, const char *next_label,
                              struct object_id *head, struct strbuf *msgbuf,
                              struct replay_opts *opts)
        if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
  
 -      read_cache();
 +      read_index(r->index);
  
        init_merge_options(&o);
        o.ancestor = base ? base_label : "(empty tree)";
        o.show_rename_progress = 1;
  
        head_tree = parse_tree_indirect(head);
 -      next_tree = next ? get_commit_tree(next) : empty_tree();
 -      base_tree = base ? get_commit_tree(base) : empty_tree();
 +      next_tree = next ? get_commit_tree(next) : empty_tree(r);
 +      base_tree = base ? get_commit_tree(base) : empty_tree(r);
  
        for (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++)
                parse_merge_opt(&o, *xopt);
                return clean;
        }
  
 -      if (write_locked_index(&the_index, &index_lock,
 +      if (write_locked_index(r->index, &index_lock,
                               COMMIT_LOCK | SKIP_IF_UNCHANGED))
                /*
                 * TRANSLATORS: %s will be "revert", "cherry-pick" or
                        _(action_name(opts)));
  
        if (!clean)
 -              append_conflicts_hint(msgbuf);
 +              append_conflicts_hint(r->index, msgbuf);
  
        return !clean;
  }
  
 -static struct object_id *get_cache_tree_oid(void)
 +static struct object_id *get_cache_tree_oid(struct index_state *istate)
  {
 -      if (!active_cache_tree)
 -              active_cache_tree = cache_tree();
 +      if (!istate->cache_tree)
 +              istate->cache_tree = cache_tree();
  
 -      if (!cache_tree_fully_valid(active_cache_tree))
 -              if (cache_tree_update(&the_index, 0)) {
 +      if (!cache_tree_fully_valid(istate->cache_tree))
 +              if (cache_tree_update(istate, 0)) {
                        error(_("unable to update cache tree"));
                        return NULL;
                }
  
 -      return &active_cache_tree->oid;
 +      return &istate->cache_tree->oid;
  }
  
 -static int is_index_unchanged(void)
 +static int is_index_unchanged(struct repository *r)
  {
        struct object_id head_oid, *cache_tree_oid;
        struct commit *head_commit;
 +      struct index_state *istate = r->index;
  
        if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
                return error(_("could not resolve HEAD commit"));
  
 -      head_commit = lookup_commit(the_repository, &head_oid);
 +      head_commit = lookup_commit(r, &head_oid);
  
        /*
         * If head_commit is NULL, check_commit, called from
        if (parse_commit(head_commit))
                return -1;
  
 -      if (!(cache_tree_oid = get_cache_tree_oid()))
 +      if (!(cache_tree_oid = get_cache_tree_oid(istate)))
                return -1;
  
        return oideq(cache_tree_oid, get_commit_tree_oid(head_commit));
@@@ -895,9 -888,7 +895,9 @@@ static int run_command_silent_on_succes
   * interactive rebase: in that case, we will want to retain the
   * author metadata.
   */
 -static int run_git_commit(const char *defmsg, struct replay_opts *opts,
 +static int run_git_commit(struct repository *r,
 +                        const char *defmsg,
 +                        struct replay_opts *opts,
                          unsigned int flags)
  {
        struct child_process cmd = CHILD_PROCESS_INIT;
                if (!defmsg)
                        BUG("root commit without message");
  
 -              if (!(cache_tree_oid = get_cache_tree_oid()))
 +              if (!(cache_tree_oid = get_cache_tree_oid(r->index)))
                        res = -1;
  
                if (!res)
@@@ -1129,9 -1120,7 +1129,9 @@@ void commit_post_rewrite(const struct c
        run_rewrite_hook(&old_head->object.oid, new_head);
  }
  
 -static int run_prepare_commit_msg_hook(struct strbuf *msg, const char *commit)
 +static int run_prepare_commit_msg_hook(struct repository *r,
 +                                     struct strbuf *msg,
 +                                     const char *commit)
  {
        struct argv_array hook_env = ARGV_ARRAY_INIT;
        int ret;
        if (write_message(msg->buf, msg->len, name, 0))
                return -1;
  
 -      argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", get_index_file());
 +      argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", r->index_file);
        argv_array_push(&hook_env, "GIT_EDITOR=:");
        if (commit)
                ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name,
@@@ -1197,9 -1186,7 +1197,9 @@@ static const char *implicit_ident_advic
  
  }
  
 -void print_commit_summary(const char *prefix, const struct object_id *oid,
 +void print_commit_summary(struct repository *r,
 +                        const char *prefix,
 +                        const struct object_id *oid,
                          unsigned int flags)
  {
        struct rev_info rev;
        struct strbuf author_ident = STRBUF_INIT;
        struct strbuf committer_ident = STRBUF_INIT;
  
 -      commit = lookup_commit(the_repository, oid);
 +      commit = lookup_commit(r, oid);
        if (!commit)
                die(_("couldn't look up newly created commit"));
        if (parse_commit(commit))
        strbuf_release(&author_ident);
        strbuf_release(&committer_ident);
  
 -      repo_init_revisions(the_repository, &rev, prefix);
 +      repo_init_revisions(r, &rev, prefix);
        setup_revisions(0, NULL, &rev, NULL);
  
        rev.diff = 1;
        strbuf_release(&format);
  }
  
 -static int parse_head(struct commit **head)
 +static int parse_head(struct repository *r, struct commit **head)
  {
        struct commit *current_head;
        struct object_id oid;
        if (get_oid("HEAD", &oid)) {
                current_head = NULL;
        } else {
 -              current_head = lookup_commit_reference(the_repository, &oid);
 +              current_head = lookup_commit_reference(r, &oid);
                if (!current_head)
                        return error(_("could not parse HEAD"));
                if (!oideq(&oid, &current_head->object.oid)) {
   *   0 - success
   *   1 - run 'git commit'
   */
 -static int try_to_commit(struct strbuf *msg, const char *author,
 +static int try_to_commit(struct repository *r,
 +                       struct strbuf *msg, const char *author,
                         struct replay_opts *opts, unsigned int flags,
                         struct object_id *oid)
  {
        enum commit_msg_cleanup_mode cleanup;
        int res = 0;
  
 -      if (parse_head(&current_head))
 +      if (parse_head(r, &current_head))
                return -1;
  
        if (flags & AMEND_MSG) {
                commit_list_insert(current_head, &parents);
        }
  
 -      if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL)) {
 +      if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
                res = error(_("git write-tree failed to write a tree"));
                goto out;
        }
        }
  
        if (find_hook("prepare-commit-msg")) {
 -              res = run_prepare_commit_msg_hook(msg, hook_commit);
 +              res = run_prepare_commit_msg_hook(r, msg, hook_commit);
                if (res)
                        goto out;
                if (strbuf_read_file(&commit_msg, git_path_commit_editmsg(),
@@@ -1416,8 -1402,7 +1416,8 @@@ out
        return res;
  }
  
 -static int do_commit(const char *msg_file, const char *author,
 +static int do_commit(struct repository *r,
 +                   const char *msg_file, const char *author,
                     struct replay_opts *opts, unsigned int flags)
  {
        int res = 1;
                                             "from '%s'"),
                                           msg_file);
  
 -              res = try_to_commit(msg_file ? &sb : NULL, author, opts, flags,
 -                                  &oid);
 +              res = try_to_commit(r, msg_file ? &sb : NULL,
 +                                  author, opts, flags, &oid);
                strbuf_release(&sb);
                if (!res) {
 -                      unlink(git_path_cherry_pick_head(the_repository));
 -                      unlink(git_path_merge_msg(the_repository));
 +                      unlink(git_path_cherry_pick_head(r));
 +                      unlink(git_path_merge_msg(r));
                        if (!is_rebase_i(opts))
 -                              print_commit_summary(NULL, &oid,
 +                              print_commit_summary(r, NULL, &oid,
                                                SUMMARY_SHOW_AUTHOR_DATE);
                        return res;
                }
        }
        if (res == 1)
 -              return run_git_commit(msg_file, opts, flags);
 +              return run_git_commit(r, msg_file, opts, flags);
  
        return res;
  }
@@@ -1473,9 -1458,7 +1473,9 @@@ static int is_original_commit_empty(str
  /*
   * Do we run "git commit" with "--allow-empty"?
   */
 -static int allow_empty(struct replay_opts *opts, struct commit *commit)
 +static int allow_empty(struct repository *r,
 +                     struct replay_opts *opts,
 +                     struct commit *commit)
  {
        int index_unchanged, empty_commit;
  
        if (!opts->allow_empty)
                return 0; /* let "git commit" barf as necessary */
  
 -      index_unchanged = is_index_unchanged();
 +      index_unchanged = is_index_unchanged(r);
        if (index_unchanged < 0)
                return index_unchanged;
        if (!index_unchanged)
@@@ -1596,10 -1579,8 +1596,10 @@@ static int is_pick_or_similar(enum todo
        }
  }
  
 -static int update_squash_messages(enum todo_command command,
 -              struct commit *commit, struct replay_opts *opts)
 +static int update_squash_messages(struct repository *r,
 +                                enum todo_command command,
 +                                struct commit *commit,
 +                                struct replay_opts *opts)
  {
        struct strbuf buf = STRBUF_INIT;
        int res;
  
                if (get_oid("HEAD", &head))
                        return error(_("need a HEAD to fixup"));
 -              if (!(head_commit = lookup_commit_reference(the_repository, &head)))
 +              if (!(head_commit = lookup_commit_reference(r, &head)))
                        return error(_("could not read HEAD"));
                if (!(head_message = get_commit_buffer(head_commit, NULL)))
                        return error(_("could not read HEAD's commit message"));
        return res;
  }
  
- static void flush_rewritten_pending(void) {
+ static void flush_rewritten_pending(void)
+ {
        struct strbuf buf = STRBUF_INIT;
        struct object_id newoid;
        FILE *out;
  }
  
  static void record_in_rewritten(struct object_id *oid,
-               enum todo_command next_command) {
+               enum todo_command next_command)
+ {
        FILE *out = fopen_or_warn(rebase_path_rewritten_pending(), "a");
  
        if (!out)
                flush_rewritten_pending();
  }
  
 -static int do_pick_commit(enum todo_command command, struct commit *commit,
 -              struct replay_opts *opts, int final_fixup)
 +static int do_pick_commit(struct repository *r,
 +                        enum todo_command command,
 +                        struct commit *commit,
 +                        struct replay_opts *opts,
 +                        int final_fixup)
  {
        unsigned int flags = opts->edit ? EDIT_MSG : 0;
 -      const char *msg_file = opts->edit ? NULL : git_path_merge_msg(the_repository);
 +      const char *msg_file = opts->edit ? NULL : git_path_merge_msg(r);
        struct object_id head;
        struct commit *base, *next, *parent;
        const char *base_label, *next_label;
                 * that represents the "current" state for merge-recursive
                 * to work on.
                 */
 -              if (write_index_as_tree(&head, &the_index, get_index_file(), 0, NULL))
 +              if (write_index_as_tree(&head, r->index, r->index_file, 0, NULL))
                        return error(_("your index file is unmerged."));
        } else {
                unborn = get_oid("HEAD", &head);
                        unborn = 1;
                } else if (unborn)
                        oidcpy(&head, the_hash_algo->empty_tree);
 -              if (index_differs_from(unborn ? empty_tree_oid_hex() : "HEAD",
 +              if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
                                       NULL, 0))
 -                      return error_dirty_index(opts);
 +                      return error_dirty_index(r->index, opts);
        }
 -      discard_cache();
 +      discard_index(r->index);
  
        if (!commit->parents)
                parent = NULL;
             (!parent && unborn))) {
                if (is_rebase_i(opts))
                        write_author_script(msg.message);
 -              res = fast_forward_to(&commit->object.oid, &head, unborn,
 +              res = fast_forward_to(r, &commit->object.oid, &head, unborn,
                        opts);
                if (res || command != TODO_REWORD)
                        goto leave;
        if (command == TODO_REWORD)
                flags |= EDIT_MSG | VERIFY_MSG;
        else if (is_fixup(command)) {
 -              if (update_squash_messages(command, commit, opts))
 +              if (update_squash_messages(r, command, commit, opts))
                        return -1;
                flags |= AMEND_MSG;
                if (!final_fixup)
                        flags |= CLEANUP_MSG;
                        msg_file = rebase_path_fixup_msg();
                } else {
 -                      const char *dest = git_path_squash_msg(the_repository);
 +                      const char *dest = git_path_squash_msg(r);
                        unlink(dest);
                        if (copy_file(dest, rebase_path_squash_msg(), 0666))
                                return error(_("could not rename '%s' to '%s'"),
                                             rebase_path_squash_msg(), dest);
 -                      unlink(git_path_merge_msg(the_repository));
 +                      unlink(git_path_merge_msg(r));
                        msg_file = dest;
                        flags |= EDIT_MSG;
                }
        if (is_rebase_i(opts) && write_author_script(msg.message) < 0)
                res = -1;
        else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) {
 -              res = do_recursive_merge(base, next, base_label, next_label,
 +              res = do_recursive_merge(r, base, next, base_label, next_label,
                                         &head, &msgbuf, opts);
                if (res < 0)
                        goto leave;
  
                res |= write_message(msgbuf.buf, msgbuf.len,
 -                                   git_path_merge_msg(the_repository), 0);
 +                                   git_path_merge_msg(r), 0);
        } else {
                struct commit_list *common = NULL;
                struct commit_list *remotes = NULL;
  
                res = write_message(msgbuf.buf, msgbuf.len,
 -                                  git_path_merge_msg(the_repository), 0);
 +                                  git_path_merge_msg(r), 0);
  
                commit_list_insert(base, &common);
                commit_list_insert(next, &remotes);
 -              res |= try_merge_command(the_repository, opts->strategy,
 +              res |= try_merge_command(r, opts->strategy,
                                         opts->xopts_nr, (const char **)opts->xopts,
                                        common, oid_to_hex(&head), remotes);
                free_commit_list(common);
                      ? _("could not revert %s... %s")
                      : _("could not apply %s... %s"),
                      short_commit_name(commit), msg.subject);
 -              print_advice(res == 1, opts);
 -              repo_rerere(the_repository, opts->allow_rerere_auto);
 +              print_advice(r, res == 1, opts);
 +              repo_rerere(r, opts->allow_rerere_auto);
                goto leave;
        }
  
 -      allow = allow_empty(opts, commit);
 +      allow = allow_empty(r, opts, commit);
        if (allow < 0) {
                res = allow;
                goto leave;
        if (!opts->no_commit) {
  fast_forward_edit:
                if (author || command == TODO_REVERT || (flags & AMEND_MSG))
 -                      res = do_commit(msg_file, author, opts, flags);
 +                      res = do_commit(r, msg_file, author, opts, flags);
                else
                        res = error(_("unable to parse commit author"));
        }
@@@ -1987,19 -1967,18 +1989,19 @@@ static int prepare_revs(struct replay_o
        return 0;
  }
  
 -static int read_and_refresh_cache(struct replay_opts *opts)
 +static int read_and_refresh_cache(struct repository *r,
 +                                struct replay_opts *opts)
  {
        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(r->index) < 0) {
                rollback_lock_file(&index_lock);
                return error(_("git %s: failed to read the index"),
                        _(action_name(opts)));
        }
 -      refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
 +      refresh_index(r->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
        if (index_fd >= 0) {
 -              if (write_locked_index(&the_index, &index_lock,
 +              if (write_locked_index(r->index, &index_lock,
                                       COMMIT_LOCK | SKIP_IF_UNCHANGED)) {
                        return error(_("git %s: failed to refresh the index"),
                                _(action_name(opts)));
@@@ -2044,8 -2023,7 +2046,8 @@@ static struct todo_item *append_new_tod
        return todo_list->items + todo_list->nr++;
  }
  
 -static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
 +static int parse_insn_line(struct repository *r, struct todo_item *item,
 +                         const char *bol, char *eol)
  {
        struct object_id commit_oid;
        char *end_of_object_name;
        if (status < 0)
                return -1;
  
 -      item->commit = lookup_commit_reference(the_repository, &commit_oid);
 +      item->commit = lookup_commit_reference(r, &commit_oid);
        return !item->commit;
  }
  
 -static int parse_insn_buffer(char *buf, struct todo_list *todo_list)
 +static int parse_insn_buffer(struct repository *r, char *buf,
 +                           struct todo_list *todo_list)
  {
        struct todo_item *item;
        char *p = buf, *next_p;
  
                item = append_new_todo(todo_list);
                item->offset_in_buf = p - todo_list->buf.buf;
 -              if (parse_insn_line(item, p, eol)) {
 +              if (parse_insn_line(r, item, p, eol)) {
                        res = error(_("invalid line %d: %.*s"),
                                i, (int)(eol - p), p);
                        item->command = TODO_NOOP;
@@@ -2212,9 -2189,8 +2214,9 @@@ static ssize_t strbuf_read_file_or_whin
        return len;
  }
  
 -static int read_populate_todo(struct todo_list *todo_list,
 -                      struct replay_opts *opts)
 +static int read_populate_todo(struct repository *r,
 +                            struct todo_list *todo_list,
 +                            struct replay_opts *opts)
  {
        struct stat st;
        const char *todo_file = get_todo_path(opts);
                return error(_("could not stat '%s'"), todo_file);
        fill_stat_data(&todo_list->stat, &st);
  
 -      res = parse_insn_buffer(todo_list->buf.buf, todo_list);
 +      res = parse_insn_buffer(r, todo_list->buf.buf, todo_list);
        if (res) {
                if (is_rebase_i(opts))
                        return error(_("please fix this using "
                FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
  
                if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
 -                              !parse_insn_buffer(done.buf.buf, &done))
 +                  !parse_insn_buffer(r, done.buf.buf, &done))
                        todo_list->done_nr = count_commands(&done);
                else
                        todo_list->done_nr = 0;
@@@ -2577,12 -2553,12 +2579,12 @@@ static int reset_for_rollback(const str
        return run_command_v_opt(argv, RUN_GIT_CMD);
  }
  
 -static int rollback_single_pick(void)
 +static int rollback_single_pick(struct repository *r)
  {
        struct object_id head_oid;
  
 -      if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
 -          !file_exists(git_path_revert_head(the_repository)))
 +      if (!file_exists(git_path_cherry_pick_head(r)) &&
 +          !file_exists(git_path_revert_head(r)))
                return error(_("no cherry-pick or revert in progress"));
        if (read_ref_full("HEAD", 0, &head_oid, NULL))
                return error(_("cannot resolve HEAD"));
        return reset_for_rollback(&head_oid);
  }
  
 -int sequencer_rollback(struct replay_opts *opts)
 +int sequencer_rollback(struct repository *r, struct replay_opts *opts)
  {
        FILE *f;
        struct object_id oid;
                 * If CHERRY_PICK_HEAD or REVERT_HEAD indicates
                 * a single-cherry-pick in progress, abort that.
                 */
 -              return rollback_single_pick();
 +              return rollback_single_pick(r);
        }
        if (!f)
                return error_errno(_("cannot open '%s'"), git_path_head_file());
@@@ -2720,9 -2696,7 +2722,9 @@@ static int save_opts(struct replay_opt
        return res;
  }
  
 -static int make_patch(struct commit *commit, struct replay_opts *opts)
 +static int make_patch(struct repository *r,
 +                    struct commit *commit,
 +                    struct replay_opts *opts)
  {
        struct strbuf buf = STRBUF_INIT;
        struct rev_info log_tree_opt;
  
        strbuf_addf(&buf, "%s/patch", get_dir(opts));
        memset(&log_tree_opt, 0, sizeof(log_tree_opt));
 -      repo_init_revisions(the_repository, &log_tree_opt, NULL);
 +      repo_init_revisions(r, &log_tree_opt, NULL);
        log_tree_opt.abbrev = 0;
        log_tree_opt.diff = 1;
        log_tree_opt.diffopt.output_format = DIFF_FORMAT_PATCH;
@@@ -2778,19 -2752,17 +2780,19 @@@ static int intend_to_amend(void
        return write_message(p, strlen(p), rebase_path_amend(), 1);
  }
  
 -static int error_with_patch(struct commit *commit,
 -      const char *subject, int subject_len,
 -      struct replay_opts *opts, int exit_code, int to_amend)
 +static int error_with_patch(struct repository *r,
 +                          struct commit *commit,
 +                          const char *subject, int subject_len,
 +                          struct replay_opts *opts,
 +                          int exit_code, int to_amend)
  {
        if (commit) {
 -              if (make_patch(commit, opts))
 +              if (make_patch(r, commit, opts))
                        return -1;
        } else if (copy_file(rebase_path_message(),
 -                           git_path_merge_msg(the_repository), 0666))
 +                           git_path_merge_msg(r), 0666))
                return error(_("unable to copy '%s' to '%s'"),
 -                           git_path_merge_msg(the_repository), rebase_path_message());
 +                           git_path_merge_msg(r), rebase_path_message());
  
        if (to_amend) {
                if (intend_to_amend())
        return exit_code;
  }
  
 -static int error_failed_squash(struct commit *commit,
 -      struct replay_opts *opts, int subject_len, const char *subject)
 +static int error_failed_squash(struct repository *r,
 +                             struct commit *commit,
 +                             struct replay_opts *opts,
 +                             int subject_len,
 +                             const char *subject)
  {
        if (copy_file(rebase_path_message(), rebase_path_squash_msg(), 0666))
                return error(_("could not copy '%s' to '%s'"),
                        rebase_path_squash_msg(), rebase_path_message());
 -      unlink(git_path_merge_msg(the_repository));
 -      if (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666))
 +      unlink(git_path_merge_msg(r));
 +      if (copy_file(git_path_merge_msg(r), rebase_path_message(), 0666))
                return error(_("could not copy '%s' to '%s'"),
                             rebase_path_message(),
 -                           git_path_merge_msg(the_repository));
 -      return error_with_patch(commit, subject, subject_len, opts, 1, 0);
 +                           git_path_merge_msg(r));
 +      return error_with_patch(r, commit, subject, subject_len, opts, 1, 0);
  }
  
 -static int do_exec(const char *command_line)
 +static int do_exec(struct repository *r, const char *command_line)
  {
        struct argv_array child_env = ARGV_ARRAY_INIT;
        const char *child_argv[] = { NULL, NULL };
                                          child_env.argv);
  
        /* force re-reading of the cache */
 -      if (discard_cache() < 0 || read_cache() < 0)
 +      if (discard_index(r->index) < 0 || read_index(r->index) < 0)
                return error(_("could not read index"));
  
 -      dirty = require_clean_work_tree("rebase", NULL, 1, 1);
 +      dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1);
  
        if (status) {
                warning(_("execution failed: %s\n%s"
@@@ -2922,9 -2891,9 +2924,9 @@@ static int safe_append(const char *file
        return 0;
  }
  
 -static int do_label(const char *name, int len)
 +static int do_label(struct repository *r, const char *name, int len)
  {
 -      struct ref_store *refs = get_main_ref_store(the_repository);
 +      struct ref_store *refs = get_main_ref_store(r);
        struct ref_transaction *transaction;
        struct strbuf ref_name = STRBUF_INIT, err = STRBUF_INIT;
        struct strbuf msg = STRBUF_INIT;
  static const char *reflog_message(struct replay_opts *opts,
        const char *sub_action, const char *fmt, ...);
  
 -static int do_reset(const char *name, int len, struct replay_opts *opts)
 +static int do_reset(struct repository *r,
 +                  const char *name, int len,
 +                  struct replay_opts *opts)
  {
        struct strbuf ref_name = STRBUF_INIT;
        struct object_id oid;
        memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
        setup_unpack_trees_porcelain(&unpack_tree_opts, "reset");
        unpack_tree_opts.head_idx = 1;
 -      unpack_tree_opts.src_index = &the_index;
 -      unpack_tree_opts.dst_index = &the_index;
 +      unpack_tree_opts.src_index = r->index;
 +      unpack_tree_opts.dst_index = r->index;
        unpack_tree_opts.fn = oneway_merge;
        unpack_tree_opts.merge = 1;
        unpack_tree_opts.update = 1;
  
 -      if (read_cache_unmerged()) {
 +      if (read_index_unmerged(r->index)) {
                rollback_lock_file(&lock);
                strbuf_release(&ref_name);
                return error_resolve_conflict(_(action_name(opts)));
        }
  
        tree = parse_tree_indirect(&oid);
 -      prime_cache_tree(&the_index, tree);
 +      prime_cache_tree(r, r->index, tree);
  
 -      if (write_locked_index(&the_index, &lock, COMMIT_LOCK) < 0)
 +      if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0)
                ret = error(_("could not write index"));
        free((void *)desc.buffer);
  
@@@ -3079,9 -3046,7 +3081,9 @@@ static struct commit *lookup_label(cons
        return commit;
  }
  
 -static int do_merge(struct commit *commit, const char *arg, int arg_len,
 +static int do_merge(struct repository *r,
 +                  struct commit *commit,
 +                  const char *arg, int arg_len,
                    int flags, struct replay_opts *opts)
  {
        int run_commit_flags = (flags & TODO_EDIT_MERGE_MSG) ?
                        ret = error(_("octopus merge cannot be executed on "
                                      "top of a [new root]"));
                else
 -                      ret = fast_forward_to(&to_merge->item->object.oid,
 +                      ret = fast_forward_to(r, &to_merge->item->object.oid,
                                              &head_commit->object.oid, 0,
                                              opts);
                goto leave_merge;
                write_author_script(message);
                find_commit_subject(message, &body);
                len = strlen(body);
 -              ret = write_message(body, len, git_path_merge_msg(the_repository), 0);
 +              ret = write_message(body, len, git_path_merge_msg(r), 0);
                unuse_commit_buffer(commit, message);
                if (ret) {
                        error_errno(_("could not write '%s'"),
 -                                  git_path_merge_msg(the_repository));
 +                                  git_path_merge_msg(r));
                        goto leave_merge;
                }
        } else {
                        len = buf.len;
                }
  
 -              ret = write_message(p, len, git_path_merge_msg(the_repository), 0);
 +              ret = write_message(p, len, git_path_merge_msg(r), 0);
                strbuf_release(&buf);
                if (ret) {
                        error_errno(_("could not write '%s'"),
 -                                  git_path_merge_msg(the_repository));
 +                                  git_path_merge_msg(r));
                        goto leave_merge;
                }
        }
  
        if (can_fast_forward) {
                rollback_lock_file(&lock);
 -              ret = fast_forward_to(&commit->object.oid,
 +              ret = fast_forward_to(r, &commit->object.oid,
                                      &head_commit->object.oid, 0, opts);
                goto leave_merge;
        }
                argv_array_push(&cmd.args, "--no-log");
                argv_array_push(&cmd.args, "--no-stat");
                argv_array_push(&cmd.args, "-F");
 -              argv_array_push(&cmd.args, git_path_merge_msg(the_repository));
 +              argv_array_push(&cmd.args, git_path_merge_msg(r));
                if (opts->gpg_sign)
                        argv_array_push(&cmd.args, opts->gpg_sign);
  
                                        oid_to_hex(&j->item->object.oid));
  
                strbuf_release(&ref_name);
 -              unlink(git_path_cherry_pick_head(the_repository));
 +              unlink(git_path_cherry_pick_head(r));
                rollback_lock_file(&lock);
  
                rollback_lock_file(&lock);
                ret = run_command(&cmd);
  
                /* force re-reading of the cache */
 -              if (!ret && (discard_cache() < 0 || read_cache() < 0))
 +              if (!ret && (discard_index(r->index) < 0 ||
 +                           read_index(r->index) < 0))
                        ret = error(_("could not read index"));
                goto leave_merge;
        }
        }
  
        write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,
 -                    git_path_merge_head(the_repository), 0);
 -      write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
 +                    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);
  
 -      read_cache();
 +      read_index(r->index);
        init_merge_options(&o);
        o.branch1 = "HEAD";
        o.branch2 = ref_name.buf;
         */
        ret = !ret;
  
 -      if (active_cache_changed &&
 -          write_locked_index(&the_index, &lock, COMMIT_LOCK)) {
 +      if (r->index->cache_changed &&
 +          write_locked_index(r->index, &lock, COMMIT_LOCK)) {
                ret = error(_("merge: Unable to write new index file"));
                goto leave_merge;
        }
  
        rollback_lock_file(&lock);
        if (ret)
 -              repo_rerere(the_repository, opts->allow_rerere_auto);
 +              repo_rerere(r, opts->allow_rerere_auto);
        else
                /*
                 * In case of problems, we now want to return a positive
                 * value (a negative one would indicate that the `merge`
                 * command needs to be rescheduled).
                 */
 -              ret = !!run_git_commit(git_path_merge_msg(the_repository), opts,
 -                                   run_commit_flags);
 +              ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
 +                                     run_commit_flags);
  
  leave_merge:
        strbuf_release(&ref_name);
@@@ -3487,14 -3451,14 +3489,14 @@@ static int checkout_onto(struct replay_
        return update_ref(NULL, "ORIG_HEAD", &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR);
  }
  
 -static int stopped_at_head(void)
 +static int stopped_at_head(struct repository *r)
  {
        struct object_id head;
        struct commit *commit;
        struct commit_message message;
  
        if (get_oid("HEAD", &head) ||
 -          !(commit = lookup_commit(the_repository, &head)) ||
 +          !(commit = lookup_commit(r, &head)) ||
            parse_commit(commit) || get_message(commit, &message))
                fprintf(stderr, _("Stopped at HEAD\n"));
        else {
@@@ -3516,9 -3480,7 +3518,9 @@@ N_("Could not execute the todo command\
  "    git rebase --edit-todo\n"
  "    git rebase --continue\n");
  
 -static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
 +static int pick_commits(struct repository *r,
 +                      struct todo_list *todo_list,
 +                      struct replay_opts *opts)
  {
        int res = 0, reschedule = 0;
  
        if (opts->allow_ff)
                assert(!(opts->signoff || opts->no_commit ||
                                opts->record_origin || opts->edit));
 -      if (read_and_refresh_cache(opts))
 +      if (read_and_refresh_cache(r, opts))
                return -1;
  
        while (todo_list->current < todo_list->nr) {
                        delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
  
                        if (item->command == TODO_BREAK)
 -                              return stopped_at_head();
 +                              return stopped_at_head(r);
                }
                if (item->command <= TODO_SQUASH) {
                        if (is_rebase_i(opts))
                                setenv("GIT_REFLOG_ACTION", reflog_message(opts,
                                        command_to_string(item->command), NULL),
                                        1);
 -                      res = do_pick_commit(item->command, item->commit,
 +                      res = do_pick_commit(r, item->command, item->commit,
                                        opts, is_final_fixup(todo_list));
                        if (is_rebase_i(opts) && res < 0) {
                                /* Reschedule */
                                                _("Stopped at %s...  %.*s\n"),
                                                short_commit_name(commit),
                                                item->arg_len, item->arg);
 -                              return error_with_patch(commit,
 +                              return error_with_patch(r, commit,
                                        item->arg, item->arg_len, opts, res,
                                        !res);
                        }
                        if (res && is_fixup(item->command)) {
                                if (res == 1)
                                        intend_to_amend();
 -                              return error_failed_squash(item->commit, opts,
 +                              return error_failed_squash(r, item->commit, opts,
                                        item->arg_len, item->arg);
                        } else if (res && is_rebase_i(opts) && item->commit) {
                                int to_amend = 0;
                                      oideq(&opts->squash_onto, &oid))))
                                        to_amend = 1;
  
 -                              return res | error_with_patch(item->commit,
 +                              return res | error_with_patch(r, item->commit,
                                                item->arg, item->arg_len, opts,
                                                res, to_amend);
                        }
                        struct stat st;
  
                        *end_of_arg = '\0';
 -                      res = do_exec(item->arg);
 +                      res = do_exec(r, item->arg);
                        *end_of_arg = saved;
  
                        /* Reread the todo file if it has changed. */
                                                  get_todo_path(opts));
                        else if (match_stat_data(&todo_list->stat, &st)) {
                                todo_list_release(todo_list);
 -                              if (read_populate_todo(todo_list, opts))
 +                              if (read_populate_todo(r, todo_list, opts))
                                        res = -1; /* message was printed */
                                /* `current` will be incremented below */
                                todo_list->current = -1;
                        }
                } else if (item->command == TODO_LABEL) {
 -                      if ((res = do_label(item->arg, item->arg_len)))
 +                      if ((res = do_label(r, item->arg, item->arg_len)))
                                reschedule = 1;
                } else if (item->command == TODO_RESET) {
 -                      if ((res = do_reset(item->arg, item->arg_len, opts)))
 +                      if ((res = do_reset(r, item->arg, item->arg_len, opts)))
                                reschedule = 1;
                } else if (item->command == TODO_MERGE) {
 -                      if ((res = do_merge(item->commit,
 +                      if ((res = do_merge(r, item->commit,
                                            item->arg, item->arg_len,
                                            item->flags, opts)) < 0)
                                reschedule = 1;
                                                    peek_command(todo_list, 1));
                        if (res > 0)
                                /* failed with merge conflicts */
 -                              return error_with_patch(item->commit,
 +                              return error_with_patch(r, item->commit,
                                                        item->arg,
                                                        item->arg_len, opts,
                                                        res, 0);
                        if (save_todo(todo_list, opts))
                                return -1;
                        if (item->commit)
 -                              return error_with_patch(item->commit,
 +                              return error_with_patch(r,
 +                                                      item->commit,
                                                        item->arg,
                                                        item->arg_len, opts,
                                                        res, 0);
@@@ -3736,7 -3697,7 +3738,7 @@@ cleanup_head_ref
                        struct object_id orig, head;
  
                        memset(&log_tree_opt, 0, sizeof(log_tree_opt));
 -                      repo_init_revisions(the_repository, &log_tree_opt, NULL);
 +                      repo_init_revisions(r, &log_tree_opt, NULL);
                        log_tree_opt.diff = 1;
                        log_tree_opt.diffopt.output_format =
                                DIFF_FORMAT_DIFFSTAT;
        return sequencer_remove_state(opts);
  }
  
 -static int continue_single_pick(void)
 +static int continue_single_pick(struct repository *r)
  {
        const char *argv[] = { "commit", NULL };
  
 -      if (!file_exists(git_path_cherry_pick_head(the_repository)) &&
 -          !file_exists(git_path_revert_head(the_repository)))
 +      if (!file_exists(git_path_cherry_pick_head(r)) &&
 +          !file_exists(git_path_revert_head(r)))
                return error(_("no cherry-pick or revert in progress"));
        return run_command_v_opt(argv, RUN_GIT_CMD);
  }
  
 -static int commit_staged_changes(struct replay_opts *opts,
 +static int commit_staged_changes(struct repository *r,
 +                               struct replay_opts *opts,
                                 struct todo_list *todo_list)
  {
        unsigned int flags = ALLOW_EMPTY | EDIT_MSG;
        unsigned int final_fixup = 0, is_clean;
  
 -      if (has_unstaged_changes(1))
 +      if (has_unstaged_changes(r, 1))
                return error(_("cannot rebase: You have unstaged changes."));
  
 -      is_clean = !has_uncommitted_changes(0);
 +      is_clean = !has_uncommitted_changes(r, 0);
  
        if (file_exists(rebase_path_amend())) {
                struct strbuf rev = STRBUF_INIT;
                                struct commit *commit;
                                const char *path = rebase_path_squash_msg();
  
 -                              if (parse_head(&commit) ||
 +                              if (parse_head(r, &commit) ||
                                    !(p = get_commit_buffer(commit, NULL)) ||
                                    write_message(p, strlen(p), path, 0)) {
                                        unuse_commit_buffer(commit, p);
        }
  
        if (is_clean) {
 -              const char *cherry_pick_head = git_path_cherry_pick_head(the_repository);
 +              const char *cherry_pick_head = git_path_cherry_pick_head(r);
  
                if (file_exists(cherry_pick_head) && unlink(cherry_pick_head))
                        return error(_("could not remove CHERRY_PICK_HEAD"));
                        return 0;
        }
  
 -      if (run_git_commit(final_fixup ? NULL : rebase_path_message(),
 +      if (run_git_commit(r, final_fixup ? NULL : rebase_path_message(),
                           opts, flags))
                return error(_("could not commit staged changes."));
        unlink(rebase_path_amend());
        return 0;
  }
  
 -int sequencer_continue(struct replay_opts *opts)
 +int sequencer_continue(struct repository *r, struct replay_opts *opts)
  {
        struct todo_list todo_list = TODO_LIST_INIT;
        int res;
  
 -      if (read_and_refresh_cache(opts))
 +      if (read_and_refresh_cache(r, opts))
                return -1;
  
        if (read_populate_opts(opts))
                return -1;
        if (is_rebase_i(opts)) {
 -              if ((res = read_populate_todo(&todo_list, opts)))
 +              if ((res = read_populate_todo(r, &todo_list, opts)))
                        goto release_todo_list;
 -              if (commit_staged_changes(opts, &todo_list))
 +              if (commit_staged_changes(r, opts, &todo_list))
                        return -1;
        } else if (!file_exists(get_todo_path(opts)))
 -              return continue_single_pick();
 -      else if ((res = read_populate_todo(&todo_list, opts)))
 +              return continue_single_pick(r);
 +      else if ((res = read_populate_todo(r, &todo_list, opts)))
                goto release_todo_list;
  
        if (!is_rebase_i(opts)) {
                /* Verify that the conflict has been resolved */
 -              if (file_exists(git_path_cherry_pick_head(the_repository)) ||
 -                  file_exists(git_path_revert_head(the_repository))) {
 -                      res = continue_single_pick();
 +              if (file_exists(git_path_cherry_pick_head(r)) ||
 +                  file_exists(git_path_revert_head(r))) {
 +                      res = continue_single_pick(r);
                        if (res)
                                goto release_todo_list;
                }
 -              if (index_differs_from("HEAD", NULL, 0)) {
 -                      res = error_dirty_index(opts);
 +              if (index_differs_from(r, "HEAD", NULL, 0)) {
 +                      res = error_dirty_index(r->index, opts);
                        goto release_todo_list;
                }
                todo_list.current++;
                strbuf_release(&buf);
        }
  
 -      res = pick_commits(&todo_list, opts);
 +      res = pick_commits(r, &todo_list, opts);
  release_todo_list:
        todo_list_release(&todo_list);
        return res;
  }
  
 -static int single_pick(struct commit *cmit, struct replay_opts *opts)
 +static int single_pick(struct repository *r,
 +                     struct commit *cmit,
 +                     struct replay_opts *opts)
  {
        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
 -      return do_pick_commit(opts->action == REPLAY_PICK ?
 +      return do_pick_commit(r, opts->action == REPLAY_PICK ?
                TODO_PICK : TODO_REVERT, cmit, opts, 0);
  }
  
 -int sequencer_pick_revisions(struct replay_opts *opts)
 +int sequencer_pick_revisions(struct repository *r,
 +                           struct replay_opts *opts)
  {
        struct todo_list todo_list = TODO_LIST_INIT;
        struct object_id oid;
        int i, res;
  
        assert(opts->revs);
 -      if (read_and_refresh_cache(opts))
 +      if (read_and_refresh_cache(r, opts))
                return -1;
  
        for (i = 0; i < opts->revs->pending.nr; i++) {
                        continue;
  
                if (!get_oid(name, &oid)) {
 -                      if (!lookup_commit_reference_gently(the_repository, &oid, 1)) {
 -                              enum object_type type = oid_object_info(the_repository,
 +                      if (!lookup_commit_reference_gently(r, &oid, 1)) {
 +                              enum object_type type = oid_object_info(r,
                                                                        &oid,
                                                                        NULL);
                                return error(_("%s: can't cherry-pick a %s"),
                        return error(_("empty commit set passed"));
                if (get_revision(opts->revs))
                        BUG("unexpected extra commit from walk");
 -              return single_pick(cmit, opts);
 +              return single_pick(r, cmit, opts);
        }
  
        /*
        if (save_opts(opts))
                return -1;
        update_abort_safety_file();
 -      res = pick_commits(&todo_list, opts);
 +      res = pick_commits(r, &todo_list, opts);
        todo_list_release(&todo_list);
        return res;
  }
@@@ -4473,8 -4430,7 +4475,8 @@@ static int make_script_with_merges(stru
        return 0;
  }
  
 -int sequencer_make_script(FILE *out, int argc, const char **argv,
 +int sequencer_make_script(struct repository *r, FILE *out,
 +                        int argc, const char **argv,
                          unsigned flags)
  {
        char *format = NULL;
        const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick";
        int rebase_merges = flags & TODO_LIST_REBASE_MERGES;
  
 -      repo_init_revisions(the_repository, &revs, NULL);
 +      repo_init_revisions(r, &revs, NULL);
        revs.verbose_header = 1;
        if (!rebase_merges)
                revs.max_parents = 1;
   * Add commands after pick and (series of) squash/fixup commands
   * in the todo list.
   */
 -int sequencer_add_exec_commands(const char *commands)
 +int sequencer_add_exec_commands(struct repository *r,
 +                              const char *commands)
  {
        const char *todo_file = rebase_path_todo();
        struct todo_list todo_list = TODO_LIST_INIT;
        if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
                return error(_("could not read '%s'."), todo_file);
  
 -      if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
 +      if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
                todo_list_release(&todo_list);
                return error(_("unusable todo list: '%s'"), todo_file);
        }
        return i;
  }
  
 -int transform_todos(unsigned flags)
 +int transform_todos(struct repository *r, unsigned flags)
  {
        const char *todo_file = rebase_path_todo();
        struct todo_list todo_list = TODO_LIST_INIT;
        if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
                return error(_("could not read '%s'."), todo_file);
  
 -      if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
 +      if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) {
                todo_list_release(&todo_list);
                return error(_("unusable todo list: '%s'"), todo_file);
        }
@@@ -4676,7 -4631,7 +4678,7 @@@ define_commit_slab(commit_seen, unsigne
   * Check if there is an unrecognized command or a
   * bad SHA-1 in a command.
   */
 -int check_todo_list(void)
 +int check_todo_list(struct repository *r)
  {
        enum missing_commit_check_level check_level = get_missing_commit_check_level();
        struct strbuf todo_file = STRBUF_INIT;
                goto leave_check;
        }
        advise_to_edit_todo = res =
 -              parse_insn_buffer(todo_list.buf.buf, &todo_list);
 +              parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
  
        if (res || check_level == MISSING_COMMIT_CHECK_IGNORE)
                goto leave_check;
                goto leave_check;
        }
        strbuf_release(&todo_file);
 -      res = !!parse_insn_buffer(todo_list.buf.buf, &todo_list);
 +      res = !!parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
  
        /* Find commits in git-rebase-todo.backup yet unseen */
        for (i = todo_list.nr - 1; i >= 0; i--) {
@@@ -4776,7 -4731,7 +4778,7 @@@ static int rewrite_file(const char *pat
  }
  
  /* skip picking commits whose parents are unchanged */
 -static int skip_unnecessary_picks(struct object_id *output_oid)
 +static int skip_unnecessary_picks(struct repository *r, struct object_id *output_oid)
  {
        const char *todo_file = rebase_path_todo();
        struct strbuf buf = STRBUF_INIT;
  
        if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
                return -1;
 -      if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) {
 +      if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
                todo_list_release(&todo_list);
                return -1;
        }
        return 0;
  }
  
 -int complete_action(struct replay_opts *opts, unsigned flags,
 +int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
                    const char *shortrevisions, const char *onto_name,
                    const char *onto, const char *orig_head, const char *cmd,
                    unsigned autosquash)
            write_message("noop\n", 5, todo_file, 0))
                return -1;
  
 -      if (autosquash && rearrange_squash())
 +      if (autosquash && rearrange_squash(r))
                return -1;
  
        if (cmd && *cmd)
 -              sequencer_add_exec_commands(cmd);
 +              sequencer_add_exec_commands(r, cmd);
  
        if (strbuf_read_file(buf, todo_file, 0) < 0)
                return error_errno(_("could not read '%s'."), todo_file);
  
 -      if (parse_insn_buffer(buf->buf, &todo_list)) {
 +      if (parse_insn_buffer(r, buf->buf, &todo_list)) {
                todo_list_release(&todo_list);
                return error(_("unusable todo list: '%s'"), todo_file);
        }
                return error(_("could not copy '%s' to '%s'."), todo_file,
                             rebase_path_todo_backup());
  
 -      if (transform_todos(flags | TODO_LIST_SHORTEN_IDS))
 +      if (transform_todos(r, flags | TODO_LIST_SHORTEN_IDS))
                return error(_("could not transform the todo list"));
  
        strbuf_reset(buf);
  
        todo_list_release(&todo_list);
  
 -      if (check_todo_list()) {
 +      if (check_todo_list(r)) {
                checkout_onto(opts, onto_name, onto, orig_head);
                return -1;
        }
  
 -      if (transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS)))
 +      if (transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS)))
                return error(_("could not transform the todo list"));
  
 -      if (opts->allow_ff && skip_unnecessary_picks(&oid))
 +      if (opts->allow_ff && skip_unnecessary_picks(r, &oid))
                return error(_("could not skip unnecessary pick commands"));
  
        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 {
@@@ -4979,7 -4934,7 +4981,7 @@@ define_commit_slab(commit_todo_item, st
   * message will have to be retrieved from the commit (as the oneline in the
   * script cannot be trusted) in order to normalize the autosquash arrangement.
   */
 -int rearrange_squash(void)
 +int rearrange_squash(struct repository *r)
  {
        const char *todo_file = rebase_path_todo();
        struct todo_list todo_list = TODO_LIST_INIT;
  
        if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
                return -1;
 -      if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) {
 +      if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
                todo_list_release(&todo_list);
                return -1;
        }
diff --combined userdiff.c
index 97007abe5b16f3fe0af70963ae728048f241659f,e0579522bd364998735379c5fcdf979f94e96f5c..3a78fbf5044fbc5d5624ce94e54eb4ab325e2cf1
@@@ -265,7 -265,8 +265,8 @@@ int userdiff_config(const char *k, cons
        return 0;
  }
  
- struct userdiff_driver *userdiff_find_by_name(const char *name) {
+ struct userdiff_driver *userdiff_find_by_name(const char *name)
+ {
        int len = strlen(name);
        return userdiff_find_by_namelen(name, len);
  }
@@@ -290,8 -291,7 +291,8 @@@ struct userdiff_driver *userdiff_find_b
        return userdiff_find_by_name(check->items[0].value);
  }
  
 -struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
 +struct userdiff_driver *userdiff_get_textconv(struct repository *r,
 +                                            struct userdiff_driver *driver)
  {
        if (!driver->textconv)
                return NULL;
                struct strbuf name = STRBUF_INIT;
  
                strbuf_addf(&name, "textconv/%s", driver->name);
 -              notes_cache_init(c, name.buf, driver->textconv);
 +              notes_cache_init(r, c, name.buf, driver->textconv);
                driver->textconv_cache = c;
                strbuf_release(&name);
        }