From 37fafee9cae576add2371bdcc9fd0f5b5fba5f65 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 05 Apr 2025 11:20:54 +0800 Subject: [PATCH] git2d: Add some descriptive comments --- git2d/session.c | 10 +++++----- diff --git a/git2d/session.c b/git2d/session.c index 8cfe8fc0fa6553c4bb5c8c8b374ac4be464c87df..9628a8c5478c17a0aa462812be32c2dbd0284321 100644 --- a/git2d/session.c +++ b/git2d/session.c @@ -12,7 +12,6 @@ int conn = *(int *)_conn; free((int *)_conn); int err; - git_repository *repo = NULL; char path[4096] = {0}; conn_io_t io = {.fd = conn }; @@ -25,18 +24,22 @@ .buffer = &io, .write = conn_write, }; + /* Repo path */ err = bare_get_data(&reader, (uint8_t *) path, sizeof(path) - 1); if (err != BARE_ERROR_NONE) { goto close; } path[sizeof(path) - 1] = '\0'; + /* Open repo */ + git_repository *repo = NULL; err = git_repository_open_ext(&repo, path, GIT_REPOSITORY_OPEN_NO_SEARCH | GIT_REPOSITORY_OPEN_BARE | GIT_REPOSITORY_OPEN_NO_DOTGIT, NULL); if (err != 0) { bare_put_uint(&writer, 1); goto close; } + /* Command */ uint64_t cmd = 0; err = bare_get_uint(&reader, &cmd); if (err != BARE_ERROR_NONE) { @@ -54,6 +57,7 @@ bare_put_uint(&writer, 3); goto free_repo; } + /* HEAD tree */ git_object *obj = NULL; err = git_revparse_single(&obj, repo, "HEAD^{tree}"); if (err != 0) { @@ -70,27 +74,23 @@ if (err != 0) { bare_put_uint(&writer, 5); goto free_tree; } - git_otype objtype = git_tree_entry_type(entry); if (objtype != GIT_OBJECT_BLOB) { bare_put_uint(&writer, 6); goto free_tree_entry; } - git_object *obj2 = NULL; err = git_tree_entry_to_object(&obj2, repo, entry); if (err != 0) { bare_put_uint(&writer, 7); goto free_tree_entry; } - git_blob *blob = (git_blob *) obj2; const void *content = git_blob_rawcontent(blob); if (content == NULL) { bare_put_uint(&writer, 8); goto free_blob; } - bare_put_uint(&writer, 0); bare_put_data(&writer, content, git_blob_rawsize(blob)); -- 2.48.1