diff options
| author | saturneric <[email protected]> | 2025-11-02 15:21:58 +0000 |
|---|---|---|
| committer | saturneric <[email protected]> | 2025-11-02 15:21:58 +0000 |
| commit | 960134bef2cd769981cad8df0bd63cb0461e6bbe (patch) | |
| tree | 6118799a8eb7ceb1efcff4e2c0be3dd21b2f4e4f /ui-blob.c | |
| parent | chore(submodule): update `git` submodule URL and commit (diff) | |
| download | cgit-960134bef2cd769981cad8df0bd63cb0461e6bbe.tar.gz cgit-960134bef2cd769981cad8df0bd63cb0461e6bbe.zip | |
refactor(repo): migrate to new object database API
* Replace legacy object store interfaces with new `odb` API
* Update function signatures to include referent param for callbacks
* Use improved object lookup and read methods for consistency
* Simplify file path handling with repository-scoped utilities
Modernizes repository object access for better maintainability and future
compatibility. No functional regressions expected.
Diffstat (limited to 'ui-blob.c')
| -rw-r--r-- | ui-blob.c | 51 |
1 files changed, 43 insertions, 8 deletions
@@ -38,7 +38,14 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, int cgit_ref_path_exists(const char *path, const char *ref, int file_only) { struct object_id oid; + enum object_type type; + void *buffer; unsigned long size; + struct object_info oi = { + .typep = &type, + .sizep = &size, + .contentp = &buffer, + }; struct pathspec_item path_items = { .match = xstrdup(path), .len = strlen(path) @@ -56,8 +63,10 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) if (repo_get_oid(the_repository, ref, &oid)) goto done; - if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) - goto done; + if (odb_read_object_info_extended(the_repository->objects, &oid, + &oi, OBJECT_INFO_LOOKUP_REPLACE) < 0 + || type != OBJ_COMMIT) goto done; + read_tree(the_repository, repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)), &paths, walk_tree, &walk_tree_ctx); @@ -91,18 +100,28 @@ int cgit_print_file(char *path, const char *head, int file_only) if (repo_get_oid(the_repository, head, &oid)) return -1; - type = oid_object_info(the_repository, &oid, &size); + + struct object_info oi = { + .typep = &type, + .sizep = &size + }; + + if (odb_read_object_info_extended(the_repository->objects, &oid, + &oi, OBJECT_INFO_LOOKUP_REPLACE) < 0) return -1; + if (type == OBJ_COMMIT) { commit = lookup_commit_reference(the_repository, &oid); read_tree(the_repository, repo_get_commit_tree(the_repository, commit), &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; - type = oid_object_info(the_repository, &oid, &size); + + if (odb_read_object_info_extended(the_repository->objects, &oid, + &oi, OBJECT_INFO_LOOKUP_REPLACE) < 0) return -1; } if (type == OBJ_BAD) return -1; - buf = repo_read_object_file(the_repository, &oid, &type, &size); + buf = odb_read_object(the_repository->objects, &oid, &type, &size); if (!buf) return -1; buf[size] = '\0'; @@ -147,13 +166,29 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl } } - type = oid_object_info(the_repository, &oid, &size); + struct object_info oi = { + .typep = &type, + .sizep = &size + }; + + if (odb_read_object_info_extended(the_repository->objects, &oid, + &oi, OBJECT_INFO_LOOKUP_REPLACE) < 0) { + cgit_print_error_page(500, "Internal server error", + "Error reading object %s", hex ? hex : head); + return; + } if ((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(the_repository, &oid); read_tree(the_repository, repo_get_commit_tree(the_repository, commit), &paths, walk_tree, &walk_tree_ctx); - type = oid_object_info(the_repository, &oid, &size); + + if (odb_read_object_info_extended(the_repository->objects, &oid, + &oi, OBJECT_INFO_LOOKUP_REPLACE) < 0) { + cgit_print_error_page(500, "Internal server error", + "Error reading object %s", hex ? hex : head); + return; + } } if (type == OBJ_BAD) { @@ -162,7 +197,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl return; } - buf = repo_read_object_file(the_repository, &oid, &type, &size); + buf = odb_read_object(the_repository->objects, &oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", hex); |
