Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-11-30 23:27:15 +0400
committerRussell Belfer <arrbee@arrbee.com>2011-12-08 11:08:15 +0400
commit97769280ba9938ae27f6e06cbd0d5e8a768a86b9 (patch)
tree4fe43e99acb55f904f6b586bd7c5158610f9512f /src/fetch.c
parenta22b14d32dd8d5f06f121aa154d45bac3b10a305 (diff)
Use git_buf for path storage instead of stack-based buffers
This converts virtually all of the places that allocate GIT_PATH_MAX buffers on the stack for manipulating paths to use git_buf objects instead. The patch is pretty careful not to touch the public API for libgit2, so there are a few places that still use GIT_PATH_MAX. This extends and changes some details of the git_buf implementation to add a couple of extra functions and to make error handling easier. This includes serious alterations to all the path.c functions, and several of the fileops.c ones, too. Also, there are a number of new functions that parallel existing ones except that use a git_buf instead of a stack-based buffer (such as git_config_find_global_r that exists alongsize git_config_find_global). This also modifies the win32 version of p_realpath to allocate whatever buffer size is needed to accommodate the realpath instead of hardcoding a GIT_PATH_MAX limit, but that change needs to be tested still.
Diffstat (limited to 'src/fetch.c')
-rw-r--r--src/fetch.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/fetch.c b/src/fetch.c
index f447248c5..f9e15b232 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -115,25 +115,31 @@ int git_fetch_download_pack(char **out, git_remote *remote)
}
/* Receiving data from a socket and storing it is pretty much the same for git and HTTP */
-int git_fetch__download_pack(char **out, const char *buffered, size_t buffered_size,
- GIT_SOCKET fd, git_repository *repo)
+int git_fetch__download_pack(
+ char **out,
+ const char *buffered,
+ size_t buffered_size,
+ GIT_SOCKET fd,
+ git_repository *repo)
{
git_filebuf file = GIT_FILEBUF_INIT;
int error;
- char buff[1024], path[GIT_PATH_MAX];
+ char buff[1024];
+ git_buf path = GIT_BUF_INIT;
static const char suff[] = "/objects/pack/pack-received";
gitno_buffer buf;
-
- git_path_join(path, repo->path_repository, suff);
-
gitno_buffer_setup(&buf, buff, sizeof(buff), fd);
if (memcmp(buffered, "PACK", strlen("PACK"))) {
return git__throw(GIT_ERROR, "The pack doesn't start with the signature");
}
- error = git_filebuf_open(&file, path, GIT_FILEBUF_TEMPORARY);
+ error = git_buf_joinpath(&path, repo->path_repository, suff);
+ if (error < GIT_SUCCESS)
+ goto cleanup;
+
+ error = git_filebuf_open(&file, path.ptr, GIT_FILEBUF_TEMPORARY);
if (error < GIT_SUCCESS)
goto cleanup;
@@ -166,7 +172,7 @@ int git_fetch__download_pack(char **out, const char *buffered, size_t buffered_s
cleanup:
if (error < GIT_SUCCESS)
git_filebuf_cleanup(&file);
+ git_buf_free(&path);
return error;
-
}