]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'nd/the-index-final'
authorJunio C Hamano <gitster@pobox.com>
Thu, 7 Feb 2019 06:05:22 +0000 (22:05 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Feb 2019 06:05:23 +0000 (22:05 -0800)
The assumption to work on the single "in-core index" instance has
been reduced from the library-ish part of the codebase.

* nd/the-index-final:
  cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
  read-cache.c: remove the_* from index_has_changes()
  merge-recursive.c: remove implicit dependency on the_repository
  merge-recursive.c: remove implicit dependency on the_index
  sha1-name.c: remove implicit dependency on the_index
  read-cache.c: replace update_index_if_able with repo_&
  read-cache.c: kill read_index()
  checkout: avoid the_index when possible
  repository.c: replace hold_locked_index() with repo_hold_locked_index()
  notes-utils.c: remove the_repository references
  grep: use grep_opt->repo instead of explict repo argument

38 files changed:
1  2 
apply.c
attr.c
builtin/add.c
builtin/am.c
builtin/cat-file.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clone.c
builtin/commit.c
builtin/difftool.c
builtin/fsck.c
builtin/grep.c
builtin/log.c
builtin/ls-files.c
builtin/merge-recursive.c
builtin/merge-tree.c
builtin/pack-objects.c
builtin/rebase--interactive.c
builtin/rebase.c
builtin/submodule--helper.c
cache.h
convert.c
dir.c
git.c
list-objects-filter-options.c
merge-recursive.c
pathspec.c
read-cache.c
repository.c
repository.h
revision.c
sequencer.c
sequencer.h
sha1-name.c
submodule.c
t/helper/test-tool.h
tree.c
unpack-trees.c

diff --cc apply.c
Simple merge
diff --cc attr.c
Simple merge
diff --cc builtin/add.c
Simple merge
diff --cc builtin/am.c
Simple merge
index cebc6d7f8a197495e7c87f6b2430f340dc224891,a5ca47c697e6ef363a40224916fd451554120fb8..8487cd7dba0681087a5700039c234084f071333c
@@@ -380,9 -382,10 +382,10 @@@ static void batch_one_object(const cha
  {
        struct object_context ctx;
        int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
 -      enum follow_symlinks_result result;
 +      enum get_oid_result result;
  
-       result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
+       result = get_oid_with_context(the_repository, obj_name,
+                                     flags, &data->oid, &ctx);
        if (result != FOUND) {
                switch (result) {
                case MISSING_OBJECT:
Simple merge
Simple merge
diff --cc builtin/clone.c
Simple merge
Simple merge
Simple merge
diff --cc builtin/fsck.c
Simple merge
diff --cc builtin/grep.c
index dd52ea968baf1b5b971c5f59152a561744cf9b92,39a8e9d4a35a02e3bba8c43f77def39fa8f75bb2..580fd38f41704b6d534c04f2dee1bf85eee67c3c
@@@ -404,10 -405,9 +405,11 @@@ static int grep_submodule(struct grep_o
                          const struct object_id *oid,
                          const char *filename, const char *path)
  {
 -      struct repository submodule;
 +      struct repository subrepo;
+       struct repository *superproject = opt->repo;
 +      const struct submodule *sub = submodule_from_path(superproject,
 +                                                        &null_oid, path);
+       struct grep_opt subopt;
        int hit;
  
        /*
         * store is no longer global and instead is a member of the repository
         * object.
         */
 -      add_to_alternates_memory(submodule.objects->odb->path);
 +      add_to_alternates_memory(subrepo.objects->odb->path);
        grep_read_unlock();
  
 -      subopt.repo = &submodule;
+       memcpy(&subopt, opt, sizeof(subopt));
++      subopt.repo = &subrepo;
        if (oid) {
                struct object *object;
                struct tree_desc tree;
                strbuf_release(&base);
                free(data);
        } else {
-               hit = grep_cache(opt, &subrepo, pathspec, 1);
+               hit = grep_cache(&subopt, pathspec, 1);
        }
  
 -      repo_clear(&submodule);
 +      repo_clear(&subrepo);
        return hit;
  }
  
@@@ -586,10 -590,10 +593,10 @@@ static int grep_tree(struct grep_opt *o
                        strbuf_addch(base, '/');
                        init_tree_desc(&sub, data, size);
                        hit |= grep_tree(opt, pathspec, &sub, base, tn_len,
-                                        check_attr, repo);
+                                        check_attr);
                        free(data);
                } else if (recurse_submodules && S_ISGITLINK(entry.mode)) {
-                       hit |= grep_submodule(opt, repo, pathspec, &entry.oid,
 -                      hit |= grep_submodule(opt, pathspec, entry.oid,
++                      hit |= grep_submodule(opt, pathspec, &entry.oid,
                                              base->buf, base->buf + tn_len);
                }
  
diff --cc builtin/log.c
Simple merge
Simple merge
index 7545136c2a6da526ab7998106f2a28bfcbe8bd81,4864f7b22f3d11a2b28f0653031ee2f74f946e91..5b910e351e4dede4527d23a04a8294e17ebd371c
@@@ -26,10 -26,9 +26,10 @@@ int cmd_merge_recursive(int argc, cons
        int i, failed;
        struct object_id h1, h2;
        struct merge_options o;
 +      char *better1, *better2;
        struct commit *result;
  
-       init_merge_options(&o);
+       init_merge_options(&o, the_repository);
        if (argv[0] && ends_with(argv[0], "-subtree"))
                o.subtree_shift = "";
  
Simple merge
Simple merge
Simple merge
index 8d49e53997b3579623a284845cd49aa9b67b14a7,b66783727628c3867683236e5afeef247c5054f4..0b039319e134d0c33df842666eddc820dc6c410c
@@@ -362,161 -334,6 +363,161 @@@ static void add_var(struct strbuf *buf
        }
  }
  
-       if (read_index_unmerged(the_repository->index) < 0) {
 +#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
 +
 +#define RESET_HEAD_DETACH (1<<0)
 +#define RESET_HEAD_HARD (1<<1)
 +#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)
 +#define RESET_HEAD_REFS_ONLY (1<<3)
 +
 +static int reset_head(struct object_id *oid, const char *action,
 +                    const char *switch_to_branch, unsigned flags,
 +                    const char *reflog_orig_head, const char *reflog_head)
 +{
 +      unsigned detach_head = flags & RESET_HEAD_DETACH;
 +      unsigned reset_hard = flags & RESET_HEAD_HARD;
 +      unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
 +      unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
 +      struct object_id head_oid;
 +      struct tree_desc desc[2] = { { NULL }, { NULL } };
 +      struct lock_file lock = LOCK_INIT;
 +      struct unpack_trees_options unpack_tree_opts;
 +      struct tree *tree;
 +      const char *reflog_action;
 +      struct strbuf msg = STRBUF_INIT;
 +      size_t prefix_len;
 +      struct object_id *orig = NULL, oid_orig,
 +              *old_orig = NULL, oid_old_orig;
 +      int ret = 0, nr = 0;
 +
 +      if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
 +              BUG("Not a fully qualified branch: '%s'", switch_to_branch);
 +
 +      if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
 +              ret = -1;
 +              goto leave_reset_head;
 +      }
 +
 +      if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) {
 +              ret = error(_("could not determine HEAD revision"));
 +              goto leave_reset_head;
 +      }
 +
 +      if (!oid)
 +              oid = &head_oid;
 +
 +      if (refs_only)
 +              goto reset_head_refs;
 +
 +      memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
 +      setup_unpack_trees_porcelain(&unpack_tree_opts, action);
 +      unpack_tree_opts.head_idx = 1;
 +      unpack_tree_opts.src_index = the_repository->index;
 +      unpack_tree_opts.dst_index = the_repository->index;
 +      unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge;
 +      unpack_tree_opts.update = 1;
 +      unpack_tree_opts.merge = 1;
 +      if (!detach_head)
 +              unpack_tree_opts.reset = 1;
 +
++      if (repo_read_index_unmerged(the_repository) < 0) {
 +              ret = error(_("could not read index"));
 +              goto leave_reset_head;
 +      }
 +
 +      if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {
 +              ret = error(_("failed to find tree of %s"),
 +                          oid_to_hex(&head_oid));
 +              goto leave_reset_head;
 +      }
 +
 +      if (!fill_tree_descriptor(&desc[nr++], oid)) {
 +              ret = error(_("failed to find tree of %s"), oid_to_hex(oid));
 +              goto leave_reset_head;
 +      }
 +
 +      if (unpack_trees(nr, desc, &unpack_tree_opts)) {
 +              ret = -1;
 +              goto leave_reset_head;
 +      }
 +
 +      tree = parse_tree_indirect(oid);
 +      prime_cache_tree(the_repository, the_repository->index, tree);
 +
 +      if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) {
 +              ret = error(_("could not write index"));
 +              goto leave_reset_head;
 +      }
 +
 +reset_head_refs:
 +      reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
 +      strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
 +      prefix_len = msg.len;
 +
 +      if (!get_oid("ORIG_HEAD", &oid_old_orig))
 +              old_orig = &oid_old_orig;
 +      if (!get_oid("HEAD", &oid_orig)) {
 +              orig = &oid_orig;
 +              if (!reflog_orig_head) {
 +                      strbuf_addstr(&msg, "updating ORIG_HEAD");
 +                      reflog_orig_head = msg.buf;
 +              }
 +              update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
 +                         UPDATE_REFS_MSG_ON_ERR);
 +      } else if (old_orig)
 +              delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
 +      if (!reflog_head) {
 +              strbuf_setlen(&msg, prefix_len);
 +              strbuf_addstr(&msg, "updating HEAD");
 +              reflog_head = msg.buf;
 +      }
 +      if (!switch_to_branch)
 +              ret = update_ref(reflog_head, "HEAD", oid, orig,
 +                               detach_head ? REF_NO_DEREF : 0,
 +                               UPDATE_REFS_MSG_ON_ERR);
 +      else {
 +              ret = update_ref(reflog_orig_head, switch_to_branch, oid,
 +                               NULL, 0, UPDATE_REFS_MSG_ON_ERR);
 +              if (!ret)
 +                      ret = create_symref("HEAD", switch_to_branch,
 +                                          reflog_head);
 +      }
 +      if (run_hook)
 +              run_hook_le(NULL, "post-checkout",
 +                          oid_to_hex(orig ? orig : &null_oid),
 +                          oid_to_hex(oid), "1", NULL);
 +
 +leave_reset_head:
 +      strbuf_release(&msg);
 +      rollback_lock_file(&lock);
 +      while (nr)
 +              free((void *)desc[--nr].buffer);
 +      return ret;
 +}
 +
 +static int move_to_original_branch(struct rebase_options *opts)
 +{
 +      struct strbuf orig_head_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT;
 +      int ret;
 +
 +      if (!opts->head_name)
 +              return 0; /* nothing to move back to */
 +
 +      if (!opts->onto)
 +              BUG("move_to_original_branch without onto");
 +
 +      strbuf_addf(&orig_head_reflog, "rebase finished: %s onto %s",
 +                  opts->head_name, oid_to_hex(&opts->onto->object.oid));
 +      strbuf_addf(&head_reflog, "rebase finished: returning to %s",
 +                  opts->head_name);
 +      ret = reset_head(NULL, "", opts->head_name, RESET_HEAD_REFS_ONLY,
 +                       orig_head_reflog.buf, head_reflog.buf);
 +
 +      strbuf_release(&orig_head_reflog);
 +      strbuf_release(&head_reflog);
 +      return ret;
 +}
 +
  static const char *resolvemsg =
  N_("Resolve all conflicts manually, mark them as resolved with\n"
  "\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n"
Simple merge
diff --cc cache.h
index bcf9fd445f47d97b07e11365421a4e39e22fc8c8,962eb127d3a9e51e3a4cb3911a856320af26f2a4..c653668340232e2610729665c6fc740ee748232a
+++ b/cache.h
@@@ -1370,9 -1328,11 +1359,10 @@@ extern int get_oid_tree(const char *str
  extern int get_oid_treeish(const char *str, struct object_id *oid);
  extern int get_oid_blob(const char *str, struct object_id *oid);
  extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
- extern enum get_oid_result get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);
 -extern int get_oid_with_context(struct repository *repo, const char *str,
++extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,
+                               unsigned flags, struct object_id *oid,
+                               struct object_context *oc);
  
 -
  typedef int each_abbrev_fn(const struct object_id *oid, void *);
  extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
  
diff --cc convert.c
Simple merge
diff --cc dir.c
Simple merge
diff --cc git.c
Simple merge
Simple merge
Simple merge
diff --cc pathspec.c
Simple merge
diff --cc read-cache.c
Simple merge
diff --cc repository.c
Simple merge
diff --cc repository.h
Simple merge
diff --cc revision.c
Simple merge
diff --cc sequencer.c
Simple merge
diff --cc sequencer.h
Simple merge
diff --cc sha1-name.c
index 4acd406b0ad7ed448878fe416c1d0221032ca65e,d8cab7b5a60095a6a61973e3a7de498ddf6c702b..d1cc77c124c11ffd49be472b1368baeda3afbe17
@@@ -1666,11 -1670,12 +1672,12 @@@ static char *resolve_relative_path(cons
                           rel);
  }
  
- static enum get_oid_result get_oid_with_context_1(const char *name,
-                                                 unsigned flags,
-                                                 const char *prefix,
-                                                 struct object_id *oid,
-                                                 struct object_context *oc)
 -static int get_oid_with_context_1(struct repository *repo,
++static enum get_oid_result get_oid_with_context_1(struct repository *repo,
+                                 const char *name,
+                                 unsigned flags,
+                                 const char *prefix,
+                                 struct object_id *oid,
+                                 struct object_context *oc)
  {
        int ret, bracket_depth;
        int namelen = strlen(name);
diff --cc submodule.c
Simple merge
Simple merge
diff --cc tree.c
Simple merge
diff --cc unpack-trees.c
Simple merge