summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-09 22:10:49 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-10 14:21:16 +0100
commitcf06de46edcabd43a642a51e31480ed1ff29bd4b (patch)
treeef3b06d537f2356f4acb4bdb1d15e62527d58de6
parenta47bc4eacbe9c1d4e8e546fba7abcd22fca537b1 (diff)
downloadlibgit2-cf06de46edcabd43a642a51e31480ed1ff29bd4b.tar.gz
iterator: support sha256
-rw-r--r--src/libgit2/iterator.c25
-rw-r--r--src/libgit2/iterator.h3
-rw-r--r--src/libgit2/refdb_fs.c5
3 files changed, 27 insertions, 6 deletions
diff --git a/src/libgit2/iterator.c b/src/libgit2/iterator.c
index 1ee8e25f5..95ded1046 100644
--- a/src/libgit2/iterator.c
+++ b/src/libgit2/iterator.c
@@ -1036,6 +1036,8 @@ typedef struct {
git_index *index;
git_vector index_snapshot;
+ git_oid_t oid_type;
+
git_array_t(filesystem_iterator_frame) frames;
git_ignores ignores;
@@ -1271,7 +1273,7 @@ static int filesystem_iterator_entry_hash(
int error;
if (S_ISDIR(entry->st.st_mode)) {
- memset(&entry->id, 0, GIT_OID_SHA1_SIZE);
+ memset(&entry->id, 0, git_oid_size(iter->oid_type));
return 0;
}
@@ -1281,7 +1283,7 @@ static int filesystem_iterator_entry_hash(
if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) &&
!(error = git_path_validate_str_length(iter->base.repo, &fullpath)))
- error = git_odb__hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB, GIT_OID_SHA1);
+ error = git_odb__hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB, iter->oid_type);
git_str_dispose(&fullpath);
return error;
@@ -1530,7 +1532,7 @@ static void filesystem_iterator_set_current(
if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH)
git_oid_cpy(&iter->entry.id, &entry->id);
else
- git_oid_clear(&iter->entry.id, GIT_OID_SHA1);
+ git_oid_clear(&iter->entry.id, iter->oid_type);
iter->entry.path = entry->path;
@@ -1975,6 +1977,8 @@ static int iterator_for_filesystem(
(iterator__flag(&iter->base, PRECOMPOSE_UNICODE) ?
GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE : 0);
+ iter->oid_type = options->oid_type;
+
if ((error = filesystem_iterator_init(iter)) < 0)
goto on_error;
@@ -1989,10 +1993,15 @@ on_error:
int git_iterator_for_filesystem(
git_iterator **out,
const char *root,
- git_iterator_options *options)
+ git_iterator_options *given_opts)
{
+ git_iterator_options options = GIT_ITERATOR_OPTIONS_INIT;
+
+ if (given_opts)
+ memcpy(&options, given_opts, sizeof(git_iterator_options));
+
return iterator_for_filesystem(out,
- NULL, root, NULL, NULL, GIT_ITERATOR_FS, options);
+ NULL, root, NULL, NULL, GIT_ITERATOR_FS, &options);
}
int git_iterator_for_workdir_ext(
@@ -2019,6 +2028,12 @@ int git_iterator_for_workdir_ext(
options.flags |= GIT_ITERATOR_HONOR_IGNORES |
GIT_ITERATOR_IGNORE_DOT_GIT;
+ if (!options.oid_type)
+ options.oid_type = repo->oid_type;
+ else if (options.oid_type != repo->oid_type)
+ git_error_set(GIT_ERROR_INVALID,
+ "specified object ID type does not match repository object ID type");
+
return iterator_for_filesystem(out,
repo, repo_workdir, index, tree, GIT_ITERATOR_WORKDIR, &options);
}
diff --git a/src/libgit2/iterator.h b/src/libgit2/iterator.h
index 6bb8489d0..7963ce7e2 100644
--- a/src/libgit2/iterator.h
+++ b/src/libgit2/iterator.h
@@ -63,6 +63,9 @@ typedef struct {
/* flags, from above */
unsigned int flags;
+
+ /* oid type - necessary for non-workdir filesystem iterators */
+ git_oid_t oid_type;
} git_iterator_options;
#define GIT_ITERATOR_OPTIONS_INIT {0}
diff --git a/src/libgit2/refdb_fs.c b/src/libgit2/refdb_fs.c
index 6000dafb3..c5b292ae3 100644
--- a/src/libgit2/refdb_fs.c
+++ b/src/libgit2/refdb_fs.c
@@ -805,7 +805,9 @@ static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
git__free(iter);
}
-static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
+static int iter_load_loose_paths(
+ refdb_fs_backend *backend,
+ refdb_fs_iter *iter)
{
int error = 0;
git_str path = GIT_STR_INIT;
@@ -819,6 +821,7 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
return 0;
fsit_opts.flags = backend->iterator_flags;
+ fsit_opts.oid_type = backend->oid_type;
if (iter->glob) {
const char *last_sep = NULL;