commit e82b1d8119d413101f11883e43119759a433edc4 from: Stefan Sperling date: Sat Jul 27 17:12:22 2019 UTC switch back to searching packed objects first; it is indeed faster commit - 31b4484f27afc8ceaf636ad8c97d8a9aa119693e commit + e82b1d8119d413101f11883e43119759a433edc4 blob - da29a068a7af497d7562f8b2baa800ae4def94a6 blob + 60a273ea713af45d42943ac3274ba6081c775576 --- lib/object.c +++ 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_re 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_re { 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_re } 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_re 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_re 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_re } 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_repos { 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_repos } 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; }