unsigned len = min_len;
int ret;
- ret = packfile_store_find_abbrev_len(files->packed, oid, len, &len);
+ ret = odb_source_find_abbrev_len(&files->packed->base, oid, len, &len);
if (ret < 0)
goto out;
return ret;
}
+static int extend_abbrev_len(const struct object_id *a,
+ const struct object_id *b,
+ unsigned *out)
+{
+ unsigned len = oid_common_prefix_hexlen(a, b);
+ if (len != hash_algos[a->algo].hexsz && len >= *out)
+ *out = len + 1;
+ return 0;
+}
+
+static void find_abbrev_len_for_midx(struct multi_pack_index *m,
+ const struct object_id *oid,
+ unsigned min_len,
+ unsigned *out)
+{
+ unsigned len = min_len;
+
+ for (; m; m = m->base_midx) {
+ int match = 0;
+ uint32_t num, first = 0;
+ struct object_id found_oid;
+
+ if (!m->num_objects)
+ continue;
+
+ num = m->num_objects + m->num_objects_in_base;
+ match = bsearch_one_midx(oid, m, &first);
+
+ /*
+ * first is now the position in the packfile where we
+ * would insert the object ID if it does not exist (or the
+ * position of the object ID if it does exist). Hence, we
+ * consider a maximum of two objects nearby for the
+ * abbreviation length.
+ */
+
+ if (!match) {
+ if (nth_midxed_object_oid(&found_oid, m, first))
+ extend_abbrev_len(&found_oid, oid, &len);
+ } else if (first < num - 1) {
+ if (nth_midxed_object_oid(&found_oid, m, first + 1))
+ extend_abbrev_len(&found_oid, oid, &len);
+ }
+ if (first > 0) {
+ if (nth_midxed_object_oid(&found_oid, m, first - 1))
+ extend_abbrev_len(&found_oid, oid, &len);
+ }
+ }
+
+ *out = len;
+}
+
+static void find_abbrev_len_for_pack(struct packed_git *p,
+ const struct object_id *oid,
+ unsigned min_len,
+ unsigned *out)
+{
+ int match;
+ uint32_t num, first = 0;
+ struct object_id found_oid;
+ unsigned len = min_len;
+
+ num = p->num_objects;
+ match = bsearch_pack(oid, p, &first);
+
+ /*
+ * first is now the position in the packfile where we would insert
+ * the object ID if it does not exist (or the position of mad->hash if
+ * it does exist). Hence, we consider a maximum of two objects
+ * nearby for the abbreviation length.
+ */
+ if (!match) {
+ if (!nth_packed_object_id(&found_oid, p, first))
+ extend_abbrev_len(&found_oid, oid, &len);
+ } else if (first < num - 1) {
+ if (!nth_packed_object_id(&found_oid, p, first + 1))
+ extend_abbrev_len(&found_oid, oid, &len);
+ }
+ if (first > 0) {
+ if (!nth_packed_object_id(&found_oid, p, first - 1))
+ extend_abbrev_len(&found_oid, oid, &len);
+ }
+
+ *out = len;
+}
+
+static int odb_source_packed_find_abbrev_len(struct odb_source *source,
+ const struct object_id *oid,
+ unsigned min_len,
+ unsigned *out)
+{
+ struct odb_source_packed *packed = odb_source_packed_downcast(source);
+ struct packfile_list_entry *e;
+ struct multi_pack_index *m;
+
+ m = get_multi_pack_index(&packed->files->base);
+ if (m)
+ find_abbrev_len_for_midx(m, oid, min_len, &min_len);
+
+ for (e = packfile_store_get_packs(packed); e; e = e->next) {
+ if (e->pack->multi_pack_index)
+ continue;
+ if (open_pack_index(e->pack) || !e->pack->num_objects)
+ continue;
+
+ find_abbrev_len_for_pack(e->pack, oid, min_len, &min_len);
+ }
+
+ *out = min_len;
+ return 0;
+}
+
void (*report_garbage)(unsigned seen_bits, const char *path);
static void report_helper(const struct string_list *list,
packed->base.read_object_stream = odb_source_packed_read_object_stream;
packed->base.for_each_object = odb_source_packed_for_each_object;
packed->base.count_objects = odb_source_packed_count_objects;
+ packed->base.find_abbrev_len = odb_source_packed_find_abbrev_len;
if (!is_absolute_path(parent->base.path))
chdir_notify_register(NULL, odb_source_packed_reparent, packed);
return r;
}
-static int extend_abbrev_len(const struct object_id *a,
- const struct object_id *b,
- unsigned *out)
-{
- unsigned len = oid_common_prefix_hexlen(a, b);
- if (len != hash_algos[a->algo].hexsz && len >= *out)
- *out = len + 1;
- return 0;
-}
-
-static void find_abbrev_len_for_midx(struct multi_pack_index *m,
- const struct object_id *oid,
- unsigned min_len,
- unsigned *out)
-{
- unsigned len = min_len;
-
- for (; m; m = m->base_midx) {
- int match = 0;
- uint32_t num, first = 0;
- struct object_id found_oid;
-
- if (!m->num_objects)
- continue;
-
- num = m->num_objects + m->num_objects_in_base;
- match = bsearch_one_midx(oid, m, &first);
-
- /*
- * first is now the position in the packfile where we
- * would insert the object ID if it does not exist (or the
- * position of the object ID if it does exist). Hence, we
- * consider a maximum of two objects nearby for the
- * abbreviation length.
- */
-
- if (!match) {
- if (nth_midxed_object_oid(&found_oid, m, first))
- extend_abbrev_len(&found_oid, oid, &len);
- } else if (first < num - 1) {
- if (nth_midxed_object_oid(&found_oid, m, first + 1))
- extend_abbrev_len(&found_oid, oid, &len);
- }
- if (first > 0) {
- if (nth_midxed_object_oid(&found_oid, m, first - 1))
- extend_abbrev_len(&found_oid, oid, &len);
- }
- }
-
- *out = len;
-}
-
-static void find_abbrev_len_for_pack(struct packed_git *p,
- const struct object_id *oid,
- unsigned min_len,
- unsigned *out)
-{
- int match;
- uint32_t num, first = 0;
- struct object_id found_oid;
- unsigned len = min_len;
-
- num = p->num_objects;
- match = bsearch_pack(oid, p, &first);
-
- /*
- * first is now the position in the packfile where we would insert
- * the object ID if it does not exist (or the position of mad->hash if
- * it does exist). Hence, we consider a maximum of two objects
- * nearby for the abbreviation length.
- */
- if (!match) {
- if (!nth_packed_object_id(&found_oid, p, first))
- extend_abbrev_len(&found_oid, oid, &len);
- } else if (first < num - 1) {
- if (!nth_packed_object_id(&found_oid, p, first + 1))
- extend_abbrev_len(&found_oid, oid, &len);
- }
- if (first > 0) {
- if (!nth_packed_object_id(&found_oid, p, first - 1))
- extend_abbrev_len(&found_oid, oid, &len);
- }
-
- *out = len;
-}
-
-int packfile_store_find_abbrev_len(struct odb_source_packed *store,
- const struct object_id *oid,
- unsigned min_len,
- unsigned *out)
-{
- struct packfile_list_entry *e;
- struct multi_pack_index *m;
-
- m = get_multi_pack_index(&store->files->base);
- if (m)
- find_abbrev_len_for_midx(m, oid, min_len, &min_len);
-
- for (e = packfile_store_get_packs(store); e; e = e->next) {
- if (e->pack->multi_pack_index)
- continue;
- if (open_pack_index(e->pack) || !e->pack->num_objects)
- continue;
-
- find_abbrev_len_for_pack(e->pack, oid, min_len, &min_len);
- }
-
- *out = min_len;
- return 0;
-}
-
struct add_promisor_object_data {
struct repository *repo;
struct oidset *set;
each_packed_object_fn, void *data,
enum odb_for_each_object_flags flags);
-int packfile_store_find_abbrev_len(struct odb_source_packed *store,
- const struct object_id *oid,
- unsigned min_len,
- unsigned *out);
-
/* A hook to report invalid files in pack directory */
#define PACKDIR_FILE_PACK 1
#define PACKDIR_FILE_IDX 2