From: Pablo Sabater <pabloosabaterr@gmail.com>
To: git@vger.kernel.org
Cc: Pablo Sabater <pabloosabaterr@gmail.com>
Subject: [PATCH RFC 1/3] cat-file: extract the transport ownership from get_remote_info()
Date: Tue, 27 Oct 2026 03:16:51 +0000 [thread overview]
Message-ID: <20261027-remote-object-info-batch-v1-1-ea7a1f0b1df1@gmail.com> (raw)
In-Reply-To: <20261027-remote-object-info-batch-v1-0-ea7a1f0b1df1@gmail.com>
get_remote_info() receives the name of the remote and from there it
builds the transport and at the end closes it.
To be able to reuse the connection for multiple batches in a subsequent
commit, it is needed to extract that responsibility from
get_remote_info() and instead have it in its caller,
parse_cmd_remote_object_info(), which will handle the batches.
While at it, rename the transport variable 'gtransport' to 'transport',
as it looks like a global when it's not.
get_remote_info() returns -1 when there are no smart options, or
otherwise the result of transport_fetch_object_info(), and its caller
dies if the result is non-zero. Move the smart options check to its
caller and die directly in get_remote_info() if
transport_fetch_object_info() fails, so get_remote_info() can return
void.
At the same time that the smart options check is moved, give it its own
error message, since "failed to get object info from the remote" used
to cover both that case and a failure while requesting the object info.
Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
builtin/cat-file.c | 61 +++++++++++++++++++++++++-----------------------------
1 file changed, 28 insertions(+), 33 deletions(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 8870a210ec..f7d75a026b 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -680,55 +680,36 @@ static void batch_one_object(const char *obj_name,
object_context_release(&ctx);
}
-static int get_remote_info(int argc,
- const char **argv,
- struct fetch_object_info_results *results,
- struct oid_array *object_info_oids)
+static void get_remote_info(struct transport *transport,
+ const char **objects,
+ size_t nr,
+ struct fetch_object_info_results *results,
+ struct oid_array *object_info_oids)
{
- int retval = 0;
- struct remote *remote = NULL;
struct object_id oid;
- struct transport *gtransport;
-
- remote = remote_get(argv[0]);
- if (!remote)
- die(_("must supply valid remote when using remote-object-info"));
oid_array_clear(object_info_oids);
- for (size_t i = 1; i < argc; i++) {
- if (get_oid_hex(argv[i], &oid)) {
- size_t len = strlen(argv[i]);
+ for (size_t i = 0; i < nr; i++) {
+ if (get_oid_hex(objects[i], &oid)) {
+ size_t len = strlen(objects[i]);
if (len < the_hash_algo->hexsz && len >= 4) {
size_t j;
for (j = 0; j < len; j++)
- if (!isxdigit(argv[i][j]))
+ if (!isxdigit(objects[i][j]))
break;
if (j == len)
die(_("remote-object-info does not support "
"short oids, %d characters required"),
(int)the_hash_algo->hexsz);
}
- die(_("not a valid object name '%s'"), argv[i]);
+ die(_("not a valid object name '%s'"), objects[i]);
}
oid_array_append(object_info_oids, &oid);
}
- if (!object_info_oids->nr)
- die(_("remote-object-info requires objects"));
-
- gtransport = transport_get(remote, NULL);
-
- if (!gtransport->smart_options) {
- retval = -1;
- goto cleanup;
- }
-
- retval = transport_fetch_object_info(gtransport, object_info_oids,
- results);
-cleanup:
- transport_disconnect(gtransport);
- return retval;
+ if (transport_fetch_object_info(transport, object_info_oids, results))
+ die(_("failed to get object info from the remote"));
}
struct object_cb_data {
@@ -824,6 +805,8 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
char *line_to_split;
struct fetch_object_info_results results = FETCH_OBJECT_INFO_RESULTS_INIT;
struct oid_array object_info_oids = OID_ARRAY_INIT;
+ struct transport *transport;
+ struct remote *remote;
if (strlen(line) >= MAX_REMOTE_OBJ_INFO_LINE)
die(_("remote-object-info command too long"));
@@ -837,13 +820,23 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
die(_("remote-object-info supports at most %d objects"),
MAX_ALLOWED_OBJ_LIMIT);
+ if (count < 2)
+ die(_("remote-object-info requires objects"));
+
if (data->info.sizep)
results.wants_size = 1;
if (data->info.typep)
results.wants_type = 1;
- if (get_remote_info(count, argv, &results, &object_info_oids))
- die(_("failed to get object info from the remote: %s"), argv[0]);
+ remote = remote_get(argv[0]);
+ if (!remote)
+ die(_("must supply valid remote when using remote-object-info"));
+
+ transport = transport_get(remote, NULL);
+
+ if (!transport->smart_options)
+ die(_("smart options required"));
+ get_remote_info(transport, argv + 1, count - 1, &results, &object_info_oids);
string_list_clear(&data->remote_allowed_atoms, 0);
string_list_append(&data->remote_allowed_atoms, "objectname");
@@ -852,6 +845,8 @@ static void parse_cmd_remote_object_info(struct batch_options *opt,
if (results.types)
string_list_append(&data->remote_allowed_atoms, "objecttype");
+ transport_disconnect(transport);
+
data->skip_object_info = 1;
for (size_t i = 0; i < results.nr; i++) {
data->oid = object_info_oids.oid[i];
--
2.56.0
next prev parent reply other threads:[~2026-10-27 3:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 3:16 [PATCH RFC 0/3] cat-file: make remote-object-info request in batches Pablo Sabater
2026-10-27 3:16 ` Pablo Sabater [this message]
2026-10-27 19:02 ` [PATCH RFC 1/3] cat-file: extract the transport ownership from get_remote_info() Junio C Hamano
2026-10-27 21:00 ` Pablo Sabater
2026-10-28 6:37 ` Junio C Hamano
2026-10-28 12:07 ` Pablo Sabater
2026-10-28 13:42 ` Junio C Hamano
2026-10-27 3:16 ` [PATCH RFC 2/3] cat-file: make remote-object-info request in batches Pablo Sabater
2026-10-27 3:16 ` [PATCH RFC 3/3] cat-file: add --remote-max-batch option Pablo Sabater
2026-10-27 19:12 ` [PATCH RFC 0/3] cat-file: make remote-object-info request in batches Junio C Hamano
2026-10-27 20:47 ` Pablo Sabater
2026-10-27 20:53 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261027-remote-object-info-batch-v1-1-ea7a1f0b1df1@gmail.com \
--to=pabloosabaterr@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox