commit 41fa143713753fc592bd4dcd8894b4de6a5f7350 from: Stefan Sperling date: Mon Nov 05 14:30:15 2018 UTC back out mini-commits; no significant performance difference commit - 710f3f4e5168164687c5586641920d82960b0a3a commit + 41fa143713753fc592bd4dcd8894b4de6a5f7350 blob - 1356457c06fba14aee526f0e6ab3bed70477ca5b blob + d0e80bc31edd85aea3d8e095d680ea7b47a23d0c --- lib/commit_graph.c +++ lib/commit_graph.c @@ -163,12 +163,12 @@ is_merge_point(struct got_commit_graph_node *node) } static const struct got_error * -detect_changed_path(int *changed, struct got_mini_commit_object *commit, +detect_changed_path(int *changed, struct got_commit_object *commit, struct got_object_id *commit_id, const char *path, struct got_repository *repo) { const struct got_error *err = NULL; - struct got_mini_commit_object *pcommit = NULL; + struct got_commit_object *pcommit = NULL; struct got_tree_object *tree = NULL, *ptree = NULL; struct got_object_qid *pid; @@ -194,7 +194,7 @@ detect_changed_path(int *changed, struct got_mini_comm *changed = 1; /* The path was created in this commit. */ free(obj_id); } else { - err = got_object_open_as_mini_commit(&pcommit, repo, pid->id); + err = got_object_open_as_commit(&pcommit, repo, pid->id); if (err) goto done; @@ -211,7 +211,7 @@ done: if (ptree) got_object_tree_close(ptree); if (pcommit) - got_object_mini_commit_close(pcommit); + got_object_commit_close(pcommit); return err; } @@ -275,7 +275,7 @@ close_branch(struct got_commit_graph *graph, struct go static const struct got_error * advance_branch(struct got_commit_graph *graph, struct got_commit_graph_node *node, - struct got_object_id *commit_id, struct got_mini_commit_object *commit, + struct got_object_id *commit_id, struct got_commit_object *commit, struct got_repository *repo) { const struct got_error *err; @@ -382,8 +382,8 @@ free_node(struct got_commit_graph_node *node) static const struct got_error * add_node(struct got_commit_graph_node **new_node, struct got_commit_graph *graph, struct got_object_id *commit_id, - struct got_mini_commit_object *commit, - struct got_commit_graph_node *child_node, struct got_repository *repo) + struct got_commit_object *commit, struct got_commit_graph_node *child_node, + struct got_repository *repo) { const struct got_error *err = NULL; struct got_commit_graph_node *node; @@ -456,11 +456,11 @@ got_commit_graph_open(struct got_commit_graph **graph, int first_parent_traversal, struct got_repository *repo) { const struct got_error *err = NULL; - struct got_mini_commit_object *commit; + struct got_commit_object *commit; *graph = NULL; - err = got_object_open_as_mini_commit(&commit, repo, commit_id); + err = got_object_open_as_commit(&commit, repo, commit_id); if (err) return err; @@ -475,7 +475,7 @@ got_commit_graph_open(struct got_commit_graph **graph, *graph = alloc_graph(path); if (*graph == NULL) { - got_object_mini_commit_close(commit); + got_object_commit_close(commit); return got_error_from_errno(); } @@ -484,7 +484,7 @@ got_commit_graph_open(struct got_commit_graph **graph, err = add_node(&(*graph)->head_node, *graph, commit_id, commit, NULL, repo); - got_object_mini_commit_close(commit); + got_object_commit_close(commit); if (err) { got_commit_graph_close(*graph); *graph = NULL; @@ -547,20 +547,20 @@ fetch_commits_from_open_branches(int *ncommits, for (i = 0; i < arg.ntips; i++) { struct got_object_id *commit_id; struct got_commit_graph_node *child_node, *new_node; - struct got_mini_commit_object *commit; + struct got_commit_object *commit; int changed; commit_id = &graph->tips[i].id; child_node = graph->tips[i].node; - err = got_object_open_as_mini_commit(&commit, repo, commit_id); + err = got_object_open_as_commit(&commit, repo, commit_id); if (err) break; err = detect_changed_path(&changed, commit, commit_id, graph->path, repo); if (err) { - got_object_mini_commit_close(commit); + got_object_commit_close(commit); if (err->code != GOT_ERR_NO_OBJ) break; err = close_branch(graph, commit_id); @@ -572,7 +572,7 @@ fetch_commits_from_open_branches(int *ncommits, *changed_id = commit_id; err = add_node(&new_node, graph, commit_id, commit, child_node, repo); - got_object_mini_commit_close(commit); + got_object_commit_close(commit); if (err) break; if (new_node) @@ -628,21 +628,21 @@ got_commit_graph_iter_start(struct got_commit_graph *g { const struct got_error *err = NULL; struct got_commit_graph_node *start_node; - struct got_mini_commit_object *commit; + struct got_commit_object *commit; int changed; start_node = got_object_idset_get(graph->node_ids, id); if (start_node == NULL) return got_error(GOT_ERR_NO_OBJ); - err = got_object_open_as_mini_commit(&commit, repo, &start_node->id); + err = got_object_open_as_commit(&commit, repo, &start_node->id); if (err) return err; err = detect_changed_path(&changed, commit, &start_node->id, graph->path, repo); if (err) { - got_object_mini_commit_close(commit); + got_object_commit_close(commit); return err; } @@ -654,13 +654,13 @@ got_commit_graph_iter_start(struct got_commit_graph *g err = fetch_commits_from_open_branches(&ncommits, &changed_id, graph, repo); if (err) { - got_object_mini_commit_close(commit); + got_object_commit_close(commit); return err; } } start_node = got_object_idset_get(graph->node_ids, changed_id); } - got_object_mini_commit_close(commit); + got_object_commit_close(commit); graph->iter_node = start_node; return NULL; blob - fe430caa865a4a08c6b2f7aff78b39ec3b1ec79b blob + fc8b2eef010a4a07760e360d7e9102d16791ddbd --- lib/got_lib_object.h +++ lib/got_lib_object.h @@ -48,20 +48,3 @@ struct got_blob_object { uint8_t *read_buf; struct got_object_id id; }; - -/* Small version of got_commit_object. Used by commit graph. */ -struct got_mini_commit_object { - struct got_object_id *tree_id; - unsigned int nparents; - struct got_object_id_queue parent_ids; - struct tm tm_committer; /* UTC */ - int refcnt; /* > 0 if open and/or cached */ -}; - -const struct got_error * -got_object_mini_commit_open(struct got_mini_commit_object **, - struct got_repository *, struct got_object *); -void got_object_mini_commit_close(struct got_mini_commit_object *); -const struct got_error *got_object_open_as_mini_commit( - struct got_mini_commit_object **, struct got_repository *, - struct got_object_id *); blob - f54f0728765dd02b604190b725d8df77b2ddf05e blob + d574268b30620f1eb67c2f20275e6987b2248aaa --- lib/got_lib_object_cache.h +++ lib/got_lib_object_cache.h @@ -18,7 +18,6 @@ enum got_object_cache_type { GOT_OBJECT_CACHE_TYPE_OBJ, GOT_OBJECT_CACHE_TYPE_TREE, GOT_OBJECT_CACHE_TYPE_COMMIT, - GOT_OBJECT_CACHE_TYPE_MINI_COMMIT, }; struct got_object_cache_entry { @@ -27,7 +26,6 @@ struct got_object_cache_entry { struct got_object *obj; struct got_tree_object *tree; struct got_commit_object *commit; - struct got_mini_commit_object *mini_commit; } data; }; blob - 45ef92bdc8abd72d2d49020aa475062d8ba4047c blob + b427544ee597fb40d4802b61166507af2c7f124e --- lib/got_lib_object_parse.h +++ lib/got_lib_object_parse.h @@ -14,11 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -const struct got_error *got_object_qid_alloc_partial(struct got_object_qid **); struct got_commit_object *got_object_commit_alloc_partial(void); -struct got_mini_commit_object *got_object_mini_commit_alloc_partial(void); -const struct got_error *got_object_commit_add_parent(struct got_commit_object *, - const char *); struct got_tree_entry *got_alloc_tree_entry_partial(void); const struct got_error *got_object_read_header_privsep(struct got_object**, struct got_repository *repo, int); @@ -27,16 +23,11 @@ const struct got_error *got_object_read_blob_privsep(s const struct got_error *got_object_read_commit_privsep( struct got_commit_object **, struct got_object *, int, struct got_repository *); -const struct got_error *got_object_read_mini_commit_privsep( - struct got_mini_commit_object **, struct got_object *, int, - struct got_repository *); const struct got_error *got_object_read_tree_privsep(struct got_tree_object **, struct got_object *, int, struct got_repository *); const struct got_error *got_object_parse_commit(struct got_commit_object **, char *, size_t); -const struct got_error *got_object_parse_mini_commit( - struct got_mini_commit_object **, char *, size_t); const struct got_error *got_object_parse_tree(struct got_tree_object **, uint8_t *, size_t); const struct got_error *got_read_file_to_mem(uint8_t **, size_t *, FILE *); @@ -51,8 +42,5 @@ const struct got_error *got_object_packed_read_privsep struct got_object_id *); const struct got_error *got_object_read_packed_commit_privsep( struct got_commit_object **, struct got_object *, struct got_pack *); -const struct got_error *got_object_read_packed_mini_commit_privsep( - struct got_mini_commit_object **, struct got_object *, struct got_pack *, - struct got_repository *); const struct got_error *got_object_read_packed_tree_privsep( struct got_tree_object **, struct got_object *, struct got_pack *); blob - 4a84a701e68e04e761b6bbb494ea7edad584cfa2 blob + b39f11fe79428dd8bc9691d9b8b2300171346459 --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -82,8 +82,6 @@ enum got_imsg_type { GOT_IMSG_COMMIT_REQUEST, GOT_IMSG_COMMIT, GOT_IMSG_COMMIT_LOGMSG, - GOT_IMSG_MINI_COMMIT_REQUEST, - GOT_IMSG_MINI_COMMIT, GOT_IMSG_TREE_REQUEST, GOT_IMSG_TREE, GOT_IMSG_TREE_ENTRY, @@ -144,22 +142,7 @@ struct got_imsg_commit_object { */ } __attribute__((__packed__)); -/* Structure for GOT_IMSG_MINI_COMMIT data. */ -struct got_imsg_commit_object_mini { - uint8_t tree_id[SHA1_DIGEST_LENGTH]; - struct tm tm_committer; - int nparents; - /* - * Set if this commit is a parent of the requested commit. - * Allows got-read-pack to seed the main process mini-commit cache. - */ - int is_parent; - uint8_t parent_id[SHA1_DIGEST_LENGTH]; - - /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */ -} __attribute__((__packed__)); - /* Structure for GOT_IMSG_TREE_ENTRY. */ struct got_imsg_tree_entry { char id[SHA1_DIGEST_LENGTH]; @@ -219,13 +202,8 @@ const struct got_error *got_privsep_recv_obj(struct go struct imsgbuf *); const struct got_error *got_privsep_send_commit(struct imsgbuf *, struct got_commit_object *); -const struct got_error *got_privsep_send_mini_commit(struct imsgbuf *, - struct got_mini_commit_object *, struct got_object_id *); const struct got_error *got_privsep_recv_commit(struct got_commit_object **, struct imsgbuf *); -const struct got_error *got_privsep_recv_mini_commit( - struct got_mini_commit_object **, struct got_object_id **, - struct imsgbuf *); const struct got_error *got_privsep_recv_tree(struct got_tree_object **, struct imsgbuf *); const struct got_error *got_privsep_send_tree(struct imsgbuf *, @@ -236,5 +214,4 @@ const struct got_error *got_privsep_init_pack_child(st struct got_pack *, struct got_packidx *); const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int, struct got_object_id *); -const struct got_error *got_privsep_send_mini_commit_req(struct imsgbuf *, int, - struct got_object *); +const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *); blob - 5211dc1d41de7829a31ea14bf405e30357303a79 blob + feabca184d20dfd1ca4c681d9ccb24e0c7717d12 --- lib/got_lib_repository.h +++ lib/got_lib_repository.h @@ -38,7 +38,6 @@ struct got_repository { struct got_object_cache objcache; struct got_object_cache treecache; struct got_object_cache commitcache; - struct got_object_cache minicommitcache; }; const struct got_error*got_repo_cache_object(struct got_repository *, @@ -53,10 +52,6 @@ const struct got_error*got_repo_cache_commit(struct go struct got_object_id *, struct got_commit_object *); struct got_commit_object *got_repo_get_cached_commit(struct got_repository *, struct got_object_id *); -const struct got_error*got_repo_cache_mini_commit(struct got_repository *, - struct got_object_id *, struct got_mini_commit_object *); -struct got_mini_commit_object *got_repo_get_cached_mini_commit( - struct got_repository *, struct got_object_id *); const struct got_error *got_repo_cache_packidx(struct got_repository *, struct got_packidx *); const struct got_error *got_repo_search_packidx(struct got_packidx **, int *, blob - 959246bfdf1644ebd7609f3be3417a60a5e723ed blob + c58c241572783b631a3bb336ed0daab98750a241 --- lib/object.c +++ lib/object.c @@ -348,90 +348,9 @@ got_object_commit_open(struct got_commit_object **comm struct got_repository *repo, struct got_object *obj) { return open_commit(commit, repo, obj, 1); -} - -static const struct got_error * -open_mini_commit(struct got_mini_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_mini_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_mini_commit_privsep(commit, obj, - pack, repo); - } else { - int fd; - err = open_loose_object(&fd, obj, repo); - if (err) - return err; - err = got_object_read_mini_commit_privsep(commit, obj, fd, - repo); - close(fd); - } - - if (err == NULL) { - (*commit)->refcnt++; - err = got_repo_cache_mini_commit(repo, &obj->id, *commit); - } - - return err; -} - -const struct got_error * -got_object_open_as_mini_commit(struct got_mini_commit_object **commit, - struct got_repository *repo, struct got_object_id *id) -{ - const struct got_error *err; - struct got_object *obj; - - *commit = got_repo_get_cached_mini_commit(repo, id); - if (*commit != NULL) { - (*commit)->refcnt++; - return NULL; - } - - err = got_object_open(&obj, repo, id); - if (err) - return err; - if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) { - err = got_error(GOT_ERR_OBJ_TYPE); - goto done; - } - - err = open_mini_commit(commit, repo, obj, 0); -done: - got_object_close(obj); - return err; } const struct got_error * -got_object_mini_commit_open(struct got_mini_commit_object **commit, - struct got_repository *repo, struct got_object *obj) -{ - return open_mini_commit(commit, repo, obj, 1); -} - -const struct got_error * got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id) { const struct got_error *err = NULL; @@ -1155,6 +1074,7 @@ done: return err; } + static const struct got_error * request_commit(struct got_commit_object **commit, struct got_repository *repo, struct got_object *obj, int fd) @@ -1171,21 +1091,6 @@ request_commit(struct got_commit_object **commit, stru return got_privsep_recv_commit(commit, ibuf); } -static const struct got_error * -request_mini_commit(struct got_mini_commit_object **commit, - struct got_repository *repo, struct got_object *obj, int fd) -{ - const struct got_error *err = NULL; - struct imsgbuf *ibuf; - - ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf; - err = got_privsep_send_mini_commit_req(ibuf, fd, obj); - if (err) - return err; - - return got_privsep_recv_mini_commit(commit, NULL, ibuf); -} - const struct got_error * got_object_read_packed_commit_privsep(struct got_commit_object **commit, struct got_object *obj, struct got_pack *pack) @@ -1200,35 +1105,6 @@ got_object_read_packed_commit_privsep(struct got_commi } const struct got_error * -got_object_read_packed_mini_commit_privsep( - struct got_mini_commit_object **commit, struct got_object *obj, - struct got_pack *pack, struct got_repository *repo) -{ - const struct got_error *err = NULL; - struct got_object_id *pid = NULL; - - err = got_privsep_send_mini_commit_req(pack->privsep_child->ibuf, -1, - obj); - if (err) - return err; - - while (1) { - err = got_privsep_recv_mini_commit(commit, &pid, - pack->privsep_child->ibuf); - if (err || pid == NULL) - break; - - /* got-read-pack has sent a parent commit; cache it. */ - err = got_repo_cache_mini_commit(repo, pid, *commit); - free(pid); - if (err) - break; - } - - return err; -} - -const struct got_error * got_object_read_commit_privsep(struct got_commit_object **commit, struct got_object *obj, int obj_fd, struct got_repository *repo) { @@ -1265,43 +1141,6 @@ got_object_read_commit_privsep(struct got_commit_objec return request_commit(commit, repo, obj, obj_fd); } -const struct got_error * -got_object_read_mini_commit_privsep(struct got_mini_commit_object **commit, - struct got_object *obj, int obj_fd, struct got_repository *repo) -{ - int imsg_fds[2]; - pid_t pid; - struct imsgbuf *ibuf; - - if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd != -1) - return request_mini_commit(commit, repo, obj, obj_fd); - - ibuf = calloc(1, sizeof(*ibuf)); - if (ibuf == NULL) - return got_error_from_errno(); - - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) - return got_error_from_errno(); - - pid = fork(); - if (pid == -1) - return got_error_from_errno(); - else if (pid == 0) { - exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_COMMIT, - repo->path); - /* not reached */ - } - - close(imsg_fds[1]); - repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd = - imsg_fds[0]; - repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].pid = pid; - imsg_init(ibuf, imsg_fds[0]); - repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf = ibuf; - - return request_mini_commit(commit, repo, obj, obj_fd); -} - static const struct got_error * request_tree(struct got_tree_object **tree, struct got_repository *repo, struct got_object *obj, int fd) blob - 112f328bc9dd80c6cd7d73c762fbc323cc7a493c blob + 24b34b5a240fdcde737f55f54a4f6755371faffc --- lib/object_cache.c +++ lib/object_cache.c @@ -32,10 +32,9 @@ #include "got_lib_object_idcache.h" #include "got_lib_object_cache.h" -#define GOT_OBJECT_CACHE_SIZE_OBJ 1024 -#define GOT_OBJECT_CACHE_SIZE_TREE 2048 -#define GOT_OBJECT_CACHE_SIZE_COMMIT 512 -#define GOT_OBJECT_CACHE_SIZE_MINI_COMMIT 32 +#define GOT_OBJECT_CACHE_SIZE_OBJ 1024 +#define GOT_OBJECT_CACHE_SIZE_TREE 2048 +#define GOT_OBJECT_CACHE_SIZE_COMMIT 512 const struct got_error * got_object_cache_init(struct got_object_cache *cache, @@ -53,9 +52,6 @@ got_object_cache_init(struct got_object_cache *cache, case GOT_OBJECT_CACHE_TYPE_COMMIT: size = GOT_OBJECT_CACHE_SIZE_COMMIT; break; - case GOT_OBJECT_CACHE_TYPE_MINI_COMMIT: - size = GOT_OBJECT_CACHE_SIZE_MINI_COMMIT; - break; } cache->idcache = got_object_idcache_alloc(size); @@ -89,9 +85,6 @@ got_object_cache_add(struct got_object_cache *cache, s case GOT_OBJECT_CACHE_TYPE_COMMIT: got_object_commit_close(ce->data.commit); break; - case GOT_OBJECT_CACHE_TYPE_MINI_COMMIT: - got_object_mini_commit_close(ce->data.mini_commit); - break; } free(ce); cache->cache_evict++; @@ -111,9 +104,6 @@ got_object_cache_add(struct got_object_cache *cache, s case GOT_OBJECT_CACHE_TYPE_COMMIT: ce->data.commit = (struct got_commit_object *)item; break; - case GOT_OBJECT_CACHE_TYPE_MINI_COMMIT: - ce->data.mini_commit = (struct got_mini_commit_object *)item; - break; } err = got_object_idcache_add(cache->idcache, id, ce); @@ -142,8 +132,6 @@ got_object_cache_get(struct got_object_cache *cache, s return ce->data.tree; case GOT_OBJECT_CACHE_TYPE_COMMIT: return ce->data.commit; - case GOT_OBJECT_CACHE_TYPE_MINI_COMMIT: - return ce->data.mini_commit; } } @@ -169,7 +157,6 @@ void check_refcount(struct got_object_id *id, void *da struct got_object *obj; struct got_tree_object *tree; struct got_commit_object *commit; - struct got_mini_commit_object *mini_commit; char *id_str; if (got_object_id_str(&id_str, id) != NULL) @@ -197,13 +184,6 @@ void check_refcount(struct got_object_id *id, void *da fprintf(stderr, "commit %s has %d unclaimed references\n", id_str, commit->refcnt - 1); break; - case GOT_OBJECT_CACHE_TYPE_MINI_COMMIT: - mini_commit = ce->data.mini_commit; - if (mini_commit->refcnt == 1) - break; - fprintf(stderr, "commit %s has %d unclaimed references\n", - id_str, mini_commit->refcnt - 1); - break; } free(id_str); } @@ -223,9 +203,6 @@ got_object_cache_close(struct got_object_cache *cache) case GOT_OBJECT_CACHE_TYPE_COMMIT: print_cache_stats(cache, "commit"); break; - case GOT_OBJECT_CACHE_TYPE_MINI_COMMIT: - print_cache_stats(cache, "mini-commit"); - break; } got_object_idcache_for_each(cache->idcache, check_refcount, cache); blob - 834b92887c6e497f05e11e3f5495591f7e7c0cf8 blob + 07d52651602537e5df106ea314f3770df1ffb56f --- lib/object_parse.c +++ lib/object_parse.c @@ -42,10 +42,10 @@ #include "got_lib_sha1.h" #include "got_lib_delta.h" -#include "got_lib_inflate.h" -#include "got_lib_object.h" #include "got_lib_privsep.h" #include "got_lib_pack.h" +#include "got_lib_inflate.h" +#include "got_lib_object.h" #include "got_lib_object_cache.h" #include "got_lib_repository.h" @@ -102,24 +102,6 @@ got_object_close(struct got_object *obj) free(obj); } -const struct got_error * -got_object_qid_alloc_partial(struct got_object_qid **qid) -{ - const struct got_error *err = NULL; - - *qid = malloc(sizeof(**qid)); - if (*qid == NULL) - return got_error_from_errno(); - - (*qid)->id = malloc(sizeof(*((*qid)->id))); - if ((*qid)->id == NULL) { - err = got_error_from_errno(); - got_object_qid_free(*qid); - *qid = NULL; - } - return err; -} - void got_object_qid_free(struct got_object_qid *qid) { @@ -146,25 +128,6 @@ got_object_commit_alloc_partial(void) return commit; } -struct got_mini_commit_object * -got_object_mini_commit_alloc_partial(void) -{ - struct got_mini_commit_object *commit; - - commit = calloc(1, sizeof(*commit)); - if (commit == NULL) - return NULL; - commit->tree_id = calloc(1, sizeof(*commit->tree_id)); - if (commit->tree_id == NULL) { - free(commit); - return NULL; - } - - SIMPLEQ_INIT(&commit->parent_ids); - - return commit; -} - const struct got_error * got_object_commit_add_parent(struct got_commit_object *commit, const char *id_str) @@ -172,34 +135,17 @@ got_object_commit_add_parent(struct got_commit_object const struct got_error *err = NULL; struct got_object_qid *qid; - err = got_object_qid_alloc_partial(&qid); - if (err) - return err; + qid = malloc(sizeof(*qid)); + if (qid == NULL) + return got_error_from_errno(); - if (!got_parse_sha1_digest(qid->id->sha1, id_str)) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - free(qid->id); - free(qid); + qid->id = malloc(sizeof(*qid->id)); + if (qid->id == NULL) { + err = got_error_from_errno(); + got_object_qid_free(qid); return err; } - SIMPLEQ_INSERT_TAIL(&commit->parent_ids, qid, entry); - commit->nparents++; - - return NULL; -} - -const struct got_error * -got_object_mini_commit_add_parent(struct got_mini_commit_object *commit, - const char *id_str) -{ - const struct got_error *err = NULL; - struct got_object_qid *qid; - - err = got_object_qid_alloc_partial(&qid); - if (err) - return err; - if (!got_parse_sha1_digest(qid->id->sha1, id_str)) { err = got_error(GOT_ERR_BAD_OBJ_DATA); free(qid->id); @@ -309,36 +255,14 @@ got_object_commit_close(struct got_commit_object *comm free(commit); } -void -got_object_mini_commit_close(struct got_mini_commit_object *commit) -{ - struct got_object_qid *qid; - - if (commit->refcnt > 0) { - commit->refcnt--; - if (commit->refcnt > 0) - return; - } - - while (!SIMPLEQ_EMPTY(&commit->parent_ids)) { - qid = SIMPLEQ_FIRST(&commit->parent_ids); - SIMPLEQ_REMOVE_HEAD(&commit->parent_ids, entry); - got_object_qid_free(qid); - } - - free(commit->tree_id); - free(commit); -} - const struct got_error * -got_object_parse_commit(struct got_commit_object **commit, char *buf, - size_t len) +got_object_parse_commit(struct got_commit_object **commit, char *buf, size_t len) { const struct got_error *err = NULL; char *s = buf; size_t tlen; ssize_t remain = (ssize_t)len; - + *commit = got_object_commit_alloc_partial(); if (*commit == NULL) return got_error_from_errno(); @@ -451,109 +375,6 @@ done: return err; } -const struct got_error * -got_object_parse_mini_commit(struct got_mini_commit_object **commit, char *buf, - size_t len) -{ - const struct got_error *err = NULL; - char *s = buf; - size_t tlen; - ssize_t remain = (ssize_t)len; - - *commit = got_object_mini_commit_alloc_partial(); - if (*commit == NULL) - return got_error_from_errno(); - - tlen = strlen(GOT_COMMIT_TAG_TREE); - if (strncmp(s, GOT_COMMIT_TAG_TREE, tlen) == 0) { - remain -= tlen; - if (remain < SHA1_DIGEST_STRING_LENGTH) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - goto done; - } - s += tlen; - if (!got_parse_sha1_digest((*commit)->tree_id->sha1, s)) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - goto done; - } - remain -= SHA1_DIGEST_STRING_LENGTH; - s += SHA1_DIGEST_STRING_LENGTH; - } else { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - goto done; - } - - tlen = strlen(GOT_COMMIT_TAG_PARENT); - while (strncmp(s, GOT_COMMIT_TAG_PARENT, tlen) == 0) { - remain -= tlen; - if (remain < SHA1_DIGEST_STRING_LENGTH) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - goto done; - } - s += tlen; - err = got_object_mini_commit_add_parent(*commit, s); - if (err) - goto done; - - remain -= SHA1_DIGEST_STRING_LENGTH; - s += SHA1_DIGEST_STRING_LENGTH; - } - - tlen = strlen(GOT_COMMIT_TAG_AUTHOR); - if (strncmp(s, GOT_COMMIT_TAG_AUTHOR, tlen) == 0) { - char *p; - size_t slen; - - remain -= tlen; - if (remain <= 0) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - goto done; - } - s += tlen; - p = strchr(s, '\n'); - if (p == NULL) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - goto done; - } - *p = '\0'; - slen = strlen(s); - s += slen + 1; - remain -= slen + 1; - } - - tlen = strlen(GOT_COMMIT_TAG_COMMITTER); - if (strncmp(s, GOT_COMMIT_TAG_COMMITTER, tlen) == 0) { - char *p; - size_t slen; - - remain -= tlen; - if (remain <= 0) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - goto done; - } - s += tlen; - p = strchr(s, '\n'); - if (p == NULL) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - goto done; - } - *p = '\0'; - slen = strlen(s); - err = parse_commit_time(&(*commit)->tm_committer, s); - if (err) - goto done; - s += slen + 1; - remain -= slen + 1; - } - -done: - if (err) { - got_object_mini_commit_close(*commit); - *commit = NULL; - } - return err; -} - void got_object_tree_entry_close(struct got_tree_entry *te) { blob - ff2cfa6aea905cc11db48b3346b4e168e9765425 blob + 2429a9462a3a8c43c3d457557c231213747aec54 --- lib/privsep.c +++ lib/privsep.c @@ -39,7 +39,6 @@ #include "got_lib_inflate.h" #include "got_lib_object.h" #include "got_lib_object_parse.h" -#include "got_lib_object_cache.h" #include "got_lib_privsep.h" #include "got_lib_pack.h" @@ -213,20 +212,6 @@ got_privsep_send_stop(int fd) err = flush_imsg(&ibuf); imsg_clear(&ibuf); return err; -} - -static void -init_imsg_object(struct got_imsg_object *iobj, struct got_object *obj) -{ - memcpy(iobj->id, obj->id.sha1, sizeof(iobj->id)); - iobj->type = obj->type; - iobj->flags = obj->flags; - iobj->hdrlen = obj->hdrlen; - iobj->size = obj->size; - if (iobj->flags & GOT_OBJ_FLAG_PACKED) { - iobj->pack_offset = obj->pack_offset; - iobj->pack_idx = obj->pack_idx; - } } const struct got_error * @@ -251,35 +236,21 @@ got_privsep_send_obj_req(struct imsgbuf *ibuf, int fd, return got_error(GOT_ERR_OBJ_TYPE); } - init_imsg_object(&iobj, obj); + memcpy(iobj.id, obj->id.sha1, sizeof(iobj.id)); + iobj.type = obj->type; + iobj.flags = obj->flags; + iobj.hdrlen = obj->hdrlen; + iobj.size = obj->size; + if (iobj.flags & GOT_OBJ_FLAG_PACKED) { + iobj.pack_offset = obj->pack_offset; + iobj.pack_idx = obj->pack_idx; + } iobjp = &iobj; iobj_size = sizeof(iobj); } if (imsg_compose(ibuf, imsg_code, 0, 0, fd, iobjp, iobj_size) == -1) - return got_error_from_errno(); - - return flush_imsg(ibuf); -} - -const struct got_error * -got_privsep_send_mini_commit_req(struct imsgbuf *ibuf, int fd, - struct got_object *obj) -{ - struct got_imsg_object iobj, *iobjp; - size_t iobj_size; - - if (obj->type != GOT_OBJ_TYPE_COMMIT) - return got_error(GOT_ERR_OBJ_TYPE); - - init_imsg_object(&iobj, obj); - - iobjp = &iobj; - iobj_size = sizeof(iobj); - - if (imsg_compose(ibuf, GOT_IMSG_MINI_COMMIT_REQUEST, 0, 0, fd, - iobjp, iobj_size) == -1) return got_error_from_errno(); return flush_imsg(ibuf); @@ -485,54 +456,6 @@ got_privsep_send_commit(struct imsgbuf *ibuf, struct g done: free(buf); return err; -} - -const struct got_error * -got_privsep_send_mini_commit(struct imsgbuf *ibuf, - struct got_mini_commit_object *commit, struct got_object_id *parent_id) -{ - const struct got_error *err = NULL; - struct got_imsg_commit_object_mini icommit; - uint8_t *buf; - size_t len, total; - struct got_object_qid *qid; - - memcpy(icommit.tree_id, commit->tree_id->sha1, sizeof(icommit.tree_id)); - memcpy(&icommit.tm_committer, &commit->tm_committer, - sizeof(icommit.tm_committer)); - icommit.nparents = commit->nparents; - - icommit.is_parent = parent_id ? 1 : 0; - if (parent_id) - memcpy(icommit.parent_id, parent_id->sha1, - sizeof(icommit.parent_id)); - else - memset(&icommit.parent_id, 0, sizeof(icommit.parent_id)); - - total = sizeof(icommit) + icommit.nparents * SHA1_DIGEST_LENGTH; - - buf = malloc(total); - if (buf == NULL) - return got_error_from_errno(); - - len = 0; - memcpy(buf + len, &icommit, sizeof(icommit)); - len += sizeof(icommit); - SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) { - memcpy(buf + len, qid->id, SHA1_DIGEST_LENGTH); - len += SHA1_DIGEST_LENGTH; - } - - if (imsg_compose(ibuf, GOT_IMSG_MINI_COMMIT, 0, 0, -1, - buf, len) == -1) { - err = got_error_from_errno(); - } - - free(buf); - if (err) - return err; - - return parent_id ? NULL : flush_imsg(ibuf); } const struct got_error * @@ -669,113 +592,23 @@ got_privsep_recv_commit(struct got_commit_object **com for (i = 0; i < icommit.nparents; i++) { struct got_object_qid *qid; - err = got_object_qid_alloc_partial(&qid); - if (err) + qid = calloc(1, sizeof(*qid)); + if (qid == NULL) { + err = got_error_from_errno(); break; + } + qid->id = calloc(1, sizeof(*qid->id)); + if (qid->id == NULL) { + err = got_error_from_errno(); + free(qid); + break; + } memcpy(qid->id, data + len + i * SHA1_DIGEST_LENGTH, sizeof(*qid->id)); SIMPLEQ_INSERT_TAIL(&(*commit)->parent_ids, qid, entry); (*commit)->nparents++; - } - break; - default: - err = got_error(GOT_ERR_PRIVSEP_MSG); - break; - } - - imsg_free(&imsg); - - return err; -} - -static const struct got_error * -get_mini_commit(struct got_mini_commit_object **commit, - struct got_imsg_commit_object_mini *icommit, uint8_t *data) -{ - const struct got_error *err = NULL; - int i; - - *commit = got_object_mini_commit_alloc_partial(); - if (*commit == NULL) - return got_error_from_errno(); - - memcpy((*commit)->tree_id->sha1, icommit->tree_id, - SHA1_DIGEST_LENGTH); - memcpy(&(*commit)->tm_committer, &icommit->tm_committer, - sizeof((*commit)->tm_committer)); - - for (i = 0; i < icommit->nparents; i++) { - struct got_object_qid *qid; - - err = got_object_qid_alloc_partial(&qid); - if (err) - break; - - memcpy(qid->id, - data + sizeof(*icommit) + (i * SHA1_DIGEST_LENGTH), - sizeof(*qid->id)); - SIMPLEQ_INSERT_TAIL(&(*commit)->parent_ids, qid, entry); - (*commit)->nparents++; - } - - return err; -} - -const struct got_error * -got_privsep_recv_mini_commit(struct got_mini_commit_object **commit, - struct got_object_id **parent_id, struct imsgbuf *ibuf) -{ - const struct got_error *err = NULL; - struct imsg imsg; - struct got_imsg_commit_object_mini icommit; - size_t datalen; - const size_t min_datalen = - MIN(sizeof(struct got_imsg_error), - sizeof(struct got_imsg_commit_object_mini)); - uint8_t *data; - - *commit = NULL; - - err = got_privsep_recv_imsg(&imsg, ibuf, min_datalen); - if (err) - return err; - - data = imsg.data; - datalen = imsg.hdr.len - IMSG_HEADER_SIZE; - - switch (imsg.hdr.type) { - case GOT_IMSG_ERROR: - err = recv_imsg_error(&imsg, datalen); - break; - case GOT_IMSG_MINI_COMMIT: - if (datalen < sizeof(icommit)) { - err = got_error(GOT_ERR_PRIVSEP_LEN); - break; - } - - memcpy(&icommit, data, sizeof(icommit)); - if (datalen != sizeof(icommit) + - icommit.nparents * SHA1_DIGEST_LENGTH) { - err = got_error(GOT_ERR_PRIVSEP_LEN); - break; - } - if (icommit.nparents < 0) { - err = got_error(GOT_ERR_PRIVSEP_LEN); - break; } - /* got-read-pack might send us parent commits for caching */ - if (icommit.is_parent) { - if (parent_id == NULL) { - err = got_error(GOT_ERR_PRIVSEP_MSG); - break; - } - *parent_id = malloc(sizeof(**parent_id)); - memcpy((*parent_id)->sha1, &icommit.parent_id, - sizeof(*(*parent_id)->sha1)); - } else if (parent_id) - *parent_id = NULL; - err = get_mini_commit(commit, &icommit, data); break; default: err = got_error(GOT_ERR_PRIVSEP_MSG); blob - 968cec4765ea692954e5f255042da6a876408e9b blob + d82e38e345a904ababe7f97b02142d026947c304 --- lib/repository.c +++ lib/repository.c @@ -232,28 +232,6 @@ got_repo_get_cached_commit(struct got_repository *repo } const struct got_error * -got_repo_cache_mini_commit(struct got_repository *repo, - struct got_object_id *id, struct got_mini_commit_object *commit) -{ -#ifndef GOT_NO_OBJ_CACHE - const struct got_error *err = NULL; - err = got_object_cache_add(&repo->minicommitcache, id, commit); - if (err) - return err; - commit->refcnt++; -#endif - return NULL; -} - -struct got_mini_commit_object * -got_repo_get_cached_mini_commit(struct got_repository *repo, - struct got_object_id *id) -{ - return (struct got_mini_commit_object *)got_object_cache_get( - &repo->minicommitcache, id); -} - -const struct got_error * open_repo(struct got_repository *repo, const char *path) { const struct got_error *err = NULL; @@ -374,10 +352,6 @@ got_repo_open(struct got_repository **repop, const cha goto done; err = got_object_cache_init(&repo->commitcache, GOT_OBJECT_CACHE_TYPE_COMMIT); - if (err) - goto done; - err = got_object_cache_init(&repo->minicommitcache, - GOT_OBJECT_CACHE_TYPE_MINI_COMMIT); if (err) goto done; @@ -439,7 +413,6 @@ got_repo_close(struct got_repository *repo) got_object_cache_close(&repo->objcache); got_object_cache_close(&repo->treecache); got_object_cache_close(&repo->commitcache); - got_object_cache_close(&repo->minicommitcache); for (i = 0; i < nitems(repo->privsep_children); i++) { if (repo->privsep_children[i].imsg_fd == -1) blob - 8ae1f392af49cd613c2b255b1716dc9310d037e2 blob + f6b5435605333d42433c5981a64efdc3cb4b18e6 --- libexec/got-read-commit/got-read-commit.c +++ libexec/got-read-commit/got-read-commit.c @@ -39,67 +39,38 @@ #include "got_lib_privsep.h" static const struct got_error * -read_commit_data(uint8_t **p, size_t *len, struct got_object *obj, FILE *f) +read_commit_object(struct got_commit_object **commit, struct got_object *obj, + FILE *f) { - const struct got_error *err; + const struct got_error *err = NULL; + size_t len; + uint8_t *p; if (obj->flags & GOT_OBJ_FLAG_PACKED) - err = got_read_file_to_mem(p, len, f); + err = got_read_file_to_mem(&p, &len, f); else - err = got_inflate_to_mem(p, len, f); + err = got_inflate_to_mem(&p, &len, f); if (err) return err; - if (*len < obj->hdrlen + obj->size) { - free(*p); - *p = NULL; - *len = 0; - return got_error(GOT_ERR_BAD_OBJ_DATA); + if (len < obj->hdrlen + obj->size) { + err = got_error(GOT_ERR_BAD_OBJ_DATA); + goto done; } /* Skip object header. */ - *len -= obj->hdrlen; - return NULL; -} - -static const struct got_error * -read_commit_object(struct got_commit_object **commit, struct got_object *obj, - FILE *f) -{ - const struct got_error *err; - uint8_t *p; - size_t len; - - err = read_commit_data(&p, &len, obj, f); - if (err) - return err; - + len -= obj->hdrlen; err = got_object_parse_commit(commit, p + obj->hdrlen, len); free(p); +done: return err; } -static const struct got_error * -read_commit_object_mini(struct got_mini_commit_object **commit, - struct got_object *obj, FILE *f) -{ - const struct got_error *err; - size_t len; - uint8_t *p; - - err = read_commit_data(&p, &len, obj, f); - if (err) - return err; - - err = got_object_parse_mini_commit(commit, p + obj->hdrlen, len); - free(p); - return err; -} - int main(int argc, char *argv[]) { const struct got_error *err = NULL; + struct got_commit_object *commit = NULL; struct imsgbuf ibuf; size_t datalen; @@ -119,7 +90,6 @@ main(int argc, char *argv[]) struct got_imsg_object iobj; FILE *f = NULL; struct got_object *obj = NULL; - int mini = 0; err = got_privsep_recv_imsg(&imsg, &ibuf, 0); if (err) { @@ -131,16 +101,9 @@ main(int argc, char *argv[]) if (imsg.hdr.type == GOT_IMSG_STOP) break; - switch (imsg.hdr.type) { - case GOT_IMSG_COMMIT_REQUEST: - mini = 0; - break; - case GOT_IMSG_MINI_COMMIT_REQUEST: - mini = 1; - break; - default: - err = got_error(GOT_ERR_PRIVSEP_MSG); - goto done; + if (imsg.hdr.type != GOT_IMSG_COMMIT_REQUEST) { + err = got_error(GOT_ERR_PRIVSEP_MSG); + goto done; } datalen = imsg.hdr.len - IMSG_HEADER_SIZE; @@ -176,21 +139,11 @@ main(int argc, char *argv[]) goto done; } - if (mini) { - struct got_mini_commit_object *commit; - err = read_commit_object_mini(&commit, obj, f); - if (err) - goto done; - err = got_privsep_send_mini_commit(&ibuf, commit, NULL); - got_object_mini_commit_close(commit); - } else { - struct got_commit_object *commit; - err = read_commit_object(&commit, obj, f); - if (err) - goto done; - err = got_privsep_send_commit(&ibuf, commit); - got_object_commit_close(commit); - } + err = read_commit_object(&commit, obj, f); + if (err) + goto done; + + err = got_privsep_send_commit(&ibuf, commit); done: if (f) fclose(f); blob - f1be1b62756ea356027a45e6568e41e7b3765f43 blob + 010b14b5519db260c50522b9ffb8d93182af1675 --- libexec/got-read-pack/got-read-pack.c +++ libexec/got-read-pack/got-read-pack.c @@ -145,115 +145,6 @@ commit_request(struct imsg *imsg, struct imsgbuf *ibuf } static const struct got_error * -send_parent_commit(size_t *totlen, struct imsgbuf *ibuf, - struct got_object_id *pid, struct got_pack *pack, - struct got_packidx *packidx, int recurse) -{ - const struct got_error *err = NULL; - struct got_object *pobj; - struct got_mini_commit_object *pcommit = NULL; - uint8_t *buf; - size_t len, plen; - int idx; - - idx = got_packidx_get_object_idx(packidx, pid); - if (idx == -1) /* parent commit not in same pack file */ - return NULL; - - err = got_packfile_open_object(&pobj, pack, packidx, idx, pid); - if (err) - return err; - - err = got_packfile_extract_object_to_mem(&buf, &len, pobj, - pack); - if (err) { - got_object_close(pobj); - return err; - } - - pobj->size = len; - err = got_object_parse_mini_commit(&pcommit, buf, len); - free(buf); - - plen = sizeof(*pcommit) + (pcommit->nparents * SHA1_DIGEST_LENGTH); - if (*totlen + plen >= MAX_IMSGSIZE - IMSG_HEADER_SIZE) - goto done; - *totlen += plen; - - err = got_privsep_send_mini_commit(ibuf, pcommit, pid); - if (err) - goto done; - - /* Send the first grandparent along as well if there is room. */ - if (recurse > 0) { - struct got_object_qid *qid; - qid = SIMPLEQ_FIRST(&pcommit->parent_ids); - if (qid) - err = send_parent_commit(totlen, ibuf, qid->id, pack, - packidx, recurse - 1); - } -done: - got_object_close(pobj); - got_object_mini_commit_close(pcommit); - return err; -} - -static const struct got_error * -mini_commit_request(struct imsg *imsg, struct imsgbuf *ibuf, - struct got_pack *pack, struct got_packidx *packidx, - struct got_object_cache *objcache) -{ - const struct got_error *err = NULL; - struct got_object *obj = NULL; - struct got_mini_commit_object *commit = NULL; - uint8_t *buf; - size_t len, totlen; - struct got_object_qid *qid; - - err = get_object(&obj, imsg, ibuf, pack, packidx, objcache, - GOT_OBJ_TYPE_COMMIT); - if (err) - return err; - - err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack); - if (err) - return err; - - obj->size = len; - err = got_object_parse_mini_commit(&commit, buf, len); - free(buf); - - /* - * Try to pre-seed the main process mini-commit cache with parent - * commits from this pack file. This makes more efficient use of - * imsg pipe buffers per system call. - */ - totlen = sizeof(struct got_imsg_commit_object_mini) + - (commit->nparents * sizeof(SHA1_DIGEST_LENGTH)); - SIMPLEQ_FOREACH(qid, &commit->parent_ids, entry) { - if (totlen >= MAX_IMSGSIZE - IMSG_HEADER_SIZE) - break; - err = send_parent_commit(&totlen, ibuf, qid->id, - pack, packidx, 1); - if (err) - goto done; - } - - err = got_privsep_send_mini_commit(ibuf, commit, NULL); -done: - got_object_close(obj); - got_object_mini_commit_close(commit); - if (err) { - if (err->code == GOT_ERR_PRIVSEP_PIPE) - err = NULL; - else - got_privsep_send_error(ibuf, err); - } - - return err; -} - -static const struct got_error * tree_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack, struct got_packidx *packidx, struct got_object_cache *objcache) { @@ -571,10 +462,6 @@ main(int argc, char *argv[]) break; case GOT_IMSG_COMMIT_REQUEST: err = commit_request(&imsg, &ibuf, pack, packidx, - &objcache); - break; - case GOT_IMSG_MINI_COMMIT_REQUEST: - err = mini_commit_request(&imsg, &ibuf, pack, packidx, &objcache); break; case GOT_IMSG_TREE_REQUEST: