commit - 509c99732c4da3e3b74c17d09aba5a38b701716f
commit + 762d73f46b73795f4f1defc7cbadd0a3c3f17604
blob - 44f8ac073b1d120169e3ef344f1caca1022da938
blob + 6b796d3554548cbf04c5c143d4e5311d6545dd03
--- lib/got_lib_object.h
+++ lib/got_lib_object.h
const struct got_error *got_object_get_id_str(char **, struct got_object *);
const struct got_error *got_object_get_path(char **, struct got_object_id *,
struct got_repository *);
+const struct got_error *got_object_open_loose_fd(int *, struct got_object_id *,
+ struct got_repository *);
const struct got_error *got_object_open(struct got_object **,
struct got_repository *, struct got_object_id *);
const struct got_error *got_object_raw_open(struct got_raw_object **,
blob - 45d8d172d3e1fc86252195cf8d104b348ef56f44
blob + d599d8a2df794fac0197af296081abaca81c9eb6
--- lib/object.c
+++ lib/object.c
return err;
}
-static const struct got_error *
-open_loose_object(int *fd, struct got_object_id *id,
+const struct got_error *
+got_object_open_loose_fd(int *fd, struct got_object_id *id,
struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_object_id *id)
{
const struct got_error *err = NULL;
- char *path;
int fd;
*obj = got_repo_get_cached_object(repo, id);
return got_repo_cache_object(repo, id, *obj);
}
- err = got_object_get_path(&path, id, repo);
+ err = got_object_open_loose_fd(&fd, id, repo);
+ if (err) {
+ if (err->code == GOT_ERR_ERRNO && errno == ENOENT)
+ err = got_error_no_obj(id);
+ return err;
+ }
+
+ err = read_object_header_privsep(obj, repo, fd);
if (err)
return err;
- fd = open(path, O_RDONLY | O_NOFOLLOW);
- if (fd == -1) {
- if (errno == ENOENT)
- err = got_error_no_obj(id);
- else
- err = got_error_from_errno2("open", path);
- goto done;
- } else {
- err = read_object_header_privsep(obj, repo, fd);
- if (err)
- goto done;
- memcpy((*obj)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
- }
+ memcpy((*obj)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
(*obj)->refcnt++;
- err = got_repo_cache_object(repo, id, *obj);
-done:
- free(path);
- return err;
+ return got_repo_cache_object(repo, id, *obj);
}
const struct got_error *
} else if (err->code == GOT_ERR_NO_OBJ) {
int fd;
- err = open_loose_object(&fd, id, repo);
+ err = got_object_open_loose_fd(&fd, id, repo);
if (err)
goto done;
err = read_object_raw_privsep(&outbuf, &size, &hdrlen, outfd,
} else if (err->code == GOT_ERR_NO_OBJ) {
int fd;
- err = open_loose_object(&fd, id, repo);
+ err = got_object_open_loose_fd(&fd, id, repo);
if (err)
return err;
err = read_commit_privsep(commit, fd, repo);
} else if (err->code == GOT_ERR_NO_OBJ) {
int fd;
- err = open_loose_object(&fd, id, repo);
+ err = got_object_open_loose_fd(&fd, id, repo);
if (err)
return err;
err = read_tree_privsep(tree, fd, repo);
} else if (err->code == GOT_ERR_NO_OBJ) {
int infd;
- err = open_loose_object(&infd, id, repo);
+ err = got_object_open_loose_fd(&infd, id, repo);
if (err)
goto done;
err = read_blob_privsep(&outbuf, &size, &hdrlen, outfd, infd,
} else if (err->code == GOT_ERR_NO_OBJ) {
int fd;
- err = open_loose_object(&fd, id, repo);
+ err = got_object_open_loose_fd(&fd, id, repo);
if (err)
return err;
err = read_object_header_privsep(&obj, repo, fd);
if (obj_type != GOT_OBJ_TYPE_TAG)
return got_error(GOT_ERR_OBJ_TYPE);
- err = open_loose_object(&fd, id, repo);
+ err = got_object_open_loose_fd(&fd, id, repo);
if (err)
return err;
err = read_tag_privsep(tag, fd, repo);