Commit f6867e63 by Vicent Marti

Fix compilation in Windows

parent 09df3f2c
......@@ -104,8 +104,10 @@ int git_indexer_new(git_indexer **out, const char *packname)
namelen = strlen(packname);
idx->pack = git__malloc(sizeof(struct git_pack_file) + namelen + 1);
if (idx->pack == NULL)
if (idx->pack == NULL) {
error = GIT_ENOMEM;
goto cleanup;
}
memset(idx->pack, 0x0, sizeof(struct git_pack_file));
memcpy(idx->pack->pack_name, packname, namelen + 1);
......@@ -127,7 +129,7 @@ int git_indexer_new(git_indexer **out, const char *packname)
}
idx->pack->mwf.fd = ret;
idx->pack->mwf.size = idx->st.st_size;
idx->pack->mwf.size = (git_off_t)idx->st.st_size;
error = parse_header(idx);
if (error < GIT_SUCCESS) {
......@@ -170,7 +172,7 @@ int git_indexer_write(git_indexer *idx)
{
git_mwindow *w = NULL;
int error, namelen;
unsigned int i, long_offsets, left;
unsigned int i, long_offsets = 0, left;
struct git_pack_idx_header hdr;
char filename[GIT_PATH_MAX];
struct entry *entry;
......
......@@ -44,8 +44,10 @@
*/
static git_mwindow_ctl ctl = {
.window_size = DEFAULT_WINDOW_SIZE,
.mapped_limit = DEFAULT_MAPPED_LIMIT
0,
0,
DEFAULT_WINDOW_SIZE,
DEFAULT_MAPPED_LIMIT
};
/*
......@@ -87,11 +89,11 @@ void git_mwindow_free_all(git_mwindow_file *mwf)
/*
* Check if a window 'win' contains the address 'offset'
*/
int git_mwindow_contains(git_mwindow *win, off_t offset)
int git_mwindow_contains(git_mwindow *win, git_off_t offset)
{
off_t win_off = win->offset;
git_off_t win_off = win->offset;
return win_off <= offset
&& offset <= (off_t)(win_off + win->window_map.len);
&& offset <= (git_off_t)(win_off + win->window_map.len);
}
/*
......@@ -156,10 +158,10 @@ int git_mwindow_close_lru(git_mwindow_file *mwf)
return git__throw(GIT_ERROR, "Failed to close memory window. Couln't find LRU");
}
static git_mwindow *new_window(git_mwindow_file *mwf, git_file fd, size_t size, off_t offset)
static git_mwindow *new_window(git_mwindow_file *mwf, git_file fd, git_off_t size, git_off_t offset)
{
size_t walign = ctl.window_size / 2;
size_t len;
git_off_t len;
git_mwindow *w;
w = git__malloc(sizeof(*w));
......@@ -170,17 +172,17 @@ static git_mwindow *new_window(git_mwindow_file *mwf, git_file fd, size_t size,
w->offset = (offset / walign) * walign;
len = size - w->offset;
if (len > ctl.window_size)
len = ctl.window_size;
if (len > (git_off_t)ctl.window_size)
len = (git_off_t)ctl.window_size;
ctl.mapped += len;
ctl.mapped += (size_t)len;
while(ctl.mapped_limit < ctl.mapped &&
git_mwindow_close_lru(mwf) == GIT_SUCCESS) {}
/* FIXME: Shouldn't we error out if there's an error in closing lru? */
if (git_futils_mmap_ro(&w->window_map, fd, w->offset, len) < GIT_SUCCESS)
if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < GIT_SUCCESS)
goto cleanup;
ctl.mmap_calls++;
......@@ -204,7 +206,7 @@ cleanup:
* enough space. Don't forget to add it to your list
*/
unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor,
off_t offset, int extra, unsigned int *left)
git_off_t offset, int extra, unsigned int *left)
{
git_mwindow *w = *cursor;
......@@ -242,12 +244,9 @@ unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor,
assert(git__is_sizet(offset));
if (left)
*left = w->window_map.len - offset;
*left = (unsigned int)(w->window_map.len - offset);
return (unsigned char *) w->window_map.data + offset;
free(w);
return NULL;
}
int git_mwindow_file_register(git_mwindow_file *mwf)
......
......@@ -33,7 +33,7 @@
typedef struct git_mwindow {
struct git_mwindow *next;
git_map window_map;
off_t offset;
git_off_t offset;
unsigned int last_used;
unsigned int inuse_cnt;
} git_mwindow;
......@@ -41,7 +41,7 @@ typedef struct git_mwindow {
typedef struct git_mwindow_file {
git_mwindow *windows;
int fd;
off_t size;
git_off_t size;
} git_mwindow_file;
typedef struct git_mwindow_ctl {
......@@ -56,9 +56,9 @@ typedef struct git_mwindow_ctl {
git_vector windowfiles;
} git_mwindow_ctl;
int git_mwindow_contains(git_mwindow *win, off_t offset);
int git_mwindow_contains(git_mwindow *win, git_off_t offset);
void git_mwindow_free_all(git_mwindow_file *mwf);
unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, off_t offset, int extra, unsigned int *left);
unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, git_off_t offset, int extra, unsigned int *left);
void git_mwindow_scan_lru(git_mwindow_file *mwf, git_mwindow **lru_w, git_mwindow **lru_l);
int git_mwindow_file_register(git_mwindow_file *mwf);
void git_mwindow_close(git_mwindow **w_cursor);
......
......@@ -179,6 +179,7 @@ static int pack_entry_find_prefix(struct git_pack_entry *e,
GIT_INLINE(void) pack_window_free_all(struct pack_backend *GIT_UNUSED(backend), struct git_pack_file *p)
{
GIT_UNUSED_ARG(backend);
git_mwindow_free_all(&p->mwf);
}
......
......@@ -160,8 +160,6 @@ static int reference_read(git_fbuffer *file_content, time_t *mtime, const char *
git_path_join(path, repo_path, ref_name);
return git_futils_readbuffer_updated(file_content, path, mtime, updated);
return GIT_SUCCESS;
}
......
......@@ -499,7 +499,7 @@ END_TEST
/* External declaration for testing the buffer parsing method */
int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int parse_flags);
int commit_parse_buffer(git_commit *commit, void *data, size_t len);
BEGIN_TEST(parse2, "parse a whole commit buffer")
const int broken_commit_count = sizeof(test_commits_broken) / sizeof(*test_commits_broken);
......@@ -519,8 +519,7 @@ BEGIN_TEST(parse2, "parse a whole commit buffer")
must_fail(commit_parse_buffer(
commit,
test_commits_broken[i],
strlen(test_commits_broken[i]),
0x1)
strlen(test_commits_broken[i]))
);
git_commit__free(commit);
......@@ -536,8 +535,7 @@ BEGIN_TEST(parse2, "parse a whole commit buffer")
must_pass(commit_parse_buffer(
commit,
test_commits_working[i],
strlen(test_commits_working[i]),
0x0)
strlen(test_commits_working[i]))
);
git_commit__free(commit);
......@@ -549,8 +547,7 @@ BEGIN_TEST(parse2, "parse a whole commit buffer")
must_pass(commit_parse_buffer(
commit,
test_commits_working[i],
strlen(test_commits_working[i]),
0x1)
strlen(test_commits_working[i]))
);
git_commit__free(commit);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment