summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blob.c6
-rw-r--r--src/checkout.c3
-rw-r--r--src/crlf.c23
-rw-r--r--src/diff.c3
-rw-r--r--src/diff_file.c3
-rw-r--r--src/filter.c17
-rw-r--r--src/repository.c3
7 files changed, 46 insertions, 12 deletions
diff --git a/src/blob.c b/src/blob.c
index 0aa2516db..ab7dec67f 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -198,7 +198,8 @@ int git_blob__create_from_paths(
if (try_load_filters)
/* Load the filters for writing this file to the ODB */
error = git_filter_list_load(
- &fl, repo, NULL, hint_path, GIT_FILTER_TO_ODB);
+ &fl, repo, NULL, hint_path,
+ GIT_FILTER_TO_ODB, GIT_FILTER_OPT_DEFAULT);
if (error < 0)
/* well, that didn't work */;
@@ -356,7 +357,8 @@ int git_blob_filtered_content(
return 0;
if (!(error = git_filter_list_load(
- &fl, git_blob_owner(blob), blob, path, GIT_FILTER_TO_WORKTREE))) {
+ &fl, git_blob_owner(blob), blob, path,
+ GIT_FILTER_TO_WORKTREE, GIT_FILTER_OPT_DEFAULT))) {
error = git_filter_list_apply_to_blob(out, fl, blob);
diff --git a/src/checkout.c b/src/checkout.c
index b869efe2b..20763fd35 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -1212,7 +1212,8 @@ static int blob_content_to_file(
if (!opts->disable_filters)
error = git_filter_list_load(
- &fl, git_blob_owner(blob), blob, hint_path, GIT_FILTER_TO_WORKTREE);
+ &fl, git_blob_owner(blob), blob, hint_path,
+ GIT_FILTER_TO_WORKTREE, GIT_FILTER_OPT_DEFAULT);
if (!error)
error = git_filter_list_apply_to_blob(&out, fl, blob);
diff --git a/src/crlf.c b/src/crlf.c
index 8be1b9a05..dad3ecebc 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -139,10 +139,19 @@ static int crlf_apply_to_odb(
return GIT_PASSTHROUGH;
/* If safecrlf is enabled, sanity-check the result. */
- if (ca->safe_crlf && (stats.cr != stats.crlf || stats.lf != stats.crlf)) {
- giterr_set(GITERR_FILTER, "LF would be replaced by CRLF in '%s'",
- git_filter_source_path(src));
- return -1;
+ if (stats.cr != stats.crlf || stats.lf != stats.crlf) {
+ switch (ca->safe_crlf) {
+ case GIT_SAFE_CRLF_FAIL:
+ giterr_set(
+ GITERR_FILTER, "LF would be replaced by CRLF in '%s'",
+ git_filter_source_path(src));
+ return -1;
+ case GIT_SAFE_CRLF_WARN:
+ /* TODO: issue warning when warning API is available */;
+ break;
+ default:
+ break;
+ }
}
/*
@@ -267,6 +276,7 @@ static int crlf_check(
if (ca.crlf_action == GIT_CRLF_GUESS ||
(ca.crlf_action == GIT_CRLF_AUTO &&
git_filter_source_mode(src) == GIT_FILTER_SMUDGE)) {
+
error = git_repository__cvar(
&ca.auto_crlf, git_filter_source_repo(src), GIT_CVAR_AUTO_CRLF);
if (error < 0)
@@ -285,6 +295,11 @@ static int crlf_check(
&ca.safe_crlf, git_filter_source_repo(src), GIT_CVAR_SAFE_CRLF);
if (error < 0)
return error;
+
+ /* downgrade FAIL to WARN if ALLOW_UNSAFE option is used */
+ if ((git_filter_source_options(src) & GIT_FILTER_OPT_ALLOW_UNSAFE) &&
+ ca.safe_crlf == GIT_SAFE_CRLF_FAIL)
+ ca.safe_crlf = GIT_SAFE_CRLF_WARN;
}
*payload = git__malloc(sizeof(ca));
diff --git a/src/diff.c b/src/diff.c
index 781f23ec6..bc23e6b0d 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -589,7 +589,8 @@ int git_diff__oid_for_entry(
entry.path);
error = -1;
} else if (!(error = git_filter_list_load(
- &fl, diff->repo, NULL, entry.path, GIT_FILTER_TO_ODB)))
+ &fl, diff->repo, NULL, entry.path,
+ GIT_FILTER_TO_ODB, GIT_FILTER_OPT_ALLOW_UNSAFE)))
{
int fd = git_futils_open_ro(full_path.ptr);
if (fd < 0)
diff --git a/src/diff_file.c b/src/diff_file.c
index b9f92df3f..f2a1d5099 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -300,7 +300,8 @@ static int diff_file_content_load_workdir_file(
goto cleanup;
if ((error = git_filter_list_load(
- &fl, fc->repo, NULL, fc->file->path, GIT_FILTER_TO_ODB)) < 0)
+ &fl, fc->repo, NULL, fc->file->path,
+ GIT_FILTER_TO_ODB, GIT_FILTER_OPT_ALLOW_UNSAFE)) < 0)
goto cleanup;
/* if there are no filters, try to mmap the file */
diff --git a/src/filter.c b/src/filter.c
index b2f57964a..b0e2b8bea 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -23,6 +23,7 @@ struct git_filter_source {
git_oid oid; /* zero if unknown (which is likely) */
uint16_t filemode; /* zero if unknown */
git_filter_mode_t mode;
+ git_filter_opt_t options;
};
typedef struct {
@@ -358,6 +359,11 @@ git_filter_mode_t git_filter_source_mode(const git_filter_source *src)
return src->mode;
}
+git_filter_opt_t git_filter_source_options(const git_filter_source *src)
+{
+ return src->options;
+}
+
static int filter_list_new(
git_filter_list **out, const git_filter_source *src)
{
@@ -372,6 +378,7 @@ static int filter_list_new(
fl->source.repo = src->repo;
fl->source.path = fl->path;
fl->source.mode = src->mode;
+ fl->source.options = src->options;
*out = fl;
return 0;
@@ -419,12 +426,16 @@ static int filter_list_check_attributes(
}
int git_filter_list_new(
- git_filter_list **out, git_repository *repo, git_filter_mode_t mode)
+ git_filter_list **out,
+ git_repository *repo,
+ git_filter_mode_t mode,
+ git_filter_opt_t options)
{
git_filter_source src = { 0 };
src.repo = repo;
src.path = NULL;
src.mode = mode;
+ src.options = options;
return filter_list_new(out, &src);
}
@@ -433,7 +444,8 @@ int git_filter_list_load(
git_repository *repo,
git_blob *blob, /* can be NULL */
const char *path,
- git_filter_mode_t mode)
+ git_filter_mode_t mode,
+ git_filter_opt_t options)
{
int error = 0;
git_filter_list *fl = NULL;
@@ -448,6 +460,7 @@ int git_filter_list_load(
src.repo = repo;
src.path = path;
src.mode = mode;
+ src.options = options;
if (blob)
git_oid_cpy(&src.oid, git_blob_id(blob));
diff --git a/src/repository.c b/src/repository.c
index ac7af7692..df5f322ce 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1789,7 +1789,8 @@ int git_repository_hashfile(
/* passing empty string for "as_path" indicated --no-filters */
if (strlen(as_path) > 0) {
error = git_filter_list_load(
- &fl, repo, NULL, as_path, GIT_FILTER_TO_ODB);
+ &fl, repo, NULL, as_path,
+ GIT_FILTER_TO_ODB, GIT_FILTER_OPT_DEFAULT);
if (error < 0)
return error;
} else {