diff options
| author | Russell Belfer <arrbee@arrbee.com> | 2011-11-30 11:27:15 -0800 |
|---|---|---|
| committer | Russell Belfer <arrbee@arrbee.com> | 2011-12-07 23:08:15 -0800 |
| commit | 97769280ba9938ae27f6e06cbd0d5e8a768a86b9 (patch) | |
| tree | 4fe43e99acb55f904f6b586bd7c5158610f9512f /src/transports | |
| parent | a22b14d32dd8d5f06f121aa154d45bac3b10a305 (diff) | |
| download | libgit2-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/transports')
| -rw-r--r-- | src/transports/git.c | 2 | ||||
| -rw-r--r-- | src/transports/http.c | 19 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/transports/git.c b/src/transports/git.c index bdb94d090..ece4d40a8 100644 --- a/src/transports/git.c +++ b/src/transports/git.c @@ -68,7 +68,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url) git_buf_put(request, url, delim - url); git_buf_putc(request, '\0'); - return git_buf_oom(request); + return git_buf_lasterror(request); } static int send_request(GIT_SOCKET s, const char *cmd, const char *url) diff --git a/src/transports/http.c b/src/transports/http.c index e463a0f59..48ea78dce 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -77,10 +77,7 @@ static int gen_request(git_buf *buf, const char *url, const char *host, const ch } git_buf_puts(buf, "\r\n"); - if (git_buf_oom(buf)) - return GIT_ENOMEM; - - return GIT_SUCCESS; + return git_buf_lasterror(buf); } static int do_connect(transport_http *t, const char *host, const char *port) @@ -608,8 +605,9 @@ static int http_download_pack(char **out, git_transport *transport, git_reposito char buffer[1024]; gitno_buffer buf; download_pack_cbdata data; - git_filebuf file; - char path[GIT_PATH_MAX], suff[] = "/objects/pack/pack-received\0"; + git_filebuf file = GIT_FILEBUF_INIT; + git_buf path = GIT_BUF_INIT; + char suff[] = "/objects/pack/pack-received\0"; /* * This is part of the previous response, so we don't want to @@ -625,13 +623,15 @@ static int http_download_pack(char **out, git_transport *transport, git_reposito gitno_buffer_setup(&buf, buffer, sizeof(buffer), t->socket); - git_path_join(path, repo->path_repository, suff); - if (memcmp(oldbuf->ptr, "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; @@ -671,6 +671,7 @@ static int http_download_pack(char **out, git_transport *transport, git_reposito cleanup: if (error < GIT_SUCCESS) git_filebuf_cleanup(&file); + git_buf_free(&path); return error; } |
