commit 44f875ad4b93ddb8d0e717a6ca564ce84de7f4e2 from: Stefan Sperling via: Thomas Adam date: Thu Jan 18 17:17:45 2024 UTC avoid opening objects in the gotd session process for no reason The session process opened an object as part of a sanity check and simply closed it again. Opening an object involves decompression and combination of deltas. Add a new interface which checks whether an object ID exists without such overhead and call it from gotd. commit - 84a2cae442d6c7544bc5e515da4e4465f69ec128 commit + 44f875ad4b93ddb8d0e717a6ca564ce84de7f4e2 blob - 779d275d76ee4ec7de49b0eb3ac7c86b3f60da72 blob + b9059883b276557469eb6e0eee0207d19e630185 --- gotd/session.c +++ gotd/session.c @@ -409,7 +409,6 @@ update_ref(int *shut, struct gotd_session_client *clie struct gotd_imsg_ref_update iref; struct got_object_id old_id, new_id; struct got_object_id *id = NULL; - struct got_object *obj = NULL; char *refname = NULL; size_t datalen; int locked = 0; @@ -439,8 +438,8 @@ update_ref(int *shut, struct gotd_session_client *clie memcpy(old_id.sha1, iref.old_id, SHA1_DIGEST_LENGTH); memcpy(new_id.sha1, iref.new_id, SHA1_DIGEST_LENGTH); - err = got_object_open(&obj, repo, - iref.delete_ref ? &old_id : &new_id); + err = got_repo_find_object_id(iref.delete_ref ? &old_id : &new_id, + repo); if (err) goto done; @@ -559,8 +558,6 @@ done: } if (ref) got_ref_close(ref); - if (obj) - got_object_close(obj); if (repo) got_repo_close(repo); free(refname); blob - f44259d099d9b70c547d238971a7cc147c4e209f blob + 606d32e822167999828d4333a09b3b6ee296bf61 --- lib/got_lib_repository.h +++ lib/got_lib_repository.h @@ -184,3 +184,6 @@ const struct got_error *got_repo_read_gitconfig(int *, const struct got_error *got_repo_temp_fds_get(int *, int *, struct got_repository *); void got_repo_temp_fds_put(int, struct got_repository *); + +const struct got_error *got_repo_find_object_id(struct got_object_id *, + struct got_repository *); blob - d03adb90174241003324f223eadcf82466c3c87b blob + 9e58244dfa2381523d54c703cd1e1059b769fe3f --- lib/repository.c +++ lib/repository.c @@ -2150,7 +2150,24 @@ got_repo_object_match_tag(struct got_tag_object **tag, GOT_OBJ_LABEL_TAG, name); return err; } + +const struct got_error * +got_repo_find_object_id(struct got_object_id *id, struct got_repository *repo) +{ + const struct got_error *err; + struct got_object_id *matched_id = NULL; + char *id_str = NULL; + err = got_object_id_str(&id_str, id); + if (err) + return err; + + err = got_repo_match_object_id_prefix(&matched_id, id_str, + GOT_OBJ_TYPE_ANY, repo); + free(id_str); + return err; +} + static const struct got_error * alloc_added_blob_tree_entry(struct got_tree_entry **new_te, const char *name, mode_t mode, struct got_object_id *blob_id)