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
3ddd0d92
Commit
3ddd0d92
authored
Jun 24, 2014
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/cmn/mixed-eol-passthrough'
parents
29fe897d
5a76ad35
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
33 deletions
+22
-33
src/buf_text.c
+9
-5
src/buf_text.h
+3
-2
tests/checkout/crlf.c
+2
-8
tests/core/buffer.c
+8
-18
No files found.
src/buf_text.c
View file @
3ddd0d92
...
...
@@ -123,9 +123,13 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
for
(;
next
;
scan
=
next
+
1
,
next
=
memchr
(
scan
,
'\n'
,
end
-
scan
))
{
size_t
copylen
=
next
-
scan
;
/* don't convert existing \r\n to \r\r\n */
size_t
extralen
=
(
next
>
start
&&
next
[
-
1
]
==
'\r'
)
?
1
:
2
;
size_t
needsize
=
tgt
->
size
+
copylen
+
extralen
+
1
;
size_t
needsize
=
tgt
->
size
+
copylen
+
2
+
1
;
/* if we find mixed line endings, bail */
if
(
next
>
start
&&
next
[
-
1
]
==
'\r'
)
{
git_buf_free
(
tgt
);
return
GIT_PASSTHROUGH
;
}
if
(
tgt
->
asize
<
needsize
&&
git_buf_grow
(
tgt
,
needsize
)
<
0
)
return
-
1
;
...
...
@@ -134,8 +138,8 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
memcpy
(
tgt
->
ptr
+
tgt
->
size
,
scan
,
copylen
);
tgt
->
size
+=
copylen
;
}
if
(
extralen
==
2
)
tgt
->
ptr
[
tgt
->
size
++
]
=
'\r'
;
tgt
->
ptr
[
tgt
->
size
++
]
=
'\r'
;
tgt
->
ptr
[
tgt
->
size
++
]
=
'\n'
;
}
...
...
src/buf_text.h
View file @
3ddd0d92
...
...
@@ -56,9 +56,10 @@ GIT_INLINE(int) git_buf_text_puts_escape_regex(git_buf *buf, const char *string)
extern
void
git_buf_text_unescape
(
git_buf
*
buf
);
/**
* Replace all \r\n with \n.
Does not modify \r without trailing \n.
* Replace all \r\n with \n.
*
* @return 0 on success, -1 on memory error
* @return 0 on success, -1 on memory error, GIT_PASSTHROUGH if the
* source buffer has mixed line endings.
*/
extern
int
git_buf_text_crlf_to_lf
(
git_buf
*
tgt
,
const
git_buf
*
src
);
...
...
tests/checkout/crlf.c
View file @
3ddd0d92
...
...
@@ -79,10 +79,7 @@ void test_checkout_crlf__more_lf_autocrlf_true(void)
git_checkout_head
(
g_repo
,
&
opts
);
if
(
GIT_EOL_NATIVE
==
GIT_EOL_LF
)
check_file_contents
(
"./crlf/more-lf"
,
MORE_LF_TEXT_RAW
);
else
check_file_contents
(
"./crlf/more-lf"
,
MORE_LF_TEXT_AS_CRLF
);
check_file_contents
(
"./crlf/more-lf"
,
MORE_LF_TEXT_RAW
);
}
void
test_checkout_crlf__more_crlf_autocrlf_true
(
void
)
...
...
@@ -94,10 +91,7 @@ void test_checkout_crlf__more_crlf_autocrlf_true(void)
git_checkout_head
(
g_repo
,
&
opts
);
if
(
GIT_EOL_NATIVE
==
GIT_EOL_LF
)
check_file_contents
(
"./crlf/more-crlf"
,
MORE_CRLF_TEXT_RAW
);
else
check_file_contents
(
"./crlf/more-crlf"
,
MORE_CRLF_TEXT_AS_CRLF
);
check_file_contents
(
"./crlf/more-crlf"
,
MORE_CRLF_TEXT_RAW
);
}
void
test_checkout_crlf__all_crlf_autocrlf_true
(
void
)
...
...
tests/core/buffer.c
View file @
3ddd0d92
...
...
@@ -1034,18 +1034,14 @@ void test_core_buffer__lf_and_crlf_conversions(void)
git_buf_sets
(
&
src
,
"crlf
\r\n
crlf
\r\n
crlf
\r\n
crlf
\r\n
"
);
cl_git_pass
(
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
check_buf
(
"crlf
\r\n
crlf
\r\n
crlf
\r\n
crlf
\r\n
"
,
tgt
);
check_buf
(
src
.
ptr
,
tgt
);
cl_git_fail_with
(
GIT_PASSTHROUGH
,
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
cl_git_pass
(
git_buf_text_crlf_to_lf
(
&
tgt
,
&
src
));
check_buf
(
"crlf
\n
crlf
\n
crlf
\n
crlf
\n
"
,
tgt
);
git_buf_sets
(
&
src
,
"
\r\n
crlf
\r\n
crlf
\r\n
crlf
\r\n
crlf
\r\n
crlf"
);
cl_git_pass
(
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
check_buf
(
"
\r\n
crlf
\r\n
crlf
\r\n
crlf
\r\n
crlf
\r\n
crlf"
,
tgt
);
check_buf
(
src
.
ptr
,
tgt
);
cl_git_fail_with
(
GIT_PASSTHROUGH
,
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
cl_git_pass
(
git_buf_text_crlf_to_lf
(
&
tgt
,
&
src
));
check_buf
(
"
\n
crlf
\n
crlf
\n
crlf
\n
crlf
\n
crlf"
,
tgt
);
...
...
@@ -1054,8 +1050,7 @@ void test_core_buffer__lf_and_crlf_conversions(void)
git_buf_sets
(
&
src
,
"
\n
lf
\n
lf
\n
crlf
\r\n
lf
\n
lf
\n
crlf
\r\n
"
);
cl_git_pass
(
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
check_buf
(
"
\r\n
lf
\r\n
lf
\r\n
crlf
\r\n
lf
\r\n
lf
\r\n
crlf
\r\n
"
,
tgt
);
cl_git_fail_with
(
GIT_PASSTHROUGH
,
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
cl_git_pass
(
git_buf_text_crlf_to_lf
(
&
tgt
,
&
src
));
check_buf
(
"
\n
lf
\n
lf
\n
crlf
\n
lf
\n
lf
\n
crlf
\n
"
,
tgt
);
...
...
@@ -1063,8 +1058,7 @@ void test_core_buffer__lf_and_crlf_conversions(void)
git_buf_sets
(
&
src
,
"
\n
crlf
\r\n
crlf
\r\n
lf
\n
crlf
\r\n
crlf"
);
cl_git_pass
(
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
check_buf
(
"
\r\n
crlf
\r\n
crlf
\r\n
lf
\r\n
crlf
\r\n
crlf"
,
tgt
);
cl_git_fail_with
(
GIT_PASSTHROUGH
,
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
cl_git_pass
(
git_buf_text_crlf_to_lf
(
&
tgt
,
&
src
));
check_buf
(
"
\n
crlf
\n
crlf
\n
lf
\n
crlf
\n
crlf"
,
tgt
);
...
...
@@ -1072,8 +1066,7 @@ void test_core_buffer__lf_and_crlf_conversions(void)
git_buf_sets
(
&
src
,
"
\r
crlf
\r\n
lf
\n
lf
\n
cr
\r
crlf
\r\n
lf
\n
cr
\r
"
);
cl_git_pass
(
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
check_buf
(
"
\r
crlf
\r\n
lf
\r\n
lf
\r\n
cr
\r
crlf
\r\n
lf
\r\n
cr
\r
"
,
tgt
);
cl_git_fail_with
(
GIT_PASSTHROUGH
,
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
cl_git_pass
(
git_buf_text_crlf_to_lf
(
&
tgt
,
&
src
));
check_buf
(
"
\r
crlf
\n
lf
\n
lf
\n
cr
\r
crlf
\n
lf
\n
cr
\r
"
,
tgt
);
...
...
@@ -1089,8 +1082,7 @@ void test_core_buffer__lf_and_crlf_conversions(void)
/* blob correspondence tests */
git_buf_sets
(
&
src
,
ALL_CRLF_TEXT_RAW
);
cl_git_pass
(
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
check_buf
(
ALL_CRLF_TEXT_AS_CRLF
,
tgt
);
cl_git_fail_with
(
GIT_PASSTHROUGH
,
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
cl_git_pass
(
git_buf_text_crlf_to_lf
(
&
tgt
,
&
src
));
check_buf
(
ALL_CRLF_TEXT_AS_LF
,
tgt
);
git_buf_free
(
&
src
);
...
...
@@ -1105,16 +1097,14 @@ void test_core_buffer__lf_and_crlf_conversions(void)
git_buf_free
(
&
tgt
);
git_buf_sets
(
&
src
,
MORE_CRLF_TEXT_RAW
);
cl_git_pass
(
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
check_buf
(
MORE_CRLF_TEXT_AS_CRLF
,
tgt
);
cl_git_fail_with
(
GIT_PASSTHROUGH
,
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
cl_git_pass
(
git_buf_text_crlf_to_lf
(
&
tgt
,
&
src
));
check_buf
(
MORE_CRLF_TEXT_AS_LF
,
tgt
);
git_buf_free
(
&
src
);
git_buf_free
(
&
tgt
);
git_buf_sets
(
&
src
,
MORE_LF_TEXT_RAW
);
cl_git_pass
(
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
check_buf
(
MORE_LF_TEXT_AS_CRLF
,
tgt
);
cl_git_fail_with
(
GIT_PASSTHROUGH
,
git_buf_text_lf_to_crlf
(
&
tgt
,
&
src
));
cl_git_pass
(
git_buf_text_crlf_to_lf
(
&
tgt
,
&
src
));
check_buf
(
MORE_LF_TEXT_AS_LF
,
tgt
);
git_buf_free
(
&
src
);
...
...
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