Commit Diff


commit - b74bd7ab16a541c7e40d2f73187e0455f5416bb2
commit + 95b631b25683415ef380e22998436c28ad3e34c0
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 - 822d23e36daa2ec8baf6ed8a425b1b3982747390
blob + 47ff224bf7a9abf8dc6dbf39d3b8c6eb7c173a02
--- lib/reference.c
+++ lib/reference.c
@@ -153,9 +153,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) {
@@ -171,7 +170,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;
@@ -226,7 +226,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);
@@ -291,9 +291,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;
 
@@ -317,7 +316,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;
@@ -346,7 +346,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)
@@ -362,7 +362,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;
@@ -391,7 +391,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);
@@ -421,14 +421,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;
 		}
@@ -454,7 +455,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");
@@ -917,7 +919,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) {
@@ -970,7 +972,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);
@@ -986,7 +989,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;
@@ -1069,7 +1073,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) {
@@ -1322,7 +1326,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 - 7557fdbf38bd4ea36129a027cef620639766bd8d
blob + f6ac7c86bcf7794ce925c45451471441e0d4827c
--- lib/repository.c
+++ lib/repository.c
@@ -115,6 +115,12 @@ 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 *
 got_repo_get_gitconfig_author_name(struct got_repository *repo)
 {
@@ -1738,7 +1744,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;
@@ -1752,7 +1757,7 @@ match_loose_object(struct got_object_id **unique_id, c
 			goto done;
 		}
 
-		if (!got_parse_hash_digest(id.sha1, id_str, algo))
+		if (!got_parse_hash_digest(id.sha1, id_str, repo->algo))
 			continue;
 
 		/*
@@ -2292,7 +2297,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)
@@ -2303,7 +2307,8 @@ got_repo_get_loose_object_info(int *nobjects, off_t *o
 				goto done;
 			}
 
-			if (!got_parse_hash_digest(id.sha1, id_str, algo)) {
+			if (!got_parse_hash_digest(id.sha1, id_str,
+			    repo->algo)) {
 				free(id_str);
 				continue;
 			}