summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-11-30 11:27:15 -0800
committerRussell Belfer <arrbee@arrbee.com>2011-12-07 23:08:15 -0800
commit97769280ba9938ae27f6e06cbd0d5e8a768a86b9 (patch)
tree4fe43e99acb55f904f6b586bd7c5158610f9512f /src/odb.c
parenta22b14d32dd8d5f06f121aa154d45bac3b10a305 (diff)
downloadlibgit2-97769280ba9938ae27f6e06cbd0d5e8a768a86b9.tar.gz
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/odb.c')
-rw-r--r--src/odb.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/odb.c b/src/odb.c
index d31f93f73..b52f87078 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -344,40 +344,47 @@ static int add_default_backends(git_odb *db, const char *objects_dir, int as_alt
static int load_alternates(git_odb *odb, const char *objects_dir)
{
- char alternates_path[GIT_PATH_MAX];
- char *buffer, *alternate;
-
+ git_buf alternates_path = GIT_BUF_INIT;
+ char *buffer;
git_fbuffer alternates_buf = GIT_FBUFFER_INIT;
+ const char *alternate;
int error;
- git_path_join(alternates_path, objects_dir, GIT_ALTERNATES_FILE);
+ error = git_buf_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE);
+ if (error < GIT_SUCCESS)
+ return error;
- if (git_futils_exists(alternates_path) < GIT_SUCCESS)
+ if (git_futils_exists(alternates_path.ptr) < GIT_SUCCESS) {
+ git_buf_free(&alternates_path);
return GIT_SUCCESS;
+ }
- if (git_futils_readbuffer(&alternates_buf, alternates_path) < GIT_SUCCESS)
+ if (git_futils_readbuffer(&alternates_buf, alternates_path.ptr) < GIT_SUCCESS) {
+ git_buf_free(&alternates_path);
return git__throw(GIT_EOSERR, "Failed to add backend. Can't read alternates");
+ }
buffer = (char *)alternates_buf.data;
error = GIT_SUCCESS;
/* add each alternate as a new backend; one alternate per line */
while ((alternate = git__strtok(&buffer, "\r\n")) != NULL) {
- char full_path[GIT_PATH_MAX];
-
if (*alternate == '\0' || *alternate == '#')
continue;
/* relative path: build based on the current `objects` folder */
if (*alternate == '.') {
- git_path_join(full_path, objects_dir, alternate);
- alternate = full_path;
+ error = git_buf_joinpath(&alternates_path, objects_dir, alternate);
+ if (error < GIT_SUCCESS)
+ break;
+ alternate = git_buf_cstr(&alternates_path);
}
if ((error = add_default_backends(odb, alternate, 1)) < GIT_SUCCESS)
break;
}
+ git_buf_free(&alternates_path);
git_futils_freebuffer(&alternates_buf);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to load alternates");