Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
386777fd
Commit
386777fd
authored
Apr 18, 2014
by
Russell Belfer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2213 from ethomson/safecrlf
Introduce core.safecrlf handling
parents
3c69bebc
7be1caf7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
1 deletions
+99
-1
src/config_cache.c
+1
-0
src/crlf.c
+15
-0
src/repository.h
+3
-1
tests/filter/crlf.c
+80
-0
No files found.
src/config_cache.c
View file @
386777fd
...
@@ -68,6 +68,7 @@ static struct map_data _cvar_maps[] = {
...
@@ -68,6 +68,7 @@ static struct map_data _cvar_maps[] = {
{
"core.trustctime"
,
NULL
,
0
,
GIT_TRUSTCTIME_DEFAULT
},
{
"core.trustctime"
,
NULL
,
0
,
GIT_TRUSTCTIME_DEFAULT
},
{
"core.abbrev"
,
_cvar_map_int
,
1
,
GIT_ABBREV_DEFAULT
},
{
"core.abbrev"
,
_cvar_map_int
,
1
,
GIT_ABBREV_DEFAULT
},
{
"core.precomposeunicode"
,
NULL
,
0
,
GIT_PRECOMPOSE_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
)
int
git_repository__cvar
(
int
*
out
,
git_repository
*
repo
,
git_cvar_cached
cvar
)
...
...
src/crlf.c
View file @
386777fd
...
@@ -21,6 +21,7 @@ struct crlf_attrs {
...
@@ -21,6 +21,7 @@ struct crlf_attrs {
int
crlf_action
;
int
crlf_action
;
int
eol
;
int
eol
;
int
auto_crlf
;
int
auto_crlf
;
int
safe_crlf
;
};
};
struct
crlf_filter
{
struct
crlf_filter
{
...
@@ -137,6 +138,13 @@ static int crlf_apply_to_odb(
...
@@ -137,6 +138,13 @@ static int crlf_apply_to_odb(
if
(
git_buf_text_gather_stats
(
&
stats
,
from
,
false
))
if
(
git_buf_text_gather_stats
(
&
stats
,
from
,
false
))
return
GIT_PASSTHROUGH
;
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
* We're currently not going to even try to convert stuff
* that has bare CR characters. Does anybody do that crazy
* that has bare CR characters. Does anybody do that crazy
...
@@ -272,6 +280,13 @@ static int crlf_check(
...
@@ -272,6 +280,13 @@ static int crlf_check(
return
GIT_PASSTHROUGH
;
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
));
*
payload
=
git__malloc
(
sizeof
(
ca
));
GITERR_CHECK_ALLOC
(
*
payload
);
GITERR_CHECK_ALLOC
(
*
payload
);
memcpy
(
*
payload
,
&
ca
,
sizeof
(
ca
));
memcpy
(
*
payload
,
&
ca
,
sizeof
(
ca
));
...
...
src/repository.h
View file @
386777fd
...
@@ -38,6 +38,7 @@ typedef enum {
...
@@ -38,6 +38,7 @@ typedef enum {
GIT_CVAR_TRUSTCTIME
,
/* core.trustctime */
GIT_CVAR_TRUSTCTIME
,
/* core.trustctime */
GIT_CVAR_ABBREV
,
/* core.abbrev */
GIT_CVAR_ABBREV
,
/* core.abbrev */
GIT_CVAR_PRECOMPOSE
,
/* core.precomposeunicode */
GIT_CVAR_PRECOMPOSE
,
/* core.precomposeunicode */
GIT_CVAR_SAFE_CRLF
,
/* core.safecrlf */
GIT_CVAR_CACHE_MAX
GIT_CVAR_CACHE_MAX
}
git_cvar_cached
;
}
git_cvar_cached
;
...
@@ -89,7 +90,8 @@ typedef enum {
...
@@ -89,7 +90,8 @@ typedef enum {
GIT_ABBREV_DEFAULT
=
7
,
GIT_ABBREV_DEFAULT
=
7
,
/* core.precomposeunicode */
/* core.precomposeunicode */
GIT_PRECOMPOSE_DEFAULT
=
GIT_CVAR_FALSE
,
GIT_PRECOMPOSE_DEFAULT
=
GIT_CVAR_FALSE
,
/* core.safecrlf */
GIT_SAFE_CRLF_DEFAULT
=
GIT_CVAR_FALSE
,
}
git_cvar_value
;
}
git_cvar_value
;
/* internal repository init flags */
/* internal repository init flags */
...
...
tests/filter/crlf.c
View file @
386777fd
#include "clar_libgit2.h"
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
#include "git2/sys/filter.h"
#include "buffer.h"
static
git_repository
*
g_repo
=
NULL
;
static
git_repository
*
g_repo
=
NULL
;
...
@@ -69,3 +70,82 @@ void test_filter_crlf__to_odb(void)
...
@@ -69,3 +70,82 @@ void test_filter_crlf__to_odb(void)
git_filter_list_free
(
fl
);
git_filter_list_free
(
fl
);
git_buf_free
(
&
out
);
git_buf_free
(
&
out
);
}
}
void
test_filter_crlf__with_safecrlf
(
void
)
{
git_filter_list
*
fl
;
git_filter
*
crlf
;
git_buf
in
=
{
0
},
out
=
GIT_BUF_INIT
;
cl_repo_set_bool
(
g_repo
,
"core.safecrlf"
,
true
);
cl_git_pass
(
git_filter_list_new
(
&
fl
,
g_repo
,
GIT_FILTER_TO_ODB
));
crlf
=
git_filter_lookup
(
GIT_FILTER_CRLF
);
cl_assert
(
crlf
!=
NULL
);
cl_git_pass
(
git_filter_list_push
(
fl
,
crlf
,
NULL
));
/* Normalized \r\n succeeds with safecrlf */
in
.
ptr
=
"Normal
\r\n
CRLF
\r\n
line-endings.
\r\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_assert_equal_s
(
"Normal
\n
CRLF
\n
line-endings.
\n
"
,
out
.
ptr
);
/* Mix of line endings fails with safecrlf */
in
.
ptr
=
"Mixed
\n
up
\r\n
LF
\n
and
\r\n
CRLF
\n
line-endings.
\r\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
cl_git_fail
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_assert_equal_i
(
giterr_last
()
->
klass
,
GITERR_FILTER
);
/* Normalized \n fails with safecrlf */
in
.
ptr
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
cl_git_fail
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_assert_equal_i
(
giterr_last
()
->
klass
,
GITERR_FILTER
);
git_filter_list_free
(
fl
);
git_buf_free
(
&
out
);
}
void
test_filter_crlf__no_safecrlf
(
void
)
{
git_filter_list
*
fl
;
git_filter
*
crlf
;
git_buf
in
=
{
0
},
out
=
GIT_BUF_INIT
;
cl_git_pass
(
git_filter_list_new
(
&
fl
,
g_repo
,
GIT_FILTER_TO_ODB
));
crlf
=
git_filter_lookup
(
GIT_FILTER_CRLF
);
cl_assert
(
crlf
!=
NULL
);
cl_git_pass
(
git_filter_list_push
(
fl
,
crlf
,
NULL
));
/* Normalized \r\n succeeds with safecrlf */
in
.
ptr
=
"Normal
\r\n
CRLF
\r\n
line-endings.
\r\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_assert_equal_s
(
"Normal
\n
CRLF
\n
line-endings.
\n
"
,
out
.
ptr
);
/* Mix of line endings fails with safecrlf */
in
.
ptr
=
"Mixed
\n
up
\r\n
LF
\n
and
\r\n
CRLF
\n
line-endings.
\r\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_assert_equal_s
(
"Mixed
\n
up
\n
LF
\n
and
\n
CRLF
\n
line-endings.
\n
"
,
out
.
ptr
);
/* Normalized \n fails with safecrlf */
in
.
ptr
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_assert_equal_s
(
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
,
out
.
ptr
);
git_filter_list_free
(
fl
);
git_buf_free
(
&
out
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment