aboutsummaryrefslogtreecommitdiff
path: root/odb/source-files.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-20 08:07:40 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-20 13:16:42 -0700
commit83869e15fa9ef3b0ea2adbfe2fe68a309f95b856 (patch)
tree40dd62b65441c70670cd5f019d11c88f9788e8ed /odb/source-files.c
parent6c2ede6e4abed754bb5891c2904212c05efcfb11 (diff)
downloadgit-83869e15fa9ef3b0ea2adbfe2fe68a309f95b856.tar.xz
odb: introduce generic `odb_find_abbrev_len()`
Introduce a new generic `odb_find_abbrev_len()` function as well as source-specific callback functions. This makes the logic to compute the required prefix length to make a given object unique fully pluggable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'odb/source-files.c')
-rw-r--r--odb/source-files.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/odb/source-files.c b/odb/source-files.c
index e90bb689bb..76797569de 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -122,6 +122,30 @@ out:
return ret;
}
+static int odb_source_files_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);
+ unsigned len = min_len;
+ int ret;
+
+ ret = packfile_store_find_abbrev_len(files->packed, oid, len, &len);
+ if (ret < 0)
+ goto out;
+
+ ret = odb_source_loose_find_abbrev_len(source, oid, len, &len);
+ if (ret < 0)
+ goto out;
+
+ *out = len;
+ ret = 0;
+
+out:
+ return ret;
+}
+
static int odb_source_files_freshen_object(struct odb_source *source,
const struct object_id *oid)
{
@@ -250,6 +274,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
files->base.read_object_stream = odb_source_files_read_object_stream;
files->base.for_each_object = odb_source_files_for_each_object;
files->base.count_objects = odb_source_files_count_objects;
+ files->base.find_abbrev_len = odb_source_files_find_abbrev_len;
files->base.freshen_object = odb_source_files_freshen_object;
files->base.write_object = odb_source_files_write_object;
files->base.write_object_stream = odb_source_files_write_object_stream;