return odb_source_loose_write_stream(odb->sources, stream, len, oid);
}
-struct object_database *odb_new(struct repository *repo)
+struct object_database *odb_new(struct repository *repo,
+ const char *primary_source,
+ const char *secondary_sources)
{
struct object_database *o = xmalloc(sizeof(*o));
+ char *to_free = NULL;
memset(o, 0, sizeof(*o));
o->repo = repo;
o->packfiles = packfile_store_new(o);
pthread_mutex_init(&o->replace_mutex, NULL);
string_list_init_dup(&o->submodule_source_paths);
+
+ if (!primary_source)
+ primary_source = to_free = xstrfmt("%s/objects", repo->commondir);
+ o->sources = odb_source_new(o, primary_source, true);
+ o->sources_tail = &o->sources->next;
+ o->alternate_db = xstrdup_or_null(secondary_sources);
+
+ free(to_free);
+
return o;
}
struct string_list submodule_source_paths;
};
-struct object_database *odb_new(struct repository *repo);
+/*
+ * Create a new object database for the given repository.
+ *
+ * If the primary source parameter is set it will override the usual primary
+ * object directory derived from the repository's common directory. The
+ * alternate sources are expected to be a PATH_SEP-separated list of secondary
+ * sources. Note that these alternate sources will be added in addition to, not
+ * instead of, the alternates identified by the primary source.
+ *
+ * Returns the newly created object database.
+ */
+struct object_database *odb_new(struct repository *repo,
+ const char *primary_source,
+ const char *alternate_sources);
/* Free the object database and release all resources. */
void odb_free(struct object_database *o);
void initialize_repository(struct repository *repo)
{
- repo->objects = odb_new(repo);
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
* until after xstrdup(root). Then we can free it.
*/
char *old_gitdir = repo->gitdir;
- char *objects_path = NULL;
repo->gitdir = xstrdup(gitfile ? gitfile : root);
free(old_gitdir);
repo_set_commondir(repo, o->commondir);
- expand_base_dir(&objects_path, o->object_dir,
- repo->commondir, "objects");
-
- if (!repo->objects->sources) {
- repo->objects->sources = odb_source_new(repo->objects,
- objects_path, true);
- repo->objects->sources_tail = &repo->objects->sources->next;
- free(objects_path);
+
+ if (!repo->objects) {
+ repo->objects = odb_new(repo, o->object_dir, o->alternate_db);
} else {
+ char *objects_path = NULL;
+ expand_base_dir(&objects_path, o->object_dir,
+ repo->commondir, "objects");
free(repo->objects->sources->path);
repo->objects->sources->path = objects_path;
+ free(repo->objects->alternate_db);
+ repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
}
repo->disable_ref_updates = o->disable_ref_updates;
- free(repo->objects->alternate_db);
- repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
expand_base_dir(&repo->graft_file, o->graft_file,
repo->commondir, "info/grafts");
expand_base_dir(&repo->index_file, o->index_file,