summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config_cache.c1
-rw-r--r--src/crlf.c15
-rw-r--r--src/repository.h4
3 files changed, 19 insertions, 1 deletions
diff --git a/src/config_cache.c b/src/config_cache.c
index ec75d1501..4bcbf02bf 100644
--- a/src/config_cache.c
+++ b/src/config_cache.c
@@ -68,6 +68,7 @@ static struct map_data _cvar_maps[] = {
{"core.trustctime", NULL, 0, GIT_TRUSTCTIME_DEFAULT },
{"core.abbrev", _cvar_map_int, 1, GIT_ABBREV_DEFAULT },
{"core.precomposeunicode", NULL, 0, GIT_PRECOMPOSE_DEFAULT },
+ {"core.safecrlf", NULL, 0, GIT_SAFE_CRLF_DEFAULT},
};
int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar)
diff --git a/src/crlf.c b/src/crlf.c
index 2480cc918..8be1b9a05 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -21,6 +21,7 @@ struct crlf_attrs {
int crlf_action;
int eol;
int auto_crlf;
+ int safe_crlf;
};
struct crlf_filter {
@@ -137,6 +138,13 @@ static int crlf_apply_to_odb(
if (git_buf_text_gather_stats(&stats, from, false))
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;
+ }
+
/*
* We're currently not going to even try to convert stuff
* that has bare CR characters. Does anybody do that crazy
@@ -272,6 +280,13 @@ static int crlf_check(
return GIT_PASSTHROUGH;
}
+ if (git_filter_source_mode(src) == GIT_FILTER_CLEAN) {
+ error = git_repository__cvar(
+ &ca.safe_crlf, git_filter_source_repo(src), GIT_CVAR_SAFE_CRLF);
+ if (error < 0)
+ return error;
+ }
+
*payload = git__malloc(sizeof(ca));
GITERR_CHECK_ALLOC(*payload);
memcpy(*payload, &ca, sizeof(ca));
diff --git a/src/repository.h b/src/repository.h
index 86db488fd..27eec9dd8 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -38,6 +38,7 @@ typedef enum {
GIT_CVAR_TRUSTCTIME, /* core.trustctime */
GIT_CVAR_ABBREV, /* core.abbrev */
GIT_CVAR_PRECOMPOSE, /* core.precomposeunicode */
+ GIT_CVAR_SAFE_CRLF, /* core.safecrlf */
GIT_CVAR_CACHE_MAX
} git_cvar_cached;
@@ -89,7 +90,8 @@ typedef enum {
GIT_ABBREV_DEFAULT = 7,
/* core.precomposeunicode */
GIT_PRECOMPOSE_DEFAULT = GIT_CVAR_FALSE,
-
+ /* core.safecrlf */
+ GIT_SAFE_CRLF_DEFAULT = GIT_CVAR_FALSE,
} git_cvar_value;
/* internal repository init flags */