mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-02 21:34:15 +00:00
Merge pull request #1865 from arrbee/various-cleanups
Various warning cleanup and minor fixes
This commit is contained in:
commit
4a1b40159b
@ -31,7 +31,7 @@ CC:=$(PREFIX)$(CC)
|
|||||||
INCLUDES= -I. -Isrc -Iinclude -Ideps/http-parser -Ideps/zlib
|
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)
|
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
|
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
|
||||||
|
|
||||||
|
@ -120,9 +120,9 @@ typedef struct git_index_entry {
|
|||||||
|
|
||||||
/** Capabilities of system that affect index actions. */
|
/** Capabilities of system that affect index actions. */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GIT_INDEXCAP_IGNORE_CASE = 1,
|
GIT_INDEXCAP_IGNORE_CASE = 1u,
|
||||||
GIT_INDEXCAP_NO_FILEMODE = 2,
|
GIT_INDEXCAP_NO_FILEMODE = 2u,
|
||||||
GIT_INDEXCAP_NO_SYMLINKS = 4,
|
GIT_INDEXCAP_NO_SYMLINKS = 4u,
|
||||||
GIT_INDEXCAP_FROM_OWNER = ~0u
|
GIT_INDEXCAP_FROM_OWNER = ~0u
|
||||||
} git_indexcap_t;
|
} 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
|
* @param caps A combination of GIT_INDEXCAP values
|
||||||
* @return 0 on success, -1 on failure
|
* @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
|
* Update the contents of an existing index object in memory
|
||||||
|
@ -211,6 +211,8 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
|
|||||||
format, args
|
format, args
|
||||||
);
|
);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
git__free(buf->ptr);
|
git__free(buf->ptr);
|
||||||
buf->ptr = git_buf__oom;
|
buf->ptr = git_buf__oom;
|
||||||
|
@ -133,9 +133,9 @@ static int crlf_apply_to_odb(
|
|||||||
if (ca->crlf_action == GIT_CRLF_AUTO || ca->crlf_action == GIT_CRLF_GUESS) {
|
if (ca->crlf_action == GIT_CRLF_AUTO || ca->crlf_action == GIT_CRLF_GUESS) {
|
||||||
git_buf_text_stats stats;
|
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))
|
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
|
* We're currently not going to even try to convert stuff
|
||||||
|
@ -336,7 +336,7 @@ static int diff_print_patch_hunk(
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
git_buf_clear(pi->buf);
|
git_buf_clear(pi->buf);
|
||||||
if (git_buf_printf(pi->buf, "%.*s", (int)header_len, header) < 0)
|
if (git_buf_put(pi->buf, header, header_len) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pi->print_cb(d, r, GIT_DIFF_LINE_HUNK_HDR,
|
if (pi->print_cb(d, r, GIT_DIFF_LINE_HUNK_HDR,
|
||||||
@ -360,13 +360,14 @@ static int diff_print_patch_line(
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
git_buf_clear(pi->buf);
|
git_buf_clear(pi->buf);
|
||||||
|
git_buf_grow(pi->buf, content_len + 2);
|
||||||
|
|
||||||
if (line_origin == GIT_DIFF_LINE_ADDITION ||
|
if (line_origin == GIT_DIFF_LINE_ADDITION ||
|
||||||
line_origin == GIT_DIFF_LINE_DELETION ||
|
line_origin == GIT_DIFF_LINE_DELETION ||
|
||||||
line_origin == GIT_DIFF_LINE_CONTEXT)
|
line_origin == GIT_DIFF_LINE_CONTEXT)
|
||||||
git_buf_printf(pi->buf, "%c%.*s", line_origin, (int)content_len, content);
|
git_buf_putc(pi->buf, line_origin);
|
||||||
else if (content_len > 0)
|
|
||||||
git_buf_printf(pi->buf, "%.*s", (int)content_len, content);
|
git_buf_put(pi->buf, content, content_len);
|
||||||
|
|
||||||
if (git_buf_oom(pi->buf))
|
if (git_buf_oom(pi->buf))
|
||||||
return -1;
|
return -1;
|
||||||
|
14
src/filter.c
14
src/filter.c
@ -657,9 +657,17 @@ int git_filter_list_apply_to_blob(
|
|||||||
git_filter_list *filters,
|
git_filter_list *filters,
|
||||||
git_blob *blob)
|
git_blob *blob)
|
||||||
{
|
{
|
||||||
git_buf in = {
|
git_buf in = GIT_BUF_INIT;
|
||||||
(char *)git_blob_rawcontent(blob), 0, git_blob_rawsize(blob)
|
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)
|
if (filters)
|
||||||
git_oid_cpy(&filters->source.oid, git_blob_id(blob));
|
git_oid_cpy(&filters->source.oid, git_blob_id(blob));
|
||||||
|
@ -408,7 +408,7 @@ static int create_index_error(int error, const char *msg)
|
|||||||
return error;
|
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;
|
unsigned int old_ignore_case;
|
||||||
|
|
||||||
|
@ -1145,17 +1145,19 @@ static int repo_init_structure(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!tdir) {
|
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;
|
tdir = template_buf.ptr;
|
||||||
default_template = true;
|
default_template = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = git_futils_cp_r(tdir, repo_dir,
|
if (tdir)
|
||||||
GIT_CPDIR_COPY_SYMLINKS | GIT_CPDIR_CHMOD_DIRS |
|
error = git_futils_cp_r(tdir, repo_dir,
|
||||||
GIT_CPDIR_SIMPLE_TO_MODE, dmode);
|
GIT_CPDIR_COPY_SYMLINKS | GIT_CPDIR_CHMOD_DIRS |
|
||||||
|
GIT_CPDIR_SIMPLE_TO_MODE, dmode);
|
||||||
|
|
||||||
git_buf_free(&template_buf);
|
git_buf_free(&template_buf);
|
||||||
git_config_free(cfg);
|
git_config_free(cfg);
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
if (!default_template)
|
if (!default_template)
|
||||||
return error;
|
return error;
|
||||||
|
@ -30,24 +30,26 @@ void cl_git_mkfile(const char *filename, const char *content)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cl_git_write2file(
|
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);
|
int fd;
|
||||||
cl_assert(fd >= 0);
|
cl_assert(path && content);
|
||||||
if (!new_content)
|
cl_assert((fd = p_open(path, flags, mode)) >= 0);
|
||||||
new_content = "\n";
|
if (!content_len)
|
||||||
cl_must_pass(p_write(fd, new_content, strlen(new_content)));
|
content_len = strlen(content);
|
||||||
|
cl_must_pass(p_write(fd, content, content_len));
|
||||||
cl_must_pass(p_close(fd));
|
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
|
#ifdef GIT_WIN32
|
||||||
|
@ -78,7 +78,8 @@ void clar__assert_equal_file(
|
|||||||
void cl_git_mkfile(const char *filename, const char *content);
|
void cl_git_mkfile(const char *filename, const char *content);
|
||||||
void cl_git_append2file(const char *filename, const char *new_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_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_toggle_filemode(const char *filename);
|
||||||
bool cl_is_chmod_supported(void);
|
bool cl_is_chmod_supported(void);
|
||||||
|
@ -24,18 +24,16 @@ void test_core_filebuf__0(void)
|
|||||||
void test_core_filebuf__1(void)
|
void test_core_filebuf__1(void)
|
||||||
{
|
{
|
||||||
git_filebuf file = GIT_FILEBUF_INIT;
|
git_filebuf file = GIT_FILEBUF_INIT;
|
||||||
int fd;
|
|
||||||
char test[] = "test";
|
char test[] = "test";
|
||||||
|
|
||||||
fd = p_creat(test, 0666); //-V536
|
cl_git_mkfile(test, "libgit2 rocks\n");
|
||||||
cl_must_pass(fd);
|
|
||||||
cl_must_pass(p_write(fd, "libgit2 rocks\n", 14));
|
|
||||||
cl_must_pass(p_close(fd));
|
|
||||||
|
|
||||||
cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
|
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_printf(&file, "%s\n", "libgit2 rocks"));
|
||||||
cl_git_pass(git_filebuf_commit(&file, 0666));
|
cl_git_pass(git_filebuf_commit(&file, 0666));
|
||||||
|
|
||||||
|
cl_assert_equal_file("libgit2 rocks\nlibgit2 rocks\n", 0, test);
|
||||||
|
|
||||||
cl_must_pass(p_unlink(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_write(&file, buf, sizeof(buf)));
|
||||||
cl_git_pass(git_filebuf_commit(&file, 0666));
|
cl_git_pass(git_filebuf_commit(&file, 0666));
|
||||||
|
|
||||||
|
cl_assert_equal_file((char *)buf, sizeof(buf), test);
|
||||||
|
|
||||||
cl_must_pass(p_unlink(test));
|
cl_must_pass(p_unlink(test));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1266,3 +1266,28 @@ void test_diff_workdir__untracked_directory_comes_last(void)
|
|||||||
|
|
||||||
git_diff_list_free(diff);
|
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);
|
||||||
|
}
|
||||||
|
@ -44,7 +44,8 @@ static void replace_file_with_mode(
|
|||||||
|
|
||||||
cl_git_pass(p_rename(path.ptr, backup));
|
cl_git_pass(p_rename(path.ptr, backup));
|
||||||
cl_git_write2file(
|
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(&path);
|
||||||
git_buf_free(&content);
|
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);
|
add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
|
||||||
|
|
||||||
/* 5 - add new 0644 -> expect 0644 */
|
/* 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);
|
O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||||
add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
|
add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ void test_index_filemodes__untrusted(void)
|
|||||||
*/
|
*/
|
||||||
if (can_filemode) {
|
if (can_filemode) {
|
||||||
/* 6 - add 0755 -> expect 0755 */
|
/* 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);
|
O_WRONLY | O_CREAT | O_TRUNC, 0755);
|
||||||
add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
|
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);
|
add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
|
||||||
|
|
||||||
/* 5 - add new 0644 -> expect 0644 */
|
/* 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);
|
O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||||
add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
|
add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
|
||||||
|
|
||||||
/* 6 - add 0755 -> expect 0755 */
|
/* 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);
|
O_WRONLY | O_CREAT | O_TRUNC, 0755);
|
||||||
add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
|
add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
|
||||||
|
|
||||||
|
@ -382,7 +382,7 @@ static void assert_hooks_match(
|
|||||||
cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
|
cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
|
||||||
cl_git_pass(git_path_lstat(actual.ptr, &st));
|
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) {
|
if (GIT_MODE_TYPE(expected_st.st_mode) != GIT_FILEMODE_LINK) {
|
||||||
mode_t expected_mode =
|
mode_t expected_mode =
|
||||||
|
Loading…
Reference in New Issue
Block a user