Skip to content

Commit 3b2f8a0

Browse files
committed
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
2 parents 13d9919 + 7317aa7 commit 3b2f8a0

18 files changed

+211
-274
lines changed

builtin/count-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ static int count_cruft(const char *basename, const char *path, void *data)
7878
return 0;
7979
}
8080

81-
static int print_alternate(struct alternate_object_database *alt, void *data)
81+
static int print_alternate(struct object_directory *odb, void *data)
8282
{
8383
printf("alternate: ");
84-
quote_c_style(alt->path, NULL, stdout, 0);
84+
quote_c_style(odb->path, NULL, stdout, 0);
8585
putchar('\n');
8686
return 0;
8787
}

builtin/fsck.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ static struct option fsck_opts[] = {
739739
int cmd_fsck(int argc, const char **argv, const char *prefix)
740740
{
741741
int i;
742-
struct alternate_object_database *alt;
742+
struct object_directory *odb;
743743

744744
/* fsck knows how to handle missing promisor objects */
745745
fetch_if_missing = 0;
@@ -775,14 +775,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
775775
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
776776
for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
777777
} else {
778-
struct alternate_object_database *alt_odb_list;
779-
780-
fsck_object_dir(get_object_directory());
781-
782778
prepare_alt_odb(the_repository);
783-
alt_odb_list = the_repository->objects->alt_odb_list;
784-
for (alt = alt_odb_list; alt; alt = alt->next)
785-
fsck_object_dir(alt->path);
779+
for (odb = the_repository->objects->odb; odb; odb = odb->next)
780+
fsck_object_dir(odb->path);
786781

787782
if (check_full) {
788783
struct packed_git *p;
@@ -884,15 +879,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
884879
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
885880
const char *verify_argv[] = { "commit-graph", "verify", NULL, NULL, NULL };
886881

887-
commit_graph_verify.argv = verify_argv;
888-
commit_graph_verify.git_cmd = 1;
889-
if (run_command(&commit_graph_verify))
890-
errors_found |= ERROR_COMMIT_GRAPH;
891-
892882
prepare_alt_odb(the_repository);
893-
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
883+
for (odb = the_repository->objects->odb; odb; odb = odb->next) {
884+
child_process_init(&commit_graph_verify);
885+
commit_graph_verify.argv = verify_argv;
886+
commit_graph_verify.git_cmd = 1;
894887
verify_argv[2] = "--object-dir";
895-
verify_argv[3] = alt->path;
888+
verify_argv[3] = odb->path;
896889
if (run_command(&commit_graph_verify))
897890
errors_found |= ERROR_COMMIT_GRAPH;
898891
}
@@ -902,15 +895,13 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
902895
struct child_process midx_verify = CHILD_PROCESS_INIT;
903896
const char *midx_argv[] = { "multi-pack-index", "verify", NULL, NULL, NULL };
904897

905-
midx_verify.argv = midx_argv;
906-
midx_verify.git_cmd = 1;
907-
if (run_command(&midx_verify))
908-
errors_found |= ERROR_COMMIT_GRAPH;
909-
910898
prepare_alt_odb(the_repository);
911-
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
899+
for (odb = the_repository->objects->odb; odb; odb = odb->next) {
900+
child_process_init(&midx_verify);
901+
midx_verify.argv = midx_argv;
902+
midx_verify.git_cmd = 1;
912903
midx_argv[2] = "--object-dir";
913-
midx_argv[3] = alt->path;
904+
midx_argv[3] = odb->path;
914905
if (run_command(&midx_verify))
915906
errors_found |= ERROR_COMMIT_GRAPH;
916907
}

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
437437
* store is no longer global and instead is a member of the repository
438438
* object.
439439
*/
440-
add_to_alternates_memory(submodule.objects->objectdir);
440+
add_to_alternates_memory(submodule.objects->odb->path);
441441
grep_read_unlock();
442442

443443
if (oid) {

builtin/submodule--helper.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,27 +1265,28 @@ struct submodule_alternate_setup {
12651265
SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
12661266

12671267
static int add_possible_reference_from_superproject(
1268-
struct alternate_object_database *alt, void *sas_cb)
1268+
struct object_directory *odb, void *sas_cb)
12691269
{
12701270
struct submodule_alternate_setup *sas = sas_cb;
1271+
size_t len;
12711272

12721273
/*
12731274
* If the alternate object store is another repository, try the
12741275
* standard layout with .git/(modules/<name>)+/objects
12751276
*/
1276-
if (ends_with(alt->path, "/objects")) {
1277+
if (strip_suffix(odb->path, "/objects", &len)) {
12771278
char *sm_alternate;
12781279
struct strbuf sb = STRBUF_INIT;
12791280
struct strbuf err = STRBUF_INIT;
1280-
strbuf_add(&sb, alt->path, strlen(alt->path) - strlen("objects"));
1281+
strbuf_add(&sb, odb->path, len);
12811282

12821283
/*
12831284
* We need to end the new path with '/' to mark it as a dir,
12841285
* otherwise a submodule name containing '/' will be broken
12851286
* as the last part of a missing submodule reference would
12861287
* be taken as a file name.
12871288
*/
1288-
strbuf_addf(&sb, "modules/%s/", sas->submodule_name);
1289+
strbuf_addf(&sb, "/modules/%s/", sas->submodule_name);
12891290

12901291
sm_alternate = compute_alternate_path(sb.buf, &err);
12911292
if (sm_alternate) {

commit-graph.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ static void prepare_commit_graph_one(struct repository *r, const char *obj_dir)
230230
*/
231231
static int prepare_commit_graph(struct repository *r)
232232
{
233-
struct alternate_object_database *alt;
234-
char *obj_dir;
233+
struct object_directory *odb;
235234
int config_value;
236235

237236
if (r->objects->commit_graph_attempted)
@@ -252,13 +251,11 @@ static int prepare_commit_graph(struct repository *r)
252251
if (!commit_graph_compatible(r))
253252
return 0;
254253

255-
obj_dir = r->objects->objectdir;
256-
prepare_commit_graph_one(r, obj_dir);
257254
prepare_alt_odb(r);
258-
for (alt = r->objects->alt_odb_list;
259-
!r->objects->commit_graph && alt;
260-
alt = alt->next)
261-
prepare_commit_graph_one(r, alt->path);
255+
for (odb = r->objects->odb;
256+
!r->objects->commit_graph && odb;
257+
odb = odb->next)
258+
prepare_commit_graph_one(r, odb->path);
262259
return !!r->objects->commit_graph;
263260
}
264261

environment.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ const char *get_git_work_tree(void)
274274

275275
char *get_object_directory(void)
276276
{
277-
if (!the_repository->objects->objectdir)
277+
if (!the_repository->objects->odb)
278278
BUG("git environment hasn't been setup");
279-
return the_repository->objects->objectdir;
279+
return the_repository->objects->odb->path;
280280
}
281281

282282
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)

fetch-pack.c

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -636,23 +636,6 @@ struct loose_object_iter {
636636
struct ref *refs;
637637
};
638638

639-
/*
640-
* If the number of refs is not larger than the number of loose objects,
641-
* this function stops inserting.
642-
*/
643-
static int add_loose_objects_to_set(const struct object_id *oid,
644-
const char *path,
645-
void *data)
646-
{
647-
struct loose_object_iter *iter = data;
648-
oidset_insert(iter->loose_object_set, oid);
649-
if (iter->refs == NULL)
650-
return 1;
651-
652-
iter->refs = iter->refs->next;
653-
return 0;
654-
}
655-
656639
/*
657640
* Mark recent commits available locally and reachable from a local ref as
658641
* COMPLETE. If args->no_dependents is false, also mark COMPLETE remote refs as
@@ -670,30 +653,14 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
670653
struct ref *ref;
671654
int old_save_commit_buffer = save_commit_buffer;
672655
timestamp_t cutoff = 0;
673-
struct oidset loose_oid_set = OIDSET_INIT;
674-
int use_oidset = 0;
675-
struct loose_object_iter iter = {&loose_oid_set, *refs};
676-
677-
/* Enumerate all loose objects or know refs are not so many. */
678-
use_oidset = !for_each_loose_object(add_loose_objects_to_set,
679-
&iter, 0);
680656

681657
save_commit_buffer = 0;
682658

683659
for (ref = *refs; ref; ref = ref->next) {
684660
struct object *o;
685-
unsigned int flags = OBJECT_INFO_QUICK;
686661

687-
if (use_oidset &&
688-
!oidset_contains(&loose_oid_set, &ref->old_oid)) {
689-
/*
690-
* I know this does not exist in the loose form,
691-
* so check if it exists in a non-loose form.
692-
*/
693-
flags |= OBJECT_INFO_IGNORE_LOOSE;
694-
}
695-
696-
if (!has_object_file_with_flags(&ref->old_oid, flags))
662+
if (!has_object_file_with_flags(&ref->old_oid,
663+
OBJECT_INFO_QUICK))
697664
continue;
698665
o = parse_object(the_repository, &ref->old_oid);
699666
if (!o)
@@ -710,8 +677,6 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
710677
}
711678
}
712679

713-
oidset_clear(&loose_oid_set);
714-
715680
if (!args->deepen) {
716681
for_each_ref(mark_complete_oid, NULL);
717682
for_each_cached_alternate(NULL, mark_alternate_complete);

http-walker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
547547
ret = error("File %s has bad hash", hex);
548548
} else if (req->rename < 0) {
549549
struct strbuf buf = STRBUF_INIT;
550-
sha1_file_name(the_repository, &buf, req->sha1);
550+
loose_object_path(the_repository, &buf, req->sha1);
551551
ret = error("unable to write sha1 filename %s", buf.buf);
552552
strbuf_release(&buf);
553553
}

http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
23532353
hashcpy(freq->sha1, sha1);
23542354
freq->localfile = -1;
23552355

2356-
sha1_file_name(the_repository, &filename, sha1);
2356+
loose_object_path(the_repository, &filename, sha1);
23572357
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
23582358

23592359
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2504,7 +2504,7 @@ int finish_http_object_request(struct http_object_request *freq)
25042504
unlink_or_warn(freq->tmpfile.buf);
25052505
return -1;
25062506
}
2507-
sha1_file_name(the_repository, &filename, freq->sha1);
2507+
loose_object_path(the_repository, &filename, freq->sha1);
25082508
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
25092509
strbuf_release(&filename);
25102510

midx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ int write_midx_file(const char *object_dir)
931931

932932
void clear_midx_file(struct repository *r)
933933
{
934-
char *midx = get_midx_filename(r->objects->objectdir);
934+
char *midx = get_midx_filename(r->objects->odb->path);
935935

936936
if (r->objects && r->objects->multi_pack_index) {
937937
close_midx(r->objects->multi_pack_index);

0 commit comments

Comments
 (0)