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
4a1b4015
Commit
4a1b4015
authored
Sep 24, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1865 from arrbee/various-cleanups
Various warning cleanup and minor fixes
parents
5dc8513b
d005885f
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
83 additions
and
41 deletions
+83
-41
Makefile.embed
+1
-1
include/git2/index.h
+4
-4
src/buffer.c
+2
-0
src/crlf.c
+2
-2
src/diff_print.c
+5
-4
src/filter.c
+11
-3
src/index.c
+1
-1
src/repository.c
+6
-4
tests-clar/clar_libgit2.c
+12
-10
tests-clar/clar_libgit2.h
+2
-1
tests-clar/core/filebuf.c
+5
-5
tests-clar/diff/workdir.c
+25
-0
tests-clar/index/filemodes.c
+6
-5
tests-clar/repo/init.c
+1
-1
No files found.
Makefile.embed
View file @
4a1b4015
...
...
@@ -31,7 +31,7 @@ CC:=$(PREFIX)$(CC)
INCLUDES
=
-I
.
-Isrc
-Iinclude
-Ideps
/http-parser
-Ideps
/zlib
DEFINES
=
$(INCLUDES)
-DNO_VIZ
-DSTDC
-DNO_GZIP
-D_FILE_OFFSET_BITS
=
64
-D_GNU_SOURCE
$(EXTRA_DEFINES)
CFLAGS
=
-g
$(DEFINES)
-Wall
-Wextra
-O2
$(EXTRA_CFLAGS)
CFLAGS
=
-g
$(DEFINES)
-Wall
-Wextra
-
Wno-missing-field-initializers
-
O2
$(EXTRA_CFLAGS)
SRCS
=
$
(
wildcard src/
*
.c
)
$
(
wildcard src/transports/
*
.c
)
$
(
wildcard src/xdiff/
*
.c
)
$
(
wildcard deps/http-parser/
*
.c
)
$
(
wildcard deps/zlib/
*
.c
)
src/hash/hash_generic.c
...
...
include/git2/index.h
View file @
4a1b4015
...
...
@@ -120,9 +120,9 @@ typedef struct git_index_entry {
/** Capabilities of system that affect index actions. */
typedef
enum
{
GIT_INDEXCAP_IGNORE_CASE
=
1
,
GIT_INDEXCAP_NO_FILEMODE
=
2
,
GIT_INDEXCAP_NO_SYMLINKS
=
4
,
GIT_INDEXCAP_IGNORE_CASE
=
1
u
,
GIT_INDEXCAP_NO_FILEMODE
=
2
u
,
GIT_INDEXCAP_NO_SYMLINKS
=
4
u
,
GIT_INDEXCAP_FROM_OWNER
=
~
0u
}
git_indexcap_t
;
...
...
@@ -219,7 +219,7 @@ GIT_EXTERN(unsigned int) git_index_caps(const git_index *index);
* @param caps A combination of GIT_INDEXCAP values
* @return 0 on success, -1 on failure
*/
GIT_EXTERN
(
int
)
git_index_set_caps
(
git_index
*
index
,
int
caps
);
GIT_EXTERN
(
int
)
git_index_set_caps
(
git_index
*
index
,
unsigned
int
caps
);
/**
* Update the contents of an existing index object in memory
...
...
src/buffer.c
View file @
4a1b4015
...
...
@@ -211,6 +211,8 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
format
,
args
);
va_end
(
args
);
if
(
len
<
0
)
{
git__free
(
buf
->
ptr
);
buf
->
ptr
=
git_buf__oom
;
...
...
src/crlf.c
View file @
4a1b4015
...
...
@@ -133,9 +133,9 @@ static int crlf_apply_to_odb(
if
(
ca
->
crlf_action
==
GIT_CRLF_AUTO
||
ca
->
crlf_action
==
GIT_CRLF_GUESS
)
{
git_buf_text_stats
stats
;
/* Check heuristics for binary vs text
...
*/
/* Check heuristics for binary vs text
- returns true if binary
*/
if
(
git_buf_text_gather_stats
(
&
stats
,
from
,
false
))
return
-
1
;
return
GIT_PASSTHROUGH
;
/*
* We're currently not going to even try to convert stuff
...
...
src/diff_print.c
View file @
4a1b4015
...
...
@@ -336,7 +336,7 @@ static int diff_print_patch_hunk(
return
0
;
git_buf_clear
(
pi
->
buf
);
if
(
git_buf_p
rintf
(
pi
->
buf
,
"%.*s"
,
(
int
)
header_len
,
header
)
<
0
)
if
(
git_buf_p
ut
(
pi
->
buf
,
header
,
header_len
)
<
0
)
return
-
1
;
if
(
pi
->
print_cb
(
d
,
r
,
GIT_DIFF_LINE_HUNK_HDR
,
...
...
@@ -360,13 +360,14 @@ static int diff_print_patch_line(
return
0
;
git_buf_clear
(
pi
->
buf
);
git_buf_grow
(
pi
->
buf
,
content_len
+
2
);
if
(
line_origin
==
GIT_DIFF_LINE_ADDITION
||
line_origin
==
GIT_DIFF_LINE_DELETION
||
line_origin
==
GIT_DIFF_LINE_CONTEXT
)
git_buf_p
rintf
(
pi
->
buf
,
"%c%.*s"
,
line_origin
,
(
int
)
content_len
,
content
);
else
if
(
content_len
>
0
)
git_buf_printf
(
pi
->
buf
,
"%.*s"
,
(
int
)
content_len
,
content
);
git_buf_p
utc
(
pi
->
buf
,
line_origin
);
git_buf_put
(
pi
->
buf
,
content
,
content_len
);
if
(
git_buf_oom
(
pi
->
buf
))
return
-
1
;
...
...
src/filter.c
View file @
4a1b4015
...
...
@@ -657,9 +657,17 @@ int git_filter_list_apply_to_blob(
git_filter_list
*
filters
,
git_blob
*
blob
)
{
git_buf
in
=
{
(
char
*
)
git_blob_rawcontent
(
blob
),
0
,
git_blob_rawsize
(
blob
)
};
git_buf
in
=
GIT_BUF_INIT
;
git_off_t
rawsize
=
git_blob_rawsize
(
blob
);
if
(
!
git__is_sizet
(
rawsize
))
{
giterr_set
(
GITERR_OS
,
"Blob is too large to filter"
);
return
-
1
;
}
in
.
ptr
=
(
char
*
)
git_blob_rawcontent
(
blob
);
in
.
asize
=
0
;
in
.
size
=
(
size_t
)
rawsize
;
if
(
filters
)
git_oid_cpy
(
&
filters
->
source
.
oid
,
git_blob_id
(
blob
));
...
...
src/index.c
View file @
4a1b4015
...
...
@@ -408,7 +408,7 @@ static int create_index_error(int error, const char *msg)
return
error
;
}
int
git_index_set_caps
(
git_index
*
index
,
int
caps
)
int
git_index_set_caps
(
git_index
*
index
,
unsigned
int
caps
)
{
unsigned
int
old_ignore_case
;
...
...
src/repository.c
View file @
4a1b4015
...
...
@@ -1145,17 +1145,19 @@ static int repo_init_structure(
}
if
(
!
tdir
)
{
if
(
(
error
=
git_futils_find_template_dir
(
&
template_buf
))
>=
0
);
if
(
!
(
error
=
git_futils_find_template_dir
(
&
template_buf
)))
tdir
=
template_buf
.
ptr
;
default_template
=
true
;
}
error
=
git_futils_cp_r
(
tdir
,
repo_dir
,
GIT_CPDIR_COPY_SYMLINKS
|
GIT_CPDIR_CHMOD_DIRS
|
GIT_CPDIR_SIMPLE_TO_MODE
,
dmode
);
if
(
tdir
)
error
=
git_futils_cp_r
(
tdir
,
repo_dir
,
GIT_CPDIR_COPY_SYMLINKS
|
GIT_CPDIR_CHMOD_DIRS
|
GIT_CPDIR_SIMPLE_TO_MODE
,
dmode
);
git_buf_free
(
&
template_buf
);
git_config_free
(
cfg
);
if
(
error
<
0
)
{
if
(
!
default_template
)
return
error
;
...
...
tests-clar/clar_libgit2.c
View file @
4a1b4015
...
...
@@ -30,24 +30,26 @@ void cl_git_mkfile(const char *filename, const char *content)
}
void
cl_git_write2file
(
const
char
*
filename
,
const
char
*
new_content
,
int
flags
,
unsigned
int
mode
)
const
char
*
path
,
const
char
*
content
,
size_t
content_len
,
int
flags
,
unsigned
int
mode
)
{
int
fd
=
p_open
(
filename
,
flags
,
mode
);
cl_assert
(
fd
>=
0
);
if
(
!
new_content
)
new_content
=
"
\n
"
;
cl_must_pass
(
p_write
(
fd
,
new_content
,
strlen
(
new_content
)));
int
fd
;
cl_assert
(
path
&&
content
);
cl_assert
((
fd
=
p_open
(
path
,
flags
,
mode
))
>=
0
);
if
(
!
content_len
)
content_len
=
strlen
(
content
);
cl_must_pass
(
p_write
(
fd
,
content
,
content_len
));
cl_must_pass
(
p_close
(
fd
));
}
void
cl_git_append2file
(
const
char
*
filename
,
const
char
*
new_
content
)
void
cl_git_append2file
(
const
char
*
path
,
const
char
*
content
)
{
cl_git_write2file
(
filename
,
new_content
,
O_WRONLY
|
O_CREAT
|
O_APPEND
,
0644
);
cl_git_write2file
(
path
,
content
,
0
,
O_WRONLY
|
O_CREAT
|
O_APPEND
,
0644
);
}
void
cl_git_rewritefile
(
const
char
*
filename
,
const
char
*
new_
content
)
void
cl_git_rewritefile
(
const
char
*
path
,
const
char
*
content
)
{
cl_git_write2file
(
filename
,
new_content
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
cl_git_write2file
(
path
,
content
,
0
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
}
#ifdef GIT_WIN32
...
...
tests-clar/clar_libgit2.h
View file @
4a1b4015
...
...
@@ -78,7 +78,8 @@ void clar__assert_equal_file(
void
cl_git_mkfile
(
const
char
*
filename
,
const
char
*
content
);
void
cl_git_append2file
(
const
char
*
filename
,
const
char
*
new_content
);
void
cl_git_rewritefile
(
const
char
*
filename
,
const
char
*
new_content
);
void
cl_git_write2file
(
const
char
*
filename
,
const
char
*
new_content
,
int
flags
,
unsigned
int
mode
);
void
cl_git_write2file
(
const
char
*
path
,
const
char
*
data
,
size_t
datalen
,
int
flags
,
unsigned
int
mode
);
bool
cl_toggle_filemode
(
const
char
*
filename
);
bool
cl_is_chmod_supported
(
void
);
...
...
tests-clar/core/filebuf.c
View file @
4a1b4015
...
...
@@ -24,18 +24,16 @@ void test_core_filebuf__0(void)
void
test_core_filebuf__1
(
void
)
{
git_filebuf
file
=
GIT_FILEBUF_INIT
;
int
fd
;
char
test
[]
=
"test"
;
fd
=
p_creat
(
test
,
0666
);
//-V536
cl_must_pass
(
fd
);
cl_must_pass
(
p_write
(
fd
,
"libgit2 rocks
\n
"
,
14
));
cl_must_pass
(
p_close
(
fd
));
cl_git_mkfile
(
test
,
"libgit2 rocks
\n
"
);
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
GIT_FILEBUF_APPEND
));
cl_git_pass
(
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
"libgit2 rocks"
));
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0666
));
cl_assert_equal_file
(
"libgit2 rocks
\n
libgit2 rocks
\n
"
,
0
,
test
);
cl_must_pass
(
p_unlink
(
test
));
}
...
...
@@ -53,6 +51,8 @@ void test_core_filebuf__2(void)
cl_git_pass
(
git_filebuf_write
(
&
file
,
buf
,
sizeof
(
buf
)));
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0666
));
cl_assert_equal_file
((
char
*
)
buf
,
sizeof
(
buf
),
test
);
cl_must_pass
(
p_unlink
(
test
));
}
...
...
tests-clar/diff/workdir.c
View file @
4a1b4015
...
...
@@ -1266,3 +1266,28 @@ void test_diff_workdir__untracked_directory_comes_last(void)
git_diff_list_free
(
diff
);
}
void
test_diff_workdir__untracked_with_bom
(
void
)
{
git_diff_options
opts
=
GIT_DIFF_OPTIONS_INIT
;
git_diff_list
*
diff
=
NULL
;
const
git_diff_delta
*
delta
;
g_repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
cl_repo_set_bool
(
g_repo
,
"core.autocrlf"
,
true
);
cl_git_write2file
(
"empty_standard_repo/bom.txt"
,
"
\xFF\xFE\x31\x00\x32\x00\x33\x00\x34\x00
"
,
10
,
O_WRONLY
|
O_CREAT
,
0664
);
opts
.
flags
=
GIT_DIFF_INCLUDE_UNTRACKED
|
GIT_DIFF_INCLUDE_UNTRACKED_CONTENT
;
cl_git_pass
(
git_diff_index_to_workdir
(
&
diff
,
g_repo
,
NULL
,
&
opts
));
cl_assert_equal_i
(
1
,
git_diff_num_deltas
(
diff
));
cl_git_pass
(
git_diff_get_patch
(
NULL
,
&
delta
,
diff
,
0
));
cl_assert_equal_i
(
GIT_DELTA_UNTRACKED
,
delta
->
status
);
cl_assert
((
delta
->
flags
&
GIT_DIFF_FLAG_BINARY
)
!=
0
);
git_diff_list_free
(
diff
);
}
tests-clar/index/filemodes.c
View file @
4a1b4015
...
...
@@ -44,7 +44,8 @@ static void replace_file_with_mode(
cl_git_pass
(
p_rename
(
path
.
ptr
,
backup
));
cl_git_write2file
(
path
.
ptr
,
content
.
ptr
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
create_mode
);
path
.
ptr
,
content
.
ptr
,
content
.
size
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
create_mode
);
git_buf_free
(
&
path
);
git_buf_free
(
&
content
);
...
...
@@ -91,7 +92,7 @@ void test_index_filemodes__untrusted(void)
add_and_check_mode
(
index
,
"exec_on"
,
GIT_FILEMODE_BLOB_EXECUTABLE
);
/* 5 - add new 0644 -> expect 0644 */
cl_git_write2file
(
"filemodes/new_off"
,
"blah"
,
cl_git_write2file
(
"filemodes/new_off"
,
"blah"
,
0
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
add_and_check_mode
(
index
,
"new_off"
,
GIT_FILEMODE_BLOB
);
...
...
@@ -100,7 +101,7 @@ void test_index_filemodes__untrusted(void)
*/
if
(
can_filemode
)
{
/* 6 - add 0755 -> expect 0755 */
cl_git_write2file
(
"filemodes/new_on"
,
"blah"
,
cl_git_write2file
(
"filemodes/new_on"
,
"blah"
,
0
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0755
);
add_and_check_mode
(
index
,
"new_on"
,
GIT_FILEMODE_BLOB_EXECUTABLE
);
}
...
...
@@ -140,12 +141,12 @@ void test_index_filemodes__trusted(void)
add_and_check_mode
(
index
,
"exec_on"
,
GIT_FILEMODE_BLOB_EXECUTABLE
);
/* 5 - add new 0644 -> expect 0644 */
cl_git_write2file
(
"filemodes/new_off"
,
"blah"
,
cl_git_write2file
(
"filemodes/new_off"
,
"blah"
,
0
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
add_and_check_mode
(
index
,
"new_off"
,
GIT_FILEMODE_BLOB
);
/* 6 - add 0755 -> expect 0755 */
cl_git_write2file
(
"filemodes/new_on"
,
"blah"
,
cl_git_write2file
(
"filemodes/new_on"
,
"blah"
,
0
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0755
);
add_and_check_mode
(
index
,
"new_on"
,
GIT_FILEMODE_BLOB_EXECUTABLE
);
...
...
tests-clar/repo/init.c
View file @
4a1b4015
...
...
@@ -382,7 +382,7 @@ static void assert_hooks_match(
cl_git_pass
(
git_buf_joinpath
(
&
actual
,
repo_dir
,
hook_path
));
cl_git_pass
(
git_path_lstat
(
actual
.
ptr
,
&
st
));
cl_assert
_equal_sz
(
expected_st
.
st_size
,
st
.
st_size
);
cl_assert
(
expected_st
.
st_size
==
st
.
st_size
);
if
(
GIT_MODE_TYPE
(
expected_st
.
st_mode
)
!=
GIT_FILEMODE_LINK
)
{
mode_t
expected_mode
=
...
...
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