summaryrefslogtreecommitdiff
path: root/src/indexer.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-04-16 14:19:27 -0700
committerVicent Marti <tanoku@gmail.com>2013-04-22 16:52:07 +0200
commit38eef6113d8523abfe6746bf727cee2651398ad3 (patch)
tree3565c7cacc968d8ddf05a8c551e3202a7a08436c /src/indexer.c
parentc628918625c7f779d2050a56998fb2b675f097fb (diff)
downloadlibgit2-38eef6113d8523abfe6746bf727cee2651398ad3.tar.gz
Make indexer use shared packfile open code
The indexer was creating a packfile object separately from the code in pack.c which was a problem since I put a call to git_mutex_init into just pack.c. This commit updates the pack function for creating a new pack object (i.e. git_packfile_check()) so that it can be used in both places and then makes indexer.c use the shared initialization routine. There are also a few minor formatting and warning message fixes.
Diffstat (limited to 'src/indexer.c')
-rw-r--r--src/indexer.c30
1 files changed, 6 insertions, 24 deletions
diff --git a/src/indexer.c b/src/indexer.c
index 2cfbd3a5a..50a9d3a37 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -60,36 +60,19 @@ const git_oid *git_indexer_stream_hash(const git_indexer_stream *idx)
static int open_pack(struct git_pack_file **out, const char *filename)
{
- size_t namelen;
struct git_pack_file *pack;
- struct stat st;
- int fd;
- namelen = strlen(filename);
- pack = git__calloc(1, sizeof(struct git_pack_file) + namelen + 1);
- GITERR_CHECK_ALLOC(pack);
-
- memcpy(pack->pack_name, filename, namelen + 1);
-
- if (p_stat(filename, &st) < 0) {
- giterr_set(GITERR_OS, "Failed to stat packfile.");
- goto cleanup;
- }
+ if (git_packfile_check(&pack, filename) < 0)
+ return -1;
- if ((fd = p_open(pack->pack_name, O_RDONLY)) < 0) {
+ if ((pack->mwf.fd = p_open(pack->pack_name, O_RDONLY)) < 0) {
giterr_set(GITERR_OS, "Failed to open packfile.");
- goto cleanup;
+ git_packfile_free(pack);
+ return -1;
}
- pack->mwf.fd = fd;
- pack->mwf.size = (git_off_t)st.st_size;
-
*out = pack;
return 0;
-
-cleanup:
- git__free(pack);
- return -1;
}
static int parse_header(struct git_pack_header *hdr, struct git_pack_file *pack)
@@ -391,7 +374,7 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
{
int error = -1;
struct git_pack_header hdr;
- size_t processed;
+ size_t processed;
git_mwindow_file *mwf = &idx->pack->mwf;
assert(idx && data && stats);
@@ -404,7 +387,6 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
/* Make sure we set the new size of the pack */
if (idx->opened_pack) {
idx->pack->mwf.size += size;
- //printf("\nadding %zu for %zu\n", size, idx->pack->mwf.size);
} else {
if (open_pack(&idx->pack, idx->pack_file.path_lock) < 0)
return -1;