repo: add git_repository_wrap_odb() to wrap an ODB Primarily useful when used together with git_odb_backend_one_pack().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/include/git2/repository.h b/include/git2/repository.h
index ff81b75..ef2f541 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -36,6 +36,19 @@ GIT_BEGIN_DECL
GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path);
/**
+ * Create a "fake" repository to wrap an object database
+ *
+ * Create a repository object to wrap an object database to be used
+ * with the API when all you have is an object database. This doesn't
+ * have any paths associated with it, so use with care.
+ *
+ * @param repository pointer to the repo
+ * @param odb the object database to wrap
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_repository_wrap_odb(git_repository **repository, git_odb *odb);
+
+/**
* Look for a git repository and copy its path in the given buffer.
* The lookup start from base_path and walk across parent directories
* if nothing has been found. The lookup ends when the first repository
diff --git a/src/repository.c b/src/repository.c
index a293171..e0104f3 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -388,6 +388,19 @@ int git_repository_open(git_repository **repo_out, const char *path)
repo_out, path, GIT_REPOSITORY_OPEN_NO_SEARCH, NULL);
}
+int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb)
+{
+ git_repository *repo;
+
+ repo = repository_alloc();
+ GITERR_CHECK_ALLOC(repo);
+
+ git_repository_set_odb(repo, odb);
+ *repo_out = repo;
+
+ return 0;
+}
+
int git_repository_discover(
char *repository_path,
size_t size,