/* otherwise, current can be discarded and candidate is still good */
}
-static int append_loose_object(const struct object_id *oid, const char *path,
- void *data)
-{
- oid_array_append(data, oid);
- return 0;
-}
-
static int match_sha(unsigned, const unsigned char *, const unsigned char *);
static void find_short_object_filename(struct disambiguate_state *ds)
{
- int subdir_nr = ds->bin_pfx.hash[0];
- struct alternate_object_database *alt;
- static struct alternate_object_database *fakeent;
+ struct object_directory *odb;
- if (!fakeent) {
- /*
- * Create a "fake" alternate object database that
- * points to our own object database, to make it
- * easier to get a temporary working space in
- * alt->name/alt->base while iterating over the
- * object databases including our own.
- */
- fakeent = alloc_alt_odb(get_object_directory());
- }
- fakeent->next = the_repository->objects->alt_odb_list;
-
- for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
+ for (odb = the_repository->objects->odb;
+ odb && !ds->ambiguous;
+ odb = odb->next) {
int pos;
+ struct oid_array *loose_objects;
- if (!alt->loose_objects_subdir_seen[subdir_nr]) {
- struct strbuf *buf = alt_scratch_buf(alt);
- for_each_file_in_obj_subdir(subdir_nr, buf,
- append_loose_object,
- NULL, NULL,
- &alt->loose_objects_cache);
- alt->loose_objects_subdir_seen[subdir_nr] = 1;
- }
-
- pos = oid_array_lookup(&alt->loose_objects_cache, &ds->bin_pfx);
+ loose_objects = odb_loose_cache(odb, &ds->bin_pfx);
+ pos = oid_array_lookup(loose_objects, &ds->bin_pfx);
if (pos < 0)
pos = -1 - pos;
- while (!ds->ambiguous && pos < alt->loose_objects_cache.nr) {
+ while (!ds->ambiguous && pos < loose_objects->nr) {
const struct object_id *oid;
- oid = alt->loose_objects_cache.oid + pos;
+ oid = loose_objects->oid + pos;
if (!match_sha(ds->len, ds->bin_pfx.hash, oid->hash))
break;
update_candidates(ds, oid);
unique_in_pack(p, ds);
}
-#define SHORT_NAME_NOT_FOUND (-1)
-#define SHORT_NAME_AMBIGUOUS (-2)
-
static int finish_object_disambiguation(struct disambiguate_state *ds,
struct object_id *oid)
{
return SHORT_NAME_AMBIGUOUS;
if (!ds->candidate_exists)
- return SHORT_NAME_NOT_FOUND;
+ return MISSING_OBJECT;
if (!ds->candidate_checked)
/*
return a_type_sort > b_type_sort ? 1 : -1;
}
-static int get_short_oid(const char *name, int len, struct object_id *oid,
- unsigned flags)
+static enum get_oid_result get_short_oid(const char *name, int len,
+ struct object_id *oid,
+ unsigned flags)
{
int status;
struct disambiguate_state ds;
return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
}
-static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
+static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
static int get_oid_basic(const char *str, int len, struct object_id *oid,
return 0;
}
-static int get_parent(const char *name, int len,
- struct object_id *result, int idx)
+static enum get_oid_result get_parent(const char *name, int len,
+ struct object_id *result, int idx)
{
struct object_id oid;
- int ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
+ enum get_oid_result ret = get_oid_1(name, len, &oid,
+ GET_OID_COMMITTISH);
struct commit *commit;
struct commit_list *p;
return ret;
commit = lookup_commit_reference(the_repository, &oid);
if (parse_commit(commit))
- return -1;
+ return MISSING_OBJECT;
if (!idx) {
oidcpy(result, &commit->object.oid);
- return 0;
+ return FOUND;
}
p = commit->parents;
while (p) {
if (!--idx) {
oidcpy(result, &p->item->object.oid);
- return 0;
+ return FOUND;
}
p = p->next;
}
- return -1;
+ return MISSING_OBJECT;
}
-static int get_nth_ancestor(const char *name, int len,
- struct object_id *result, int generation)
+static enum get_oid_result get_nth_ancestor(const char *name, int len,
+ struct object_id *result,
+ int generation)
{
struct object_id oid;
struct commit *commit;
return ret;
commit = lookup_commit_reference(the_repository, &oid);
if (!commit)
- return -1;
+ return MISSING_OBJECT;
while (generation--) {
if (parse_commit(commit) || !commit->parents)
- return -1;
+ return MISSING_OBJECT;
commit = commit->parents->item;
}
oidcpy(result, &commit->object.oid);
- return 0;
+ return FOUND;
}
struct object *peel_to_type(const char *name, int namelen,
return -1;
}
-static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags)
+static enum get_oid_result get_oid_1(const char *name, int len,
+ struct object_id *oid,
+ unsigned lookup_flags)
{
int ret, has_suffix;
const char *cp;
ret = peel_onion(name, len, oid, lookup_flags);
if (!ret)
- return 0;
+ return FOUND;
ret = get_oid_basic(name, len, oid, lookup_flags);
if (!ret)
- return 0;
+ return FOUND;
/* It could be describe output that is "SOMETHING-gXXXX" */
ret = get_describe_name(name, len, oid);
if (!ret)
- return 0;
+ return FOUND;
return get_short_oid(name, len, oid, lookup_flags);
}
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);
}
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);
}
}
/* 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)
{
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"
/* 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"
rel);
}
-static int get_oid_with_context_1(const char *name,
+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,
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;
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;
}
{
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);
}