summaryrefslogtreecommitdiff
path: root/src/crlf.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-05-06 16:01:49 -0700
committerRussell Belfer <rb@github.com>2014-05-06 16:01:49 -0700
commit5269008cf632efcd6a16f6160ec44244ce442400 (patch)
treead3be5bcf12e9c046fab24fac3063e22b6843d5c /src/crlf.c
parent6e9afb97d14545f9cea292f581de89d610ae8c07 (diff)
downloadlibgit2-5269008cf632efcd6a16f6160ec44244ce442400.tar.gz
Add filter options and ALLOW_UNSAFE
Diff and status do not want core.safecrlf to actually raise an error regardless of the setting, so this extends the filter API with an additional options flags parameter and adds a flag so that filters can be applied with GIT_FILTER_OPT_ALLOW_UNSAFE, indicating that unsafe filter application should be downgraded from a failure to a warning.
Diffstat (limited to 'src/crlf.c')
-rw-r--r--src/crlf.c23
1 files changed, 19 insertions, 4 deletions
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));