summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/attrcache.c5
-rw-r--r--src/checkout.c8
-rw-r--r--src/filter.c2
-rw-r--r--src/ignore.c2
-rw-r--r--src/iterator.c8
-rw-r--r--src/mailmap.c2
-rw-r--r--src/path.c47
-rw-r--r--src/path.h22
-rw-r--r--src/repository.c53
-rw-r--r--src/repository.h23
-rw-r--r--src/submodule.c2
-rw-r--r--src/worktree.c2
12 files changed, 91 insertions, 85 deletions
diff --git a/src/attrcache.c b/src/attrcache.c
index 2b36b7a9c..ad3453197 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -66,7 +66,8 @@ int git_attr_cache__alloc_file_entry(
}
memcpy(&ce->fullpath[baselen], path, pathlen);
- if (git_path_validate_workdir_with_len(repo, ce->fullpath, pathlen + baselen) < 0)
+ if (git_repository_validate_workdir_path_with_len(repo,
+ ce->fullpath, pathlen + baselen) < 0)
return -1;
ce->path = &ce->fullpath[baselen];
@@ -173,7 +174,7 @@ static int attr_cache_lookup(
git_buf *p = attr_session ? &attr_session->tmp : &path;
if (git_buf_joinpath(p, source->base, source->filename) < 0 ||
- git_path_validate_workdir_buf(repo, p) < 0)
+ git_repository_validate_workdir_path_buf(repo, p) < 0)
return -1;
filename = p->ptr;
diff --git a/src/checkout.c b/src/checkout.c
index 3a171066b..75c06c14e 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -328,7 +328,7 @@ static int checkout_target_fullpath(
if (path && git_buf_puts(&data->target_path, path) < 0)
return -1;
- if (git_path_validate_workdir_buf(data->repo, &data->target_path) < 0)
+ if (git_repository_validate_workdir_path_buf(data->repo, &data->target_path) < 0)
return -1;
*out = &data->target_path;
@@ -2034,7 +2034,7 @@ static int checkout_merge_path(
int error = 0;
if ((error = git_buf_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
- (error = git_path_validate_workdir_buf(data->repo, out)) < 0)
+ (error = git_repository_validate_workdir_path_buf(data->repo, out)) < 0)
return error;
/* Most conflicts simply use the filename in the index */
@@ -2337,7 +2337,7 @@ static int validate_target_directory(checkout_data *data)
{
int error;
- if ((error = git_path_validate_workdir(data->repo, data->opts.target_directory)) < 0)
+ if ((error = git_repository_validate_workdir_path(data->repo, data->opts.target_directory)) < 0)
return error;
if (git_path_isdir(data->opts.target_directory))
@@ -2623,7 +2623,7 @@ int git_checkout_iterator(
if (data.strategy & GIT_CHECKOUT_DRY_RUN)
goto cleanup;
-
+
data.total_steps = counts[CHECKOUT_ACTION__REMOVE] +
counts[CHECKOUT_ACTION__REMOVE_CONFLICT] +
counts[CHECKOUT_ACTION__UPDATE_BLOB] +
diff --git a/src/filter.c b/src/filter.c
index 73497cb30..480b3e2dd 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -1042,7 +1042,7 @@ int git_filter_list_stream_file(
if ((error = stream_list_init(
&stream_start, &filter_streams, filters, target)) < 0 ||
(error = git_path_join_unrooted(&abspath, path, base, NULL)) < 0 ||
- (error = git_path_validate_workdir_buf(repo, &abspath)) < 0)
+ (error = git_repository_validate_workdir_path_buf(repo, &abspath)) < 0)
goto done;
initialized = 1;
diff --git a/src/ignore.c b/src/ignore.c
index 9ead96ba6..4c7e13c68 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -320,7 +320,7 @@ int git_ignore__for_path(
(error = git_path_resolve_relative(&local, 0)) < 0 ||
(error = git_path_to_dir(&local)) < 0 ||
(error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0 ||
- (error = git_path_validate_workdir_buf(repo, &ignores->dir)) < 0) {
+ (error = git_repository_validate_workdir_path_buf(repo, &ignores->dir)) < 0) {
/* Nothing, we just want to stop on the first error */
}
diff --git a/src/iterator.c b/src/iterator.c
index ce9f305ef..19bdf7662 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -1279,7 +1279,7 @@ static int filesystem_iterator_entry_hash(
iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL);
if (!(error = git_buf_joinpath(&fullpath, iter->root, entry->path)) &&
- !(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)))
+ !(error = git_repository_validate_workdir_path_buf(iter->base.repo, &fullpath)))
error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB);
git_buf_dispose(&fullpath);
@@ -1361,7 +1361,7 @@ static int filesystem_iterator_frame_push(
git_buf_puts(&root, iter->root);
if (git_buf_oom(&root) ||
- git_path_validate_workdir_buf(iter->base.repo, &root) < 0) {
+ git_repository_validate_workdir_path_buf(iter->base.repo, &root) < 0) {
error = -1;
goto done;
}
@@ -1392,7 +1392,7 @@ static int filesystem_iterator_frame_push(
bool dir_expected = false;
if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 ||
- (error = git_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0)
+ (error = git_repository_validate_workdir_path_with_len(iter->base.repo, path, path_len)) < 0)
goto done;
GIT_ASSERT(path_len > iter->root_len);
@@ -1565,7 +1565,7 @@ static int filesystem_iterator_is_dir(
}
if ((error = git_buf_joinpath(&fullpath, iter->root, entry->path)) < 0 ||
- (error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 ||
+ (error = git_repository_validate_workdir_path_buf(iter->base.repo, &fullpath)) < 0 ||
(error = p_stat(fullpath.ptr, &st)) < 0)
goto done;
diff --git a/src/mailmap.c b/src/mailmap.c
index b69d55e2e..bd571413e 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -330,7 +330,7 @@ static int mailmap_add_file_ondisk(
if (error < 0)
goto cleanup;
- error = git_path_validate_workdir_buf(repo, &fullpath);
+ error = git_repository_validate_workdir_path_buf(repo, &fullpath);
if (error < 0)
goto cleanup;
diff --git a/src/path.c b/src/path.c
index c444b31a7..9412833eb 100644
--- a/src/path.c
+++ b/src/path.c
@@ -9,6 +9,7 @@
#include "posix.h"
#include "repository.h"
+
#ifdef GIT_WIN32
#include "win32/posix.h"
#include "win32/w32_buffer.h"
@@ -1902,52 +1903,6 @@ bool git_path_validate(
return verify_component(repo, start, (c - start), mode, flags);
}
-#ifdef GIT_WIN32
-GIT_INLINE(bool) should_validate_longpaths(git_repository *repo)
-{
- int longpaths = 0;
-
- if (repo &&
- git_repository__configmap_lookup(&longpaths, repo, GIT_CONFIGMAP_LONGPATHS) < 0)
- longpaths = 0;
-
- return (longpaths == 0);
-}
-
-#else
-
-GIT_INLINE(bool) should_validate_longpaths(git_repository *repo)
-{
- GIT_UNUSED(repo);
-
- return false;
-}
-#endif
-
-int git_path_validate_workdir(git_repository *repo, const char *path)
-{
- if (should_validate_longpaths(repo))
- return git_path_validate_filesystem(path, strlen(path));
-
- return 0;
-}
-
-int git_path_validate_workdir_with_len(
- git_repository *repo,
- const char *path,
- size_t path_len)
-{
- if (should_validate_longpaths(repo))
- return git_path_validate_filesystem(path, path_len);
-
- return 0;
-}
-
-int git_path_validate_workdir_buf(git_repository *repo, git_buf *path)
-{
- return git_path_validate_workdir_with_len(repo, path->ptr, path->size);
-}
-
int git_path_normalize_slashes(git_buf *out, const char *path)
{
int error;
diff --git a/src/path.h b/src/path.h
index de6ec8ff2..473ef9ae3 100644
--- a/src/path.h
+++ b/src/path.h
@@ -694,28 +694,6 @@ GIT_INLINE(int) git_path_validate_filesystem(
}
/**
- * Validate a path relative to the repo's worktree. This ensures that
- * the given working tree path is valid for the operating system/platform.
- * This will ensure that an absolute path is smaller than MAX_PATH on
- * Windows, while keeping `core.longpaths` configuration settings in mind.
- *
- * This should be checked by mechamisms like `git_checkout` after
- * contructing on-disk paths and before trying to write them.
- *
- * If the repository is null, no repository configuration is applied.
- */
-extern int git_path_validate_workdir(
- git_repository *repo,
- const char *path);
-extern int git_path_validate_workdir_with_len(
- git_repository *repo,
- const char *path,
- size_t path_len);
-extern int git_path_validate_workdir_buf(
- git_repository *repo,
- git_buf *buf);
-
-/**
* Convert any backslashes into slashes
*/
int git_path_normalize_slashes(git_buf *out, const char *path);
diff --git a/src/repository.c b/src/repository.c
index 9b3e9c9e3..5901dd308 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -2654,7 +2654,7 @@ int git_repository_workdir_path(
}
if (!(error = git_buf_joinpath(out, repo->workdir, path)))
- error = git_path_validate_workdir_buf(repo, out);
+ error = git_repository_validate_workdir_path_buf(repo, out);
return error;
}
@@ -2848,7 +2848,7 @@ int git_repository_hashfile(
GIT_ASSERT_ARG(repo);
if ((error = git_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
- (error = git_path_validate_workdir_buf(repo, &full_path)) < 0)
+ (error = git_repository_validate_workdir_path_buf(repo, &full_path)) < 0)
return error;
/*
@@ -3236,3 +3236,52 @@ int git_repository_submodule_cache_clear(git_repository *repo)
repo->submodule_cache = NULL;
return error;
}
+
+
+#ifdef GIT_WIN32
+GIT_INLINE(bool) should_validate_longpaths(git_repository *repo)
+{
+ int longpaths = 0;
+
+ if (repo &&
+ git_repository__configmap_lookup(&longpaths, repo, GIT_CONFIGMAP_LONGPATHS) < 0)
+ longpaths = 0;
+
+ return (longpaths == 0);
+}
+
+#else
+
+GIT_INLINE(bool) should_validate_longpaths(git_repository *repo)
+{
+ GIT_UNUSED(repo);
+
+ return false;
+}
+#endif
+
+int git_repository_validate_workdir_path(
+ git_repository *repo,
+ const char *path)
+{
+ if (should_validate_longpaths(repo))
+ return git_path_validate_filesystem(path, strlen(path));
+
+ return 0;
+}
+
+int git_repository_validate_workdir_path_with_len(
+ git_repository *repo,
+ const char *path,
+ size_t path_len)
+{
+ if (should_validate_longpaths(repo))
+ return git_path_validate_filesystem(path, path_len);
+
+ return 0;
+}
+
+int git_repository_validate_workdir_path_buf(git_repository *repo, git_buf *path)
+{
+ return git_repository_validate_workdir_path_with_len(repo, path->ptr, path->size);
+}
diff --git a/src/repository.h b/src/repository.h
index cbc160140..688ab4fbf 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -249,6 +249,29 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo);
*/
int git_repository_workdir_path(git_buf *out, git_repository *repo, const char *path);
+/*
+ * Path validation within repository working directories; these
+ * functions ensure a working tree paths is valid for the operating
+ * system/platform. For example, these will ensure that an absolute
+ * path is smaller than `MAX_PATH` on Windows, while keeping the
+ * repository configuration (`core.longpaths`) into account.
+ *
+ * These should be checked by mechamisms like `git_checkout` after
+ * contructing on-disk paths and before trying to write them.
+ *
+ * If the repository is null, no repository configuration is applied.
+ */
+int git_repository_validate_workdir_path(
+ git_repository *repo,
+ const char *path);
+int git_repository_validate_workdir_path_with_len(
+ git_repository *repo,
+ const char *path,
+ size_t path_len);
+int git_repository_validate_workdir_path_buf(
+ git_repository *repo,
+ git_buf *buf);
+
int git_repository__extensions(char ***out, size_t *out_len);
int git_repository__set_extensions(const char **extensions, size_t len);
void git_repository__free_extensions(void);
diff --git a/src/submodule.c b/src/submodule.c
index 7cbb9fa3a..415e83d96 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -382,7 +382,7 @@ int git_submodule__lookup_with_cache(
if (git_buf_join3(&path, '/',
git_repository_workdir(repo),
name, DOT_GIT) < 0 ||
- git_path_validate_workdir_buf(NULL, &path) < 0)
+ git_repository_validate_workdir_path_buf(NULL, &path) < 0)
return -1;
if (git_path_exists(path.ptr))
diff --git a/src/worktree.c b/src/worktree.c
index fe8db7743..1816a6d05 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -135,7 +135,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
goto out;
}
- if ((error = git_path_validate_workdir(NULL, dir)) < 0)
+ if ((error = git_repository_validate_workdir_path(NULL, dir)) < 0)
goto out;
if ((wt = git__calloc(1, sizeof(*wt))) == NULL) {