switch back to searching packed objects first; it is indeed faster
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
diff --git a/lib/object.c b/lib/object.c
index da29a06..60a273e 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -147,10 +147,7 @@ open_loose_object(int *fd, struct got_object_id *id,
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);
+ err = got_error_from_errno2("open", path);
goto done;
}
done:
@@ -425,17 +422,25 @@ got_object_open(struct got_object **obj, struct got_repository *repo,
return NULL;
}
+ err = open_packed_object(obj, id, repo);
+ if (err && err->code != GOT_ERR_NO_OBJ)
+ return err;
+ if (*obj) {
+ (*obj)->refcnt++;
+ return got_repo_cache_object(repo, id, *obj);
+ }
+
err = got_object_get_path(&path, id, repo);
if (err)
return err;
fd = open(path, O_RDONLY | O_NOFOLLOW);
if (fd == -1) {
- if (errno != ENOENT) {
+ if (errno == ENOENT)
+ err = got_error_no_obj(id);
+ else
err = got_error_from_errno2("open", path);
- goto done;
- }
- err = open_packed_object(obj, id, repo);
+ goto done;
} else {
err = read_object_header_privsep(obj, repo, fd);
if (err)
@@ -574,7 +579,7 @@ open_commit(struct got_commit_object **commit,
{
const struct got_error *err = NULL;
struct got_packidx *packidx = NULL;
- int idx, fd;
+ int idx;
char *path_packfile;
if (check_cache) {
@@ -586,17 +591,10 @@ open_commit(struct got_commit_object **commit,
} else
*commit = NULL;
- err = open_loose_object(&fd, id, repo);
- if (err) {
+ err = got_repo_search_packidx(&packidx, &idx, repo, id);
+ if (err == NULL) {
struct got_pack *pack = NULL;
- if (err->code != GOT_ERR_NO_OBJ)
- return err;
-
- err = got_repo_search_packidx(&packidx, &idx, repo, id);
- if (err)
- return err;
-
err = get_packfile_path(&path_packfile, packidx);
if (err)
return err;
@@ -610,8 +608,14 @@ open_commit(struct got_commit_object **commit,
}
err = read_packed_commit_privsep(commit, pack,
packidx, idx, id);
- } else
+ } else if (err->code == GOT_ERR_NO_OBJ) {
+ int fd;
+
+ err = open_loose_object(&fd, id, repo);
+ if (err)
+ return err;
err = read_commit_privsep(commit, fd, repo);
+ }
if (err == NULL) {
(*commit)->refcnt++;
@@ -753,7 +757,7 @@ open_tree(struct got_tree_object **tree, struct got_repository *repo,
{
const struct got_error *err = NULL;
struct got_packidx *packidx = NULL;
- int fd, idx;
+ int idx;
char *path_packfile;
if (check_cache) {
@@ -765,32 +769,31 @@ open_tree(struct got_tree_object **tree, struct got_repository *repo,
} else
*tree = NULL;
- err = open_loose_object(&fd, id, repo);
- if (err) {
+ err = got_repo_search_packidx(&packidx, &idx, repo, id);
+ if (err == NULL) {
struct got_pack *pack = NULL;
- if (err->code != GOT_ERR_NO_OBJ)
- return err;
-
- err = got_repo_search_packidx(&packidx, &idx, repo, id);
- if (err)
- return err;
-
err = get_packfile_path(&path_packfile, packidx);
if (err)
return err;
pack = got_repo_get_cached_pack(repo, path_packfile);
if (pack == NULL) {
- err = got_repo_cache_pack(&pack, repo,
- path_packfile, packidx);
+ err = got_repo_cache_pack(&pack, repo, path_packfile,
+ packidx);
if (err)
return err;
}
err = read_packed_tree_privsep(tree, pack,
packidx, idx, id);
- } else
+ } else if (err->code == GOT_ERR_NO_OBJ) {
+ int fd;
+
+ err = open_loose_object(&fd, id, repo);
+ if (err)
+ return err;
err = read_tree_privsep(tree, fd, repo);
+ }
if (err == NULL) {
(*tree)->refcnt++;
@@ -976,7 +979,7 @@ open_blob(struct got_blob_object **blob, struct got_repository *repo,
int idx;
char *path_packfile;
uint8_t *outbuf;
- int infd, outfd;
+ int outfd;
size_t size, hdrlen;
struct stat sb;
@@ -994,17 +997,10 @@ open_blob(struct got_blob_object **blob, struct got_repository *repo,
goto done;
}
- err = open_loose_object(&infd, id, repo);
- if (err) {
+ err = got_repo_search_packidx(&packidx, &idx, repo, id);
+ if (err == NULL) {
struct got_pack *pack = NULL;
- if (err->code != GOT_ERR_NO_OBJ)
- goto done;
-
- err = got_repo_search_packidx(&packidx, &idx, repo, id);
- if (err)
- goto done;
-
err = get_packfile_path(&path_packfile, packidx);
if (err)
goto done;
@@ -1018,9 +1014,15 @@ open_blob(struct got_blob_object **blob, struct got_repository *repo,
}
err = read_packed_blob_privsep(&outbuf, &size, &hdrlen, outfd,
pack, packidx, idx, id);
- } else
+ } else if (err->code == GOT_ERR_NO_OBJ) {
+ int infd;
+
+ err = open_loose_object(&infd, id, repo);
+ if (err)
+ goto done;
err = read_blob_privsep(&outbuf, &size, &hdrlen, outfd, infd,
repo);
+ }
if (err)
goto done;
@@ -1287,7 +1289,7 @@ open_tag(struct got_tag_object **tag, struct got_repository *repo,
{
const struct got_error *err = NULL;
struct got_packidx *packidx = NULL;
- int fd, idx;
+ int idx;
char *path_packfile;
if (check_cache) {
@@ -1299,36 +1301,37 @@ open_tag(struct got_tag_object **tag, struct got_repository *repo,
} else
*tag = NULL;
- err = open_loose_object(&fd, id, repo);
- if (err) {
+ err = got_repo_search_packidx(&packidx, &idx, repo, id);
+ if (err == NULL) {
struct got_pack *pack = NULL;
- if (err->code != GOT_ERR_NO_OBJ)
- return err;
-
- err = got_repo_search_packidx(&packidx, &idx, repo, id);
- if (err)
- return err;
-
err = get_packfile_path(&path_packfile, packidx);
if (err)
return err;
pack = got_repo_get_cached_pack(repo, path_packfile);
if (pack == NULL) {
- err = got_repo_cache_pack(&pack, repo,
- path_packfile, packidx);
+ err = got_repo_cache_pack(&pack, repo, path_packfile,
+ packidx);
if (err)
return err;
}
- err = read_packed_tag_privsep(tag, pack, packidx, idx, id);
- } else
+ err = read_packed_tag_privsep(tag, pack,
+ packidx, idx, id);
+ } else if (err->code == GOT_ERR_NO_OBJ) {
+ int fd;
+
+ err = open_loose_object(&fd, id, repo);
+ if (err)
+ return err;
err = read_tag_privsep(tag, fd, repo);
+ }
if (err == NULL) {
(*tag)->refcnt++;
err = got_repo_cache_tag(repo, id, *tag);
}
+
return err;
}