Commit Diff


commit - e4e80ba431438f463a867e2d2d80b264faa19b07
commit + f4204d57318d19f7a972ace5b15ba58f443e2c73
blob - 53e99801ab01ad8804d048c5f59a94930e5ef10a
blob + 17dcc926d4cae7fa2f169eb003ed4aeebba92346
--- include/got_repository.h
+++ include/got_repository.h
@@ -35,6 +35,9 @@ const char *got_repo_get_path_git_dir(struct got_repos
 /* Obtain the file descriptor of the repository's .git directory. */
 int got_repo_get_fd(struct got_repository *);
 
+/* Obtain the object format */
+enum got_hash_algorithm got_repo_get_object_format(struct got_repository *);
+
 /* Obtain the commit author name if parsed from gitconfig, else NULL. */
 const char *got_repo_get_gitconfig_author_name(struct got_repository *);
 
blob - 83d718aa029bf9afded3debb15731d617de2169c
blob + 38259e224eecc4b0deaaaff9b35ca1c7e54810fb
--- lib/got_lib_repository.h
+++ lib/got_lib_repository.h
@@ -63,6 +63,7 @@ struct got_repository {
 	char *path;
 	char *path_git_dir;
 	int gitdir_fd;
+	enum got_hash_algorithm algo;
 
 	struct got_pathlist_head packidx_paths;
 	struct timespec pack_path_mtime;
blob - e6c5b39513e6605848a31acea189b5cefa9825d2
blob + 9edc17e29a83d241a4c94296f6a23e0c4335767f
--- lib/reference.c
+++ lib/reference.c
@@ -152,9 +152,8 @@ parse_symref(struct got_reference **ref, const char *n
 
 static const struct got_error *
 parse_ref_line(struct got_reference **ref, const char *name, const char *line,
-    time_t mtime)
+    time_t mtime, enum got_hash_algorithm algo)
 {
-	enum got_hash_algorithm algo = GOT_HASH_SHA1;
 	struct got_object_id id;
 
 	if (strncmp(line, "ref: ", 5) == 0) {
@@ -170,7 +169,8 @@ parse_ref_line(struct got_reference **ref, const char 
 
 static const struct got_error *
 parse_ref_file(struct got_reference **ref, const char *name,
-    const char *absname, const char *abspath, int lock)
+    const char *absname, const char *abspath, int lock,
+    enum got_hash_algorithm algo)
 {
 	const struct got_error *err = NULL;
 	FILE *f;
@@ -225,7 +225,7 @@ parse_ref_file(struct got_reference **ref, const char 
 		linelen--;
 	}
 
-	err = parse_ref_line(ref, absname, line, sb.st_mtime);
+	err = parse_ref_line(ref, absname, line, sb.st_mtime, algo);
 	if (lock) {
 		if (err)
 			got_lockfile_unlock(lf, -1);
@@ -290,9 +290,8 @@ got_ref_alloc_symref(struct got_reference **ref, const
 
 static const struct got_error *
 parse_packed_ref_line(struct got_reference **ref, const char *abs_refname,
-    const char *line, time_t mtime)
+    const char *line, time_t mtime, enum got_hash_algorithm algo)
 {
-	enum got_hash_algorithm algo = GOT_HASH_SHA1;
 	struct got_object_id id;
 	const char *name;
 
@@ -316,7 +315,8 @@ parse_packed_ref_line(struct got_reference **ref, cons
 
 static const struct got_error *
 open_packed_ref(struct got_reference **ref, FILE *f, const char **subdirs,
-    int nsubdirs, const char *refname, time_t mtime)
+    int nsubdirs, const char *refname, time_t mtime,
+    enum got_hash_algorithm algo)
 {
 	const struct got_error *err = NULL;
 	char *abs_refname;
@@ -345,7 +345,7 @@ open_packed_ref(struct got_reference **ref, FILE *f, c
 			    refname) == -1)
 				return got_error_from_errno("asprintf");
 			err = parse_packed_ref_line(ref, abs_refname, line,
-			    mtime);
+			    mtime, algo);
 			if (!ref_is_absolute)
 				free(abs_refname);
 			if (err || *ref != NULL)
@@ -361,7 +361,7 @@ open_packed_ref(struct got_reference **ref, FILE *f, c
 
 static const struct got_error *
 open_ref(struct got_reference **ref, const char *path_refs, const char *subdir,
-    const char *name, int lock)
+    const char *name, int lock, enum got_hash_algorithm algo)
 {
 	const struct got_error *err = NULL;
 	char *path = NULL;
@@ -390,7 +390,7 @@ open_ref(struct got_reference **ref, const char *path_
 		}
 	}
 
-	err = parse_ref_file(ref, name, absname, path, lock);
+	err = parse_ref_file(ref, name, absname, path, lock, algo);
 done:
 	if (!ref_is_absolute && !ref_is_well_known)
 		free(absname);
@@ -420,14 +420,15 @@ got_ref_open(struct got_reference **ref, struct got_re
 	}
 
 	if (well_known) {
-		err = open_ref(ref, path_refs, "", refname, lock);
+		err = open_ref(ref, path_refs, "", refname, lock,
+		    got_repo_get_object_format(repo));
 	} else {
 		FILE *f;
 
 		/* Search on-disk refs before packed refs! */
 		for (i = 0; i < nitems(subdirs); i++) {
 			err = open_ref(ref, path_refs, subdirs[i], refname,
-			    lock);
+			    lock, got_repo_get_object_format(repo));
 			if ((err && err->code != GOT_ERR_NOT_REF) || *ref)
 				goto done;
 		}
@@ -453,7 +454,8 @@ got_ref_open(struct got_reference **ref, struct got_re
 				goto done;
 			}
 			err = open_packed_ref(ref, f, subdirs, nitems(subdirs),
-			    refname, sb.st_mtime);
+			    refname, sb.st_mtime,
+			    got_repo_get_object_format(repo));
 			if (!err) {
 				if (fclose(f) == EOF) {
 					err = got_error_from_errno("fclose");
@@ -916,7 +918,7 @@ gather_on_disk_refs(struct got_reflist_head *refs, con
 		switch (type) {
 		case DT_REG:
 			err = open_ref(&ref, path_refs, subdir, dent->d_name,
-			    0);
+			    0, got_repo_get_object_format(repo));
 			if (err)
 				goto done;
 			if (ref) {
@@ -969,7 +971,8 @@ got_ref_list(struct got_reflist_head *refs, struct got
 			err = got_error_from_errno("get_refs_dir_path");
 			goto done;
 		}
-		err = open_ref(&ref, path_refs, "", GOT_REF_HEAD, 0);
+		err = open_ref(&ref, path_refs, "", GOT_REF_HEAD, 0,
+		    got_repo_get_object_format(repo));
 		if (err)
 			goto done;
 		err = got_reflist_insert(&new, refs, ref, cmp_cb, cmp_arg);
@@ -985,7 +988,8 @@ got_ref_list(struct got_reflist_head *refs, struct got
 			err = got_error_from_errno("get_refs_dir_path");
 			goto done;
 		}
-		err = open_ref(&ref, path_refs, "", refname, 0);
+		err = open_ref(&ref, path_refs, "", refname, 0,
+		    got_repo_get_object_format(repo));
 		if (err) {
 			if (err->code != GOT_ERR_NOT_REF)
 				goto done;
@@ -1068,7 +1072,7 @@ got_ref_list(struct got_reflist_head *refs, struct got
 			if (linelen > 0 && line[linelen - 1] == '\n')
 				line[linelen - 1] = '\0';
 			err = parse_packed_ref_line(&ref, NULL, line,
-			    sb.st_mtime);
+			    sb.st_mtime, got_repo_get_object_format(repo));
 			if (err)
 				goto done;
 			if (ref) {
@@ -1321,7 +1325,8 @@ delete_packed_ref(struct got_reference *delref, struct
 		}
 		if (linelen > 0 && line[linelen - 1] == '\n')
 			line[linelen - 1] = '\0';
-		err = parse_packed_ref_line(&ref, NULL, line, 0);
+		err = parse_packed_ref_line(&ref, NULL, line, 0,
+		    got_repo_get_object_format(repo));
 		if (err)
 			goto done;
 		if (ref == NULL)
blob - dc6e10be3fb65b371d7477b1baeca9e65ee5ba53
blob + f0c2434d5bb47c3df672fd0fc8a0de49c06ac979
--- lib/repository.c
+++ lib/repository.c
@@ -107,6 +107,12 @@ int
 got_repo_get_fd(struct got_repository *repo)
 {
 	return repo->gitdir_fd;
+}
+
+enum got_hash_algorithm
+got_repo_get_object_format(struct got_repository *repo)
+{
+	return repo->algo;
 }
 
 const char *
@@ -1733,7 +1739,6 @@ match_loose_object(struct got_object_id **unique_id, c
 	}
 	while ((dent = readdir(dir)) != NULL) {
 		int cmp;
-		enum got_hash_algorithm algo = GOT_HASH_SHA1;
 
 		free(id_str);
 		id_str = NULL;
@@ -1747,7 +1752,7 @@ match_loose_object(struct got_object_id **unique_id, c
 			goto done;
 		}
 
-		if (!got_parse_object_id(&id, id_str, algo))
+		if (!got_parse_object_id(&id, id_str, repo->algo))
 			continue;
 
 		/*
@@ -2287,7 +2292,6 @@ got_repo_get_loose_object_info(int *nobjects, off_t *o
 			char *id_str;
 			int fd;
 			struct stat sb;
-			enum got_hash_algorithm algo = GOT_HASH_SHA1;
 
 			if (strcmp(dent->d_name, ".") == 0 ||
 			    strcmp(dent->d_name, "..") == 0)
@@ -2298,7 +2302,7 @@ got_repo_get_loose_object_info(int *nobjects, off_t *o
 				goto done;
 			}
 
-			if (!got_parse_object_id(&id, id_str, algo)) {
+			if (!got_parse_object_id(&id, id_str, repo->algo)) {
 				free(id_str);
 				continue;
 			}
blob - dbb8389afe03f47e77d8417a8687a9ca9b678e04
blob + 1f97d3b5f98fe4c353a3086843e69a8d679b7674
--- lib/repository_admin.c
+++ lib/repository_admin.c
@@ -481,7 +481,7 @@ got_repo_find_pack(FILE **packfile, struct got_object_
 		goto done;
 	}
 	*dot = '\0';
-	if (!got_parse_object_id(&id, p, GOT_HASH_SHA1)) {
+	if (!got_parse_object_id(&id, p, repo->algo)) {
 		err = got_error_fmt(GOT_ERR_BAD_PATH,
 		    "'%s' is not a valid pack file name",
 		    packfile_name);
@@ -680,8 +680,7 @@ get_loose_object_ids(struct got_object_idset **loose_i
 				goto done;
 			}
 
-			if (!got_parse_object_id(&id, id_str,
-			    GOT_HASH_SHA1)) {
+			if (!got_parse_object_id(&id, id_str, repo->algo)) {
 				free(id_str);
 				continue;
 			}