commit - 9334723a60466be8c0bff5875128e9f02c32e5b1
commit + b54930d53597467f9112f45e9bfd192e352531ac
blob - 53e99801ab01ad8804d048c5f59a94930e5ef10a
blob + 17dcc926d4cae7fa2f169eb003ed4aeebba92346
--- include/got_repository.h
+++ include/got_repository.h
/* 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
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 - fd8aa92b4400836a36c9ff24e521107661b42342
blob + 63ca6d274ce665df8f732c43075f6e6a0954e540
--- lib/reference.c
+++ lib/reference.c
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) {
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;
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);
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;
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;
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)
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;
}
}
- 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);
}
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;
}
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");
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) {
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);
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;
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) {
}
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 - bb181bc9236aba33630380d438c03cdfc85ae0d9
blob + 6a757d85bc1ec107e2faa5b5d8a2f03388bef3d7
--- lib/repository.c
+++ lib/repository.c
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 *
}
while ((dent = readdir(dir)) != NULL) {
int cmp;
- enum got_hash_algorithm algo = GOT_HASH_SHA1;
free(id_str);
id_str = NULL;
goto done;
}
- if (!got_parse_object_id(&id, id_str, algo))
+ if (!got_parse_object_id(&id, id_str, repo->algo))
continue;
/*
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)
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 - 8608ef9dfd20957fb5e02caccfd03c8ca891ebc4
blob + 48bed8a15e5f885c25ca796741f37fb70f1b87e3
--- lib/repository_admin.c
+++ lib/repository_admin.c
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);
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;
}