Am 12.11.2018 um 15:50 schrieb Jeff King: > --- a/sha1-file.c > +++ b/sha1-file.c > @@ -2125,6 +2125,32 @@ int for_each_loose_object(each_loose_object_fn cb, void *data, > return 0; > } > > +static int append_loose_object(const struct object_id *oid, const char *path, > + void *data) > +{ > + oid_array_append(data, oid); > + return 0; > +} > + > +void odb_load_loose_cache(struct object_directory *odb, int subdir_nr) > +{ > + struct strbuf buf = STRBUF_INIT; > + > + if (subdir_nr < 0 || Why not make subdir_nr unsigned (like in for_each_file_in_obj_subdir()), and get rid of this first check? > + subdir_nr >= ARRAY_SIZE(odb->loose_objects_subdir_seen)) Using unsigned char for subdir_nr would allow removing the second check as well, but might hide invalid values in implicit conversions, I guess. > + BUG("subdir_nr out of range"); Showing the invalid value (like in for_each_file_in_obj_subdir()) would make debugging easier in case the impossible actually happens. > + > + if (odb->loose_objects_subdir_seen[subdir_nr]) > + return; > + > + strbuf_addstr(&buf, odb->path); > + for_each_file_in_obj_subdir(subdir_nr, &buf, > + append_loose_object, > + NULL, NULL, > + &odb->loose_objects_cache); > + odb->loose_objects_subdir_seen[subdir_nr] = 1; About here would be the ideal new home for ... > +} > + > static int check_stream_sha1(git_zstream *stream, > const char *hdr, > unsigned long size, > diff --git a/sha1-name.c b/sha1-name.c > index 358ca5e288..b24502811b 100644 > --- a/sha1-name.c > +++ b/sha1-name.c > @@ -83,36 +83,19 @@ static void update_candidates(struct disambiguate_state *ds, const struct object > /* otherwise, current can be discarded and candidate is still good */ > } > > -static int append_loose_object(const struct object_id *oid, const char *path, > - void *data) > -{ > - oid_array_append(data, oid); > - return 0; > -} > - > static int match_sha(unsigned, const unsigned char *, const unsigned char *); > > static void find_short_object_filename(struct disambiguate_state *ds) > { > int subdir_nr = ds->bin_pfx.hash[0]; > struct object_directory *odb; > - struct strbuf buf = STRBUF_INIT; > > for (odb = the_repository->objects->odb; > odb && !ds->ambiguous; > odb = odb->next) { > int pos; > > - if (!odb->loose_objects_subdir_seen[subdir_nr]) { > - strbuf_reset(&buf); > - strbuf_addstr(&buf, odb->path); > - for_each_file_in_obj_subdir(subdir_nr, &buf, > - append_loose_object, > - NULL, NULL, > - &odb->loose_objects_cache); > - odb->loose_objects_subdir_seen[subdir_nr] = 1; > - } > - > + odb_load_loose_cache(odb, subdir_nr); > pos = oid_array_lookup(&odb->loose_objects_cache, &ds->bin_pfx); > if (pos < 0) > pos = -1 - pos; > @@ -125,8 +108,6 @@ static void find_short_object_filename(struct disambiguate_state *ds) > pos++; > } > } > - > - strbuf_release(&buf); ... this line. > } > > static int match_sha(unsigned len, const unsigned char *a, const unsigned char *b) >