summaryrefslogtreecommitdiff
path: root/sha1-name.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2019-01-04 13:33:32 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-01-04 13:33:32 -0800
commit3b2f8a02fa9a9e68d5215828e1d97bb4f6996976 (patch)
tree95480e645fe16f17fd9ccc43a893699476b60a63 /sha1-name.c
parentMerge branch 'fc/http-version' (diff)
parentodb_load_loose_cache: fix strbuf leak (diff)
downloadtgif-3b2f8a02fa9a9e68d5215828e1d97bb4f6996976.tar.xz
Merge branch 'jk/loose-object-cache'
Code clean-up with optimization for the codepath that checks (non-)existence of loose objects. * jk/loose-object-cache: odb_load_loose_cache: fix strbuf leak fetch-pack: drop custom loose object cache sha1-file: use loose object cache for quick existence check object-store: provide helpers for loose_objects_cache sha1-file: use an object_directory for the main object dir handle alternates paths the same as the main object dir sha1_file_name(): overwrite buffer instead of appending rename "alternate_object_database" to "object_directory" submodule--helper: prefer strip_suffix() to ends_with() fsck: do not reuse child_process structs
Diffstat (limited to 'sha1-name.c')
-rw-r--r--sha1-name.c42
1 files changed, 8 insertions, 34 deletions
diff --git a/sha1-name.c b/sha1-name.c
index faa60f69e3..b24502811b 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -83,51 +83,25 @@ 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 alternate_object_database *alt;
- static struct alternate_object_database *fakeent;
+ struct object_directory *odb;
- if (!fakeent) {
- /*
- * Create a "fake" alternate object database that
- * points to our own object database, to make it
- * easier to get a temporary working space in
- * alt->name/alt->base while iterating over the
- * object databases including our own.
- */
- fakeent = alloc_alt_odb(get_object_directory());
- }
- fakeent->next = the_repository->objects->alt_odb_list;
-
- for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
+ for (odb = the_repository->objects->odb;
+ odb && !ds->ambiguous;
+ odb = odb->next) {
int pos;
- if (!alt->loose_objects_subdir_seen[subdir_nr]) {
- struct strbuf *buf = alt_scratch_buf(alt);
- for_each_file_in_obj_subdir(subdir_nr, buf,
- append_loose_object,
- NULL, NULL,
- &alt->loose_objects_cache);
- alt->loose_objects_subdir_seen[subdir_nr] = 1;
- }
-
- pos = oid_array_lookup(&alt->loose_objects_cache, &ds->bin_pfx);
+ odb_load_loose_cache(odb, subdir_nr);
+ pos = oid_array_lookup(&odb->loose_objects_cache, &ds->bin_pfx);
if (pos < 0)
pos = -1 - pos;
- while (!ds->ambiguous && pos < alt->loose_objects_cache.nr) {
+ while (!ds->ambiguous && pos < odb->loose_objects_cache.nr) {
const struct object_id *oid;
- oid = alt->loose_objects_cache.oid + pos;
+ oid = odb->loose_objects_cache.oid + pos;
if (!match_sha(ds->len, ds->bin_pfx.hash, oid->hash))
break;
update_candidates(ds, oid);