@@ -169,6 +169,44 @@ static int odb_source_inmemory_for_each_object(struct odb_source *source,
169169 odb_source_inmemory_for_each_object_cb , & payload );
170170}
171171
172+ struct find_abbrev_len_data {
173+ const struct object_id * oid ;
174+ unsigned len ;
175+ };
176+
177+ static int find_abbrev_len_cb (const struct object_id * oid ,
178+ struct object_info * oi UNUSED ,
179+ void * cb_data )
180+ {
181+ struct find_abbrev_len_data * data = cb_data ;
182+ unsigned len = oid_common_prefix_hexlen (oid , data -> oid );
183+ if (len != hash_algos [oid -> algo ].hexsz && len >= data -> len )
184+ data -> len = len + 1 ;
185+ return 0 ;
186+ }
187+
188+ static int odb_source_inmemory_find_abbrev_len (struct odb_source * source ,
189+ const struct object_id * oid ,
190+ unsigned min_len ,
191+ unsigned * out )
192+ {
193+ struct odb_for_each_object_options opts = {
194+ .prefix = oid ,
195+ .prefix_hex_len = min_len ,
196+ };
197+ struct find_abbrev_len_data data = {
198+ .oid = oid ,
199+ .len = min_len ,
200+ };
201+ int ret ;
202+
203+ ret = odb_source_inmemory_for_each_object (source , NULL , find_abbrev_len_cb ,
204+ & data , & opts );
205+ * out = data .len ;
206+
207+ return ret ;
208+ }
209+
172210static int odb_source_inmemory_write_object (struct odb_source * source ,
173211 const void * buf , unsigned long len ,
174212 enum object_type type ,
@@ -275,6 +313,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
275313 source -> base .read_object_info = odb_source_inmemory_read_object_info ;
276314 source -> base .read_object_stream = odb_source_inmemory_read_object_stream ;
277315 source -> base .for_each_object = odb_source_inmemory_for_each_object ;
316+ source -> base .find_abbrev_len = odb_source_inmemory_find_abbrev_len ;
278317 source -> base .write_object = odb_source_inmemory_write_object ;
279318 source -> base .write_object_stream = odb_source_inmemory_write_object_stream ;
280319
0 commit comments