RelNotes: the tenth batch
[gitweb.git] / repository.c
index 97c732bd48ca8776203ae0936fe8ee61bb330ad9..998413b8bb8deaddef76d93f67be4a1435c9e3a7 100644 (file)
@@ -5,7 +5,7 @@
 
 /* The main repository */
 static struct repository the_repo = {
-       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, 0, 0
+       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, NULL, 0, 0
 };
 struct repository *the_repository = &the_repo;
 
@@ -64,6 +64,11 @@ void repo_set_gitdir(struct repository *repo, const char *path)
        free(old_gitdir);
 }
 
+void repo_set_hash_algo(struct repository *repo, int hash_algo)
+{
+       repo->hash_algo = &hash_algos[hash_algo];
+}
+
 /*
  * Attempt to resolve and set the provided 'gitdir' for repository 'repo'.
  * Return 0 upon success and a non-zero value upon failure.
@@ -136,6 +141,8 @@ int repo_init(struct repository *repo, const char *gitdir, const char *worktree)
        if (read_and_verify_repository_format(&format, repo->commondir))
                goto error;
 
+       repo_set_hash_algo(repo, format.hash_algo);
+
        if (worktree)
                repo_set_worktree(repo, worktree);
 
@@ -200,25 +207,17 @@ int repo_submodule_init(struct repository *submodule,
 
 void repo_clear(struct repository *repo)
 {
-       free(repo->gitdir);
-       repo->gitdir = NULL;
-       free(repo->commondir);
-       repo->commondir = NULL;
-       free(repo->objectdir);
-       repo->objectdir = NULL;
-       free(repo->graft_file);
-       repo->graft_file = NULL;
-       free(repo->index_file);
-       repo->index_file = NULL;
-       free(repo->worktree);
-       repo->worktree = NULL;
-       free(repo->submodule_prefix);
-       repo->submodule_prefix = NULL;
+       FREE_AND_NULL(repo->gitdir);
+       FREE_AND_NULL(repo->commondir);
+       FREE_AND_NULL(repo->objectdir);
+       FREE_AND_NULL(repo->graft_file);
+       FREE_AND_NULL(repo->index_file);
+       FREE_AND_NULL(repo->worktree);
+       FREE_AND_NULL(repo->submodule_prefix);
 
        if (repo->config) {
                git_configset_clear(repo->config);
-               free(repo->config);
-               repo->config = NULL;
+               FREE_AND_NULL(repo->config);
        }
 
        if (repo->submodule_cache) {
@@ -228,8 +227,7 @@ void repo_clear(struct repository *repo)
 
        if (repo->index) {
                discard_index(repo->index);
-               free(repo->index);
-               repo->index = NULL;
+               FREE_AND_NULL(repo->index);
        }
 }