sequencer: move stale comment into correct location
[gitweb.git] / sha1-name.c
index d8cab7b5a60095a6a61973e3a7de498ddf6c702b..6dda2c16df1026e50b7d9be255b6bbfc4e92725c 100644 (file)
@@ -87,21 +87,21 @@ 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 object_directory *odb;
 
        for (odb = the_repository->objects->odb;
             odb && !ds->ambiguous;
             odb = odb->next) {
                int pos;
+               struct oid_array *loose_objects;
 
-               odb_load_loose_cache(odb, subdir_nr);
-               pos = oid_array_lookup(&odb->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 < odb->loose_objects_cache.nr) {
+               while (!ds->ambiguous && pos < loose_objects->nr) {
                        const struct object_id *oid;
-                       oid = odb->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);
@@ -190,9 +190,6 @@ static void find_short_packed_object(struct disambiguate_state *ds)
                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)
 {
@@ -200,7 +197,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
                return SHORT_NAME_AMBIGUOUS;
 
        if (!ds->candidate_exists)
-               return SHORT_NAME_NOT_FOUND;
+               return MISSING_OBJECT;
 
        if (!ds->candidate_checked)
                /*
@@ -414,8 +411,9 @@ static int sort_ambiguous(const void *a, const void *b)
        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;
@@ -733,7 +731,7 @@ static inline int push_mark(const char *string, int len)
        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,
@@ -883,11 +881,12 @@ 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;
 
@@ -895,24 +894,25 @@ static int get_parent(const char *name, int len,
                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;
@@ -923,15 +923,15 @@ static int get_nth_ancestor(const char *name, int len,
                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,
@@ -1077,7 +1077,9 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
        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;
@@ -1111,16 +1113,16 @@ static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned
 
        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);
 }
@@ -1670,7 +1672,7 @@ static char *resolve_relative_path(const char *rel)
                           rel);
 }
 
-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,
@@ -1818,9 +1820,11 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
                               prefix, &oid, &oc);
 }
 
-int get_oid_with_context(struct repository *repo, const char *str,
-                        unsigned flags, struct object_id *oid,
-                        struct object_context *oc)
+enum get_oid_result 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");