commit - e8eb494afad8556bf5105f01c316b49e68ba6842
commit + 434025f31270ab0b50063ed81909d2c32c9f3e98
blob - 5d6b4ff1b5dd49ad7489b12a5a3c1b90d95fa5d2
blob + ef9404c6e447aa45156564e02328d2e8729e4de8
--- lib/object.c
+++ lib/object.c
return got_error(GOT_ERR_BAD_OBJ_ID_STR);
return got_object_open(obj, repo, &id);
+}
+
+static const struct got_error *
+open_commit(struct got_commit_object **commit,
+ struct got_repository *repo, struct got_object *obj, int check_cache)
+{
+ const struct got_error *err = NULL;
+
+ if (check_cache) {
+ *commit = got_repo_get_cached_commit(repo, &obj->id);
+ if (*commit != NULL) {
+ (*commit)->refcnt++;
+ return NULL;
+ }
+ } else
+ *commit = NULL;
+
+ if (obj->type != GOT_OBJ_TYPE_COMMIT)
+ return got_error(GOT_ERR_OBJ_TYPE);
+
+ if (obj->flags & GOT_OBJ_FLAG_PACKED) {
+ struct got_pack *pack;
+ pack = got_repo_get_cached_pack(repo, obj->path_packfile);
+ if (pack == NULL) {
+ err = got_repo_cache_pack(&pack, repo,
+ obj->path_packfile, NULL);
+ if (err)
+ return err;
+ }
+ err = got_object_read_packed_commit_privsep(commit, obj, pack);
+ } else {
+ int fd;
+ err = open_loose_object(&fd, obj, repo);
+ if (err)
+ return err;
+ err = got_object_read_commit_privsep(commit, obj, fd, repo);
+ close(fd);
+ }
+
+ if (err == NULL) {
+ (*commit)->refcnt++;
+ err = got_repo_cache_commit(repo, &obj->id, *commit);
+ }
+
+ return err;
}
const struct got_error *
goto done;
}
- err = got_object_commit_open(commit, repo, obj);
+ err = open_commit(commit, repo, obj, 0);
done:
got_object_close(obj);
return err;
+}
+
+const struct got_error *
+got_object_commit_open(struct got_commit_object **commit,
+ struct got_repository *repo, struct got_object *obj)
+{
+ return open_commit(commit, repo, obj, 1);
}
const struct got_error *
}
const struct got_error *
-got_object_commit_open(struct got_commit_object **commit,
- struct got_repository *repo, struct got_object *obj)
-{
- const struct got_error *err = NULL;
-
- *commit = got_repo_get_cached_commit(repo, &obj->id);
- if (*commit != NULL) {
- (*commit)->refcnt++;
- return NULL;
- }
-
- if (obj->type != GOT_OBJ_TYPE_COMMIT)
- return got_error(GOT_ERR_OBJ_TYPE);
-
- if (obj->flags & GOT_OBJ_FLAG_PACKED) {
- struct got_pack *pack;
- pack = got_repo_get_cached_pack(repo, obj->path_packfile);
- if (pack == NULL) {
- err = got_repo_cache_pack(&pack, repo,
- obj->path_packfile, NULL);
- if (err)
- return err;
- }
- err = got_object_read_packed_commit_privsep(commit, obj, pack);
- } else {
- int fd;
- err = open_loose_object(&fd, obj, repo);
- if (err)
- return err;
- err = got_object_read_commit_privsep(commit, obj, fd, repo);
- close(fd);
- }
-
- if (err == NULL) {
- (*commit)->refcnt++;
- err = got_repo_cache_commit(repo, &obj->id, *commit);
- }
-
- return err;
-}
-
-const struct got_error *
got_object_tree_open(struct got_tree_object **tree,
struct got_repository *repo, struct got_object *obj)
{