From patchwork Mon May 16 20:10:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12851385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4EADC433EF for ; Mon, 16 May 2022 20:28:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347311AbiEPU2i (ORCPT ); Mon, 16 May 2022 16:28:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348774AbiEPU1o (ORCPT ); Mon, 16 May 2022 16:27:44 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7F118386 for ; Mon, 16 May 2022 13:11:10 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id v191-20020a1cacc8000000b00397001398c0so213577wme.5 for ; Mon, 16 May 2022 13:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=wZpY20xg1QCdEl2cqv2CF8ziDvQ7Pr5cuiwF4YhmDLU=; b=nfZoMMHxphRrNNcRLWH1wRQq9/MRlFT9YpUf0ikmjayE9W7aOUixzABBQ9lIznz++A 8/ddkjqOQ484H7RM/RTJW9UURXHEGDMc/FHjx9uKivPbir3uD2E3qHtzAqGPHau/3yZL oCyW+y+KM8To73qffrbBzlljt5mpONrUzRk2mbsozy6PX0oBYgrr6YPoY5LKN6CZNRhi 4YZEO4RudilAAtjfSzUpLjfqy5NY5lt84vUznxgW2tqus3CTLHl64OxAhQFDgUPH6+ly HK8bObLO1DvIKUxeFeFSwcsD1nnzzrFEi93k3vGc+m7/qCX9xqeWV4TetbCTGv7s7Vpv 1dNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=wZpY20xg1QCdEl2cqv2CF8ziDvQ7Pr5cuiwF4YhmDLU=; b=gZIM2S/ON/9wvHTeAH8f+L54/B7U9LvugBoUnKPv9XBotwFDaJWYERh5/zDw6of2Lp zi0aFh3zoruUyTIRH2g8Fn4x9Sv7C5xqI3nedpwWsqCMrhGYsnSLiHF1/TGi7dJmuVCg THCMz4EnvWpfODZ4Rv81+auDlK5Hd4tXSODp+0sqnAgLJaR4eTG/tNfcFHTjCqPBFYBg pYADa2FeHNMKVXuoWPTm4nQwGECSFQSr4O7L4ByTrH3apg3jUjgk9AjbYvscDgNGilUY x73nq7hturw89wbM/dWdOozdImp22migcLC+ESXITdjbjY6p1yDTHV9L2IPQ1mslB26a NY/w== X-Gm-Message-State: AOAM531kJMC/Wfr0+FzimOVB1T3KoRPU+VaV0FhQlGK2O9VMF30YktNG DbJxqdhUQNEdMk66mnI990Mqj3B4T2s= X-Google-Smtp-Source: ABdhPJwxVqPnz5LdCFbxr9311G+qJuYfs6wu0PJYU7lnmYt1xuVxaluM0BlmXpArcJQeZzYtt1d9DA== X-Received: by 2002:a05:600c:1f13:b0:396:fee5:ebcf with SMTP id bd19-20020a05600c1f1300b00396fee5ebcfmr8169041wmb.201.1652731868615; Mon, 16 May 2022 13:11:08 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d8-20020adf9c88000000b0020d106c0386sm1766364wre.89.2022.05.16.13.11.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 13:11:08 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 16 May 2022 20:10:58 +0000 Subject: [PATCH 1/8] connect.c: refactor sending of agent & object-format MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com, albertqcui@gmail.com, robbat2@gentoo.org, dyroneteng@gmail.com, Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Refactor the sending of the "agent" and "object-format" capabilities into a function. This was added in its current form in ab67235bc4 (connect: parse v2 refs with correct hash algorithm, 2020-05-25). When we connect to a v2 server we need to know about its object-format, and it needs to know about ours. Since most things in connect.c and transport.c piggy-back on the eager getting of remote refs via the handshake() those commands can make use of the just-sent-over object-format by ls-refs. But I'm about to add a command that may come after ls-refs, and may not, but we need the server to know about our user-agent and object-format. So let's split this into a function. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee --- connect.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/connect.c b/connect.c index afc79a6236e..e6d0b1d34bd 100644 --- a/connect.c +++ b/connect.c @@ -473,6 +473,24 @@ void check_stateless_delimiter(int stateless_rpc, die("%s", error); } +static void send_capabilities(int fd_out, struct packet_reader *reader) +{ + const char *hash_name; + + if (server_supports_v2("agent", 0)) + packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized()); + + if (server_feature_v2("object-format", &hash_name)) { + int hash_algo = hash_algo_by_name(hash_name); + if (hash_algo == GIT_HASH_UNKNOWN) + die(_("unknown object format '%s' specified by server"), hash_name); + reader->hash_algo = &hash_algos[hash_algo]; + packet_write_fmt(fd_out, "object-format=%s", reader->hash_algo->name); + } else { + reader->hash_algo = &hash_algos[GIT_HASH_SHA1]; + } +} + struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, struct ref **list, int for_push, struct transport_ls_refs_options *transport_options, @@ -480,7 +498,6 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, int stateless_rpc) { int i; - const char *hash_name; struct strvec *ref_prefixes = transport_options ? &transport_options->ref_prefixes : NULL; const char **unborn_head_target = transport_options ? @@ -490,18 +507,8 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, if (server_supports_v2("ls-refs", 1)) packet_write_fmt(fd_out, "command=ls-refs\n"); - if (server_supports_v2("agent", 0)) - packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized()); - - if (server_feature_v2("object-format", &hash_name)) { - int hash_algo = hash_algo_by_name(hash_name); - if (hash_algo == GIT_HASH_UNKNOWN) - die(_("unknown object format '%s' specified by server"), hash_name); - reader->hash_algo = &hash_algos[hash_algo]; - packet_write_fmt(fd_out, "object-format=%s", reader->hash_algo->name); - } else { - reader->hash_algo = &hash_algos[GIT_HASH_SHA1]; - } + /* Send capabilities */ + send_capabilities(fd_out, reader); if (server_options && server_options->nr && server_supports_v2("server-option", 1)) From patchwork Mon May 16 20:10:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12851386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E46D4C433EF for ; Mon, 16 May 2022 20:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347330AbiEPU2l (ORCPT ); Mon, 16 May 2022 16:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348773AbiEPU1o (ORCPT ); Mon, 16 May 2022 16:27:44 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3671C183B4 for ; Mon, 16 May 2022 13:11:12 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id n6so1627375wms.0 for ; Mon, 16 May 2022 13:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=vC+3VBngUP/LzAZEqzV97Lb6vRwh5cHZuQ8TMTALQWE=; b=SBhrDJQ80QmqS62Cd96QHOFdHb3ZziZsEj3YNjdkI0iG+Ka8ZwMzYlWoP7EzVGsh3Q G7RBiHY8VV4ABvIj9jqejodyIh7ER7UIj8uoRRu+F7OrvaYgXRSAFBPnNj1tDMoZDEoz Uo8Ir+EO+60UceKlUQl6rdqs+2hLWFFEtcKx3vJp8DcoeyVxguhSyIaxPg6fr1EuBA9l dExEGAOhDQ6EonjMoZWslNFso7ljON/ce4VoZ+Gvl7/GCsh8B6HzC1zMXEN9wRB+PGFI /HrigqgilCA0iz9CQ4qAkK2N6Cgg/HWoTjufV3YzuibawTGznNahnCCGxI9/YkaHaIig 8dVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=vC+3VBngUP/LzAZEqzV97Lb6vRwh5cHZuQ8TMTALQWE=; b=0AO/OlCS5vpjWnriTzVm9kFkFgBloZRw+mUj2aAdhKvGeE3j5Ly619NMgzvs2EkJHO xw2mxF4Xejg68SgMXpwhRsW/2a5TB7ItT/eDFHHi1kOp1cOLHICYZ+n2mtSMuuJd2LGM ltXTxxSNpGEzkmNdtm6hLzpZ0Mp4wvkKC4wiDHBCkABx0lVkQNaOmNC/pEyngsBsqKkr TH91+2V4+nxP8l9UHkfbr61pS0giIEhR3wDWw1K0cinkAK0GWlvlvC6mXHGTJto9rPIs CTcre90FIEtjbjf8yJTcXeXXuHADdfvvc6fwzc2pZhVKZNGlQcNzLO2J+JAIRiZh6gFc FxHA== X-Gm-Message-State: AOAM533BTwlMPzxCHRNRfyMTf7So45t6WBbaux3eQW2ctSO8z5rB35gO 4TxmwQ6ZO8C2wglUZ59XRh0tLRGRrEc= X-Google-Smtp-Source: ABdhPJz25uTcsgoG2jkGlNrUulBroFtBoyvT2korHDmDZSObCGLZ/zC/bHg4YE4oKO91W5Nb2vSZCg== X-Received: by 2002:a05:600c:4142:b0:394:4f24:d5c with SMTP id h2-20020a05600c414200b003944f240d5cmr29109263wmm.171.1652731870008; Mon, 16 May 2022 13:11:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d7-20020adfc807000000b0020c5253d8e4sm10156007wrh.48.2022.05.16.13.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 13:11:09 -0700 (PDT) Message-Id: <61eb82fb79ca4739e993c136064ba159ce65192e.1652731865.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 May 2022 20:10:59 +0000 Subject: [PATCH 2/8] dir API: add a generalized path_match_flags() function MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com, albertqcui@gmail.com, robbat2@gentoo.org, dyroneteng@gmail.com, Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Add a path_match_flags() function and have the two sets of starts_with_dot_{,dot_}slash() functions added in 63e95beb085 (submodule: port resolve_relative_url from shell to C, 2016-04-15) and a2b26ffb1a8 (fsck: convert gitmodules url to URL passed to curl, 2020-04-18) be thin wrappers for it. As the latter of those notes the fsck version was copied from the initial builtin/submodule--helper.c version. Since the code added in a2b26ffb1a8 was doing really doing the same as win32_is_dir_sep() added in 1cadad6f658 (git clone C:\cygwin\home\USER\repo' is working (again), 2018-12-15) let's move the latter to git-compat-util.h is a is_xplatform_dir_sep(). We can then call either it or the platform-specific is_dir_sep() from this new function. Let's likewise change code in various other places that was hardcoding checks for "'/' || '\\'" with the new is_xplatform_dir_sep(). As can be seen in those callers some of them still concern themselves with ':' (Mac OS classic?), but let's leave the question of whether that should be consolidated for some other time. As we expect to make wider use of the "native" case in the future, define and use two starts_with_dot_{,dot_}slash_native() convenience wrappers. This makes the diff in builtin/submodule--helper.c much smaller. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee --- builtin/submodule--helper.c | 20 ++++++------ compat/mingw.c | 2 +- compat/win32/path-utils.h | 6 +--- dir.c | 29 +++++++++++++++++ dir.h | 63 +++++++++++++++++++++++++++++++++++++ fsck.c | 23 ++++---------- git-compat-util.h | 8 ++++- path.c | 2 +- submodule-config.c | 6 ++-- 9 files changed, 121 insertions(+), 38 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 2c87ef9364f..b68102bb3ed 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -72,16 +72,6 @@ static char *get_default_remote(void) return repo_get_default_remote(the_repository); } -static int starts_with_dot_slash(const char *str) -{ - return str[0] == '.' && is_dir_sep(str[1]); -} - -static int starts_with_dot_dot_slash(const char *str) -{ - return str[0] == '.' && str[1] == '.' && is_dir_sep(str[2]); -} - /* * Returns 1 if it was the last chop before ':'. */ @@ -108,6 +98,16 @@ static int chop_last_dir(char **remoteurl, int is_relative) return 0; } +static int starts_with_dot_slash(const char *const path) +{ + return starts_with_dot_slash_native(path);; +} + +static int starts_with_dot_dot_slash(const char *const path) +{ + return starts_with_dot_dot_slash_native(path); +} + /* * The `url` argument is the URL that navigates to the submodule origin * repo. When relative, this URL is relative to the superproject origin diff --git a/compat/mingw.c b/compat/mingw.c index 6fe80fdf014..b94b473d978 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2830,7 +2830,7 @@ not_a_reserved_name: } c = path[i]; - if (c && c != '.' && c != ':' && c != '/' && c != '\\') + if (c && c != '.' && c != ':' && !is_xplatform_dir_sep(c)) goto not_a_reserved_name; /* contains reserved name */ diff --git a/compat/win32/path-utils.h b/compat/win32/path-utils.h index bba2b644080..65fa3b9263a 100644 --- a/compat/win32/path-utils.h +++ b/compat/win32/path-utils.h @@ -6,11 +6,7 @@ int win32_has_dos_drive_prefix(const char *path); int win32_skip_dos_drive_prefix(char **path); #define skip_dos_drive_prefix win32_skip_dos_drive_prefix -static inline int win32_is_dir_sep(int c) -{ - return c == '/' || c == '\\'; -} -#define is_dir_sep win32_is_dir_sep +#define is_dir_sep is_xplatform_dir_sep static inline char *win32_find_last_dir_sep(const char *path) { char *ret = NULL; diff --git a/dir.c b/dir.c index f2b0f242101..d25aa6ade55 100644 --- a/dir.c +++ b/dir.c @@ -3890,3 +3890,32 @@ void relocate_gitdir(const char *path, const char *old_git_dir, const char *new_ connect_work_tree_and_git_dir(path, new_git_dir, 0); } + +int path_match_flags(const char *const str, const enum path_match_flags flags) +{ + const char *p = str; + + if (flags & PATH_MATCH_NATIVE && + flags & PATH_MATCH_XPLATFORM) + BUG("path_match_flags() must get one match kind, not multiple!"); + else if (!(flags & PATH_MATCH_KINDS_MASK)) + BUG("path_match_flags() must get at least one match kind!"); + + if (flags & PATH_MATCH_STARTS_WITH_DOT_SLASH && + flags & PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH) + BUG("path_match_flags() must get one platform kind, not multiple!"); + else if (!(flags & PATH_MATCH_PLATFORM_MASK)) + BUG("path_match_flags() must get at least one platform kind!"); + + if (*p++ != '.') + return 0; + if (flags & PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH && + *p++ != '.') + return 0; + + if (flags & PATH_MATCH_NATIVE) + return is_dir_sep(*p); + else if (flags & PATH_MATCH_XPLATFORM) + return is_xplatform_dir_sep(*p); + BUG("unreachable"); +} diff --git a/dir.h b/dir.h index 8e02dfb505d..7bc862030cf 100644 --- a/dir.h +++ b/dir.h @@ -578,4 +578,67 @@ void connect_work_tree_and_git_dir(const char *work_tree, void relocate_gitdir(const char *path, const char *old_git_dir, const char *new_git_dir); + +/** + * The "enum path_matches_kind" determines how path_match_flags() will + * behave. The flags come in sets, and one (and only one) must be + * provided out of each "set": + * + * PATH_MATCH_NATIVE: + * Path separator is is_dir_sep() + * PATH_MATCH_XPLATFORM: + * Path separator is is_xplatform_dir_sep() + * + * Do we use is_dir_sep() to check for a directory separator + * (*_NATIVE), or do we always check for '/' or '\' (*_XPLATFORM). The + * "*_NATIVE" version on Windows is the same as "*_XPLATFORM", + * everywhere else "*_NATIVE" means "only /". + * + * PATH_MATCH_STARTS_WITH_DOT_SLASH: + * Match a path starting with "./" + * PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH: + * Match a path starting with "../" + * + * The "/" in the above is adjusted based on the "*_NATIVE" and + * "*_XPLATFORM" flags. + */ +enum path_match_flags { + PATH_MATCH_NATIVE = 1 << 0, + PATH_MATCH_XPLATFORM = 1 << 1, + PATH_MATCH_STARTS_WITH_DOT_SLASH = 1 << 2, + PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH = 1 << 3, +}; +#define PATH_MATCH_KINDS_MASK (PATH_MATCH_STARTS_WITH_DOT_SLASH | \ + PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH) +#define PATH_MATCH_PLATFORM_MASK (PATH_MATCH_NATIVE | PATH_MATCH_XPLATFORM) + +/** + * path_match_flags() checks if a given "path" matches a given "enum + * path_match_flags" criteria. + */ +int path_match_flags(const char *const path, const enum path_match_flags f); + +/** + * starts_with_dot_slash_native(): convenience wrapper for + * path_match_flags() with PATH_MATCH_STARTS_WITH_DOT_SLASH and + * PATH_MATCH_NATIVE. + */ +static inline int starts_with_dot_slash_native(const char *const path) +{ + const enum path_match_flags what = PATH_MATCH_STARTS_WITH_DOT_SLASH; + + return path_match_flags(path, what | PATH_MATCH_NATIVE); +} + +/** + * starts_with_dot_slash_native(): convenience wrapper for + * path_match_flags() with PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH and + * PATH_MATCH_NATIVE. + */ +static inline int starts_with_dot_dot_slash_native(const char *const path) +{ + const enum path_match_flags what = PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH; + + return path_match_flags(path, what | PATH_MATCH_NATIVE); +} #endif diff --git a/fsck.c b/fsck.c index 3ec500d707a..dd4822ba1be 100644 --- a/fsck.c +++ b/fsck.c @@ -975,27 +975,16 @@ done: return ret; } -/* - * Like builtin/submodule--helper.c's starts_with_dot_slash, but without - * relying on the platform-dependent is_dir_sep helper. - * - * This is for use in checking whether a submodule URL is interpreted as - * relative to the current directory on any platform, since \ is a - * directory separator on Windows but not on other platforms. - */ -static int starts_with_dot_slash(const char *str) +static int starts_with_dot_slash(const char *const path) { - return str[0] == '.' && (str[1] == '/' || str[1] == '\\'); + return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_SLASH | + PATH_MATCH_XPLATFORM); } -/* - * Like starts_with_dot_slash, this is a variant of submodule--helper's - * helper of the same name with the twist that it accepts backslash as a - * directory separator even on non-Windows platforms. - */ -static int starts_with_dot_dot_slash(const char *str) +static int starts_with_dot_dot_slash(const char *const path) { - return str[0] == '.' && starts_with_dot_slash(str + 1); + return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH | + PATH_MATCH_XPLATFORM); } static int submodule_url_is_relative(const char *url) diff --git a/git-compat-util.h b/git-compat-util.h index 58fd813bd01..ba3436db9a1 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -236,6 +236,12 @@ #include #endif +/* Used by compat/win32/path-utils.h, and more */ +static inline int is_xplatform_dir_sep(int c) +{ + return c == '/' || c == '\\'; +} + #if defined(__CYGWIN__) #include "compat/win32/path-utils.h" #endif @@ -416,11 +422,11 @@ static inline int git_skip_dos_drive_prefix(char **path) #define skip_dos_drive_prefix git_skip_dos_drive_prefix #endif -#ifndef is_dir_sep static inline int git_is_dir_sep(int c) { return c == '/'; } +#ifndef is_dir_sep #define is_dir_sep git_is_dir_sep #endif diff --git a/path.c b/path.c index d73146b6cd2..2ab78278943 100644 --- a/path.c +++ b/path.c @@ -1413,7 +1413,7 @@ int is_ntfs_dotgit(const char *name) for (;;) { c = *(name++); - if (!c || c == '\\' || c == '/' || c == ':') + if (!c || is_xplatform_dir_sep(c) || c == ':') return 1; if (c != '.' && c != ' ') return 0; diff --git a/submodule-config.c b/submodule-config.c index 29668b0620d..ce3beaf5d4f 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -204,17 +204,17 @@ int check_submodule_name(const char *name) return -1; /* - * Look for '..' as a path component. Check both '/' and '\\' as + * Look for '..' as a path component. Check is_xplatform_dir_sep() as * separators rather than is_dir_sep(), because we want the name rules * to be consistent across platforms. */ goto in_component; /* always start inside component */ while (*name) { char c = *name++; - if (c == '/' || c == '\\') { + if (is_xplatform_dir_sep(c)) { in_component: if (name[0] == '.' && name[1] == '.' && - (!name[2] || name[2] == '/' || name[2] == '\\')) + (!name[2] || is_xplatform_dir_sep(name[2]))) return -1; } } From patchwork Mon May 16 20:11:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12851387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C48EBC433F5 for ; Mon, 16 May 2022 20:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347364AbiEPU2p (ORCPT ); Mon, 16 May 2022 16:28:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348776AbiEPU1o (ORCPT ); Mon, 16 May 2022 16:27:44 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7BED18B04 for ; Mon, 16 May 2022 13:11:13 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id r30so4248195wra.13 for ; Mon, 16 May 2022 13:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=Rxz1a4zZC6o57lCcj9M69sbc6FwXw2jSbZhUr70qzu4=; b=etAX13F7sY5lN+AU3WzK8rT1IO99Kbdoxw6QMDiNAT8x6/VbrDjddIb+pvfU9LzKNI AwnHNFW+jO8K72cMKufs8z7YZes4IiB3JZnA1u1Qi7y1NVkyG9YYovYr7Zk3JllxiGCj 5bO1sAjE232nr/U5b/Bi27ShEtmBZ56NsSrfSX4zRQMk4/UQkwVtRsOL2HpVC+4z0BWv HRYcwKy48h1o34ZtTIzt1aUlTqYjUh35kaksgO4AAgu4VG6Ybka7E22r+HTU6e+npjWw jd81rYOB0eSE5KCEOVOFX8VVHZ+XgmaJCSLGbdZzGLE7IMJm95S1+0alaRA15+WZwOnT nSFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=Rxz1a4zZC6o57lCcj9M69sbc6FwXw2jSbZhUr70qzu4=; b=aaCX0P6D/m1z9ohv7O3zMyvGiaNnLXDcA/pzCTd8La5OoyFZaTub1/3MD6vk9kqIoW KoJT/aoghrcleOqn/AbJrCHodRgohGqw0sh1IaXHTNBwJK+qSVYYycOSVS9KTxKmIATw Han2SSJV/UxlxuqSNbl2Q+L2S31uLIxaCAnIFn5H7apgP4bD9DOcORRwHxdrxp1Iizf5 Rt3BLEz7kbY5qFccehVE/sldacqLcpjR2M5fBGJFv3afxhBqOs9d2MXcD8kEwH3KvcRW KnYNVarvX74/JLzP7i7kVGZzvh+SJpZtyxTIwJWmwSL9r5glDOpvFL80h0bC8wqbLX3k kECQ== X-Gm-Message-State: AOAM532aLDhDq2H5jkHpmYOGKeR5Gv9e9ZrIEMy6sJm68IPABFxq3gAR Uto6dr4pzH5xYJhaOHAGIuMopQvxjxw= X-Google-Smtp-Source: ABdhPJz0jvMaYv1O4Q15SlOy2RXA08KPtDfEnJSXPT8acGdJmT864zr6kgC7puUgmQzmiYJSN6lTGA== X-Received: by 2002:a5d:47cc:0:b0:20c:6b7c:8a19 with SMTP id o12-20020a5d47cc000000b0020c6b7c8a19mr14859951wrc.608.1652731871386; Mon, 16 May 2022 13:11:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 6-20020a056000154600b0020d0b2de858sm3471337wry.33.2022.05.16.13.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 13:11:10 -0700 (PDT) Message-Id: <2a563b5f18cc9c42cb71a9547344a5435f6bc058.1652731865.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 May 2022 20:11:00 +0000 Subject: [PATCH 3/8] fetch-pack: add a deref_without_lazy_fetch_extended() MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com, albertqcui@gmail.com, robbat2@gentoo.org, dyroneteng@gmail.com, Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Add a version of the deref_without_lazy_fetch function which can be called with custom oi_flags and to grab information about the "object_type". This will be used for the bundle-uri client in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee --- fetch-pack.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index 4e1e88eea09..d0aa3a5c229 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -115,11 +115,12 @@ static void for_each_cached_alternate(struct fetch_negotiator *negotiator, cb(negotiator, cache.items[i]); } -static struct commit *deref_without_lazy_fetch(const struct object_id *oid, - int mark_tags_complete) +static struct commit *deref_without_lazy_fetch_extended(const struct object_id *oid, + int mark_tags_complete, + enum object_type *type, + unsigned int oi_flags) { - enum object_type type; - struct object_info info = { .typep = &type }; + struct object_info info = { .typep = type }; struct commit *commit; commit = lookup_commit_in_graph(the_repository, oid); @@ -128,9 +129,9 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid, while (1) { if (oid_object_info_extended(the_repository, oid, &info, - OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)) + oi_flags)) return NULL; - if (type == OBJ_TAG) { + if (*type == OBJ_TAG) { struct tag *tag = (struct tag *) parse_object(the_repository, oid); @@ -144,7 +145,7 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid, } } - if (type == OBJ_COMMIT) { + if (*type == OBJ_COMMIT) { struct commit *commit = lookup_commit(the_repository, oid); if (!commit || repo_parse_commit(the_repository, commit)) return NULL; @@ -154,6 +155,16 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid, return NULL; } + +static struct commit *deref_without_lazy_fetch(const struct object_id *oid, + int mark_tags_complete) +{ + enum object_type type; + unsigned flags = OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK; + return deref_without_lazy_fetch_extended(oid, mark_tags_complete, + &type, flags); +} + static int rev_list_insert_ref(struct fetch_negotiator *negotiator, const struct object_id *oid) { From patchwork Mon May 16 20:11:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12851388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB91BC433F5 for ; Mon, 16 May 2022 20:28:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347426AbiEPU25 (ORCPT ); Mon, 16 May 2022 16:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238836AbiEPU1p (ORCPT ); Mon, 16 May 2022 16:27:45 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB4C218B24 for ; Mon, 16 May 2022 13:11:14 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id r188-20020a1c44c5000000b003946c466c17so216697wma.4 for ; Mon, 16 May 2022 13:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=CMM7XzceafSd/2uhqTgyB2yXqhYZx5oO0BrLu1l4zW0=; b=cHXwsEZDKG5L3upgTzN5RUe5InkyfexdmL/Gh0rakuURoQaSqzouiBvwCI5bTFYOoS z+RC/iXWcV8tG1bKbxkoiZhJkHusUBpOdiYRUNes/jAHfLgzLt7heykGJUS/zrDpEN+n +imYG0gWBfj4n79Dhh6QgukTcbkZsMgZDZVWnUxMh65Er5YTwDbjd8V5sdamnTREd9jn 5NOePKwDpfIZuIiMP5iBzXJ5zS3Tf/MvWc+J89bxrfoLB9fnEtOutStLxx2pViUyBUBs +xkeWgHCfFW4FfRhSaFNtc0NY6BHBwbpXbcamN54R22NUVuQYe5DUT3tGmo5NpWlkYTV TuWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=CMM7XzceafSd/2uhqTgyB2yXqhYZx5oO0BrLu1l4zW0=; b=A9kDON8oa4otEf8Dc28vMBuJd6NHvTkD50o3iVmrKhCvSvghhDYFJpZHVA5BhD2K8L C8hm58cTK6xY9i8T3WU/bjavuIKkEITM4syqUQxklq1AwmlVpkoY8sPSgc27jLx6Gv4U RmXVgloxpAPM/DACZf6HOXZ8zgI5DyrZSwnytNomAIQYuesKqW3GAzQThF8qjHQm7rxo k7zyVZsuEY640zOKIMK8Rm21ceUEfAb1t3dN/EzV5wsVLwPaPaIszn9hwScUfG8h7Byj 9EmkVTdLnvCMvlwkFJc02HBSPl0O4x2U+KBOZwCCLqBfleUKfA/bK1wEXpNT8eoc0i7M qItQ== X-Gm-Message-State: AOAM531mugkHmrhzwGz64i2zA09sDgZKOHouUz6gTGCbjZ29qfUDJ0en 8EhNJG+tsqIXoOgD7zeJONNhzM/l2k8= X-Google-Smtp-Source: ABdhPJxW0KQNxZMu77mszTiObuiUeX1NCwTFeKy2yh55qab1HNKu7fIeyztBjWIvA80ejSDsMW+WZg== X-Received: by 2002:a05:600c:4885:b0:393:fac6:f409 with SMTP id j5-20020a05600c488500b00393fac6f409mr28603578wmp.150.1652731872773; Mon, 16 May 2022 13:11:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w6-20020adf8bc6000000b0020c5253d8besm10607948wra.10.2022.05.16.13.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 13:11:12 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 16 May 2022 20:11:01 +0000 Subject: [PATCH 4/8] fetch-pack: move --keep=* option filling to a function MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com, albertqcui@gmail.com, robbat2@gentoo.org, dyroneteng@gmail.com, Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Move the populating of the --keep=* option argument to "index-pack" to a static function, a subsequent commit will make use of it in another function. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee --- fetch-pack.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index d0aa3a5c229..b1d90d1914f 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -847,6 +847,16 @@ static void parse_gitmodules_oids(int fd, struct oidset *gitmodules_oids) } while (1); } +static void add_index_pack_keep_option(struct strvec *args) +{ + char hostname[HOST_NAME_MAX + 1]; + + if (xgethostname(hostname, sizeof(hostname))) + xsnprintf(hostname, sizeof(hostname), "localhost"); + strvec_pushf(args, "--keep=fetch-pack %"PRIuMAX " on %s", + (uintmax_t)getpid(), hostname); +} + /* * If packfile URIs were provided, pass a non-NULL pointer to index_pack_args. * The strings to pass as the --index-pack-arg arguments to http-fetch will be @@ -916,14 +926,8 @@ static int get_pack(struct fetch_pack_args *args, strvec_push(&cmd.args, "-v"); if (args->use_thin_pack) strvec_push(&cmd.args, "--fix-thin"); - if ((do_keep || index_pack_args) && (args->lock_pack || unpack_limit)) { - char hostname[HOST_NAME_MAX + 1]; - if (xgethostname(hostname, sizeof(hostname))) - xsnprintf(hostname, sizeof(hostname), "localhost"); - strvec_pushf(&cmd.args, - "--keep=fetch-pack %"PRIuMAX " on %s", - (uintmax_t)getpid(), hostname); - } + if ((do_keep || index_pack_args) && (args->lock_pack || unpack_limit)) + add_index_pack_keep_option(&cmd.args); if (!index_pack_args && args->check_self_contained_and_connected) strvec_push(&cmd.args, "--check-self-contained-and-connected"); else From patchwork Mon May 16 20:11:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12851389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92D70C433F5 for ; Mon, 16 May 2022 20:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347483AbiEPU27 (ORCPT ); Mon, 16 May 2022 16:28:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbiEPU1p (ORCPT ); Mon, 16 May 2022 16:27:45 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E779218E12 for ; Mon, 16 May 2022 13:11:15 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id d21so6040884wra.10 for ; Mon, 16 May 2022 13:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=xe4mMWm75qppTGdTaj8uVSs0xTobaeCr6mEjy+hpChU=; b=BrRHLBclhyksWmmDQeO5Dde3HLjdvxO91z+E5JjpFSnOwmN9Y0oOCIarJnGDIIF8tJ UNPOKgAo2frIu7aKi7BNnQ51/5K7wOs0qR0+E1JapPKHA7Twi9ynoD/wjoTiIHEi7bIi gPDfbRoqOiZIZJslNr97gRMyAiEadmRkhpJIFCWrxOdDl49HHOjkJjsJ3F++LezdFQ42 CDAmSI8l4aVpFdWXX5UgINQPSwbpPfBhjm7jgl6rKDHzf8xeyptP1c7TvCqulrZviYlU R2Bca1H1goycR3naPw5tsnY5FIUPmRRH9DJLRX3X8+KF3IE+6JRysO5Xw25LtdnP0ZlX Rg1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=xe4mMWm75qppTGdTaj8uVSs0xTobaeCr6mEjy+hpChU=; b=4hZ4Kl9NhPJvTtVm/5HZgbfy1pNUxLTSTwGeH3ba6dbo+Sc5afdtemVmL2zpuPXFUl ZYYNZ5GfHllPazEbFqUlF3yI8gibfWg7XyBmAjVHrsTe6HPWfNCgxh0vCuiphgWl7Ulx uBGRVnG5yvhHozyWjJb3G7DnUE3/ZlMX//uWrQ9PcklsZ2Y7ehOGQA5+0TDBfQI+1zAc WFHK9x0yt8J113PfXJ9QbcWexLQoA5gXA+yJP7QuL3UvfimUulSd3CxiqbkfUGZ+C060 nP+XHbHXrhJPNe0Awt8y6ep0Cri3GQVM7JeP4QO2wa4xafFZ3ZcmxM2xQg1jrG5VuIYj rU1g== X-Gm-Message-State: AOAM53337lD+7KfSymeWSj1a1LkfNFqveg70NK2EQsvAM3qFFbmXqiCi 8YuVggSH4jGGXaXI8Yby9dUgGkuFjf4= X-Google-Smtp-Source: ABdhPJynyLCTgJrlHAKbwMmNDXV7g2JM10sKMkF1CJ8SPO4zhwyRVz/0el07s79IdJBPpYiuHxEBmQ== X-Received: by 2002:adf:f24d:0:b0:20c:f5a0:be7e with SMTP id b13-20020adff24d000000b0020cf5a0be7emr12547661wrp.344.1652731874150; Mon, 16 May 2022 13:11:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h28-20020adfaa9c000000b0020d02ddf4d5sm3162068wrc.5.2022.05.16.13.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 13:11:13 -0700 (PDT) Message-Id: <47ecf804d9ce58527b55c6217fb3b6928b8feb8f.1652731865.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 May 2022 20:11:02 +0000 Subject: [PATCH 5/8] http: make http_get_file() external Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com, albertqcui@gmail.com, robbat2@gentoo.org, dyroneteng@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee This method will be used in an upcoming extension of git-remote-curl to download a single file over HTTP(S) by request. Signed-off-by: Derrick Stolee --- http.c | 4 ++-- http.h | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/http.c b/http.c index 229da4d1488..04e73149357 100644 --- a/http.c +++ b/http.c @@ -1945,8 +1945,8 @@ int http_get_strbuf(const char *url, * If a previous interrupted download is detected (i.e. a previous temporary * file is still around) the download is resumed. */ -static int http_get_file(const char *url, const char *filename, - struct http_get_options *options) +int http_get_file(const char *url, const char *filename, + struct http_get_options *options) { int ret; struct strbuf tmpfile = STRBUF_INIT; diff --git a/http.h b/http.h index df1590e53a4..ba303cfb372 100644 --- a/http.h +++ b/http.h @@ -163,6 +163,15 @@ struct http_get_options { */ int http_get_strbuf(const char *url, struct strbuf *result, struct http_get_options *options); +/* + * Downloads a URL and stores the result in the given file. + * + * If a previous interrupted download is detected (i.e. a previous temporary + * file is still around) the download is resumed. + */ +int http_get_file(const char *url, const char *filename, + struct http_get_options *options); + int http_fetch_ref(const char *base, struct ref *ref); /* Helpers for fetching packs */ From patchwork Mon May 16 20:11:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12851390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59387C433EF for ; Mon, 16 May 2022 20:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347640AbiEPU3G (ORCPT ); Mon, 16 May 2022 16:29:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348794AbiEPU1t (ORCPT ); Mon, 16 May 2022 16:27:49 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F6F118E3F for ; Mon, 16 May 2022 13:11:17 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id a14-20020a7bc1ce000000b00393fb52a386so232319wmj.1 for ; Mon, 16 May 2022 13:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=rG6jjBs5VSUk2EQErUa63hyA+/r1QGxnxgw3w++B1kw=; b=WOF2dhYKaQAji7j6TxBLwn/fcAIACMkDx+VOdiHHSN0fIaAfNTo3wnn9EW7b1N+Hg0 ws1Sv/Ja+p3OH3F9+9FWlS8IYpJ3Kn6gJMzXhCiWqY/0rdHja9WBw0Lmxigmkzmvx2w7 A4W0DpZ7PJD6KdR8uc8ewGFRCaujzDH8tvuTbzq3fBKo/QW2hc+X4Ojh0R+4mDMnjfzz iDLU2ZkZuCCiejWRb+lgFe7bCBGqGAUh6ke+t3tfQtkPTX2A6Zs+130ymJ00fgFZf0oq j9UAhI+TmU5wtpxHHQNVHgiKJwnt7NZfSkeaFDh4xd+6ebz8AJZE4DN45a6v05lDBQtx pWFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=rG6jjBs5VSUk2EQErUa63hyA+/r1QGxnxgw3w++B1kw=; b=78B7x0M2CZSfFfJuwCJ9h1mjs4WMhAXxFNnFlP7NEbWqjfrszhiBiSSYhTGH3MI2+i aqaoBkxjsmn4vz76V605wgO75S7Q3MaAYApO5WMmwkJDqnMlngOk9XIusaLrAiGS8P4y 96ojh1pzxC93cI8/CEn8Wyw2sVDGDLj+w+HNZGFKn4i43ZakIlICp1nsUDHlZGr8xm0d n3tSKzM8Ai2gidqCv9s8RCW9fSnA4Io57M3Z1gkrqdaTicKF/TKfEAFHHCzyFWKW7Iwx /zT2p7tUmc/05g0on8dMK0dCosyzh02tcT6Psc0BipkQbyftXdGtUdL8YEPNMQbcskJM TCiw== X-Gm-Message-State: AOAM533ya3oH9/8kCv982OFLE8QLTt/+/HY6oRfZQgqY8Gw3MBjSNM07 2AwDauvkvwSDSPvsMiSCfVs5ycK3PXU= X-Google-Smtp-Source: ABdhPJxn7TB1mobK35L8NKrLB9lSFX02J+LjUzM0+Vucacck2ihscgxgywXHFYxEDnebb83EnYNBrA== X-Received: by 2002:a05:600c:365a:b0:394:58e:6a5c with SMTP id y26-20020a05600c365a00b00394058e6a5cmr27994198wmq.122.1652731875371; Mon, 16 May 2022 13:11:15 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i7-20020adfa507000000b0020d012692dbsm7751003wrb.18.2022.05.16.13.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 13:11:14 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 16 May 2022 20:11:03 +0000 Subject: [PATCH 6/8] remote: move relative_url() MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com, albertqcui@gmail.com, robbat2@gentoo.org, dyroneteng@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee This method was initially written in 63e95beb0 (submodule: port resolve_relative_url from shell to C, 2016-05-15). As we will need similar functionality in the bundle URI feature, extract this to be available in remote.h. The code is almost exactly the same, except for the following trivial differences: * Fix whitespace and wrapping issues with the prototype and argument lists. * Let's call starts_with_dot_{,dot_}slash_native() instead of the functionally identical "starts_with_dot_{,dot_}slash()" wrappers "builtin/submodule--helper.c". Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee --- builtin/submodule--helper.c | 141 +++--------------------------------- remote.c | 91 +++++++++++++++++++++++ remote.h | 31 ++++++++ 3 files changed, 134 insertions(+), 129 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b68102bb3ed..86f38e489b0 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -72,135 +72,6 @@ static char *get_default_remote(void) return repo_get_default_remote(the_repository); } -/* - * Returns 1 if it was the last chop before ':'. - */ -static int chop_last_dir(char **remoteurl, int is_relative) -{ - char *rfind = find_last_dir_sep(*remoteurl); - if (rfind) { - *rfind = '\0'; - return 0; - } - - rfind = strrchr(*remoteurl, ':'); - if (rfind) { - *rfind = '\0'; - return 1; - } - - if (is_relative || !strcmp(".", *remoteurl)) - die(_("cannot strip one component off url '%s'"), - *remoteurl); - - free(*remoteurl); - *remoteurl = xstrdup("."); - return 0; -} - -static int starts_with_dot_slash(const char *const path) -{ - return starts_with_dot_slash_native(path);; -} - -static int starts_with_dot_dot_slash(const char *const path) -{ - return starts_with_dot_dot_slash_native(path); -} - -/* - * The `url` argument is the URL that navigates to the submodule origin - * repo. When relative, this URL is relative to the superproject origin - * URL repo. The `up_path` argument, if specified, is the relative - * path that navigates from the submodule working tree to the superproject - * working tree. Returns the origin URL of the submodule. - * - * Return either an absolute URL or filesystem path (if the superproject - * origin URL is an absolute URL or filesystem path, respectively) or a - * relative file system path (if the superproject origin URL is a relative - * file system path). - * - * When the output is a relative file system path, the path is either - * relative to the submodule working tree, if up_path is specified, or to - * the superproject working tree otherwise. - * - * NEEDSWORK: This works incorrectly on the domain and protocol part. - * remote_url url outcome expectation - * http://a.com/b ../c http://a.com/c as is - * http://a.com/b/ ../c http://a.com/c same as previous line, but - * ignore trailing slash in url - * http://a.com/b ../../c http://c error out - * http://a.com/b ../../../c http:/c error out - * http://a.com/b ../../../../c http:c error out - * http://a.com/b ../../../../../c .:c error out - * NEEDSWORK: Given how chop_last_dir() works, this function is broken - * when a local part has a colon in its path component, too. - */ -static char *relative_url(const char *remote_url, - const char *url, - const char *up_path) -{ - int is_relative = 0; - int colonsep = 0; - char *out; - char *remoteurl = xstrdup(remote_url); - struct strbuf sb = STRBUF_INIT; - size_t len = strlen(remoteurl); - - if (is_dir_sep(remoteurl[len-1])) - remoteurl[len-1] = '\0'; - - if (!url_is_local_not_ssh(remoteurl) || is_absolute_path(remoteurl)) - is_relative = 0; - else { - is_relative = 1; - /* - * Prepend a './' to ensure all relative - * remoteurls start with './' or '../' - */ - if (!starts_with_dot_slash(remoteurl) && - !starts_with_dot_dot_slash(remoteurl)) { - strbuf_reset(&sb); - strbuf_addf(&sb, "./%s", remoteurl); - free(remoteurl); - remoteurl = strbuf_detach(&sb, NULL); - } - } - /* - * When the url starts with '../', remove that and the - * last directory in remoteurl. - */ - while (url) { - if (starts_with_dot_dot_slash(url)) { - url += 3; - colonsep |= chop_last_dir(&remoteurl, is_relative); - } else if (starts_with_dot_slash(url)) - url += 2; - else - break; - } - strbuf_reset(&sb); - strbuf_addf(&sb, "%s%s%s", remoteurl, colonsep ? ":" : "/", url); - if (ends_with(url, "/")) - strbuf_setlen(&sb, sb.len - 1); - free(remoteurl); - - if (starts_with_dot_slash(sb.buf)) - out = xstrdup(sb.buf + 2); - else - out = xstrdup(sb.buf); - - if (!up_path || !is_relative) { - strbuf_release(&sb); - return out; - } - - strbuf_reset(&sb); - strbuf_addf(&sb, "%s%s", up_path, out); - free(out); - return strbuf_detach(&sb, NULL); -} - static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet) { char *remoteurl, *resolved_url; @@ -592,6 +463,18 @@ static int module_foreach(int argc, const char **argv, const char *prefix) return 0; } +static int starts_with_dot_slash(const char *const path) +{ + return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_SLASH | + PATH_MATCH_XPLATFORM); +} + +static int starts_with_dot_dot_slash(const char *const path) +{ + return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH | + PATH_MATCH_XPLATFORM); +} + struct init_cb { const char *prefix; const char *superprefix; diff --git a/remote.c b/remote.c index 42a4e7106e1..87656138645 100644 --- a/remote.c +++ b/remote.c @@ -14,6 +14,7 @@ #include "strvec.h" #include "commit-reach.h" #include "advice.h" +#include "connect.h" enum map_direction { FROM_SRC, FROM_DST }; @@ -2727,3 +2728,93 @@ void remote_state_clear(struct remote_state *remote_state) hashmap_clear_and_free(&remote_state->remotes_hash, struct remote, ent); hashmap_clear_and_free(&remote_state->branches_hash, struct remote, ent); } + +/* + * Returns 1 if it was the last chop before ':'. + */ +static int chop_last_dir(char **remoteurl, int is_relative) +{ + char *rfind = find_last_dir_sep(*remoteurl); + if (rfind) { + *rfind = '\0'; + return 0; + } + + rfind = strrchr(*remoteurl, ':'); + if (rfind) { + *rfind = '\0'; + return 1; + } + + if (is_relative || !strcmp(".", *remoteurl)) + die(_("cannot strip one component off url '%s'"), + *remoteurl); + + free(*remoteurl); + *remoteurl = xstrdup("."); + return 0; +} + +char *relative_url(const char *remote_url, const char *url, + const char *up_path) +{ + int is_relative = 0; + int colonsep = 0; + char *out; + char *remoteurl = xstrdup(remote_url); + struct strbuf sb = STRBUF_INIT; + size_t len = strlen(remoteurl); + + if (is_dir_sep(remoteurl[len-1])) + remoteurl[len-1] = '\0'; + + if (!url_is_local_not_ssh(remoteurl) || is_absolute_path(remoteurl)) + is_relative = 0; + else { + is_relative = 1; + /* + * Prepend a './' to ensure all relative + * remoteurls start with './' or '../' + */ + if (!starts_with_dot_slash_native(remoteurl) && + !starts_with_dot_dot_slash_native(remoteurl)) { + strbuf_reset(&sb); + strbuf_addf(&sb, "./%s", remoteurl); + free(remoteurl); + remoteurl = strbuf_detach(&sb, NULL); + } + } + /* + * When the url starts with '../', remove that and the + * last directory in remoteurl. + */ + while (url) { + if (starts_with_dot_dot_slash_native(url)) { + url += 3; + colonsep |= chop_last_dir(&remoteurl, is_relative); + } else if (starts_with_dot_slash_native(url)) + url += 2; + else + break; + } + strbuf_reset(&sb); + strbuf_addf(&sb, "%s%s%s", remoteurl, colonsep ? ":" : "/", url); + if (ends_with(url, "/")) + strbuf_setlen(&sb, sb.len - 1); + free(remoteurl); + + if (starts_with_dot_slash_native(sb.buf)) + out = xstrdup(sb.buf + 2); + else + out = xstrdup(sb.buf); + + if (!up_path || !is_relative) { + strbuf_release(&sb); + return out; + } + + strbuf_reset(&sb); + strbuf_addf(&sb, "%s%s", up_path, out); + free(out); + return strbuf_detach(&sb, NULL); +} diff --git a/remote.h b/remote.h index 4a1209ae2c8..f18fd27e530 100644 --- a/remote.h +++ b/remote.h @@ -409,4 +409,35 @@ int parseopt_push_cas_option(const struct option *, const char *arg, int unset); int is_empty_cas(const struct push_cas_option *); void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *); +/* + * The `url` argument is the URL that navigates to the submodule origin + * repo. When relative, this URL is relative to the superproject origin + * URL repo. The `up_path` argument, if specified, is the relative + * path that navigates from the submodule working tree to the superproject + * working tree. Returns the origin URL of the submodule. + * + * Return either an absolute URL or filesystem path (if the superproject + * origin URL is an absolute URL or filesystem path, respectively) or a + * relative file system path (if the superproject origin URL is a relative + * file system path). + * + * When the output is a relative file system path, the path is either + * relative to the submodule working tree, if up_path is specified, or to + * the superproject working tree otherwise. + * + * NEEDSWORK: This works incorrectly on the domain and protocol part. + * remote_url url outcome expectation + * http://a.com/b ../c http://a.com/c as is + * http://a.com/b/ ../c http://a.com/c same as previous line, but + * ignore trailing slash in url + * http://a.com/b ../../c http://c error out + * http://a.com/b ../../../c http:/c error out + * http://a.com/b ../../../../c http:c error out + * http://a.com/b ../../../../../c .:c error out + * NEEDSWORK: Given how chop_last_dir() works, this function is broken + * when a local part has a colon in its path component, too. + */ +char *relative_url(const char *remote_url, const char *url, + const char *up_path); + #endif From patchwork Mon May 16 20:11:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12851391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F973C433FE for ; Mon, 16 May 2022 20:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242120AbiEPU3K (ORCPT ); Mon, 16 May 2022 16:29:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347638AbiEPU1y (ORCPT ); Mon, 16 May 2022 16:27:54 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6595819020 for ; Mon, 16 May 2022 13:11:18 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id t6so21974978wra.4 for ; Mon, 16 May 2022 13:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=IA0kKKKs58LIhalOyAIitJlhv4C2akwYJCreZK372cs=; b=PsWcx4bTdpEGftHbQ1Oin9aOBwzLrraQQYDDeUlgQRm8fOe6aUh1DNa+EXhZTtusn1 tqCNtl0LYt2cAEG2ybbY73vJKmy1V8Ot7CA/3mM+jJRoky60sYKOufnCUhNn446qnnlv YPXnxBg/nk70V6iwHFBSWkyGDbPbEQbhgwUrRxiFbIeEEXcBcJ6Zp+Ninun+yMewJr5E mZXMSrjSd/hr8XwoHSK0Ff95lWKtzlnOfyOJ7BkeluQay+MkvfbgSSTZJWckBgXsAZiR YcfDKFDZ1kEJL/11eUVoDfcN+C9g8eXuwoyT4CL2fe3dokF3OfM0c7hVbZ5pcn3SMP4N pKgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=IA0kKKKs58LIhalOyAIitJlhv4C2akwYJCreZK372cs=; b=toXIxInVjVgMUgWV2/7NqWg2e+2QDkLrRxKJ2ADksuAHnatGpHZDhpcCtuLsekxuUs baK9/O2vjVMQ61qyolU/k3GyUt3FkOsg+0DSMV5Vjq/LPrNkXKhs1pCn72yCLhkayg/1 sEHm0n4/CG7zdNbFopnsczs4/TjYewCBJd1XWwq6zlCSGQRAZirLlMAtBPyiOFBvBwsJ 5nQF9TZHGOxOflynsIF+eHZ8tZpC8eFDsMI9wMcrSE6J1UvnCMyfYJeumIOwGQun88tv 2iSfLiBam4UeZbKAsHbKB7tsmawY/Hjf6Alk0fneqkiV6P17/l6LCQBHrNi/1m0IQB4e Uflw== X-Gm-Message-State: AOAM533YGOjobdMe/IKN2/YT33Jkvn28uOH2ovebZTslkTcfwh5g/qHD Y1R2gRTcECkN6ets4uos5ZbnUYHeeyw= X-Google-Smtp-Source: ABdhPJzz76MXt7AsUhzTAAhnQ+Znv9TVE/mhO7yX3/le03v/8zRUN/LDU1/UtPDEASHKrOhbA/btrw== X-Received: by 2002:a5d:4529:0:b0:20d:1108:8d76 with SMTP id j9-20020a5d4529000000b0020d11088d76mr2596723wra.60.1652731876636; Mon, 16 May 2022 13:11:16 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n6-20020a05600c500600b00395b809dfd3sm224250wmr.12.2022.05.16.13.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 13:11:16 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 16 May 2022 20:11:04 +0000 Subject: [PATCH 7/8] remote: allow relative_url() to return an absolute url MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com, albertqcui@gmail.com, robbat2@gentoo.org, dyroneteng@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When the 'url' parameter was absolute, the previous implementation would concatenate 'remote_url' with 'url'. Instead, we want to return 'url' in this case. The documentation now discusses what happens when supplying two absolute URLs. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee --- remote.c | 12 ++++++++++-- remote.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/remote.c b/remote.c index 87656138645..7576f673fcd 100644 --- a/remote.c +++ b/remote.c @@ -2761,10 +2761,18 @@ char *relative_url(const char *remote_url, const char *url, int is_relative = 0; int colonsep = 0; char *out; - char *remoteurl = xstrdup(remote_url); + char *remoteurl; struct strbuf sb = STRBUF_INIT; - size_t len = strlen(remoteurl); + size_t len; + + if (!url_is_local_not_ssh(url) || is_absolute_path(url)) + return xstrdup(url); + + len = strlen(remote_url); + if (!len) + BUG("invalid empty remote_url"); + remoteurl = xstrdup(remote_url); if (is_dir_sep(remoteurl[len-1])) remoteurl[len-1] = '\0'; diff --git a/remote.h b/remote.h index f18fd27e530..dd4402436f1 100644 --- a/remote.h +++ b/remote.h @@ -434,6 +434,7 @@ void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *); * http://a.com/b ../../../c http:/c error out * http://a.com/b ../../../../c http:c error out * http://a.com/b ../../../../../c .:c error out + * http://a.com/b http://d.org/e http://d.org/e as is * NEEDSWORK: Given how chop_last_dir() works, this function is broken * when a local part has a colon in its path component, too. */ From patchwork Mon May 16 20:11:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12851392 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F18F3C433EF for ; Mon, 16 May 2022 20:29:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347101AbiEPU3N (ORCPT ); Mon, 16 May 2022 16:29:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348837AbiEPU1z (ORCPT ); Mon, 16 May 2022 16:27:55 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29E6F1928A for ; Mon, 16 May 2022 13:11:20 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id p189so9344817wmp.3 for ; Mon, 16 May 2022 13:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=U/r/9EV8L9YP7PY4ue/BiQabkdglT5aaqWXkZsxe3Uo=; b=q0LfEFXNHlTRxWEQXN+Un3Yik5mr9+fPuUzP2DqxwWsOT1EO9vVq4sEVkE2/9OTJsj 1ERld5Ev+WYyemr0LzER/0w7uQS3pwdFrHQNvVQrPfR14lRYKvtP3A8DnxFqMSYd7GdN lcYuLI6psugXXfPPqH+bQJBBUi+N/a2R6pXmhMhou9zGrRI75cRS/8DUv2jwCDE3n6Fh g0Wt0f9KWOdkhznEXtiRHzTCg6Y3ud+K3oLNaubP1qWrf6BO4GTW/UsvhApykV2iWG1M Xa8ohnQysIask8ESnjgZkQFHnF6dgFvPt2fF5eDPx9V3QGcBCNRSOKTMQCo6+XgbU3II 4aZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=U/r/9EV8L9YP7PY4ue/BiQabkdglT5aaqWXkZsxe3Uo=; b=e/dprYB312BFl14g5g6ZUrGdkeaP1JirkiJvhwfWMrC+NaMZ4CdTYCGdAUuXRhJjCy 5xp82bcXIBBJ8Wshve5ecanPfqO+JT/2W+W/qgcwNJsOZgoxGiELLfLUdOVM6ri+LTeJ T4z0RA1SFzBoSlHCbeS0h3ZXmysa7l8TZHPglxTIiSMR+cbtDO6teLNdA3wt0K8t050p e2lV/jiIvY7SSnE15dHEpaFG3ipyB0nFcfazuS7ZSqGZjTbm3N7Sbs1kPDggESuxlpHi SxJiOCC0pPZGqOGq0SpYuP7iUXtTv6itMN6g1Afeq/b5eC3OdQMTAENaxjizkh4Urv8s sx2Q== X-Gm-Message-State: AOAM533IydGx6HRS5gd4M53wfrkSpcupowXk1Tuzp1dLbUXqesLOI8Q+ rkJi1xiOeRYBs10qnNAct2JJPoXJWOQ= X-Google-Smtp-Source: ABdhPJyDkcAdspidqRaZqbe66YjHG2f3//vpRRSEhGQHeejwQObJlDb6tl/gsnzEGYUizQ5o3MW6Ww== X-Received: by 2002:a05:600c:4f15:b0:394:8ea0:bb45 with SMTP id l21-20020a05600c4f1500b003948ea0bb45mr18355125wmq.206.1652731878351; Mon, 16 May 2022 13:11:18 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x3-20020a1c7c03000000b0039482d95ab7sm187206wmc.24.2022.05.16.13.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 13:11:17 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 16 May 2022 20:11:05 +0000 Subject: [PATCH 8/8] bundle.h: make "fd" version of read_bundle_header() public MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com, albertqcui@gmail.com, robbat2@gentoo.org, dyroneteng@gmail.com, Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Change the parse_bundle_header() function to be non-static, and rename it to parse_bundle_header_fd(). The parse_bundle_header() function is already public, and it's a thin wrapper around this function. This will be used by code that wants to pass a fd to the bundle API. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee --- bundle.c | 8 ++++---- bundle.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bundle.c b/bundle.c index d50cfb5aa7e..5fa41a52f11 100644 --- a/bundle.c +++ b/bundle.c @@ -66,8 +66,8 @@ static int parse_bundle_signature(struct bundle_header *header, const char *line return -1; } -static int parse_bundle_header(int fd, struct bundle_header *header, - const char *report_path) +int read_bundle_header_fd(int fd, struct bundle_header *header, + const char *report_path) { struct strbuf buf = STRBUF_INIT; int status = 0; @@ -143,7 +143,7 @@ int read_bundle_header(const char *path, struct bundle_header *header) if (fd < 0) return error(_("could not open '%s'"), path); - return parse_bundle_header(fd, header, path); + return read_bundle_header_fd(fd, header, path); } int is_bundle(const char *path, int quiet) @@ -153,7 +153,7 @@ int is_bundle(const char *path, int quiet) if (fd < 0) return 0; - fd = parse_bundle_header(fd, &header, quiet ? NULL : path); + fd = read_bundle_header_fd(fd, &header, quiet ? NULL : path); if (fd >= 0) close(fd); bundle_header_release(&header); diff --git a/bundle.h b/bundle.h index 7fef2108f43..0c052f54964 100644 --- a/bundle.h +++ b/bundle.h @@ -24,6 +24,8 @@ void bundle_header_release(struct bundle_header *header); int is_bundle(const char *path, int quiet); int read_bundle_header(const char *path, struct bundle_header *header); +int read_bundle_header_fd(int fd, struct bundle_header *header, + const char *report_path); int create_bundle(struct repository *r, const char *path, int argc, const char **argv, struct strvec *pack_options, int version);