From b74c867a1acfdc5ef0cfa91ba49d3f52d0ac6237 Mon Sep 17 00:00:00 2001 From: Jakob Pfender Date: Tue, 7 Jun 2011 11:11:09 +0200 Subject: [PATCH] blob: Stat path inside git_blob_create_fromfile 00582bc introduced a change that required the caller of git_blob_create_fromfile() to pass a struct stat with the stat information for the file. Several developers pointed out that this would make life hard for the bindings developers as struct stat isn't widely supported by other languages. Make git_blob_create_fromfile() stat the path itself, eliminating the need for the file to be stat'ed by the caller. This makes index_init_entry() more costly as the file will be stat'ed twice but makes life easier for everyone else. --- include/git2/blob.h | 2 +- src/blob.c | 5 ++++- src/index.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/git2/blob.h b/include/git2/blob.h index 1cfff841d..e366ce880 100644 --- a/include/git2/blob.h +++ b/include/git2/blob.h @@ -119,7 +119,7 @@ GIT_EXTERN(int) git_blob_rawsize(git_blob *blob); * relative to the repository's working dir * @return 0 on success; error code otherwise */ -GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path, struct stat st); +GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path); /** diff --git a/src/blob.c b/src/blob.c index b00fc25af..12f468ef7 100644 --- a/src/blob.c +++ b/src/blob.c @@ -78,7 +78,7 @@ int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *b return GIT_SUCCESS; } -int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path, struct stat st) +int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path) { int error, islnk; int fd = 0; @@ -86,6 +86,9 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat char buffer[2048]; git_off_t size; git_odb_stream *stream; + struct stat st; + + gitfo_lstat(path, &st); islnk = S_ISLNK(st.st_mode); diff --git a/src/index.c b/src/index.c index afd9cfccd..3d2e72e56 100644 --- a/src/index.c +++ b/src/index.c @@ -434,7 +434,7 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char entry->file_size = st.st_size; /* write the blob to disk and get the oid */ - if ((error = git_blob_create_fromfile(&entry->oid, index->repository, rel_path, st)) < GIT_SUCCESS) + if ((error = git_blob_create_fromfile(&entry->oid, index->repository, rel_path)) < GIT_SUCCESS) return git__rethrow(error, "Failed to initialize index entry"); entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT);