static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
struct disambiguate_state {
int len; /* length of prefix in hex chars */
char hex_pfx[GIT_MAX_HEXSZ + 1];
struct object_id bin_pfx;
+ struct repository *repo;
disambiguate_hint_fn fn;
void *cb_data;
struct object_id candidate;
static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
{
if (ds->always_call_fn) {
- ds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;
+ ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
return;
}
if (!ds->candidate_exists) {
}
if (!ds->candidate_checked) {
- ds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);
+ ds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);
ds->disambiguate_fn_used = 1;
ds->candidate_checked = 1;
}
}
/* if we reach this point, we know ds->candidate satisfies fn */
- if (ds->fn(current, ds->cb_data)) {
+ if (ds->fn(ds->repo, current, ds->cb_data)) {
/*
* if both current and candidate satisfy fn, we cannot
* disambiguate.
{
struct object_directory *odb;
- for (odb = the_repository->objects->odb;
- odb && !ds->ambiguous;
- odb = odb->next) {
+ for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {
int pos;
struct oid_array *loose_objects;
struct multi_pack_index *m;
struct packed_git *p;
- for (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;
+ for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
m = m->next)
unique_in_midx(m, ds);
- for (p = get_packed_git(the_repository); p && !ds->ambiguous;
+ for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
p = p->next)
unique_in_pack(p, ds);
}
* same repository!
*/
ds->candidate_ok = (!ds->disambiguate_fn_used ||
- ds->fn(&ds->candidate, ds->cb_data));
+ ds->fn(ds->repo, &ds->candidate, ds->cb_data));
if (!ds->candidate_ok)
return SHORT_NAME_AMBIGUOUS;
return 0;
}
-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_commit_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
- int kind = oid_object_info(the_repository, oid, NULL);
+ int kind = oid_object_info(r, oid, NULL);
return kind == OBJ_COMMIT;
}
-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_committish_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
struct object *obj;
int kind;
- kind = oid_object_info(the_repository, oid, NULL);
+ kind = oid_object_info(r, oid, NULL);
if (kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
return 0;
/* We need to do this the hard way... */
- obj = deref_tag(the_repository, parse_object(the_repository, oid),
- NULL, 0);
+ obj = deref_tag(r, parse_object(r, oid), NULL, 0);
if (obj && obj->type == OBJ_COMMIT)
return 1;
return 0;
}
-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_tree_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
- int kind = oid_object_info(the_repository, oid, NULL);
+ int kind = oid_object_info(r, oid, NULL);
return kind == OBJ_TREE;
}
-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_treeish_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
struct object *obj;
int kind;
- kind = oid_object_info(the_repository, oid, NULL);
+ kind = oid_object_info(r, oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
return 0;
/* We need to do this the hard way... */
- obj = deref_tag(the_repository, parse_object(the_repository, oid),
- NULL, 0);
+ obj = deref_tag(r, parse_object(r, oid), NULL, 0);
if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
return 1;
return 0;
}
-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_blob_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
- int kind = oid_object_info(the_repository, oid, NULL);
+ int kind = oid_object_info(r, oid, NULL);
return kind == OBJ_BLOB;
}
return error("unknown hint type for '%s': %s", var, value);
}
-static int init_object_disambiguation(const char *name, int len,
+static int init_object_disambiguation(struct repository *r,
+ const char *name, int len,
struct disambiguate_state *ds)
{
int i;
ds->len = len;
ds->hex_pfx[len] = '\0';
- prepare_alt_odb(the_repository);
+ ds->repo = r;
+ prepare_alt_odb(r);
return 0;
}
struct strbuf desc = STRBUF_INIT;
int type;
- if (ds->fn && !ds->fn(oid, ds->cb_data))
+ if (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))
return 0;
- type = oid_object_info(the_repository, oid, NULL);
+ type = oid_object_info(ds->repo, oid, NULL);
if (type == OBJ_COMMIT) {
- struct commit *commit = lookup_commit(the_repository, oid);
+ struct commit *commit = lookup_commit(ds->repo, oid);
if (commit) {
struct pretty_print_context pp = {0};
pp.date_mode.type = DATE_SHORT;
format_commit_message(commit, " %ad - %s", &desc, &pp);
}
} else if (type == OBJ_TAG) {
- struct tag *tag = lookup_tag(the_repository, oid);
+ struct tag *tag = lookup_tag(ds->repo, oid);
if (!parse_tag(tag) && tag->tag)
strbuf_addf(&desc, " %s", tag->tag);
}
advise(" %s %s%s",
- find_unique_abbrev(oid, DEFAULT_ABBREV),
+ repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),
type_name(type) ? type_name(type) : "unknown type",
desc.buf);
return 0;
}
+static int repo_collect_ambiguous(struct repository *r,
+ const struct object_id *oid,
+ void *data)
+{
+ return collect_ambiguous(oid, data);
+}
+
static struct repository *sort_ambiguous_repo;
static int sort_ambiguous(const void *a, const void *b)
{
struct disambiguate_state ds;
int quietly = !!(flags & GET_OID_QUIETLY);
- if (init_object_disambiguation(name, len, &ds) < 0)
+ if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
return -1;
if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
struct disambiguate_state ds;
int ret;
- if (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)
+ if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
return -1;
ds.always_call_fn = 1;
- ds.fn = collect_ambiguous;
+ ds.fn = repo_collect_ambiguous;
ds.cb_data = &collect;
find_short_object_filename(&ds);
find_short_packed_object(&ds);
return 0;
}
+static int repo_extend_abbrev_len(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data)
+{
+ return extend_abbrev_len(oid, cb_data);
+}
+
static void find_abbrev_len_for_midx(struct multi_pack_index *m,
struct min_abbrev_data *mad)
{
find_abbrev_len_packed(&mad);
- if (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)
+ if (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)
return -1;
- ds.fn = extend_abbrev_len;
+ ds.fn = repo_extend_abbrev_len;
ds.always_call_fn = 1;
ds.cb_data = (void *)&mad;