From patchwork Mon Dec 23 23:25:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Ju X-Patchwork-Id: 13919549 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E5D818A6D7 for ; Mon, 23 Dec 2024 23:25:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996356; cv=none; b=LHSItQmpXghSfc6PWH7Wh0+iOcrF4iUJJi4aVu/ql3QTaRJH51oXafpUQPHYcK62uANmt1hXD3b+JOZ2L5sdZIFCeGrxQzTMkDwpfqmEWTswEwcT8GzSGw96RibwX8kfI3Wb90YKjbCZzVVEdNJ6vtaPwcBJqOYCTWxVzX3O33s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996356; c=relaxed/simple; bh=AR70hk6E4F2585AB9FuGf+LbJawpKuTJfk18XHW+5F4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bcMFA/PNLhXH3l6VO2mqSq7zMpEyexSit45gnU4okqob0EVGNG5nqPLg1uo74vrqOvtbDGShr0YQGbJKRJeqj4FH9LBzyc41b90jFWRBb+5l2Cv+3v/ux7Via5M0XGs0ogg+zQgOTDavM1gO153IQ5eoqn2E6DMHnoxP3ua95Nw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PRpK3GeY; arc=none smtp.client-ip=209.85.219.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PRpK3GeY" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6dd1962a75bso33150936d6.3 for ; Mon, 23 Dec 2024 15:25:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734996354; x=1735601154; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ED23Y9czMSb7AGSbbsyvcfCTTC2OzgzdUsan54CKZYQ=; b=PRpK3GeYDmL+EdWAHwBBRGqGWN3sNrjBbO0vCWTh2I7JCMIJqXRfRTW810vp6JbVDt MIFJB6QahKQcYuNQowoXMF+pyQma3iDAXe/enaMQiFwQQz5ybs+a0nyqo8zD/ah4AXYm fxxzWhvpFwpJBeD7pBZrsafwjisDm+mLpDT4+HBcwirPR6v07Br5CHs7A948h45mXLlJ WyZX6mJOdY7eMxrvhMiD7Qxm05qPIdP0sFH/OvVveHZSn1dBUxQbegczSesQ5QkDdjvd CMeObKJ1H23eScHAM8Ec12MlbvGaRh5Th2jJyLnzGTUqhu3fEL5qV1II0Y5u/ZtSZybS DOmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734996354; x=1735601154; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ED23Y9czMSb7AGSbbsyvcfCTTC2OzgzdUsan54CKZYQ=; b=xGrtFhxqNJ+UImL0PZtYfpK+KAvsvt64gv1hLXgaD4r87wXXrD+de1v6VyEjkiEltT Hozl+H5nxeSz9dHHAOj+t/tbImWjOb7gfnW+BBwm7T+tewbiywBXNex2EOmNFnfwXS5t kcV8CHJprZXN9U/Gha4ZCYEdUizZQm2dEmWFEza0Fd5hvodd8pmjBwuldFUbpTp6tY7T R582fz5q4wG6/0J3uq6sLy3fJRTdl8A4gXL+ofUwqrGNbeTeLjVjutjtwlK0Ln3gVknn V9VaETwjpeTU/UUJEP4cobr7aDQzeKT73VieVsQ0g1Di4FSXmGZO2rCRMVvK6imd4Chs JeJw== X-Gm-Message-State: AOJu0YwqZmUv+fEdYOsrm0OpkbaFxY1pl5Rb8Y9HsAyg+206G4vyHjEY dfKvoBOx4Ekv7cBrOfnLpScJIK17A65V38UB8RdelnZIwCw+KoOlgGWBE41Z X-Gm-Gg: ASbGncslYzrxWeV9cRQEgRSD9PiiDqdPKBxGbE3rM7918+cmQAYaIrtcNMUNDnvYl4E VE4O7XhoSoPbdrcdyowxYl8Q76paXUBxZmtSHXZeZPTQiHqMfL61kcQQTGbtKPUnpkPpppa0Ggj g6B6IXWN3Cq86csNiXK4sJj3gSozGrrHLHpqJ+1t9NRVclPAokirD/hfiUtx5dAK214XU9IKnQa idvKdkWZFtM07NXW5kKquqP/1djaGkhvkzO0+TcgZnxMBRlX1ND71WZwvzh612qkWSj4m60U9lA s7+VB9LEqcbr+XqHWnoW+2CqpesWBRLM/f6cfBLRXyqhiIC0g5THTBViPY6tiA== X-Google-Smtp-Source: AGHT+IEmZdzjbBSl9FnFARcp25pWWkGIumeaZ7sofS8QLpC0RWQ7VRTznhNjO2rtsdgXcBkzfDJfgQ== X-Received: by 2002:a05:6214:1d26:b0:6d4:b1e:541b with SMTP id 6a1803df08f44-6dd23355afdmr217932226d6.21.1734996353984; Mon, 23 Dec 2024 15:25:53 -0800 (PST) Received: from localhost.localdomain (pool-174-118-208-220.cpe.net.cable.rogers.com. [174.118.208.220]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd18136e56sm47672496d6.61.2024.12.23.15.25.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 15:25:53 -0800 (PST) From: Eric Ju To: git@vger.kernel.org Cc: calvinwan@google.com, jonathantanmy@google.com, chriscool@tuxfamily.org, eric.peijian@gmail.com, karthik.188@gmail.com, toon@iotcl.com, jltobler@gmail.com Subject: [PATCH v8 1/6] cat-file: add declaration of variable i inside its for loop Date: Mon, 23 Dec 2024 19:25:18 -0400 Message-ID: <20241223232523.76236-2-eric.peijian@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241223232523.76236-1-eric.peijian@gmail.com> References: <20240628190503.67389-1-eric.peijian@gmail.com> <20241223232523.76236-1-eric.peijian@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some code used in this series declares variable i and only uses it in a for loop, not in any other logic outside the loop. Change the declaration of i to be inside the for loop for readability. Helped-by: Christian Couder Signed-off-by: Eric Ju --- builtin/cat-file.c | 11 +++-------- fetch-pack.c | 3 +-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index b13561cf73..69ea642dc6 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -676,12 +676,10 @@ static void dispatch_calls(struct batch_options *opt, struct queued_cmd *cmd, int nr) { - int i; - if (!opt->buffer_output) die(_("flush is only for --buffer mode")); - for (i = 0; i < nr; i++) + for (size_t i = 0; i < nr; i++) cmd[i].fn(opt, cmd[i].line, output, data); fflush(stdout); @@ -689,9 +687,7 @@ static void dispatch_calls(struct batch_options *opt, static void free_cmds(struct queued_cmd *cmd, size_t *nr) { - size_t i; - - for (i = 0; i < *nr; i++) + for (size_t i = 0; i < *nr; i++) FREE_AND_NULL(cmd[i].line); *nr = 0; @@ -717,7 +713,6 @@ static void batch_objects_command(struct batch_options *opt, size_t alloc = 0, nr = 0; while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) { - int i; const struct parse_cmd *cmd = NULL; const char *p = NULL, *cmd_end; struct queued_cmd call = {0}; @@ -727,7 +722,7 @@ static void batch_objects_command(struct batch_options *opt, if (isspace(*input.buf)) die(_("whitespace before command: '%s'"), input.buf); - for (i = 0; i < ARRAY_SIZE(commands); i++) { + for (size_t i = 0; i < ARRAY_SIZE(commands); i++) { if (!skip_prefix(input.buf, commands[i].name, &cmd_end)) continue; diff --git a/fetch-pack.c b/fetch-pack.c index 3a227721ed..72c6a254c9 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1329,9 +1329,8 @@ static void write_fetch_command_and_capabilities(struct strbuf *req_buf, if (advertise_sid && server_supports_v2("session-id")) packet_buf_write(req_buf, "session-id=%s", trace2_session_id()); if (server_options && server_options->nr) { - int i; ensure_server_supports_v2("server-option"); - for (i = 0; i < server_options->nr; i++) + for (int i = 0; i < server_options->nr; i++) packet_buf_write(req_buf, "server-option=%s", server_options->items[i].string); } From patchwork Mon Dec 23 23:25:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Ju X-Patchwork-Id: 13919551 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77B0C1C5F1C for ; Mon, 23 Dec 2024 23:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996358; cv=none; b=ON6TTmT6IlqUN1M2wQ8eEKQmz9Nw0geyBeTvSmHyTcN/gSJMqvVtyiGr9tjfD3aCa1tWrJwXw9ubpIiqqTaqFWU9rQEPKz+NvliD38l0yI50UzXfKQVZHdH1sziBMqJR9HyXPgu29YomezEH2EHd/QXdRqzX/4V+L4BkjsUn6kA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996358; c=relaxed/simple; bh=xEIfI0WgMzR2ex+pWILzX9i5HvbAokYZOntVeDOPzbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZBSQjIiPCRleM4bQmatbHY0KG+ceZlNfbQLtAsNaqEzZIkZ/papFVID0tAOV2+bxT9T9wJ3oXKCXZFRVTK+w+GVbECrnPfffxn/C9I4vkSfrdIyMZm+uOcZ+KViqyMEtuwa8dMleYvIS5+oQkbMG7mAizOEAYUGsNwZev7Hp97M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ih+RvY16; arc=none smtp.client-ip=209.85.219.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ih+RvY16" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6d888fc8300so21955696d6.3 for ; Mon, 23 Dec 2024 15:25:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734996355; x=1735601155; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3uvAssubBOmPx78nm4+Rh9dueCvU0Liv8u+rH9R5LLI=; b=ih+RvY16pMdvvNsANZYo9RoPmWFiq2T0xIEJf/5zWK7r93cd+KYn03bpsrMx5E+WJt wduuEzApdy5sgcUNB8aFXgs6IABxaxawy45zvJiujARPA1jIby3gBn1ticinaafgVt+o OnqrOG2cw1KAyKO5n6HaOioNeNy8ldJjG0bOaUnUAKWzHVTLsRM8N33hDB8a+JZ89A7A KkzdVtYHvucDtvWjAaYOptRgUiCUbpKOsG7u8WxZCTVgNBj94Ng/aJlCrdjqFx/bW4M6 jXxlWEYWOUIX3zofCsHi3L5p+doWLru20foUb/JtK3BmXOrrJQkoVfeJ0Br6meaQp4GQ DZ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734996355; x=1735601155; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3uvAssubBOmPx78nm4+Rh9dueCvU0Liv8u+rH9R5LLI=; b=KBS5W6DYbb92c24Sai4hppID1xxflz7L/qX3c2v4YilskRe/AmUouQCnGrg3Q1r26D zNPljUVbVlz9TRRaVswdfmy/ejpoz1cQCKSk3wgZ85djOQY0eocb96//Rdl/xXSv8fTm yLO7+/Lrd6BLwKCA4SJsaaxWZTCfkumeEMXbjnTnMF+XYbTXRd4NpoFyYu8zt8VxIbta rSUavZxvzu27P70l3fXB6VWPDAGGHDuOOcgnWRjgVHq/qpGrrc5KgrTicbGiJ+9QoI1n +DnhzjzYFkO08Y1vmWjXa3qFDf9rIVl0p47foDrXf6GQ+q8gKleubrBA1MmHGH9MQutu PaLQ== X-Gm-Message-State: AOJu0YwUEsfDPBB3036hytRJNXG0xcfYTRFzx/InQxFex/RWv+CXS7Kl x8rTiHP89qJeIwYN8sBIMywGyJfqghGZRfI//2/1vuCLjc2EXAoJwm2jOUQ4 X-Gm-Gg: ASbGncvnYbBBphHV8Pq0pxaKUcUjZpnDCUf6CsExp+B9nSrqoF+rzvESU3ncYeFO2TE OzCIjVHvx3/zW4qL4KLWKm9gr+tEmGCpckHCq6hN7WDT+BvbxMEGBn4idSIzxgoxyHz2Td7cy33 XhPuknp2TEugS+Mt6d6i4VSxCvCkBMmO6JWYoheGdShfwen4wku/s5BOIF4VU191RctZBewfxSQ HajtK19O2FhbfE1wcc4i7O/N7OzPowCqdLKkKrN7126rEHvQlKqwXLw/yR9mgD1CBRtPIZ1OgTj 7A5ktMYki3PcOcFMkRJTko1FWvCylWfD8HtQ+uDQH7Kq0voUGq/Q2+ghLAvA1Q== X-Google-Smtp-Source: AGHT+IEc4OXLr+t5p6RTpRkKLoggadErBSxJEhc2YF0+YmrhDXlyCDd1gfCnaUVt/3qgPjxvw9gilA== X-Received: by 2002:a05:6214:260b:b0:6d4:2646:108a with SMTP id 6a1803df08f44-6dd23329655mr245699076d6.12.1734996355146; Mon, 23 Dec 2024 15:25:55 -0800 (PST) Received: from localhost.localdomain (pool-174-118-208-220.cpe.net.cable.rogers.com. [174.118.208.220]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd18136e56sm47672496d6.61.2024.12.23.15.25.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 15:25:54 -0800 (PST) From: Eric Ju To: git@vger.kernel.org Cc: calvinwan@google.com, jonathantanmy@google.com, chriscool@tuxfamily.org, eric.peijian@gmail.com, karthik.188@gmail.com, toon@iotcl.com, jltobler@gmail.com Subject: [PATCH v8 2/6] fetch-pack: refactor packet writing Date: Mon, 23 Dec 2024 19:25:19 -0400 Message-ID: <20241223232523.76236-3-eric.peijian@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241223232523.76236-1-eric.peijian@gmail.com> References: <20240628190503.67389-1-eric.peijian@gmail.com> <20241223232523.76236-1-eric.peijian@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Calvin Wan Refactor write_fetch_command_and_capabilities() to a more general-purpose function, write_command_and_capabilities(), enabling it to serve both fetch and additional commands. In this context, "command" refers to the "operations" supported by Git's wire protocol https://git-scm.com/docs/protocol-v2, such as a Git subcommand (e.g., git-fetch(1)) or a server-side operation like "object-info" as implemented in commit a2ba162c (object-info: support for retrieving object info, 2021-04-20). Furthermore, write_command_and_capabilities() is moved to connect.c, making it accessible to additional commands in the future. To move write_command_and_capabilities() to connect.c, we need to adjust how `advertise_sid` is managed. Previously, in fetch_pack.c, `advertise_sid` was a static variable, modified using git_config_get_bool(). In connect.c, we now initialize `advertise_sid` at the beginning by directly using git_config_get_bool(). This change is safe because: In the original fetch-pack.c code, there are only two places that write `advertise_sid` : 1. In function do_fetch_pack: if (!server_supports("session-id")) advertise_sid = 0; 2. In function fetch_pack_config(): git_config_get_bool("transfer.advertisesid", &advertise_sid); About 1, since do_fetch_pack() is only relevant for protocol v1, this assignment can be ignored in our refactor, as write_command_and_capabilities() is only used in protocol v2. About 2, git_config_get_bool() is from config.h and it is an out-of-box dependency of connect.c, so we can reuse it directly. Helped-by: Jonathan Tan Helped-by: Christian Couder Signed-off-by: Calvin Wan Signed-off-by: Eric Ju --- connect.c | 34 ++++++++++++++++++++++++++++++++++ connect.h | 8 ++++++++ fetch-pack.c | 35 ++--------------------------------- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/connect.c b/connect.c index 10fad43e98..2b51cf09bf 100644 --- a/connect.c +++ b/connect.c @@ -689,6 +689,40 @@ int server_supports(const char *feature) return !!server_feature_value(feature, NULL); } +void write_command_and_capabilities(struct strbuf *req_buf, const char *command, + const struct string_list *server_options) +{ + const char *hash_name; + int advertise_sid; + + git_config_get_bool("transfer.advertisesid", &advertise_sid); + + ensure_server_supports_v2(command); + packet_buf_write(req_buf, "command=%s", command); + if (server_supports_v2("agent")) + packet_buf_write(req_buf, "agent=%s", git_user_agent_sanitized()); + if (advertise_sid && server_supports_v2("session-id")) + packet_buf_write(req_buf, "session-id=%s", trace2_session_id()); + if (server_options && server_options->nr) { + ensure_server_supports_v2("server-option"); + for (int i = 0; i < server_options->nr; i++) + packet_buf_write(req_buf, "server-option=%s", + server_options->items[i].string); + } + + if (server_feature_v2("object-format", &hash_name)) { + const int hash_algo = hash_algo_by_name(hash_name); + if (hash_algo_by_ptr(the_hash_algo) != hash_algo) + die(_("mismatched algorithms: client %s; server %s"), + the_hash_algo->name, hash_name); + packet_buf_write(req_buf, "object-format=%s", the_hash_algo->name); + } else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1) { + die(_("the server does not support algorithm '%s'"), + the_hash_algo->name); + } + packet_buf_delim(req_buf); +} + enum protocol { PROTO_LOCAL = 1, PROTO_FILE, diff --git a/connect.h b/connect.h index 1645126c17..8b56a68b62 100644 --- a/connect.h +++ b/connect.h @@ -1,6 +1,7 @@ #ifndef CONNECT_H #define CONNECT_H +#include "string-list.h" #include "protocol.h" #define CONNECT_VERBOSE (1u << 0) @@ -30,4 +31,11 @@ void check_stateless_delimiter(int stateless_rpc, struct packet_reader *reader, const char *error); +/** + * write_command_and_capabilities writes a command along with the requested + * server capabilities/features into a request buffer. + */ +void write_command_and_capabilities(struct strbuf *req_buf, const char *command, + const struct string_list *server_options); + #endif diff --git a/fetch-pack.c b/fetch-pack.c index 72c6a254c9..78e7d38c47 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1317,37 +1317,6 @@ static int add_haves(struct fetch_negotiator *negotiator, return haves_added; } -static void write_fetch_command_and_capabilities(struct strbuf *req_buf, - const struct string_list *server_options) -{ - const char *hash_name; - - ensure_server_supports_v2("fetch"); - packet_buf_write(req_buf, "command=fetch"); - if (server_supports_v2("agent")) - packet_buf_write(req_buf, "agent=%s", git_user_agent_sanitized()); - if (advertise_sid && server_supports_v2("session-id")) - packet_buf_write(req_buf, "session-id=%s", trace2_session_id()); - if (server_options && server_options->nr) { - ensure_server_supports_v2("server-option"); - for (int i = 0; i < server_options->nr; i++) - packet_buf_write(req_buf, "server-option=%s", - server_options->items[i].string); - } - - if (server_feature_v2("object-format", &hash_name)) { - int hash_algo = hash_algo_by_name(hash_name); - if (hash_algo_by_ptr(the_hash_algo) != hash_algo) - die(_("mismatched algorithms: client %s; server %s"), - the_hash_algo->name, hash_name); - packet_buf_write(req_buf, "object-format=%s", the_hash_algo->name); - } else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1) { - die(_("the server does not support algorithm '%s'"), - the_hash_algo->name); - } - packet_buf_delim(req_buf); -} - static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out, struct fetch_pack_args *args, const struct ref *wants, struct oidset *common, @@ -1358,7 +1327,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out, int done_sent = 0; struct strbuf req_buf = STRBUF_INIT; - write_fetch_command_and_capabilities(&req_buf, args->server_options); + write_command_and_capabilities(&req_buf, "fetch", args->server_options); if (args->use_thin_pack) packet_buf_write(&req_buf, "thin-pack"); @@ -2186,7 +2155,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips, the_repository, "%d", negotiation_round); strbuf_reset(&req_buf); - write_fetch_command_and_capabilities(&req_buf, server_options); + write_command_and_capabilities(&req_buf, "fetch", server_options); packet_buf_write(&req_buf, "wait-for-done"); From patchwork Mon Dec 23 23:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Ju X-Patchwork-Id: 13919552 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6698D1D63FB for ; Mon, 23 Dec 2024 23:25:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996359; cv=none; b=GQJzGVAlvhtsRxJfb+OBnqbB1eQkr50J9NGWud01DS18wq9JUUbeqKIVyfu7OAlKG7pl25BF95GNQZL2BDqaLL/wAu+okQm53wP4r+SyD34LxuQzHyHeJdITOHd3kn3atZMFMPbpIHafSuDf3OXZJQfSN5gRfdsPdh98a5Bn/Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996359; c=relaxed/simple; bh=6v6kmj6IoJTTVenBvDN0ySpPKhvA1nmYwnT31qsuLH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XlfR3HnBTabnV4+E1YinVuBJ+kFZzajmBuKbiH+dSkpUxR9YvHomm0BWJ4XMoEMw/09NN0g8sUJX3mC+JyRzgjDs5XbADEijmMlWnl22z7onBJOh5iCsadW6E3AbdqquULi7l80JLxMPUTn7683zQBdmvojSlcD6So5oR4pXYDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QOdPz5G9; arc=none smtp.client-ip=209.85.219.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QOdPz5G9" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6d8e8445219so41098076d6.0 for ; Mon, 23 Dec 2024 15:25:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734996356; x=1735601156; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BuvuFUMBdM9FyTWZ9IdBTNsQLl3Xz4xTvWGs2nwwYrg=; b=QOdPz5G9392EWziu1enROnyht6laBkqzEPYZICEM7Hji2wksMHYG453hMVwIUm0Fcj 60TygY5Yt646OpsEAD7ph2+KoTCBhO9b9lCTMkWjKW+ikSd4VNzrqFRSrkto4ajAoiyJ mXOH3AchA75VWeIemyVoZbnAdnKoG1f31N1yIQw1qMNAxvaaGE9dX+ASzGhiymQbm12P JvnssNNcHTEX5rvgrSjNpp+bBiuaAjhLMgpa/BD0lLj8XrUtQP7jrA3c2EemekuxsUav DWxPZPI0UJPCViUFGbqPTd4tOexaFZ3RSSNSJUY0j4mp2hoIxSLEr3D24gWPsgk1c24X 2kXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734996356; x=1735601156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BuvuFUMBdM9FyTWZ9IdBTNsQLl3Xz4xTvWGs2nwwYrg=; b=UeFiKX5BCr2I/gvUyCwBl3zLqXfkNSP6UC3sOCY7xZ/v7p9fbKxdZICjWpOS3EbCY8 1VoPgQaheOOuSq/wLR+MqaqTSxzpBd2/wGiaZWRFG6X2ziqM1Y8hyroDFf8egZm4BXQ7 4HXF0XYUxheE+Rq0zVDfn0JzrnAno42+rkTqDLYaeuJ+mHnhqvxaiIPIegtj3NKIwJr8 v+EMJUwNudsAQD9kn5Ip7mrIiWnWT2TO8jbtXXCHn/93chuwiYS9eMj8qkyft2RGNfmW ALglqqil5kl/q6Ofc5wBk2vu9BCuxabcSBJ8blb3UKHVQFoSvpm1n8wvHOHq6FSQMnLh kO5w== X-Gm-Message-State: AOJu0YweA5ZDo6iOrMyMRwbvz9CZljgCyA9DYqCoYWM5V6u5exT8J9lh 1CC4aj5cdgfeyls84AtAGRIpVA1xVyAlcrx6wQjJrs3p3xzCcKxgffBr7G+y X-Gm-Gg: ASbGncs6Wo4vAmgKn9ZyGQkY1o8LkBA4hj571wIrmL36Jg8+dkCTxvVHC+9GZzcQoBs qrxakpiFvpT38HJuyY2GMH64b4+SUbkAS5yD7Ob6c1KQcDj2zME2j59QWlLSM6QemHVOcyJsXJO x6WXIkAZKJr3Nm92WJ1adDUpyXEWOUbGddrVeWCJWy4Tq6t14hup4CFQAZupC3v1f7MeXhxajBw nuwCBR20nCZPbZf+ARfmFvujVW1fwa5A8t3tgCCeOau/NPeFinGCrqD4AeAPwi9XJNzdEnyJkvM NtsJOugKPoHu127hlShULQET8BZVY8NALDQuRFTFxwaxY+nzQdTLudOBkRwgSw== X-Google-Smtp-Source: AGHT+IFPu9iih5JmnqzLHbRXmm1otgmj4KYZ68hqJ7G4I2DFfl7pkqEri6c8uuITsuKHy3RgHdXsPw== X-Received: by 2002:a05:6214:483:b0:6d8:86c8:c2a9 with SMTP id 6a1803df08f44-6dd233acb55mr226325446d6.31.1734996356203; Mon, 23 Dec 2024 15:25:56 -0800 (PST) Received: from localhost.localdomain (pool-174-118-208-220.cpe.net.cable.rogers.com. [174.118.208.220]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd18136e56sm47672496d6.61.2024.12.23.15.25.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 15:25:55 -0800 (PST) From: Eric Ju To: git@vger.kernel.org Cc: calvinwan@google.com, jonathantanmy@google.com, chriscool@tuxfamily.org, eric.peijian@gmail.com, karthik.188@gmail.com, toon@iotcl.com, jltobler@gmail.com Subject: [PATCH v8 3/6] fetch-pack: move fetch initialization Date: Mon, 23 Dec 2024 19:25:20 -0400 Message-ID: <20241223232523.76236-4-eric.peijian@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241223232523.76236-1-eric.peijian@gmail.com> References: <20240628190503.67389-1-eric.peijian@gmail.com> <20241223232523.76236-1-eric.peijian@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Calvin Wan There are some variables initialized at the start of the do_fetch_pack_v2() state machine. Currently, they are initialized in FETCH_CHECK_LOCAL, which is the initial state set at the beginning of the function. However, a subsequent patch will allow for another initial state, while still requiring these initialized variables. Move the initialization to be before the state machine, so that they are set regardless of the initial state. Note that there is no change in behavior, because we're moving code from the beginning of the first state to just before the execution of the state machine. Helped-by: Jonathan Tan Helped-by: Christian Couder Signed-off-by: Calvin Wan Signed-off-by: Eric Ju --- fetch-pack.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index 78e7d38c47..51de82e414 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1648,18 +1648,18 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, reader.me = "fetch-pack"; } + /* v2 supports these by default */ + allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1; + use_sideband = 2; + if (args->depth > 0 || args->deepen_since || args->deepen_not) + args->deepen = 1; + while (state != FETCH_DONE) { switch (state) { case FETCH_CHECK_LOCAL: sort_ref_list(&ref, ref_compare_name); QSORT(sought, nr_sought, cmp_ref_by_name); - /* v2 supports these by default */ - allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1; - use_sideband = 2; - if (args->depth > 0 || args->deepen_since || args->deepen_not) - args->deepen = 1; - /* Filter 'ref' by 'sought' and those that aren't local */ mark_complete_and_common_ref(negotiator, args, &ref); filter_refs(args, &ref, sought, nr_sought); From patchwork Mon Dec 23 23:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Ju X-Patchwork-Id: 13919553 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74C521D7E46 for ; Mon, 23 Dec 2024 23:25:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996360; cv=none; b=GPA6qV0MeJ0uT1KePbTUJIvmKIpiLeOoSk9LtPngx8DmK1PtpnTvN+oEW0gsPkUGcSc12A2FUyqBtrCc6nNzhQBPQI0ZMn7azxq+ZGmMTLhAwYQ9rEZuVArqjE8dXtiU8NX+jvo/5PYIB/IIA9L+zsr/+VOPiI0jHjB+kDnRdrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996360; c=relaxed/simple; bh=DgBA291+j6ejZVIrtQoPG7txaLVr23L8sLBk2ll5bUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XZd+VvOORycfAW1O+5o21PXkv6JKzRk02T/8aKz9cvn2NomWLpyBgNnMbxJuesTJLRkTcT+oLGgUuusYmaCe92W4xjBbmLFZpVuGTfAgsm+tTC/4i9sigJX92pBRGVj8LKn2lNshvVATjXlOUZGAzLm3xkI2LGoIb6BKMCMEATQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VjHA53MO; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VjHA53MO" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6d92cd1e811so49901066d6.1 for ; Mon, 23 Dec 2024 15:25:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734996357; x=1735601157; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nq2fqDypuUUjO63eoWLT+d8CeGIKnq0xPOyYXXa21L0=; b=VjHA53MOTfx6rr1jjiHBS6ecqs+OE7+y5TkyiFdmrd85ltrbooKLA9VxDVGVFG4Jby MSy5X3alxwGrXPgbtWBqiDoW5HtW9bmszGSfZw/Va6JJEgf8a0giuNBSS0pBtBueKhvd i/pSmMdEMRR5L4WpGpjZ4uONasr5ddFX+Vge9SEUFk7Lk/4LlUZinALzoecsF3TjLX2H 8IjPk3A868BpXIWrBRF0u4rLYS3JgSeoRn3J2axn6M5OHO3GUXAojQ6WYOqYodJzPv3m qG47+4CoxA6sn09Ln/BqSWB8ZgeDdIusAKgxroyNjCdYlCanH0Std8o7ccH85wQdAfTS wyrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734996357; x=1735601157; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nq2fqDypuUUjO63eoWLT+d8CeGIKnq0xPOyYXXa21L0=; b=sOXMjD4Dei3LUhbxcdmHcxJVyTk2dvCaBUZ2H1a+A/4GquxDA6RI2S7aEUnqeiOQuL q6WK2A3LWiwhOdTs2Ymx0VHsBvryM8+j4Gcrt7L/03UKbrwWWf5oGczxMRm8I67vbmdB 4k89l+CyS8mVCnXI3qF0irWaqObPP3HmeUyt40khfb2f9dpzsmeqXLqCpf5+0aAYl+5L gMt1Vz28m2VAYDM8B8qy4UEsOdHEZAbvciUtrQoTRa8CP6IvJUEbaxNRqLoSuXCqxHq5 HPYwR6jSule8fZIDDQRVecxuGKLfZtNT+rO0zLkMxYaqqfzi8TONhCSCDvZ56dWH8O8L By0Q== X-Gm-Message-State: AOJu0Yyqu39Vnb+RIugeMEAU1LbDb+KD1ps6fMeMzRxyFY0indAarVIg if24Ac6sNZHE0rVCOV7xfs1+hhEtQaDnxKhjhc6iNF7ISVenwplLzy2HW/3x X-Gm-Gg: ASbGncvPlnymDLVaedRCwARZYe8r7d6x5RJONMG6JLAdf77wr9fO5BLU5hRWhhJE7wH ZjeuCc2mZ6IDzTscwFpPKyMpPfT+aHN4mxlUyD7wR6i/aHcAIXwGC6tCLbqnMVf0XDFAIaVlDuw 2eEOM4k4mR3fsbBSR2eM2ntieDbLHM3TqjLenFxSkqp3t+5IatwhE10I4IP8ZJGPdOmz37I3nVj 3s0ieqUVSfChd/56UWHH8qEm85QdiI2g4b1MrN8yADMLLs3pd7Kt9LUY0fWZMN9RT4SQT7N3u/g C3mDgZoL4uzvR2wZeU3rvFNuGUDRwuNVmfKLZcm6Nt2Ru5q7UI3QZ3R+TV9eoQ== X-Google-Smtp-Source: AGHT+IFWohacmVW/GJYDMZVOwfUM3TQzVAShPHFQPRRiy/643DngpMEzSB7Eh2XMYn0vmq9VV7FFAA== X-Received: by 2002:a05:6214:124d:b0:6d8:ad28:adce with SMTP id 6a1803df08f44-6dd2360e147mr252751866d6.15.1734996357335; Mon, 23 Dec 2024 15:25:57 -0800 (PST) Received: from localhost.localdomain (pool-174-118-208-220.cpe.net.cable.rogers.com. [174.118.208.220]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd18136e56sm47672496d6.61.2024.12.23.15.25.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 15:25:57 -0800 (PST) From: Eric Ju To: git@vger.kernel.org Cc: calvinwan@google.com, jonathantanmy@google.com, chriscool@tuxfamily.org, eric.peijian@gmail.com, karthik.188@gmail.com, toon@iotcl.com, jltobler@gmail.com Subject: [PATCH v8 4/6] serve: advertise object-info feature Date: Mon, 23 Dec 2024 19:25:21 -0400 Message-ID: <20241223232523.76236-5-eric.peijian@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241223232523.76236-1-eric.peijian@gmail.com> References: <20240628190503.67389-1-eric.peijian@gmail.com> <20241223232523.76236-1-eric.peijian@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Calvin Wan In order for a client to know what object-info components a server can provide, advertise supported object-info features. This will allow a client to decide whether to query the server for object-info or fetch as a fallback. Helped-by: Jonathan Tan Helped-by: Christian Couder Signed-off-by: Calvin Wan Signed-off-by: Eric Ju --- serve.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/serve.c b/serve.c index c8694e3751..7a388d26d9 100644 --- a/serve.c +++ b/serve.c @@ -70,7 +70,7 @@ static void session_id_receive(struct repository *r UNUSED, trace2_data_string("transfer", NULL, "client-sid", client_sid); } -static int object_info_advertise(struct repository *r, struct strbuf *value UNUSED) +static int object_info_advertise(struct repository *r, struct strbuf *value) { if (advertise_object_info == -1 && repo_config_get_bool(r, "transfer.advertiseobjectinfo", @@ -78,6 +78,8 @@ static int object_info_advertise(struct repository *r, struct strbuf *value UNUS /* disabled by default */ advertise_object_info = 0; } + if (value && advertise_object_info) + strbuf_addstr(value, "size"); return advertise_object_info; } From patchwork Mon Dec 23 23:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Ju X-Patchwork-Id: 13919554 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 942AE1D86FF for ; Mon, 23 Dec 2024 23:25:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996361; cv=none; b=NZbTZRVsNlJFXXVIbsARqjJid+CWTb73UJWL9c/eGjBUIDW5t+Qyj0Om/wWFApzw8MvamHJ2WCOpuzX1Swb4a0Z8NHq8caGK3eYuHzONZILIaOSiJS9MSI5pjDrpKN/57QKkYwYWDbKamaUDP9wLvaVkR1up+Hu9+IeaIlu1zi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996361; c=relaxed/simple; bh=V0O3TlwXXxuB8jbR7uQ59jfqgrijH82uwKFFfW/OTUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BCeVuIPfnng4pp6YxbMBMCcukpwLVBEjgG+PXm3asSX27oUCxVzQtyawlocTC9jNOinrivQy6AZ8HxCZVBGjuUYsFIWwM/r6ZDcC8F7QfGzY2y8gMnD1GR3LEQJK/pukyZrrlrE4tEzf35TFaNS0jLEo+17nCKLsWSWJ4Mg3+ig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kGCpH3jo; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kGCpH3jo" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6dd01781b56so53417776d6.0 for ; Mon, 23 Dec 2024 15:25:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734996358; x=1735601158; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dGRwggJzHd9q46lyNDrzh8IJklhpuIWqfiSitHBTdnE=; b=kGCpH3jo69Qs89r/9VOIw71Eus7BqsOfRECPRe2tLYFgymU3HRL9YK8Wo4K7DGoAII vPkFshkdN3foUeclMuXXFQ2nJUxA/dHSm6w2t69GJ8I2+6T6nxR5AUEACs+wuXtxSgH5 RpFMorH7oSB5MVnFERvHFb3gNwruOroiRTQ4rOkaJW20UgSjg0H0eOrcwD2uDRQBFEXA UgQwJqtjhhU40QyrGK2bbFvrWZjOEs1hKh05HrJjYo/8/uuZEJC6TTgIKUFtMxKW6tlW 2kM9UIlQxJQudH+itbvZJUbCxQTriQcuhBU9QqV7dVR4b3/VadJQF5KrJWu0MlbtOb4O wtMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734996358; x=1735601158; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dGRwggJzHd9q46lyNDrzh8IJklhpuIWqfiSitHBTdnE=; b=juNlbRp5Tt7xmDDal3R+M2hjr2PJXi4LgH3079XbsLAnYP+b9mI7G02laf9O28z03L SQZC1QwrMJ9MQ5HYm36zNYE6EMc/t3w3z2YceeKVHXxSDcayS72l7JG4b8PX4OHeD9E4 5nzwk81b140lSGmcBbocvobGr9r/e7lXSA7K61493aH0jIyX4MsH52/U5Dc/3PuXGJmF iYZaaCHt3bIqsw/JtPJHcgido93X9fQ55fuU4Kppb4XxxmKU3c6v3eMfitMoSyAoj4iz 4JffXAOMzRjgWVNJ64y00DXu1/uOZb6djeWbTdBhIm/4BGfS3ZMNic9uritJ7rHgXSuh H44Q== X-Gm-Message-State: AOJu0Yw8nlkg33Tot7t0OENUlKVTI9E98T4uqRzgzQYK/zun4oHLvnY9 0sFfWVtNhpm5V2DDCJUDrHqenBhaowxsirGPbuahO6P6ligxKGQUUniq2Q7P X-Gm-Gg: ASbGncsJTG7De3qmihbITRBmRNRcaDFDTLdXKojxw5pzA6Of4oEqkqxe2MXrDlLxQQu kW2/WOTsKJkCZDzvABqHmQyulnilHCcL5VLemNUwJ7K7X9qTURzuBlCYElfP39wH0kHN/IzfOi/ KP0BUeLjR1cLbgBcoM7i/9SzE+CQwoqu9i5H+TGkV/jvl7tcvvfNvP8NWl7jYd+aTEGQad98w0g /WFPwKPf9z8RYPU9m1M2Hi5oqmLBctYES+xhjeaG2tyQw3DXNABz/yN6/8lJ3m4eceacldNj5oo vg5y/Z95euUos/ucbRvqburKyUH4IM4yNyL+BsPrFe9T1TsdqWIJ8h/3UxLBgg== X-Google-Smtp-Source: AGHT+IHH2sjg8rGyeQQpkrch8wQvmb5+6c//CXsYEFKAqUaUmsAwADi1TTHbVN9kuzrqDFbU+gS3Ig== X-Received: by 2002:a05:6214:48c:b0:6d8:7ed4:336c with SMTP id 6a1803df08f44-6dd2332ed1bmr283210816d6.9.1734996358370; Mon, 23 Dec 2024 15:25:58 -0800 (PST) Received: from localhost.localdomain (pool-174-118-208-220.cpe.net.cable.rogers.com. [174.118.208.220]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd18136e56sm47672496d6.61.2024.12.23.15.25.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 15:25:58 -0800 (PST) From: Eric Ju To: git@vger.kernel.org Cc: calvinwan@google.com, jonathantanmy@google.com, chriscool@tuxfamily.org, eric.peijian@gmail.com, karthik.188@gmail.com, toon@iotcl.com, jltobler@gmail.com Subject: [PATCH v8 5/6] transport: add client support for object-info Date: Mon, 23 Dec 2024 19:25:22 -0400 Message-ID: <20241223232523.76236-6-eric.peijian@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241223232523.76236-1-eric.peijian@gmail.com> References: <20240628190503.67389-1-eric.peijian@gmail.com> <20241223232523.76236-1-eric.peijian@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Calvin Wan Sometimes, it is beneficial to retrieve information about an object without downloading it entirely. The server-side logic for this functionality was implemented in commit "a2ba162cda (object-info: support for retrieving object info, 2021-04-20)." This commit introduces client functions to interact with the server. Currently, the client supports requesting a list of object IDs with the ‘size’ feature from a v2 server. If the server does not advertise this feature (i.e., transfer.advertiseobjectinfo is set to false), the client will return an error and exit. Helped-by: Jonathan Tan Helped-by: Christian Couder Signed-off-by: Calvin Wan Signed-off-by: Eric Ju --- Makefile | 1 + fetch-object-info.c | 92 +++++++++++++++++++++++++++++++++++++++++++++ fetch-object-info.h | 18 +++++++++ fetch-pack.c | 3 ++ fetch-pack.h | 2 + transport-helper.c | 11 +++++- transport.c | 28 +++++++++++++- transport.h | 11 ++++++ 8 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 fetch-object-info.c create mode 100644 fetch-object-info.h diff --git a/Makefile b/Makefile index 3fa4bf0d06..70e9ec0464 100644 --- a/Makefile +++ b/Makefile @@ -1020,6 +1020,7 @@ LIB_OBJS += ewah/ewah_rlw.o LIB_OBJS += exec-cmd.o LIB_OBJS += fetch-negotiator.o LIB_OBJS += fetch-pack.o +LIB_OBJS += fetch-object-info.o LIB_OBJS += fmt-merge-msg.o LIB_OBJS += fsck.o LIB_OBJS += fsmonitor.o diff --git a/fetch-object-info.c b/fetch-object-info.c new file mode 100644 index 0000000000..2aa9f2b70d --- /dev/null +++ b/fetch-object-info.c @@ -0,0 +1,92 @@ +#include "git-compat-util.h" +#include "gettext.h" +#include "hex.h" +#include "pkt-line.h" +#include "connect.h" +#include "oid-array.h" +#include "object-store-ll.h" +#include "fetch-object-info.h" +#include "string-list.h" + +/** + * send_object_info_request sends git-cat-file object-info command and its + * arguments into the request buffer. + */ +static void send_object_info_request(const int fd_out, struct object_info_args *args) +{ + struct strbuf req_buf = STRBUF_INIT; + + write_command_and_capabilities(&req_buf, "object-info", args->server_options); + + if (unsorted_string_list_has_string(args->object_info_options, "size")) + packet_buf_write(&req_buf, "size"); + + if (args->oids) { + for (size_t i = 0; i < args->oids->nr; i++) + packet_buf_write(&req_buf, "oid %s", oid_to_hex(&args->oids->oid[i])); + } + + packet_buf_flush(&req_buf); + if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0) + die_errno(_("unable to write request to remote")); + + strbuf_release(&req_buf); +} + +/** + * fetch_object_info sends git-cat-file object-info command into the request buf + * and read the results from packets. + */ +int fetch_object_info(const enum protocol_version version, struct object_info_args *args, + struct packet_reader *reader, struct object_info *object_info_data, + const int stateless_rpc, const int fd_out) +{ + int size_index = -1; + + switch (version) { + case protocol_v2: + if (!server_supports_v2("object-info")) + die(_("object-info capability is not enabled on the server")); + send_object_info_request(fd_out, args); + break; + case protocol_v1: + case protocol_v0: + die(_("wrong protocol version. expected v2")); + case protocol_unknown_version: + BUG("unknown protocol version"); + } + + for (size_t i = 0; i < args->object_info_options->nr; i++) { + if (packet_reader_read(reader) != PACKET_READ_NORMAL) { + check_stateless_delimiter(stateless_rpc, reader, "stateless delimiter expected"); + return -1; + } + if (unsorted_string_list_has_string(args->object_info_options, reader->line)) { + if (!strcmp(reader->line, "size")) { + size_index = i; + for (size_t j = 0; j < args->oids->nr; j++) + object_info_data[j].sizep = xcalloc(1, sizeof(long)); + } + continue; + } + return -1; + } + + for (size_t i = 0; packet_reader_read(reader) == PACKET_READ_NORMAL && i < args->oids->nr; i++){ + struct string_list object_info_values = STRING_LIST_INIT_DUP; + + string_list_split(&object_info_values, reader->line, ' ', -1); + if (0 <= size_index) { + if (!strcmp(object_info_values.items[1 + size_index].string, "")) + die("object-info: not our ref %s", + object_info_values.items[0].string); + + *object_info_data[i].sizep = strtoul(object_info_values.items[1 + size_index].string, NULL, 10); + } + + string_list_clear(&object_info_values, 0); + } + check_stateless_delimiter(stateless_rpc, reader, "stateless delimiter expected"); + + return 0; +} diff --git a/fetch-object-info.h b/fetch-object-info.h new file mode 100644 index 0000000000..ce1a05dc96 --- /dev/null +++ b/fetch-object-info.h @@ -0,0 +1,18 @@ +#ifndef FETCH_OBJECT_INFO_H +#define FETCH_OBJECT_INFO_H + +#include "pkt-line.h" +#include "protocol.h" +#include "object-store-ll.h" + +struct object_info_args { + struct string_list *object_info_options; + const struct string_list *server_options; + struct oid_array *oids; +}; + +int fetch_object_info(enum protocol_version version, struct object_info_args *args, + struct packet_reader *reader, struct object_info *object_info_data, + int stateless_rpc, int fd_out); + +#endif /* FETCH_OBJECT_INFO_H */ diff --git a/fetch-pack.c b/fetch-pack.c index 51de82e414..704bc21b47 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1654,6 +1654,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, if (args->depth > 0 || args->deepen_since || args->deepen_not) args->deepen = 1; + if (args->object_info) + state = FETCH_SEND_REQUEST; + while (state != FETCH_DONE) { switch (state) { case FETCH_CHECK_LOCAL: diff --git a/fetch-pack.h b/fetch-pack.h index 9d3470366f..119d3369f1 100644 --- a/fetch-pack.h +++ b/fetch-pack.h @@ -16,6 +16,7 @@ struct fetch_pack_args { const struct string_list *deepen_not; struct list_objects_filter_options filter_options; const struct string_list *server_options; + struct object_info *object_info_data; /* * If not NULL, during packfile negotiation, fetch-pack will send "have" @@ -42,6 +43,7 @@ struct fetch_pack_args { unsigned reject_shallow_remote:1; unsigned deepen:1; unsigned refetch:1; + unsigned object_info:1; /* * Indicate that the remote of this request is a promisor remote. The diff --git a/transport-helper.c b/transport-helper.c index d457b42550..9da1547b2c 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -710,8 +710,8 @@ static int fetch_refs(struct transport *transport, /* * If we reach here, then the server, the client, and/or the transport - * helper does not support protocol v2. --negotiate-only requires - * protocol v2. + * helper does not support protocol v2. --negotiate-only and cat-file + * remote-object-info require protocol v2. */ if (data->transport_options.acked_commits) { warning(_("--negotiate-only requires protocol v2")); @@ -727,6 +727,13 @@ static int fetch_refs(struct transport *transport, free_refs(dummy); } + /* fail the command explicitly to avoid further commands input. */ + if (transport->smart_options->object_info) + die(_("remote-object-info requires protocol v2")); + + if (!data->get_refs_list_called) + get_refs_list_using_list(transport, 0); + count = 0; for (i = 0; i < nr_heads; i++) if (!(to_fetch[i]->status & REF_STATUS_UPTODATE)) diff --git a/transport.c b/transport.c index 10d820c333..5a2629de52 100644 --- a/transport.c +++ b/transport.c @@ -9,6 +9,7 @@ #include "hook.h" #include "pkt-line.h" #include "fetch-pack.h" +#include "fetch-object-info.h" #include "remote.h" #include "connect.h" #include "send-pack.h" @@ -464,8 +465,33 @@ static int fetch_refs_via_pack(struct transport *transport, args.server_options = transport->server_options; args.negotiation_tips = data->options.negotiation_tips; args.reject_shallow_remote = transport->smart_options->reject_shallow; + args.object_info = transport->smart_options->object_info; + + if (transport->smart_options + && transport->smart_options->object_info + && transport->smart_options->object_info_oids->nr > 0) { + struct packet_reader reader; + struct object_info_args obj_info_args = { 0 }; + + obj_info_args.server_options = transport->server_options; + obj_info_args.object_info_options = transport->smart_options->object_info_options; + obj_info_args.oids = transport->smart_options->object_info_oids; + + connect_setup(transport, 0); + packet_reader_init(&reader, data->fd[0], NULL, 0, + PACKET_READ_CHOMP_NEWLINE | + PACKET_READ_GENTLE_ON_EOF | + PACKET_READ_DIE_ON_ERR_PACKET); + + data->version = discover_version(&reader); + transport->hash_algo = reader.hash_algo; + + ret = fetch_object_info(data->version, &obj_info_args, &reader, + data->options.object_info_data, transport->stateless_rpc, + data->fd[1]); + goto cleanup; - if (!data->finished_handshake) { + } else if (!data->finished_handshake) { int i; int must_list_refs = 0; for (i = 0; i < nr_heads; i++) { diff --git a/transport.h b/transport.h index 44100fa9b7..e61e931863 100644 --- a/transport.h +++ b/transport.h @@ -5,6 +5,7 @@ #include "remote.h" #include "list-objects-filter-options.h" #include "string-list.h" +#include "object-store.h" struct git_transport_options { unsigned thin : 1; @@ -30,6 +31,12 @@ struct git_transport_options { */ unsigned connectivity_checked:1; + /* + * Transport will attempt to retrieve only object-info. + * If object-info is not supported, the operation will error and exit. + */ + unsigned object_info : 1; + int depth; const char *deepen_since; const struct string_list *deepen_not; @@ -53,6 +60,10 @@ struct git_transport_options { * common commits to this oidset instead of fetching any packfiles. */ struct oidset *acked_commits; + + struct oid_array *object_info_oids; + struct object_info *object_info_data; + struct string_list *object_info_options; }; enum transport_family { From patchwork Mon Dec 23 23:25:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Ju X-Patchwork-Id: 13919555 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF2DA1D8A0B for ; Mon, 23 Dec 2024 23:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996363; cv=none; b=fVH2OrsvIw6pRP4YK9ywcwtikSFMMMHhZW3Pxam0ALeKcX3CEMjrhTP1BYyOHISsdeW3XEBy80QXXMAKnLDengDC9JEF0vNFKE2inLkGGgqrf2rVMDS5+FwFFV/CtB7dlHHI9aTKCTixEaPZGsQRcqbFOLzMSQcazOeumhzG9bM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734996363; c=relaxed/simple; bh=5DMvgg/yLdf6XjMzjvn0xc4sjeW1YsmsO/GzxHqOvE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D8iGRJ6VzWLvF/endZkOQtYukG3y/xKBso0iZxVFUg0NuaVFflbC0VtQEYg2C62E3SeJ38ZSHMTdKlvocJqlMQjoJb5EAdDY5bVIsWdh3/Aze+z+J5U/eWMvu7QD2sGesVXvWo+ExWwR0STpFJs5IZ3rFQ/+67nQibGQYIdU4xM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Pe0PjFLN; arc=none smtp.client-ip=209.85.219.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pe0PjFLN" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-6d884e8341bso33715216d6.0 for ; Mon, 23 Dec 2024 15:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734996360; x=1735601160; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+iwR/D/sd1ij1Ipd1T8s+JVk+jqyJQDC5ogNoUdGuNI=; b=Pe0PjFLNi9/r5vnDH7Kd+k7VcoNxaeAwpgJWHtnrl4dvHeBDLO0dIJi5wKKUbeayB5 wSvcNdrgQJOyOnnJ5v+UeN21yopUWETGOjkfZHu6XpRnDPg1EgmkK/LKF4exQK/IJKpZ bIiyaU9iHzONxdUJk/J2kJm/QwZf1tarIbPCC+i+csWosUZfRbOBadcOuj71LJAgACQN /9r1/0ul3xqU/ymu5G2gyMP8FxeDW/R4+kgSleuWHIK5z4NGLugQkm+Jgti5gwrVQoBu 7E2biDdmYkHZrY6ahbb66HY2z1yAGNw3mVj/5wE/dZx3FUebDOLk4mIg00TIBAf76Kzo ezEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734996360; x=1735601160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+iwR/D/sd1ij1Ipd1T8s+JVk+jqyJQDC5ogNoUdGuNI=; b=kOgvsOlixrGCEp06PgCEMHmlJuBW92JmoBiJk0S+0jBWP+sd1GgdLVYxy85I1d92iU tCqEj38ToWZwI5XE5GGRA2tFX576+IVpvUqwRR+N7ft/xjeLl4xQOV1I9UNZDB4XzzP2 B+gDnOV4QNmwLDHJZje7NhKWnWfP7OS/UaBK/D3qJrbnCMX61rGbUOLa368twQeK4+VG ZciKrTUk+Dq1THj2lRowdJ/IgxrGwOo3PTil7FhrRA17TA6H9nw4yk+LyJ5w+S3P+FYd nhuviLfAsMlIvQQOwLrWyoQVb9TXbIYfoUbI2THsrTbrXjABkuAL5FU6LGO99Iai9ysm uuAQ== X-Gm-Message-State: AOJu0YzoGELEc79axelatbnVIM+Dz4ShCdayx6alDwsohtyqT8dCBP9j dUPPVenSNTCxwkq9P0pJNCVuaujMmi1q9Vrj9i1HripQXCr8D9xYzOjnW2Gj X-Gm-Gg: ASbGncsaXSOwWOdVH3S1GqBx3nGXZHlzs+fXDEUhx4qaLtPN+AzlLs4nRJj9SI/Tiks EqVAttPdEeqSKEO0UDYtgm3a7milOQS6ju9AynfB4N/mRSlAmrRUxgWgU30eBTeqq8M/0om5DIE rycB2x7kEa1nIr8njM48HRKQOJwBaNk3/UVlWQJyTl4POK7+0JCyZDkJNcp8smozZxlHyXeuyDL j6BjgxP6tpJEVO4Kl0okR2Fy6H3NlLzOvebCYM5eYXTvwZ5Gt56Fc0U/Gp7Bfwk0JD9+9q1Ygm+ 1yjNVreI1Ojfa6/eUpRrMvR9LCor45d1MB0glx5v3Yrsov8+NVZzVgSrwEeIoQ== X-Google-Smtp-Source: AGHT+IH6/cX0HWAQF3bhstiTIeA3J3G+fNmoiUW2wx0NP4raCjvAkWY+KmPmI0F52powC3JKxtkLMA== X-Received: by 2002:a05:6214:2a48:b0:6d8:a591:fb8 with SMTP id 6a1803df08f44-6dd2339db02mr231239626d6.37.1734996359456; Mon, 23 Dec 2024 15:25:59 -0800 (PST) Received: from localhost.localdomain (pool-174-118-208-220.cpe.net.cable.rogers.com. [174.118.208.220]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd18136e56sm47672496d6.61.2024.12.23.15.25.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 15:25:59 -0800 (PST) From: Eric Ju To: git@vger.kernel.org Cc: calvinwan@google.com, jonathantanmy@google.com, chriscool@tuxfamily.org, eric.peijian@gmail.com, karthik.188@gmail.com, toon@iotcl.com, jltobler@gmail.com Subject: [PATCH v8 6/6] cat-file: add remote-object-info to batch-command Date: Mon, 23 Dec 2024 19:25:23 -0400 Message-ID: <20241223232523.76236-7-eric.peijian@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241223232523.76236-1-eric.peijian@gmail.com> References: <20240628190503.67389-1-eric.peijian@gmail.com> <20241223232523.76236-1-eric.peijian@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since the `info` command in cat-file --batch-command prints object info for a given object, it is natural to add another command in cat-file --batch-command to print object info for a given object from a remote. Add `remote-object-info` to cat-file --batch-command. While `info` takes object ids one at a time, this creates overhead when making requests to a server.So `remote-object-info` instead can take multiple object ids at once. cat-file --batch-command is generally implemented in the following manner: - Receive and parse input from user - Call respective function attached to command - Get object info, print object info In --buffer mode, this changes to: - Receive and parse input from user - Store respective function attached to command in a queue - After flush, loop through commands in queue - Call respective function attached to command - Get object info, print object info Notice how the getting and printing of object info is accomplished one at a time. As described above, this creates a problem for making requests to a server. Therefore, `remote-object-info` is implemented in the following manner: - Receive and parse input from user If command is `remote-object-info`: - Get object info from remote - Loop through and print each object info Else: - Call respective function attached to command - Parse input, get object info, print object info And finally for --buffer mode `remote-object-info`: - Receive and parse input from user - Store respective function attached to command in a queue - After flush, loop through commands in queue: If command is `remote-object-info`: - Get object info from remote - Loop through and print each object info Else: - Call respective function attached to command - Get object info, print object info To summarize, `remote-object-info` gets object info from the remote and then loop through the object info passed in, printing the info. In order for remote-object-info to avoid remote communication overhead in the non-buffer mode, the objects are passed in as such: remote-object-info ... rather than remote-object-info remote-object-info ... remote-object-info Helped-by: Jonathan Tan Helped-by: Christian Couder Signed-off-by: Calvin Wan Signed-off-by: Eric Ju --- Documentation/git-cat-file.txt | 24 +- builtin/cat-file.c | 99 ++++ object-file.c | 11 + object-store-ll.h | 3 + t/lib-cat-file.sh | 16 + t/t1006-cat-file.sh | 13 +- t/t1017-cat-file-remote-object-info.sh | 652 +++++++++++++++++++++++++ 7 files changed, 802 insertions(+), 16 deletions(-) create mode 100644 t/lib-cat-file.sh create mode 100755 t/t1017-cat-file-remote-object-info.sh diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt index d5890ae368..6a2f9fd752 100644 --- a/Documentation/git-cat-file.txt +++ b/Documentation/git-cat-file.txt @@ -149,6 +149,13 @@ info :: Print object info for object reference ``. This corresponds to the output of `--batch-check`. +remote-object-info ...:: + Print object info for object references `` at specified + `` without downloading objects from the remote. + Error when the `object-info` capability is not supported by the server. + Error when no object references are provided. + This command may be combined with `--buffer`. + flush:: Used with `--buffer` to execute all preceding commands that were issued since the beginning or since the last flush was issued. When `--buffer` @@ -290,7 +297,8 @@ newline. The available atoms are: The full hex representation of the object name. `objecttype`:: - The type of the object (the same as `cat-file -t` reports). + The type of the object (the same as `cat-file -t` reports). See + `CAVEATS` below. Not supported by `remote-object-info`. `objectsize`:: The size, in bytes, of the object (the same as `cat-file -s` @@ -298,13 +306,14 @@ newline. The available atoms are: `objectsize:disk`:: The size, in bytes, that the object takes up on disk. See the - note about on-disk sizes in the `CAVEATS` section below. + note about on-disk sizes in the `CAVEATS` section below. Not + supported by `remote-object-info`. `deltabase`:: If the object is stored as a delta on-disk, this expands to the full hex representation of the delta base object name. Otherwise, expands to the null OID (all zeroes). See `CAVEATS` - below. + below. Not supported by `remote-object-info`. `rest`:: If this atom is used in the output string, input lines are split @@ -314,7 +323,10 @@ newline. The available atoms are: line) are output in place of the `%(rest)` atom. If no format is specified, the default format is `%(objectname) -%(objecttype) %(objectsize)`. +%(objecttype) %(objectsize)`, except for `remote-object-info` commands which use +`%(objectname) %(objectsize)` for now because "%(objecttype)" is not supported yet. +WARNING: When "%(objecttype)" is supported, the default format WILL be unified, so +DO NOT RELY on the current the default format to stay the same!!! If `--batch` is specified, or if `--batch-command` is used with the `contents` command, the object information is followed by the object contents (consisting @@ -396,6 +408,10 @@ scripting purposes. CAVEATS ------- +Note that since %(objecttype), %(objectsize:disk) and %(deltabase) are +currently not supported by the `remote-object-info` command, we will error +and exit when they are in the format string. + Note that the sizes of objects on disk are reported accurately, but care should be taken in drawing conclusions about which refs or objects are responsible for disk usage. The size of a packed non-delta object may be diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 69ea642dc6..998addf28c 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -27,6 +27,9 @@ #include "promisor-remote.h" #include "mailmap.h" #include "write-or-die.h" +#include "alias.h" +#include "remote.h" +#include "transport.h" enum batch_mode { BATCH_MODE_CONTENTS, @@ -45,9 +48,12 @@ struct batch_options { char input_delim; char output_delim; const char *format; + int use_remote_info; }; static const char *force_path; +static struct object_info *remote_object_info; +static struct oid_array object_info_oids = OID_ARRAY_INIT; static struct string_list mailmap = STRING_LIST_INIT_NODUP; static int use_mailmap; @@ -579,6 +585,59 @@ static void batch_one_object(const char *obj_name, object_context_release(&ctx); } +static int get_remote_info(struct batch_options *opt, int argc, const char **argv) +{ + int retval = 0; + struct remote *remote = NULL; + struct object_id oid; + struct string_list object_info_options = STRING_LIST_INIT_NODUP; + static struct transport *gtransport; + + /* + * Change the format to "%(objectname) %(objectsize)" when + * remote-object-info command is used. Once we start supporting objecttype + * the default format should change to DEFAULT_FORMAT + */ + if (!opt->format) + opt->format = "%(objectname) %(objectsize)"; + + 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)) + die(_("Not a valid object name %s"), argv[i]); + oid_array_append(&object_info_oids, &oid); + } + + gtransport = transport_get(remote, NULL); + if (gtransport->smart_options) { + CALLOC_ARRAY(remote_object_info, object_info_oids.nr); + gtransport->smart_options->object_info = 1; + gtransport->smart_options->object_info_oids = &object_info_oids; + + /* 'objectsize' is the only option currently supported */ + if (!strstr(opt->format, "%(objectsize)")) + die(_("%s is currently not supported with remote-object-info"), opt->format); + + string_list_append(&object_info_options, "size"); + + if (object_info_options.nr > 0) { + gtransport->smart_options->object_info_options = &object_info_options; + gtransport->smart_options->object_info_data = remote_object_info; + retval = transport_fetch_refs(gtransport, NULL); + } + } else { + retval = -1; + } + + string_list_clear(&object_info_options, 0); + transport_disconnect(gtransport); + return retval; +} + struct object_cb_data { struct batch_options *opt; struct expand_data *expand; @@ -670,6 +729,45 @@ static void parse_cmd_info(struct batch_options *opt, batch_one_object(line, output, opt, data); } +static void parse_cmd_remote_object_info(struct batch_options *opt, + const char *line, struct strbuf *output, + struct expand_data *data) +{ + int count; + const char **argv; + + char *line_to_split = xstrdup_or_null(line); + count = split_cmdline(line_to_split, &argv); + if (get_remote_info(opt, count, argv)) + goto cleanup; + + opt->use_remote_info = 1; + data->skip_object_info = 1; + for (size_t i = 0; i < object_info_oids.nr; i++) { + + data->oid = object_info_oids.oid[i]; + + if (remote_object_info[i].sizep) { + /* + * When reaching here, it means remote-object-info can retrieve + * information from server without downloading them. + */ + data->size = *remote_object_info[i].sizep; + opt->batch_mode = BATCH_MODE_INFO; + batch_object_write(argv[i+1], output, opt, data, NULL, 0); + } + } + opt->use_remote_info = 0; + data->skip_object_info = 0; + +cleanup: + for (size_t i = 0; i < object_info_oids.nr; i++) + free_object_info_contents(&remote_object_info[i]); + free(line_to_split); + free(argv); + free(remote_object_info); +} + static void dispatch_calls(struct batch_options *opt, struct strbuf *output, struct expand_data *data, @@ -701,6 +799,7 @@ static const struct parse_cmd { } commands[] = { { "contents", parse_cmd_contents, 1}, { "info", parse_cmd_info, 1}, + { "remote-object-info", parse_cmd_remote_object_info, 1}, { "flush", NULL, 0}, }; diff --git a/object-file.c b/object-file.c index 5b792b3dd4..96f204c93a 100644 --- a/object-file.c +++ b/object-file.c @@ -3128,3 +3128,14 @@ int read_loose_object(const char *path, munmap(map, mapsize); return ret; } + +void free_object_info_contents(struct object_info *object_info) +{ + if (!object_info) + return; + free(object_info->typep); + free(object_info->sizep); + free(object_info->disk_sizep); + free(object_info->delta_base_oid); + free(object_info->type_name); +} diff --git a/object-store-ll.h b/object-store-ll.h index cd3bd5bd99..20208e1d4f 100644 --- a/object-store-ll.h +++ b/object-store-ll.h @@ -553,4 +553,7 @@ int for_each_object_in_pack(struct packed_git *p, int for_each_packed_object(struct repository *repo, each_packed_object_fn cb, void *data, enum for_each_object_flags flags); +/* Free pointers inside of object_info, but not object_info itself */ +void free_object_info_contents(struct object_info *object_info); + #endif /* OBJECT_STORE_LL_H */ diff --git a/t/lib-cat-file.sh b/t/lib-cat-file.sh new file mode 100644 index 0000000000..9fb20be308 --- /dev/null +++ b/t/lib-cat-file.sh @@ -0,0 +1,16 @@ +# Library of git-cat-file related tests. + +# Print a string without a trailing newline +echo_without_newline () { + printf '%s' "$*" +} + +# Print a string without newlines and replaces them with a NULL character (\0). +echo_without_newline_nul () { + echo_without_newline "$@" | tr '\n' '\0' +} + +# Calculate the length of a string removing any leading spaces. +strlen () { + echo_without_newline "$1" | wc -c | sed -e 's/^ *//' +} diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index ff9bf213aa..5c7d581ea2 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -3,6 +3,7 @@ test_description='git cat-file' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-cat-file.sh test_cmdmode_usage () { test_expect_code 129 "$@" 2>err && @@ -98,18 +99,6 @@ do ' done -echo_without_newline () { - printf '%s' "$*" -} - -echo_without_newline_nul () { - echo_without_newline "$@" | tr '\n' '\0' -} - -strlen () { - echo_without_newline "$1" | wc -c | sed -e 's/^ *//' -} - run_tests () { type=$1 oid=$2 diff --git a/t/t1017-cat-file-remote-object-info.sh b/t/t1017-cat-file-remote-object-info.sh new file mode 100755 index 0000000000..0e3044d8d6 --- /dev/null +++ b/t/t1017-cat-file-remote-object-info.sh @@ -0,0 +1,652 @@ +#!/bin/sh + +test_description='git cat-file --batch-command with remote-object-info command' + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-cat-file.sh + +hello_content="Hello World" +hello_size=$(strlen "$hello_content") +hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin) + +# This is how we get 13: +# 13 = + + + , where +# file mode is 100644, which is 6 characters; +# file name is hello, which is 5 characters +# a space is 1 character and a null is 1 character +tree_size=$(($(test_oid rawsz) + 13)) + +commit_message="Initial commit" + +# This is how we get 137: +# 137 = + + + +# + + +# + + +# + +# +# An easier way to calculate is: 1. use `git cat-file commit | wc -c`, +# to get 177, 2. then deduct 40 hex characters to get 137 +commit_size=$(($(test_oid hexsz) + 137)) + +tag_header_without_oid="type blob +tag hellotag +tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" +tag_header_without_timestamp="object $hello_oid +$tag_header_without_oid" +tag_description="This is a tag" +tag_content="$tag_header_without_timestamp 0 +0000 + +$tag_description" + +tag_oid=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w) +tag_size=$(strlen "$tag_content") + +set_transport_variables () { + hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin) + tree_oid=$(git -C "$1" write-tree) + commit_oid=$(echo_without_newline "$commit_message" | git -C "$1" commit-tree $tree_oid) + tag_oid=$(echo_without_newline "$tag_content" | git -C "$1" hash-object -t tag --stdin -w) + tag_size=$(strlen "$tag_content") +} + +# This section tests --batch-command with remote-object-info command +# Since "%(objecttype)" is currently not supported by the command remote-object-info , +# the filters are set to "%(objectname) %(objectsize)" in some test cases. + +# Test --batch-command remote-object-info with 'git://' transport with +# transfer.advertiseobjectinfo set to true, i.e. server has object-info capability +. "$TEST_DIRECTORY"/lib-git-daemon.sh +start_git_daemon --export-all --enable=receive-pack +daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent + +test_expect_success 'create repo to be served by git-daemon' ' + git init "$daemon_parent" && + echo_without_newline "$hello_content" > $daemon_parent/hello && + git -C "$daemon_parent" update-index --add hello && + git -C "$daemon_parent" config transfer.advertiseobjectinfo true && + git clone "$GIT_DAEMON_URL/parent" -n "$daemon_parent/daemon_client_empty" +' + +test_expect_success 'batch-command remote-object-info git://' ' + ( + set_transport_variables "$daemon_parent" && + cd "$daemon_parent/daemon_client_empty" && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF && + remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid + remote-object-info "$GIT_DAEMON_URL/parent" $tree_oid + remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid + remote-object-info "$GIT_DAEMON_URL/parent" $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command remote-object-info git:// multiple sha1 per line' ' + ( + set_transport_variables "$daemon_parent" && + cd "$daemon_parent/daemon_client_empty" && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF && + remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid $commit_oid $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command remote-object-info git:// default filter' ' + ( + set_transport_variables "$daemon_parent" && + cd "$daemon_parent/daemon_client_empty" && + + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + GIT_TRACE_PACKET=1 git cat-file --batch-command >actual <<-EOF && + remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid + remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command --buffer remote-object-info git://' ' + ( + set_transport_variables "$daemon_parent" && + cd "$daemon_parent/daemon_client_empty" && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF && + remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid + remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + flush + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command -Z remote-object-info git:// default filter' ' + ( + set_transport_variables "$daemon_parent" && + cd "$daemon_parent/daemon_client_empty" && + + printf "%s\0" "$hello_oid $hello_size" >expect && + printf "%s\0" "$tree_oid $tree_size" >>expect && + printf "%s\0" "$commit_oid $commit_size" >>expect && + printf "%s\0" "$tag_oid $tag_size" >>expect && + + printf "%s\0" "$hello_oid missing" >>expect && + printf "%s\0" "$tree_oid missing" >>expect && + printf "%s\0" "$commit_oid missing" >>expect && + printf "%s\0" "$tag_oid missing" >>expect && + + batch_input="remote-object-info $GIT_DAEMON_URL/parent $hello_oid $tree_oid +remote-object-info $GIT_DAEMON_URL/parent $commit_oid $tag_oid +info $hello_oid +info $tree_oid +info $commit_oid +info $tag_oid +" && + echo_without_newline_nul "$batch_input" >commands_null_delimited && + + git cat-file --batch-command -Z < commands_null_delimited >actual && + test_cmp expect actual + ) +' + +# Test --batch-command remote-object-info with 'git://' and +# transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability +test_expect_success 'batch-command remote-object-info git:// fails when transfer.advertiseobjectinfo=false' ' + ( + git -C "$daemon_parent" config transfer.advertiseobjectinfo false && + set_transport_variables "$daemon_parent" && + + test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF && + remote-object-info $GIT_DAEMON_URL/parent $hello_oid $tree_oid $commit_oid $tag_oid + EOF + test_grep "object-info capability is not enabled on the server" err && + + # revert server state back + git -C "$daemon_parent" config transfer.advertiseobjectinfo true + + ) +' + +stop_git_daemon + +# Test --batch-command remote-object-info with 'file://' transport with +# transfer.advertiseobjectinfo set to true, i.e. server has object-info capability +# shellcheck disable=SC2016 +test_expect_success 'create repo to be served by file:// transport' ' + git init server && + git -C server config protocol.version 2 && + git -C server config transfer.advertiseobjectinfo true && + echo_without_newline "$hello_content" > server/hello && + git -C server update-index --add hello && + git clone -n "file://$(pwd)/server" file_client_empty +' + +test_expect_success 'batch-command remote-object-info file://' ' + ( + set_transport_variables "server" && + server_path="$(pwd)/server" && + cd file_client_empty && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF && + remote-object-info "file://${server_path}" $hello_oid + remote-object-info "file://${server_path}" $tree_oid + remote-object-info "file://${server_path}" $commit_oid + remote-object-info "file://${server_path}" $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command remote-object-info file:// multiple sha1 per line' ' + ( + set_transport_variables "server" && + server_path="$(pwd)/server" && + cd file_client_empty && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + + git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF && + remote-object-info "file://${server_path}" $hello_oid $tree_oid $commit_oid $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command --buffer remote-object-info file://' ' + ( + set_transport_variables "server" && + server_path="$(pwd)/server" && + cd file_client_empty && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF && + remote-object-info "file://${server_path}" $hello_oid $tree_oid + remote-object-info "file://${server_path}" $commit_oid $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + flush + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command remote-object-info file:// default filter' ' + ( + set_transport_variables "server" && + server_path="$(pwd)/server" && + cd file_client_empty && + + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + git cat-file --batch-command >actual <<-EOF && + remote-object-info "file://${server_path}" $hello_oid $tree_oid + remote-object-info "file://${server_path}" $commit_oid $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command -Z remote-object-info file:// default filter' ' + ( + set_transport_variables "server" && + server_path="$(pwd)/server" && + cd file_client_empty && + + printf "%s\0" "$hello_oid $hello_size" >expect && + printf "%s\0" "$tree_oid $tree_size" >>expect && + printf "%s\0" "$commit_oid $commit_size" >>expect && + printf "%s\0" "$tag_oid $tag_size" >>expect && + + printf "%s\0" "$hello_oid missing" >>expect && + printf "%s\0" "$tree_oid missing" >>expect && + printf "%s\0" "$commit_oid missing" >>expect && + printf "%s\0" "$tag_oid missing" >>expect && + + batch_input="remote-object-info \"file://${server_path}\" $hello_oid $tree_oid +remote-object-info \"file://${server_path}\" $commit_oid $tag_oid +info $hello_oid +info $tree_oid +info $commit_oid +info $tag_oid +" && + echo_without_newline_nul "$batch_input" >commands_null_delimited && + + git cat-file --batch-command -Z < commands_null_delimited >actual && + test_cmp expect actual + ) +' + +# Test --batch-command remote-object-info with 'file://' and +# transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability +test_expect_success 'batch-command remote-object-info file:// fails when transfer.advertiseobjectinfo=false' ' + ( + set_transport_variables "server" && + server_path="$(pwd)/server" && + git -C "${server_path}" config transfer.advertiseobjectinfo false && + + test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF && + remote-object-info "file://${server_path}" $hello_oid $tree_oid $commit_oid $tag_oid + EOF + test_grep "object-info capability is not enabled on the server" err && + + # revert server state back + git -C "${server_path}" config transfer.advertiseobjectinfo true + ) +' + +# Test --batch-command remote-object-info with 'http://' transport with +# transfer.advertiseobjectinfo set to true, i.e. server has object-info capability + +. "$TEST_DIRECTORY"/lib-httpd.sh +start_httpd + +test_expect_success 'create repo to be served by http:// transport' ' + git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true && + git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo true && + echo_without_newline "$hello_content" > $HTTPD_DOCUMENT_ROOT_PATH/http_parent/hello && + git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" update-index --add hello && + git clone "$HTTPD_URL/smart/http_parent" -n "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" +' + +test_expect_success 'batch-command remote-object-info http://' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid + remote-object-info "$HTTPD_URL/smart/http_parent" $tree_oid + remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid + remote-object-info "$HTTPD_URL/smart/http_parent" $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command remote-object-info http:// one line' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid $commit_oid $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command --buffer remote-object-info http://' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" && + + # These results prove remote-object-info can get object info from the remote + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + # These results prove remote-object-info did not download objects from the remote + echo "$hello_oid missing" >>expect && + echo "$tree_oid missing" >>expect && + echo "$commit_oid missing" >>expect && + echo "$tag_oid missing" >>expect && + + git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid + remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid $tag_oid + info $hello_oid + info $tree_oid + info $commit_oid + info $tag_oid + flush + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command remote-object-info http:// default filter' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" && + + echo "$hello_oid $hello_size" >expect && + echo "$tree_oid $tree_size" >>expect && + echo "$commit_oid $commit_size" >>expect && + echo "$tag_oid $tag_size" >>expect && + + git cat-file --batch-command >actual <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid + remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid $tag_oid + EOF + test_cmp expect actual + ) +' + +test_expect_success 'batch-command -Z remote-object-info http:// default filter' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" && + + printf "%s\0" "$hello_oid $hello_size" >expect && + printf "%s\0" "$tree_oid $tree_size" >>expect && + printf "%s\0" "$commit_oid $commit_size" >>expect && + printf "%s\0" "$tag_oid $tag_size" >>expect && + + batch_input="remote-object-info $HTTPD_URL/smart/http_parent $hello_oid $tree_oid +remote-object-info $HTTPD_URL/smart/http_parent $commit_oid $tag_oid +" && + echo_without_newline_nul "$batch_input" >commands_null_delimited && + + git cat-file --batch-command -Z < commands_null_delimited >actual && + test_cmp expect actual + ) +' + +test_expect_success 'remote-object-info fails on unspported filter option (objectsize:disk)' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + + test_must_fail git cat-file --batch-command="%(objectsize:disk)" 2>err <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid + EOF + test_grep "%(objectsize:disk) is currently not supported with remote-object-info" err + ) +' + +test_expect_success 'remote-object-info fails on unspported filter option (deltabase)' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + + test_must_fail git cat-file --batch-command="%(deltabase)" 2>err <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid + EOF + test_grep "%(deltabase) is currently not supported with remote-object-info" err + ) +' + +test_expect_success 'remote-object-info fails on server with legacy protocol' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + + test_must_fail git -c protocol.version=0 cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid + EOF + test_grep "remote-object-info requires protocol v2" err + ) +' + +test_expect_success 'remote-object-info fails on server with legacy protocol' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + + test_must_fail git -c protocol.version=0 cat-file --batch-command 2>err <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid + EOF + test_grep "remote-object-info requires protocol v2" err + ) +' + +test_expect_success 'remote-object-info fails on malformed OID' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + malformed_object_id="this_id_is_not_valid" && + + test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $malformed_object_id + EOF + test_grep "Not a valid object name '$malformed_object_id'" err + ) +' + +test_expect_success 'remote-object-info fails on malformed OID with default filter' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + malformed_object_id="this_id_is_not_valid" && + + test_must_fail git cat-file --batch-command 2>err <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $malformed_object_id + EOF + test_grep "Not a valid object name '$malformed_object_id'" err + ) +' + +test_expect_success 'remote-object-info fails on missing OID' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + git clone "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" missing_oid_repo && + test_commit -C missing_oid_repo message1 c.txt && + cd missing_oid_repo && + + object_id=$(git rev-parse message1:c.txt) && + test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $object_id + EOF + test_grep "object-info: not our ref $object_id" err + ) +' + + +# Test --batch-command remote-object-info with 'http://' transport and +# transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability +test_expect_success 'batch-command remote-object-info http:// fails when transfer.advertiseobjectinfo=false ' ' + ( + set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo false && + + test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF && + remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid $commit_oid $tag_oid + EOF + test_grep "object-info capability is not enabled on the server" err && + + # revert server state back + git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo true + ) +' + +# DO NOT add non-httpd-specific tests here, because the last part of this +# test script is only executed when httpd is available and enabled. + +test_done