summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-12-11 15:02:20 -0800
committerRussell Belfer <rb@github.com>2013-12-11 15:02:20 -0800
commit7697e54176ccab22ed6d4597d7256e9a1e6ff202 (patch)
tree69c1bdd91bcf767b28bd6bc5ea9612084c1a765c /src
parent8b22d862fb4419b219210027f18c1e97dd36fa8b (diff)
downloadlibgit2-7697e54176ccab22ed6d4597d7256e9a1e6ff202.tar.gz
Test cancel from indexer progress callback
This adds tests that try canceling an indexer operation from within the progress callback. After writing the tests, I wanted to run this under valgrind and had a number of errors in that situation because mmap wasn't working. I added a CMake option to force emulation of mmap and consolidated the Amiga-specific code into that new place (so we don't actually need separate Amiga code now, just have to turn on -DNO_MMAP). Additionally, I made the indexer code propagate error codes more reliably than it used to.
Diffstat (limited to 'src')
-rw-r--r--src/amiga/map.c48
-rw-r--r--src/indexer.c28
-rw-r--r--src/posix.c36
-rw-r--r--src/unix/map.c2
-rw-r--r--src/win32/map.c3
5 files changed, 54 insertions, 63 deletions
diff --git a/src/amiga/map.c b/src/amiga/map.c
deleted file mode 100644
index 0ba7995c6..000000000
--- a/src/amiga/map.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#include <git2/common.h>
-
-#ifndef GIT_WIN32
-
-#include "posix.h"
-#include "map.h"
-#include <errno.h>
-
-int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
-{
- GIT_MMAP_VALIDATE(out, len, prot, flags);
-
- out->data = NULL;
- out->len = 0;
-
- if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) {
- giterr_set(GITERR_OS, "Trying to map shared-writeable");
- return -1;
- }
-
- out->data = malloc(len);
- GITERR_CHECK_ALLOC(out->data);
-
- if ((p_lseek(fd, offset, SEEK_SET) < 0) || ((size_t)p_read(fd, out->data, len) != len)) {
- giterr_set(GITERR_OS, "mmap emulation failed");
- return -1;
- }
-
- out->len = len;
- return 0;
-}
-
-int p_munmap(git_map *map)
-{
- assert(map != NULL);
- free(map->data);
-
- return 0;
-}
-
-#endif
-
diff --git a/src/indexer.c b/src/indexer.c
index 88897d07d..718c69814 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -441,8 +441,8 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
processed = stats->indexed_objects;
- if (git_filebuf_write(&idx->pack_file, data, size) < 0)
- return -1;
+ if ((error = git_filebuf_write(&idx->pack_file, data, size)) < 0)
+ return error;
hash_partially(idx, data, (int)size);
@@ -450,12 +450,12 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
if (idx->opened_pack) {
idx->pack->mwf.size += size;
} else {
- if (open_pack(&idx->pack, idx->pack_file.path_lock) < 0)
- return -1;
+ if ((error = open_pack(&idx->pack, idx->pack_file.path_lock)) < 0)
+ return error;
idx->opened_pack = 1;
mwf = &idx->pack->mwf;
- if (git_mwindow_file_register(&idx->pack->mwf) < 0)
- return -1;
+ if ((error = git_mwindow_file_register(&idx->pack->mwf)) < 0)
+ return error;
}
if (!idx->parsed_header) {
@@ -464,8 +464,8 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
if ((unsigned)idx->pack->mwf.size < sizeof(struct git_pack_header))
return 0;
- if (parse_header(&idx->hdr, idx->pack) < 0)
- return -1;
+ if ((error = parse_header(&idx->hdr, idx->pack)) < 0)
+ return error;
idx->parsed_header = 1;
idx->nr_objects = ntohl(hdr->hdr_entries);
@@ -503,6 +503,7 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
/* As the file grows any windows we try to use will be out of date */
git_mwindow_free_all(mwf);
+
while (processed < idx->nr_objects) {
git_packfile_stream *stream = &idx->stream;
git_off_t entry_start = idx->off;
@@ -520,7 +521,7 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
return 0;
}
if (error < 0)
- return error;
+ goto on_error;
git_mwindow_close(&w);
idx->entry_start = entry_start;
@@ -533,7 +534,7 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
return 0;
}
if (error < 0)
- return error;
+ goto on_error;
idx->have_delta = 1;
} else {
@@ -542,9 +543,10 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
}
idx->have_stream = 1;
- if (git_packfile_stream_open(stream, idx->pack, idx->off) < 0)
- goto on_error;
+ error = git_packfile_stream_open(stream, idx->pack, idx->off);
+ if (error < 0)
+ goto on_error;
}
if (idx->have_delta) {
@@ -858,7 +860,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
/* Test for this before resolve_deltas(), as it plays with idx->off */
if (idx->off < idx->pack->mwf.size - 20) {
- giterr_set(GITERR_INDEXER, "unexpected data at the end of the pack");
+ giterr_set(GITERR_INDEXER, "Unexpected data at the end of the pack");
return -1;
}
diff --git a/src/posix.c b/src/posix.c
index b75109b83..525785f35 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -203,4 +203,40 @@ int p_write(git_file fd, const void *buf, size_t cnt)
return 0;
}
+#ifdef NO_MMAP
+#include "map.h"
+
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+{
+ GIT_MMAP_VALIDATE(out, len, prot, flags);
+
+ out->data = NULL;
+ out->len = 0;
+
+ if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) {
+ giterr_set(GITERR_OS, "Trying to map shared-writeable");
+ return -1;
+ }
+
+ out->data = malloc(len);
+ GITERR_CHECK_ALLOC(out->data);
+
+ if ((p_lseek(fd, offset, SEEK_SET) < 0) || ((size_t)p_read(fd, out->data, len) != len)) {
+ giterr_set(GITERR_OS, "mmap emulation failed");
+ return -1;
+ }
+
+ out->len = len;
+ return 0;
+}
+
+int p_munmap(git_map *map)
+{
+ assert(map != NULL);
+ free(map->data);
+
+ return 0;
+}
+
+#endif
diff --git a/src/unix/map.c b/src/unix/map.c
index 7de99c99d..e62ab3e76 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -6,7 +6,7 @@
*/
#include <git2/common.h>
-#ifndef GIT_WIN32
+#if !defined(GIT_WIN32) && !defined(NO_MMAP)
#include "map.h"
#include <sys/mman.h>
diff --git a/src/win32/map.c b/src/win32/map.c
index 44c6c4e2e..902ea3994 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -8,6 +8,7 @@
#include "map.h"
#include <errno.h>
+#ifndef NO_MMAP
static DWORD get_page_size(void)
{
@@ -112,4 +113,4 @@ int p_munmap(git_map *map)
return error;
}
-
+#endif