diff options
author | Junio C Hamano <gitster@pobox.com> | 2019-02-07 09:05:22 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-02-07 09:05:23 +0300 |
commit | 7589e63648bf5224e186990931b1491f36e10a4b (patch) | |
tree | dfd3004e735b69ae91dc08ac4f742f1cb84eae5d /sha1-name.c | |
parent | e52c6bbd131f1f4f17b95e28d12ead0c81a8e890 (diff) | |
parent | f8adbec9feaa7a1ab9814db1115826e87033712e (diff) |
Merge branch 'nd/the-index-final'
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
Diffstat (limited to 'sha1-name.c')
-rw-r--r-- | sha1-name.c | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/sha1-name.c b/sha1-name.c index 4acd406b0a..d1cc77c124 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1515,7 +1515,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name) int get_oid(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, 0, oid, &unused); + return get_oid_with_context(the_repository, name, 0, oid, &unused); } @@ -1532,35 +1532,40 @@ int get_oid(const char *name, struct object_id *oid) int get_oid_committish(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_COMMITTISH, + return get_oid_with_context(the_repository, + name, GET_OID_COMMITTISH, oid, &unused); } int get_oid_treeish(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_TREEISH, + return get_oid_with_context(the_repository, + name, GET_OID_TREEISH, oid, &unused); } int get_oid_commit(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_COMMIT, + return get_oid_with_context(the_repository, + name, GET_OID_COMMIT, oid, &unused); } int get_oid_tree(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_TREE, + return get_oid_with_context(the_repository, + name, GET_OID_TREE, oid, &unused); } int get_oid_blob(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_BLOB, + return get_oid_with_context(the_repository, + name, GET_OID_BLOB, oid, &unused); } @@ -1599,7 +1604,8 @@ static void diagnose_invalid_oid_path(const char *prefix, } /* Must be called only when :stage:filename doesn't exist. */ -static void diagnose_invalid_index_path(int stage, +static void diagnose_invalid_index_path(struct index_state *istate, + int stage, const char *prefix, const char *filename) { @@ -1612,11 +1618,11 @@ static void diagnose_invalid_index_path(int stage, prefix = ""; /* Wrong stage number? */ - pos = cache_name_pos(filename, namelen); + pos = index_name_pos(istate, filename, namelen); if (pos < 0) pos = -pos - 1; - if (pos < active_nr) { - ce = active_cache[pos]; + if (pos < istate->cache_nr) { + ce = istate->cache[pos]; if (ce_namelen(ce) == namelen && !memcmp(ce->name, filename, namelen)) die("Path '%s' is in the index, but not at stage %d.\n" @@ -1628,11 +1634,11 @@ static void diagnose_invalid_index_path(int stage, /* Confusion between relative and absolute filenames? */ strbuf_addstr(&fullname, prefix); strbuf_addstr(&fullname, filename); - pos = cache_name_pos(fullname.buf, fullname.len); + pos = index_name_pos(istate, fullname.buf, fullname.len); if (pos < 0) pos = -pos - 1; - if (pos < active_nr) { - ce = active_cache[pos]; + if (pos < istate->cache_nr) { + ce = istate->cache[pos]; if (ce_namelen(ce) == fullname.len && !memcmp(ce->name, fullname.buf, fullname.len)) die("Path '%s' is in the index, but not '%s'.\n" @@ -1666,11 +1672,12 @@ static char *resolve_relative_path(const char *rel) 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 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); @@ -1725,13 +1732,13 @@ static enum get_oid_result get_oid_with_context_1(const char *name, if (flags & GET_OID_RECORD_PATH) oc->path = xstrdup(cp); - if (!active_cache) - read_cache(); - pos = cache_name_pos(cp, namelen); + if (!repo->index->cache) + repo_read_index(the_repository); + pos = index_name_pos(repo->index, cp, namelen); if (pos < 0) pos = -pos - 1; - while (pos < active_nr) { - ce = active_cache[pos]; + while (pos < repo->index->cache_nr) { + ce = repo->index->cache[pos]; if (ce_namelen(ce) != namelen || memcmp(ce->name, cp, namelen)) break; @@ -1744,7 +1751,7 @@ static enum get_oid_result get_oid_with_context_1(const char *name, pos++; } if (only_to_die && name[1] && name[1] != '/') - diagnose_invalid_index_path(stage, prefix, cp); + diagnose_invalid_index_path(repo->index, stage, prefix, cp); free(new_path); return -1; } @@ -1809,12 +1816,15 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix) { struct object_context oc; struct object_id oid; - get_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc); + get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE, + prefix, &oid, &oc); } -int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc) +int get_oid_with_context(struct repository *repo, const char *str, + unsigned flags, struct object_id *oid, + struct object_context *oc) { if (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE) BUG("incompatible flags for get_sha1_with_context"); - return get_oid_with_context_1(str, flags, NULL, oid, oc); + return get_oid_with_context_1(repo, str, flags, NULL, oid, oc); } |