return ret;
}
-struct find_abbrev_len_data {
- const struct object_id *oid;
- unsigned len;
-};
-
-static int find_abbrev_len_cb(const struct object_id *oid,
- struct object_info *oi UNUSED,
- void *cb_data)
-{
- struct find_abbrev_len_data *data = cb_data;
- unsigned len = oid_common_prefix_hexlen(oid, data->oid);
- if (len != hash_algos[oid->algo].hexsz && len >= data->len)
- data->len = len + 1;
- return 0;
-}
-
-int odb_source_loose_find_abbrev_len(struct odb_source *source,
- const struct object_id *oid,
- unsigned min_len,
- unsigned *out)
-{
- struct odb_source_files *files = odb_source_files_downcast(source);
- struct odb_for_each_object_options opts = {
- .prefix = oid,
- .prefix_hex_len = min_len,
- };
- struct find_abbrev_len_data data = {
- .oid = oid,
- .len = min_len,
- };
- int ret;
-
- ret = odb_source_for_each_object(&files->loose->base, NULL, find_abbrev_len_cb,
- &data, &opts);
- *out = data.len;
-
- return ret;
-}
-
static int check_stream_oid(git_zstream *stream,
const char *hdr,
unsigned long size,
enum odb_count_objects_flags flags,
unsigned long *out);
-/*
- * Find the shortest unique prefix for the given object ID, where `min_len` is
- * the minimum length that the prefix should have.
- *
- * Returns 0 on success, in which case the computed length will be written to
- * `out`. Otherwise, a negative error code is returned.
- */
-int odb_source_loose_find_abbrev_len(struct odb_source *source,
- const struct object_id *oid,
- unsigned min_len,
- unsigned *out);
-
/**
* format_object_header() is a thin wrapper around s xsnprintf() that
* writes the initial "<type> <obj-len>" part of the loose object
if (ret < 0)
goto out;
- ret = odb_source_loose_find_abbrev_len(source, oid, len, &len);
+ ret = odb_source_find_abbrev_len(&files->loose->base, oid, len, &len);
if (ret < 0)
goto out;
NULL, NULL, &data);
}
+struct find_abbrev_len_data {
+ const struct object_id *oid;
+ unsigned len;
+};
+
+static int find_abbrev_len_cb(const struct object_id *oid,
+ struct object_info *oi UNUSED,
+ void *cb_data)
+{
+ struct find_abbrev_len_data *data = cb_data;
+ unsigned len = oid_common_prefix_hexlen(oid, data->oid);
+ if (len != hash_algos[oid->algo].hexsz && len >= data->len)
+ data->len = len + 1;
+ return 0;
+}
+
+static int odb_source_loose_find_abbrev_len(struct odb_source *source,
+ const struct object_id *oid,
+ unsigned min_len,
+ unsigned *out)
+{
+ struct odb_source_loose *loose = odb_source_loose_downcast(source);
+ struct odb_for_each_object_options opts = {
+ .prefix = oid,
+ .prefix_hex_len = min_len,
+ };
+ struct find_abbrev_len_data data = {
+ .oid = oid,
+ .len = min_len,
+ };
+ int ret;
+
+ ret = odb_source_for_each_object(&loose->base, NULL, find_abbrev_len_cb,
+ &data, &opts);
+ *out = data.len;
+
+ return ret;
+}
+
static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
{
oidtree_clear(loose->cache);
loose->base.read_object_info = odb_source_loose_read_object_info;
loose->base.read_object_stream = odb_source_loose_read_object_stream;
loose->base.for_each_object = odb_source_loose_for_each_object;
+ loose->base.find_abbrev_len = odb_source_loose_find_abbrev_len;
if (!is_absolute_path(loose->base.path))
chdir_notify_register(NULL, odb_source_loose_reparent, loose);