Commit b74c867a by Jakob Pfender

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.
parent cbf4f9f4
...@@ -119,7 +119,7 @@ GIT_EXTERN(int) git_blob_rawsize(git_blob *blob); ...@@ -119,7 +119,7 @@ GIT_EXTERN(int) git_blob_rawsize(git_blob *blob);
* relative to the repository's working dir * relative to the repository's working dir
* @return 0 on success; error code otherwise * @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);
/** /**
......
...@@ -78,7 +78,7 @@ int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *b ...@@ -78,7 +78,7 @@ int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *b
return GIT_SUCCESS; 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 error, islnk;
int fd = 0; int fd = 0;
...@@ -86,6 +86,9 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat ...@@ -86,6 +86,9 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
char buffer[2048]; char buffer[2048];
git_off_t size; git_off_t size;
git_odb_stream *stream; git_odb_stream *stream;
struct stat st;
gitfo_lstat(path, &st);
islnk = S_ISLNK(st.st_mode); islnk = S_ISLNK(st.st_mode);
......
...@@ -434,7 +434,7 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char ...@@ -434,7 +434,7 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char
entry->file_size = st.st_size; entry->file_size = st.st_size;
/* write the blob to disk and get the oid */ /* 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"); return git__rethrow(error, "Failed to initialize index entry");
entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT); entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment