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/index.c | |
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/index.c')
-rw-r--r-- | src/index.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/index.c b/src/index.c index 9f336ba0a..9baab16a9 100644 --- a/src/index.c +++ b/src/index.c @@ -294,40 +294,30 @@ git_index_entry *git_index_get(git_index *index, unsigned int n) static int index_entry_init(git_index_entry **entry_out, git_index *index, const char *rel_path, int stage) { - git_index_entry *entry; - char full_path[GIT_PATH_MAX]; + git_index_entry *entry = NULL; struct stat st; git_oid oid; int error; - const char *workdir; if (INDEX_OWNER(index) == NULL) return git__throw(GIT_EBAREINDEX, "Failed to initialize entry. Repository is bare"); - workdir = git_repository_workdir(INDEX_OWNER(index)); - if (workdir == NULL) - return git__throw(GIT_EBAREINDEX, - "Failed to initialize entry. Cannot resolved workdir"); - - git_path_join(full_path, workdir, rel_path); - - if (p_lstat(full_path, &st) < 0) - return git__throw(GIT_ENOTFOUND, - "Failed to initialize entry. '%s' cannot be opened", full_path); - if (stage < 0 || stage > 3) return git__throw(GIT_ERROR, "Failed to initialize entry. Invalid stage %i", stage); + /* There is no need to validate the rel_path here, since it will be + * immediately validated by the call to git_blob_create_fromfile. + */ + /* write the blob to disk and get the oid */ if ((error = git_blob_create_fromfile(&oid, INDEX_OWNER(index), rel_path)) < GIT_SUCCESS) return git__rethrow(error, "Failed to initialize index entry"); - entry = git__malloc(sizeof(git_index_entry)); + entry = git__calloc(1, sizeof(git_index_entry)); if (!entry) return GIT_ENOMEM; - memset(entry, 0x0, sizeof(git_index_entry)); entry->ctime.seconds = (git_time_t)st.st_ctime; entry->mtime.seconds = (git_time_t)st.st_mtime; |