24
#include "strbuf.h"
25
#include "strvec.h"
26
#include "submodule.h"
27
+#include "trace2.h"
28
#include "write-or-die.h"
29
30
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
470
return source;
471
}
472
473
+void odb_add_submodule_source_by_path(struct object_database *odb,
474
+ const char *path)
475
+{
476
+ string_list_insert(&odb->submodule_source_paths, path);
477
+}
478
+
479
static void fill_alternate_refs_command(struct child_process *cmd,
480
const char *repo_path)
481
{
630
631
int fetch_if_missing = 1;
632
633
+static int register_all_submodule_sources(struct object_database *odb)
634
+{
635
+ int ret = odb->submodule_source_paths.nr;
636
+
637
+ for (size_t i = 0; i < odb->submodule_source_paths.nr; i++)
638
+ odb_add_to_alternates_memory(odb,
639
+ odb->submodule_source_paths.items[i].string);
640
+ if (ret) {
641
+ string_list_clear(&odb->submodule_source_paths, 0);
642
+ trace2_data_intmax("submodule", odb->repo,
643
+ "register_all_submodule_sources/registered", ret);
644
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
645
+ BUG("register_all_submodule_sources() called");
646
+ }
647
+ return ret;
648
+}
649
+
650
static int do_oid_object_info_extended(struct repository *r,
651
const struct object_id *oid,
652
struct object_info *oi, unsigned flags)
700
}
701
702
/*
679
- * If r is the_repository, this might be an attempt at
680
- * accessing a submodule object as if it were in the_repository
681
- * (having called add_submodule_odb() on that submodule's ODB).
682
- * If any such ODBs exist, register them and try again.
703
+ * This might be an attempt at accessing a submodule object as
704
+ * if it were in main object store (having called
705
+ * `odb_add_submodule_source_by_path()` on that submodule's
706
+ * ODB). If any such ODBs exist, register them and try again.
707
*/
684
- if (r == the_repository &&
685
- register_all_submodule_odb_as_alternates())
708
+ if (register_all_submodule_sources(r->objects))
709
/* We added some alternates; retry */
710
continue;
711
991
INIT_LIST_HEAD(&o->packed_git_mru);
992
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
993
pthread_mutex_init(&o->replace_mutex, NULL);
994
+ string_list_init_dup(&o->submodule_source_paths);
995
return o;
996
}
997
1041
o->packed_git = NULL;
1042
1043
hashmap_clear(&o->pack_map);
1044
+ string_list_clear(&o->submodule_source_paths, 0);
1045
}