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
05548e66
Unverified
Commit
05548e66
authored
May 11, 2021
by
Edward Thomson
Committed by
GitHub
May 11, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5859 from libgit2/ethomson/filter_buf
filter: stop taking git_buf as user input
parents
4bd17208
31d9c24b
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
209 additions
and
118 deletions
+209
-118
include/git2/deprecated.h
+34
-0
include/git2/filter.h
+9
-17
src/checkout.c
+1
-1
src/diff_file.c
+1
-4
src/filter.c
+64
-20
src/filter.h
+9
-0
src/odb.c
+1
-3
tests/filter/crlf.c
+64
-52
tests/filter/custom.c
+20
-9
tests/filter/wildcard.c
+6
-12
No files found.
include/git2/deprecated.h
View file @
05548e66
...
...
@@ -18,6 +18,7 @@
#include "describe.h"
#include "diff.h"
#include "errors.h"
#include "filter.h"
#include "index.h"
#include "indexer.h"
#include "merge.h"
...
...
@@ -119,6 +120,39 @@ GIT_EXTERN(int) git_blob_filtered_content(
/**@}*/
/** @name Deprecated Filter Functions
*
* These functions are retained for backward compatibility. The
* newer versions of these functions should be preferred in all
* new code.
*
* There is no plan to remove these backward compatibility values at
* this time.
*/
/**@{*/
/** Deprecated in favor of `git_filter_list_stream_buffer`.
*
* @deprecated Use git_filter_list_stream_buffer
* @see Use git_filter_list_stream_buffer
*/
GIT_EXTERN
(
int
)
git_filter_list_stream_data
(
git_filter_list
*
filters
,
git_buf
*
data
,
git_writestream
*
target
);
/** Deprecated in favor of `git_filter_list_apply_to_buffer`.
*
* @deprecated Use git_filter_list_apply_to_buffer
* @see Use git_filter_list_apply_to_buffer
*/
GIT_EXTERN
(
int
)
git_filter_list_apply_to_data
(
git_buf
*
out
,
git_filter_list
*
filters
,
git_buf
*
in
);
/**@}*/
/** @name Deprecated Tree Functions
*
* These functions are retained for backward compatibility. The
...
...
include/git2/filter.h
View file @
05548e66
...
...
@@ -122,27 +122,17 @@ GIT_EXTERN(int) git_filter_list_contains(
/**
* Apply filter list to a data buffer.
*
* See `git2/buffer.h` for background on `git_buf` objects.
*
* If the `in` buffer holds data allocated by libgit2 (i.e. `in->asize` is
* not zero), then it will be overwritten when applying the filters. If
* not, then it will be left untouched.
*
* If there are no filters to apply (or `filters` is NULL), then the `out`
* buffer will reference the `in` buffer data (with `asize` set to zero)
* instead of allocating data. This keeps allocations to a minimum, but
* it means you have to be careful about freeing the `in` data since `out`
* may be pointing to it!
*
* @param out Buffer to store the result of the filtering
* @param filters A loaded git_filter_list (or NULL)
* @param in Buffer containing the data to filter
* @param in_len The length of the input buffer
* @return 0 on success, an error code otherwise
*/
GIT_EXTERN
(
int
)
git_filter_list_apply_to_
data
(
GIT_EXTERN
(
int
)
git_filter_list_apply_to_
buffer
(
git_buf
*
out
,
git_filter_list
*
filters
,
git_buf
*
in
);
const
char
*
in
,
size_t
in_len
);
/**
* Apply a filter list to the contents of a file on disk
...
...
@@ -175,12 +165,14 @@ GIT_EXTERN(int) git_filter_list_apply_to_blob(
* Apply a filter list to an arbitrary buffer as a stream
*
* @param filters the list of filters to apply
* @param data the buffer to filter
* @param buffer the buffer to filter
* @param len the size of the buffer
* @param target the stream into which the data will be written
*/
GIT_EXTERN
(
int
)
git_filter_list_stream_
data
(
GIT_EXTERN
(
int
)
git_filter_list_stream_
buffer
(
git_filter_list
*
filters
,
git_buf
*
data
,
const
char
*
buffer
,
size_t
len
,
git_writestream
*
target
);
/**
...
...
src/checkout.c
View file @
05548e66
...
...
@@ -2121,7 +2121,7 @@ static int checkout_write_merge(
if
((
error
=
git_filter_list__load_ext
(
&
fl
,
data
->
repo
,
NULL
,
git_buf_cstr
(
&
path_workdir
),
GIT_FILTER_TO_WORKTREE
,
&
filter_opts
))
<
0
||
(
error
=
git_filter_list_
apply_to_data
(
&
out_data
,
fl
,
&
in_data
))
<
0
)
(
error
=
git_filter_list_
_convert_buf
(
&
out_data
,
fl
,
&
in_data
))
<
0
)
goto
done
;
}
else
{
out_data
.
ptr
=
(
char
*
)
result
.
ptr
;
...
...
src/diff_file.c
View file @
05548e66
...
...
@@ -362,10 +362,7 @@ static int diff_file_content_load_workdir_file(
if
(
!
(
error
=
git_futils_readbuffer_fd
(
&
raw
,
fd
,
(
size_t
)
fc
->
file
->
size
)))
{
git_buf
out
=
GIT_BUF_INIT
;
error
=
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
raw
);
if
(
out
.
ptr
!=
raw
.
ptr
)
git_buf_dispose
(
&
raw
);
error
=
git_filter_list__convert_buf
(
&
out
,
fl
,
&
raw
);
if
(
!
error
)
{
fc
->
map
.
len
=
out
.
size
;
...
...
src/filter.c
View file @
05548e66
...
...
@@ -720,28 +720,47 @@ static void buf_stream_init(struct buf_stream *writer, git_buf *target)
git_buf_clear
(
target
);
}
int
git_filter_list_apply_to_data
(
git_buf
*
tgt
,
git_filter_list
*
filters
,
git_buf
*
src
)
int
git_filter_list_apply_to_buffer
(
git_buf
*
out
,
git_filter_list
*
filters
,
const
char
*
in
,
size_t
in_len
)
{
struct
buf_stream
writer
;
int
error
;
if
((
error
=
git_buf_sanitize
(
tgt
))
<
0
||
(
error
=
git_buf_sanitize
(
src
))
<
0
)
return
error
;
if
((
error
=
git_buf_sanitize
(
out
))
<
0
)
return
error
;
if
(
!
filters
)
{
git_buf_attach_notowned
(
tgt
,
src
->
ptr
,
src
->
size
);
buf_stream_init
(
&
writer
,
out
);
if
((
error
=
git_filter_list_stream_buffer
(
filters
,
in
,
in_len
,
&
writer
.
parent
))
<
0
)
return
error
;
GIT_ASSERT
(
writer
.
complete
);
return
error
;
}
int
git_filter_list__convert_buf
(
git_buf
*
out
,
git_filter_list
*
filters
,
git_buf
*
in
)
{
int
error
;
if
(
!
filters
||
git_filter_list_length
(
filters
)
==
0
)
{
git_buf_swap
(
out
,
in
);
git_buf_dispose
(
in
);
return
0
;
}
buf_stream_init
(
&
writer
,
tgt
);
error
=
git_filter_list_apply_to_buffer
(
out
,
filters
,
in
->
ptr
,
in
->
size
);
if
((
error
=
git_filter_list_stream_data
(
filters
,
src
,
&
writer
.
parent
))
<
0
)
return
error
;
if
(
!
error
)
git_buf_dispose
(
in
);
GIT_ASSERT
(
writer
.
complete
);
return
error
;
}
...
...
@@ -1002,24 +1021,21 @@ done:
return
error
;
}
int
git_filter_list_stream_
data
(
int
git_filter_list_stream_
buffer
(
git_filter_list
*
filters
,
git_buf
*
data
,
const
char
*
buffer
,
size_t
len
,
git_writestream
*
target
)
{
git_vector
filter_streams
=
GIT_VECTOR_INIT
;
git_writestream
*
stream_start
;
int
error
,
initialized
=
0
;
if
((
error
=
git_buf_sanitize
(
data
))
<
0
)
return
error
;
if
((
error
=
stream_list_init
(
&
stream_start
,
&
filter_streams
,
filters
,
target
))
<
0
)
goto
out
;
initialized
=
1
;
if
((
error
=
stream_start
->
write
(
stream_start
,
data
->
ptr
,
data
->
size
))
<
0
)
if
((
error
=
stream_start
->
write
(
stream_start
,
buffer
,
len
))
<
0
)
goto
out
;
out:
...
...
@@ -1043,7 +1059,7 @@ int git_filter_list_stream_blob(
if
(
filters
)
git_oid_cpy
(
&
filters
->
source
.
oid
,
git_blob_id
(
blob
));
return
git_filter_list_stream_
data
(
filters
,
&
in
,
target
);
return
git_filter_list_stream_
buffer
(
filters
,
in
.
ptr
,
in
.
size
,
target
);
}
int
git_filter_init
(
git_filter
*
filter
,
unsigned
int
version
)
...
...
@@ -1051,3 +1067,31 @@ int git_filter_init(git_filter *filter, unsigned int version)
GIT_INIT_STRUCTURE_FROM_TEMPLATE
(
filter
,
version
,
git_filter
,
GIT_FILTER_INIT
);
return
0
;
}
#ifndef GIT_DEPRECATE_HARD
int
git_filter_list_stream_data
(
git_filter_list
*
filters
,
git_buf
*
data
,
git_writestream
*
target
)
{
int
error
;
if
((
error
=
git_buf_sanitize
(
data
))
<
0
)
return
error
;
return
git_filter_list_stream_buffer
(
filters
,
data
->
ptr
,
data
->
size
,
target
);
}
int
git_filter_list_apply_to_data
(
git_buf
*
tgt
,
git_filter_list
*
filters
,
git_buf
*
src
)
{
int
error
;
if
((
error
=
git_buf_sanitize
(
src
))
<
0
)
return
error
;
return
git_filter_list_apply_to_buffer
(
tgt
,
filters
,
src
->
ptr
,
src
->
size
);
}
#endif
src/filter.h
View file @
05548e66
...
...
@@ -36,6 +36,15 @@ extern int git_filter_list__load_ext(
git_filter_options
*
filter_opts
);
/*
* The given input buffer will be converted to the given output buffer.
* The input buffer will be freed (_if_ it was allocated).
*/
extern
int
git_filter_list__convert_buf
(
git_buf
*
out
,
git_filter_list
*
filters
,
git_buf
*
in
);
/*
* Available filters
*/
...
...
src/odb.c
View file @
05548e66
...
...
@@ -260,9 +260,7 @@ int git_odb__hashfd_filtered(
if
(
!
(
error
=
git_futils_readbuffer_fd
(
&
raw
,
fd
,
size
)))
{
git_buf
post
=
GIT_BUF_INIT
;
error
=
git_filter_list_apply_to_data
(
&
post
,
fl
,
&
raw
);
git_buf_dispose
(
&
raw
);
error
=
git_filter_list__convert_buf
(
&
post
,
fl
,
&
raw
);
if
(
!
error
)
error
=
git_odb_hash
(
out
,
post
.
ptr
,
post
.
size
,
type
);
...
...
tests/filter/crlf.c
View file @
05548e66
...
...
@@ -23,7 +23,9 @@ void test_filter_crlf__to_worktree(void)
{
git_filter_list
*
fl
;
git_filter
*
crlf
;
git_buf
in
=
{
0
},
out
=
{
0
};
git_buf
out
=
GIT_BUF_INIT
;
const
char
*
in
;
size_t
in_len
;
cl_git_pass
(
git_filter_list_new
(
&
fl
,
g_repo
,
GIT_FILTER_TO_WORKTREE
,
0
));
...
...
@@ -33,10 +35,10 @@ void test_filter_crlf__to_worktree(void)
cl_git_pass
(
git_filter_list_push
(
fl
,
crlf
,
NULL
));
in
.
ptr
=
"Some text
\n
Right here
\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Some text
\n
Right here
\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_s
(
"Some text
\r\n
Right here
\r\n
"
,
out
.
ptr
);
...
...
@@ -48,7 +50,9 @@ void test_filter_crlf__to_odb(void)
{
git_filter_list
*
fl
;
git_filter
*
crlf
;
git_buf
in
=
{
0
},
out
=
{
0
};
git_buf
out
=
GIT_BUF_INIT
;
const
char
*
in
;
size_t
in_len
;
cl_git_pass
(
git_filter_list_new
(
&
fl
,
g_repo
,
GIT_FILTER_TO_ODB
,
0
));
...
...
@@ -58,10 +62,10 @@ void test_filter_crlf__to_odb(void)
cl_git_pass
(
git_filter_list_push
(
fl
,
crlf
,
NULL
));
in
.
ptr
=
"Some text
\r\n
Right here
\r\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Some text
\r\n
Right here
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_s
(
"Some text
\n
Right here
\n
"
,
out
.
ptr
);
...
...
@@ -73,7 +77,9 @@ void test_filter_crlf__with_safecrlf(void)
{
git_filter_list
*
fl
;
git_filter
*
crlf
;
git_buf
in
=
{
0
},
out
=
GIT_BUF_INIT
;
git_buf
out
=
GIT_BUF_INIT
;
const
char
*
in
;
size_t
in_len
;
cl_repo_set_bool
(
g_repo
,
"core.safecrlf"
,
true
);
...
...
@@ -86,31 +92,31 @@ void test_filter_crlf__with_safecrlf(void)
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
);
in
=
"Normal
\r\n
CRLF
\r\n
line-endings.
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
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
);
in
=
"Mixed
\n
up
\r\n
LF
\n
and
\r\n
CRLF
\n
line-endings.
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_fail
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_fail
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_i
(
git_error_last
()
->
klass
,
GIT_ERROR_FILTER
);
/* Normalized \n fails for autocrlf=true when safecrlf=true */
in
.
ptr
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
_len
=
strlen
(
in
);
cl_git_fail
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_fail
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_i
(
git_error_last
()
->
klass
,
GIT_ERROR_FILTER
);
/* String with \r but without \r\n does not fail with safecrlf */
in
.
ptr
=
"Normal
\n
CR only
\r
and some more
\n
line-endings.
\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Normal
\n
CR only
\r
and some more
\n
line-endings.
\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_s
(
"Normal
\n
CR only
\r
and some more
\n
line-endings.
\n
"
,
out
.
ptr
);
git_filter_list_free
(
fl
);
...
...
@@ -121,7 +127,9 @@ void test_filter_crlf__with_safecrlf_and_unsafe_allowed(void)
{
git_filter_list
*
fl
;
git_filter
*
crlf
;
git_buf
in
=
{
0
},
out
=
GIT_BUF_INIT
;
git_buf
out
=
GIT_BUF_INIT
;
const
char
*
in
;
size_t
in_len
;
cl_repo_set_bool
(
g_repo
,
"core.safecrlf"
,
true
);
...
...
@@ -134,25 +142,25 @@ void test_filter_crlf__with_safecrlf_and_unsafe_allowed(void)
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
);
in
=
"Normal
\r\n
CRLF
\r\n
line-endings.
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_s
(
"Normal
\n
CRLF
\n
line-endings.
\n
"
,
out
.
ptr
);
/* Mix of line endings fails with safecrlf, but allowed to pass */
in
.
ptr
=
"Mixed
\n
up
\r\n
LF
\n
and
\r\n
CRLF
\n
line-endings.
\r\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Mixed
\n
up
\r\n
LF
\n
and
\r\n
CRLF
\n
line-endings.
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
/* TODO: check for warning */
cl_assert_equal_s
(
"Mixed
\n
up
\n
LF
\n
and
\n
CRLF
\n
line-endings.
\n
"
,
out
.
ptr
);
/* Normalized \n fails with safecrlf, but allowed to pass */
in
.
ptr
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
/* TODO: check for warning */
cl_assert_equal_s
(
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
,
out
.
ptr
);
...
...
@@ -164,7 +172,9 @@ void test_filter_crlf__no_safecrlf(void)
{
git_filter_list
*
fl
;
git_filter
*
crlf
;
git_buf
in
=
{
0
},
out
=
GIT_BUF_INIT
;
git_buf
out
=
GIT_BUF_INIT
;
const
char
*
in
;
size_t
in_len
;
cl_git_pass
(
git_filter_list_new
(
&
fl
,
g_repo
,
GIT_FILTER_TO_ODB
,
0
));
...
...
@@ -175,24 +185,24 @@ void test_filter_crlf__no_safecrlf(void)
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
);
in
=
"Normal
\r\n
CRLF
\r\n
line-endings.
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
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
);
in
=
"Mixed
\n
up
\r\n
LF
\n
and
\r\n
CRLF
\n
line-endings.
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
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
);
in
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_s
(
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
,
out
.
ptr
);
git_filter_list_free
(
fl
);
...
...
@@ -203,7 +213,9 @@ void test_filter_crlf__safecrlf_warn(void)
{
git_filter_list
*
fl
;
git_filter
*
crlf
;
git_buf
in
=
{
0
},
out
=
GIT_BUF_INIT
;
git_buf
out
=
GIT_BUF_INIT
;
const
char
*
in
;
size_t
in_len
;
cl_repo_set_string
(
g_repo
,
"core.safecrlf"
,
"warn"
);
...
...
@@ -216,26 +228,26 @@ void test_filter_crlf__safecrlf_warn(void)
cl_git_pass
(
git_filter_list_push
(
fl
,
crlf
,
NULL
));
/* Normalized \r\n succeeds with safecrlf=warn */
in
.
ptr
=
"Normal
\r\n
CRLF
\r\n
line-endings.
\r\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Normal
\r\n
CRLF
\r\n
line-endings.
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_s
(
"Normal
\n
CRLF
\n
line-endings.
\n
"
,
out
.
ptr
);
/* Mix of line endings succeeds with safecrlf=warn */
in
.
ptr
=
"Mixed
\n
up
\r\n
LF
\n
and
\r\n
CRLF
\n
line-endings.
\r\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Mixed
\n
up
\r\n
LF
\n
and
\r\n
CRLF
\n
line-endings.
\r\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
/* TODO: check for warning */
cl_assert_equal_s
(
"Mixed
\n
up
\n
LF
\n
and
\n
CRLF
\n
line-endings.
\n
"
,
out
.
ptr
);
/* Normalized \n is reversible, so does not fail with safecrlf=warn */
in
.
ptr
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
.
size
=
strlen
(
in
.
ptr
);
in
=
"Normal
\n
LF
\n
only
\n
line-endings.
\n
"
;
in
_len
=
strlen
(
in
);
cl_git_pass
(
git_filter_list_apply_to_
data
(
&
out
,
fl
,
&
i
n
));
cl_assert_equal_s
(
in
.
ptr
,
out
.
ptr
);
cl_git_pass
(
git_filter_list_apply_to_
buffer
(
&
out
,
fl
,
in
,
in_le
n
));
cl_assert_equal_s
(
in
,
out
.
ptr
);
git_filter_list_free
(
fl
);
git_buf_dispose
(
&
out
);
...
...
tests/filter/custom.c
View file @
05548e66
...
...
@@ -95,13 +95,17 @@ static void register_custom_filters(void)
void
test_filter_custom__to_odb
(
void
)
{
git_filter_list
*
fl
;
git_buf
out
=
{
0
};
git_buf
in
=
GIT_BUF_INIT_CONST
(
workdir_data
,
strlen
(
workdir_data
));
git_buf
out
=
GIT_BUF_INIT
;
const
char
*
in
;
size_t
in_len
;
cl_git_pass
(
git_filter_list_load
(
&
fl
,
g_repo
,
NULL
,
"herofile"
,
GIT_FILTER_TO_ODB
,
0
));
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
in
=
workdir_data
;
in_len
=
strlen
(
workdir_data
);
cl_git_pass
(
git_filter_list_apply_to_buffer
(
&
out
,
fl
,
in
,
in_len
));
cl_assert_equal_i
(
BITFLIPPED_AND_REVERSED_DATA_LEN
,
out
.
size
);
...
...
@@ -115,14 +119,17 @@ void test_filter_custom__to_odb(void)
void
test_filter_custom__to_workdir
(
void
)
{
git_filter_list
*
fl
;
git_buf
out
=
{
0
}
;
git_buf
in
=
GIT_BUF_INIT_CONST
(
bitflipped_and_reversed_data
,
BITFLIPPED_AND_REVERSED_DATA_LEN
)
;
git_buf
out
=
GIT_BUF_INIT
;
const
char
*
in
;
size_t
in_len
;
cl_git_pass
(
git_filter_list_load
(
&
fl
,
g_repo
,
NULL
,
"herofile"
,
GIT_FILTER_TO_WORKTREE
,
0
));
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
in
=
(
char
*
)
bitflipped_and_reversed_data
;
in_len
=
BITFLIPPED_AND_REVERSED_DATA_LEN
;
cl_git_pass
(
git_filter_list_apply_to_buffer
(
&
out
,
fl
,
in
,
in_len
));
cl_assert_equal_i
(
strlen
(
workdir_data
),
out
.
size
);
...
...
@@ -246,12 +253,16 @@ void test_filter_custom__erroneous_filter_fails(void)
{
git_filter_list
*
filters
;
git_buf
out
=
GIT_BUF_INIT
;
git_buf
in
=
GIT_BUF_INIT_CONST
(
workdir_data
,
strlen
(
workdir_data
));
const
char
*
in
;
size_t
in_len
;
cl_git_pass
(
git_filter_list_load
(
&
filters
,
g_repo
,
NULL
,
"villain"
,
GIT_FILTER_TO_WORKTREE
,
0
));
cl_git_fail
(
git_filter_list_apply_to_data
(
&
out
,
filters
,
&
in
));
in
=
workdir_data
;
in_len
=
strlen
(
workdir_data
);
cl_git_fail
(
git_filter_list_apply_to_buffer
(
&
out
,
filters
,
in
,
in_len
));
git_filter_list_free
(
filters
);
git_buf_dispose
(
&
out
);
...
...
tests/filter/wildcard.c
View file @
05548e66
...
...
@@ -123,13 +123,12 @@ static git_filter *create_wildcard_filter(void)
void
test_filter_wildcard__reverse
(
void
)
{
git_filter_list
*
fl
;
git_buf
in
=
GIT_BUF_INIT
,
out
=
GIT_BUF_INIT
;
git_buf
out
=
GIT_BUF_INIT
;
cl_git_pass
(
git_filter_list_load
(
&
fl
,
g_repo
,
NULL
,
"hero-reverse-foo"
,
GIT_FILTER_TO_ODB
,
0
));
cl_git_pass
(
git_buf_put
(
&
in
,
(
char
*
)
input
,
DATA_LEN
));
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_git_pass
(
git_filter_list_apply_to_buffer
(
&
out
,
fl
,
(
char
*
)
input
,
DATA_LEN
));
cl_assert_equal_i
(
DATA_LEN
,
out
.
size
);
...
...
@@ -138,19 +137,17 @@ void test_filter_wildcard__reverse(void)
git_filter_list_free
(
fl
);
git_buf_dispose
(
&
out
);
git_buf_dispose
(
&
in
);
}
void
test_filter_wildcard__flip
(
void
)
{
git_filter_list
*
fl
;
git_buf
in
=
GIT_BUF_INIT
,
out
=
GIT_BUF_INIT
;
git_buf
out
=
GIT_BUF_INIT
;
cl_git_pass
(
git_filter_list_load
(
&
fl
,
g_repo
,
NULL
,
"hero-flip-foo"
,
GIT_FILTER_TO_ODB
,
0
));
cl_git_pass
(
git_buf_put
(
&
in
,
(
char
*
)
input
,
DATA_LEN
));
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_git_pass
(
git_filter_list_apply_to_buffer
(
&
out
,
fl
,
(
char
*
)
input
,
DATA_LEN
));
cl_assert_equal_i
(
DATA_LEN
,
out
.
size
);
...
...
@@ -159,19 +156,17 @@ void test_filter_wildcard__flip(void)
git_filter_list_free
(
fl
);
git_buf_dispose
(
&
out
);
git_buf_dispose
(
&
in
);
}
void
test_filter_wildcard__none
(
void
)
{
git_filter_list
*
fl
;
git_buf
in
=
GIT_BUF_INIT
,
out
=
GIT_BUF_INIT
;
git_buf
out
=
GIT_BUF_INIT
;
cl_git_pass
(
git_filter_list_load
(
&
fl
,
g_repo
,
NULL
,
"none-foo"
,
GIT_FILTER_TO_ODB
,
0
));
cl_git_pass
(
git_buf_put
(
&
in
,
(
char
*
)
input
,
DATA_LEN
));
cl_git_pass
(
git_filter_list_apply_to_data
(
&
out
,
fl
,
&
in
));
cl_git_pass
(
git_filter_list_apply_to_buffer
(
&
out
,
fl
,
(
char
*
)
input
,
DATA_LEN
));
cl_assert_equal_i
(
DATA_LEN
,
out
.
size
);
...
...
@@ -180,5 +175,4 @@ void test_filter_wildcard__none(void)
git_filter_list_free
(
fl
);
git_buf_dispose
(
&
out
);
git_buf_dispose
(
&
in
);
}
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