From patchwork Fri Sep 21 18:47:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10610859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE9A01390 for ; Fri, 21 Sep 2018 18:47:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCC4A2E705 for ; Fri, 21 Sep 2018 18:47:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFD3D2E723; Fri, 21 Sep 2018 18:47:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DC8B2E705 for ; Fri, 21 Sep 2018 18:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391238AbeIVAhx (ORCPT ); Fri, 21 Sep 2018 20:37:53 -0400 Received: from mail-io1-f54.google.com ([209.85.166.54]:33993 "EHLO mail-io1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732114AbeIVAhx (ORCPT ); Fri, 21 Sep 2018 20:37:53 -0400 Received: by mail-io1-f54.google.com with SMTP id h16-v6so2862954ioj.1 for ; Fri, 21 Sep 2018 11:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EWXslfzsnnkgUJ8j3E31KFzjrP+4XmJGMGdcLdnXBxo=; b=ZqkYvDfIQhon1UdX6PiypF3Xfzx+CgooKPPasOiG3Hkegd1uicXglldrv/U8LUP02C PiW833aBdzWkmpfxPdwsdudEHKP8vjAS+fap48zNcCTkSzjJmt9vD8RHJNaJCU4MvGqn 8Q9b03NIPXxm0bFgbICtRGuPpqx1jeLY8PaHKvLHGU26yrdDjjPF/9rbPq17rB48sq7U aWRY65RIj+GYAQdo5renEU35BFcGOYvwLd9Zu2J8YgLVcbcWrcuEy6go+UnNCFfKfC10 i7TsFxuU1ZN7a+R6xhxuxx9mUvEtSc7J9KIN5+PBi9ADS83Em7ht0D3ZWbuYIsJKdrFi bDJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=EWXslfzsnnkgUJ8j3E31KFzjrP+4XmJGMGdcLdnXBxo=; b=rHrFN8UGQm2KR82V0yp4QACq72u/DXZagAwz2NvkiFe8pP6j6ARYEbsUkIXRbbntca LZFhMcrW/cwusQChNF+JDhCUs5iVKFRAlJqzJU03gLwWjQRP6sAWvgZbVZ0Sv6uzMP15 BKgDtDKJpjYPaw5Nqpb3gJGABsp07aZuDoftn69YdLYBDIrbTN3z+CDsaBm1dW6+FGMj WKc//rz5z8IrUR3T4JAket3JqSPwiUUwO9VLvI737IDMUr5ZBN9U2g+5O7+chx8Eb7C0 +moluv+D+I+eMjRVR7JIi8PRQLe4gQivqMGd18LuGeLyoZwImgxANMT2TPPHeVdCXIEt 38qg== X-Gm-Message-State: ABuFfohaqjxxVKEwKmvrydpqZyeZxM8RavKrge3VGOPG4akLtjN2Cu6j OTNTGwo2UfQdIYsGcmUp+pyiSvVinG4= X-Google-Smtp-Source: ACcGV60NrTBJTfdFWEFxf69tIzRLXOU53GJmvvBezUabq01ysS72jv0PNY0CvrOS6q9a3jHQ04RBdw== X-Received: by 2002:a6b:9b42:: with SMTP id d63-v6mr6006298ioe.183.1537555662422; Fri, 21 Sep 2018 11:47:42 -0700 (PDT) Received: from localhost ([173.225.52.220]) by smtp.gmail.com with ESMTPSA id v3-v6sm2833692ita.6.2018.09.21.11.47.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 11:47:41 -0700 (PDT) Date: Fri, 21 Sep 2018 14:47:39 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com Subject: [PATCH v2 1/3] transport.c: extract 'fill_alternate_refs_command' Message-ID: <6e3a58afe7cd18d663f481cdc9eb65cc941765b1.1537555544.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To list alternate references, 'read_alternate_refs' creates a child process running 'git for-each-ref' in the alternate's Git directory. Prepare to run other commands besides 'git for-each-ref' by introducing and moving the relevant code from 'read_alternate_refs' to 'fill_alternate_refs_command'. Signed-off-by: Taylor Blau --- transport.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/transport.c b/transport.c index 1c76d64aba..24ae3f375d 100644 --- a/transport.c +++ b/transport.c @@ -1325,6 +1325,17 @@ char *transport_anonymize_url(const char *url) return xstrdup(url); } +static void fill_alternate_refs_command(struct child_process *cmd, + const char *repo_path) +{ + cmd->git_cmd = 1; + argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path); + argv_array_push(&cmd->args, "for-each-ref"); + argv_array_push(&cmd->args, "--format=%(objectname) %(refname)"); + cmd->env = local_repo_env; + cmd->out = -1; +} + static void read_alternate_refs(const char *path, alternate_ref_fn *cb, void *data) @@ -1333,12 +1344,7 @@ static void read_alternate_refs(const char *path, struct strbuf line = STRBUF_INIT; FILE *fh; - cmd.git_cmd = 1; - argv_array_pushf(&cmd.args, "--git-dir=%s", path); - argv_array_push(&cmd.args, "for-each-ref"); - argv_array_push(&cmd.args, "--format=%(objectname) %(refname)"); - cmd.env = local_repo_env; - cmd.out = -1; + fill_alternate_refs_command(&cmd, path); if (start_command(&cmd)) return; From patchwork Fri Sep 21 18:47:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10610861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21F375A4 for ; Fri, 21 Sep 2018 18:47:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DF512E705 for ; Fri, 21 Sep 2018 18:47:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F420E2E723; Fri, 21 Sep 2018 18:47:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 675662E705 for ; Fri, 21 Sep 2018 18:47:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391248AbeIVAh5 (ORCPT ); Fri, 21 Sep 2018 20:37:57 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:38988 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732114AbeIVAh5 (ORCPT ); Fri, 21 Sep 2018 20:37:57 -0400 Received: by mail-it1-f194.google.com with SMTP id h1-v6so3066703itj.4 for ; Fri, 21 Sep 2018 11:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=uwBRAdsZiCrfA7VTi0AOd1WYGt6uOM8bI/XpTa2DQ1U=; b=PnzqZij28/AUkCFwmVUL64uCOai/DEnlll7Pp+fkYR6bGYBTed4XezJqiyXYBZMoxd Vk5X9ML1tT17TSoacdIMbin3wGWx55uPUthFzTL+mHFLG2IS/y9FuFr4xeTmAWGsbO5X sLXAYGSwc71S/KfF5jU5aXNmrGxXexXJLG80MVnpg3yVJhD0awDEV1sYbMM6WNYnq97k b4/PTLDP5mQO4p5m6bSpGSx3xTErDGcgel0aYdcwap5f3aHvcWcQKhHJDqMP+ftnyLom xGtveIMAHsFfleypYHQMUvofko2A2IFUej5CsvRgAvpbZoPzrnDmZEZryrSU5T5ZCKwI 8B0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=uwBRAdsZiCrfA7VTi0AOd1WYGt6uOM8bI/XpTa2DQ1U=; b=giYCLoHEycllv9+z6uUSJDLZa4JJqLizYns4cFSf15+rNUYBevHM0WLrXCxy9SpIv9 sFQmrtj1UySDnucQaYGoTdOfcTEw6mbHPLHZJmpeRNItFhHJz8fIysSe9llfwwHD3Aeb MvofxpfN9IlwXdmC02yMq1+g2LytdgWr55XnoIo6N3UJXsFMcn0diOZDaLKwZyM6yJa6 /meTEy8QmbJ+3rpsON0Xlpv4spGrAQJwxwSHXgaoA7Hl727WuJUp+X4j1guqT2Z0Lf4S G9mPN/Abx+1/tcojxC6f3oWPRzCYkdFUmfm+14eOXugu9XlFM1w7k4/B2Ch6yJb9L29G 0nUA== X-Gm-Message-State: APzg51A64nkqDNK2ioAghKpPiJjTLyFLtTZz0T3hxkGwNrRwJuv4BqBa TySnBkG4vJcTqWcLTHWjnQWn6PXA4JA= X-Google-Smtp-Source: ANB0VdZoWr5O6b/oXkFbKpozp8iafxetMEDIM2MO911oeGTmmuKd/FVg0S41b5IG3yEIk4q37dHC+g== X-Received: by 2002:a02:702:: with SMTP id f2-v6mr42463108jaf.70.1537555665126; Fri, 21 Sep 2018 11:47:45 -0700 (PDT) Received: from localhost ([173.225.52.220]) by smtp.gmail.com with ESMTPSA id 68-v6sm977162iou.88.2018.09.21.11.47.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 11:47:44 -0700 (PDT) Date: Fri, 21 Sep 2018 14:47:43 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com Subject: [PATCH v2 2/3] transport.c: introduce core.alternateRefsCommand Message-ID: <9797f525517142b3494cfbd17a10dfeb3bf586e2.1537555544.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When in a repository containing one or more alternates, Git would sometimes like to list references from its alternates. For example, 'git receive-pack' list the objects pointed to by alternate references as special ".have" references. Listing ".have" references is designed to make pushing changes from upstream to a fork a lightweight operation, by advertising to the pusher that the fork already has the objects (via its alternate). Thus, the client can avoid sending them. However, when the alternate has a pathologically large number of references, the initial advertisement is too expensive. In fact, it can dominate any such optimization where the pusher avoids sending certain objects. Introduce "core.alternateRefsCommand" in order to provide a facility to limit or filter alternate references. This can be used, for example, to filter out "uninteresting" references from the initial advertisement in the above scenario. Let the repository that has alternates configure this command to avoid trusting the alternate to provide us a safe command to run in the shell. To behave differently on each alternate (e.g., only list tags from alternate A, only heads from B) provide the path of the alternate as the first argument. Signed-off-by: Taylor Blau --- Documentation/config.txt | 11 ++++++++ t/t5410-receive-pack.sh | 54 ++++++++++++++++++++++++++++++++++++++++ transport.c | 19 +++++++++++--- 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100755 t/t5410-receive-pack.sh diff --git a/Documentation/config.txt b/Documentation/config.txt index 112041f407..526557e494 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -616,6 +616,17 @@ core.preferSymlinkRefs:: This is sometimes needed to work with old scripts that expect HEAD to be a symbolic link. +core.alternateRefsCommand:: + When listing references from an alternate (e.g., in the case of ".have"), use + the shell to execute the specified command instead of + linkgit:git-for-each-ref[1]. The first argument is the path of the alternate. + Output must be of the form: `%(objectname) SPC %(refname)`. ++ +This is useful when a repository only wishes to advertise some of its +alternate's references as ".have"'s. For example, to only advertise branch +heads, configure `core.alternateRefsCommand` to the path of a script which runs +`git --git-dir="$1" for-each-ref refs/heads`. + core.bare:: If true this repository is assumed to be 'bare' and has no working directory associated with it. If this is the case a diff --git a/t/t5410-receive-pack.sh b/t/t5410-receive-pack.sh new file mode 100755 index 0000000000..2f21f1cb8f --- /dev/null +++ b/t/t5410-receive-pack.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +test_description='git receive-pack test' + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit one && + git update-ref refs/heads/a HEAD && + test_commit two && + git update-ref refs/heads/b HEAD && + test_commit three && + git update-ref refs/heads/c HEAD && + git clone --bare . fork && + git clone fork pusher && + ( + cd fork && + git config receive.advertisealternates true && + cat <<-EOF | git update-ref --stdin && + delete refs/heads/a + delete refs/heads/b + delete refs/heads/c + delete refs/heads/master + delete refs/tags/one + delete refs/tags/two + delete refs/tags/three + EOF + echo "../../.git/objects" >objects/info/alternates + ) +' + +expect_haves () { + printf "%s .have\n" $(git rev-parse $@) >expect +} + +extract_haves () { + depacketize - | grep '\.have' | sed -e 's/\\0.*$//g' +} + +test_expect_success 'with core.alternateRefsCommand' ' + write_script fork/alternate-refs <<-\EOF && + git --git-dir="$1" for-each-ref \ + --format="%(objectname) %(refname)" \ + refs/heads/a \ + refs/heads/c + EOF + test_config -C fork core.alternateRefsCommand alternate-refs && + expect_haves a c >expect && + printf "0000" | git receive-pack fork >actual && + extract_haves actual.haves && + test_cmp expect actual.haves +' + +test_done diff --git a/transport.c b/transport.c index 24ae3f375d..e7d2cdf00b 100644 --- a/transport.c +++ b/transport.c @@ -1328,10 +1328,21 @@ char *transport_anonymize_url(const char *url) static void fill_alternate_refs_command(struct child_process *cmd, const char *repo_path) { - cmd->git_cmd = 1; - argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path); - argv_array_push(&cmd->args, "for-each-ref"); - argv_array_push(&cmd->args, "--format=%(objectname) %(refname)"); + const char *value; + + if (!git_config_get_value("core.alternateRefsCommand", &value)) { + cmd->use_shell = 1; + + argv_array_push(&cmd->args, value); + argv_array_push(&cmd->args, repo_path); + } else { + cmd->git_cmd = 1; + + argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path); + argv_array_push(&cmd->args, "for-each-ref"); + argv_array_push(&cmd->args, "--format=%(objectname) %(refname)"); + } + cmd->env = local_repo_env; cmd->out = -1; } From patchwork Fri Sep 21 18:47:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10610863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E84E1390 for ; Fri, 21 Sep 2018 18:47:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B48A2E705 for ; Fri, 21 Sep 2018 18:47:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F8732E723; Fri, 21 Sep 2018 18:47:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13C6F2E705 for ; Fri, 21 Sep 2018 18:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391253AbeIVAh7 (ORCPT ); Fri, 21 Sep 2018 20:37:59 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:40644 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391243AbeIVAh6 (ORCPT ); Fri, 21 Sep 2018 20:37:58 -0400 Received: by mail-it1-f194.google.com with SMTP id h23-v6so3068226ita.5 for ; Fri, 21 Sep 2018 11:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DQeShH8Z6dTYiTO3fW9HmuaF28YFRisVcTLwHCxx5BA=; b=cxvcKJZ0CKXTYu77P972vOMk3sV+xjFUp7vXSvl+Kz8I05TWetGl4tYu8FkT/sMhDU J8aTNq1hrcJV+Uq1geZNiAw1P9WInmnDxWFPYL7qMtI99ezDMgscXWf/gVGzZDrIzi/O Wv5XNEYDWbnCXXHOKAivT8vElgLNqW9qdX9ys1dcmnDjb5SGyRuO8DcyX3xT/d+k4q4Z glEdwWl5UdcRpBhcWme3dG5ic9uZnabULkA0X0iuLhASuW8Jx0M8dBq+VmDlJdcpcCbt fBNmQQM7Dq++B/R2Vj1BKdd2U7nN0ye5A/ZGWBcMxye2yKWDF58/gWgx2nJrXuAsM3Vh bGWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=DQeShH8Z6dTYiTO3fW9HmuaF28YFRisVcTLwHCxx5BA=; b=gw7YnkMU6SO2PL4UpvN2wnYKLXqpK2dJ+4F8b5clBzXinE69NWMoat+HH+dTpduEkv ati3tta4gpuI2N+InkpUPOo2e3ASsL5AYgYF3uOqdneTyRvGPlT2T9Ws3MVUa/0oLMfi cc2M8rOZyv9uRlRB+ugpbdjDOdNKlUv3G6YpZCltWDI47nppkX8qsNIldWRMp49VhZ88 I0vgJM7ctUehz6z58kgQH6tfCPjTggZq8tfEfGhNlk8fF+sLr2NumR7kU9+dDuDq7wUH nC3MnXu3FsM8Fz58C46m4gqvdJUmWGQeRay8HMbkkUDMr7kkevZRWiG6p2mtHJ3bbjy4 em/A== X-Gm-Message-State: APzg51BGi9LW25dnbOpfSuxxh9BQ5w6ZDNYLu/kecQVsMWT3x0oZRRxm sAyZSQrW0QWI/wD1IvAz2WIQGAEK4z0= X-Google-Smtp-Source: ANB0VdYUkpk0PKxNesLSMC7+6lAyHNDTqOKHtfj/IkN2bdbXQMX8n2oRPrZM0Sc5k6+Nc13v6hGuvw== X-Received: by 2002:a02:6552:: with SMTP id u79-v6mr5445273jab.102.1537555668218; Fri, 21 Sep 2018 11:47:48 -0700 (PDT) Received: from localhost ([173.225.52.220]) by smtp.gmail.com with ESMTPSA id q196-v6sm10336716iod.23.2018.09.21.11.47.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 11:47:46 -0700 (PDT) Date: Fri, 21 Sep 2018 14:47:45 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com Subject: [PATCH v2 3/3] transport.c: introduce core.alternateRefsPrefixes Message-ID: <6e8f65a16dc0be84234d2be93bb4a5c9a585dd57.1537555544.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The recently-introduced "core.alternateRefsCommand" allows callers to specify with high flexibility the tips that they wish to advertise from alternates. This flexibility comes at the cost of some inconvenience when the caller only wishes to limit the advertisement to one or more prefixes. For example, to advertise only tags, a caller using 'core.alternateRefsCommand' would have to do: $ git config core.alternateRefsCommand ' \ git -C "$1" for-each-ref refs/tags \ --format="%(objectname) %(refname)" \ ' The above is cumbersome to write, so let's introduce a "core.alternateRefsPrefixes" to address this common case. Instead, the caller can run: $ git config core.alternateRefsPrefixes 'refs/tags' Which will behave identically to the longer example using "core.alternateRefsCommand". Since the value of "core.alternateRefsPrefixes" is appended to 'git for-each-ref' and then executed, include a "--" before taking the configured value to avoid misinterpreting arguments as flags to 'git for-each-ref'. In the case that the caller wishes to specify multiple prefixes, they may separate them by whitespace. If "core.alternateRefsCommand" is set, it will take precedence over "core.alternateRefsPrefixes". Signed-off-by: Taylor Blau Signed-off-by: Jeff King --- Documentation/config.txt | 7 +++++++ t/t5410-receive-pack.sh | 8 ++++++++ transport.c | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index 526557e494..7df6c22925 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -627,6 +627,13 @@ alternate's references as ".have"'s. For example, to only advertise branch heads, configure `core.alternateRefsCommand` to the path of a script which runs `git --git-dir="$1" for-each-ref refs/heads`. +core.alternateRefsPrefixes:: + When listing references from an alternate, list only references that begin + with the given prefix. Prefixes match as if they were given as arguments to + linkgit:git-for-each-ref[1]. To list multiple prefixes, separate them with + whitespace. If `core.alternateRefsCommand` is set, setting + `core.alternateRefsPrefixes` has no effect. + core.bare:: If true this repository is assumed to be 'bare' and has no working directory associated with it. If this is the case a diff --git a/t/t5410-receive-pack.sh b/t/t5410-receive-pack.sh index 2f21f1cb8f..b656c9b30c 100755 --- a/t/t5410-receive-pack.sh +++ b/t/t5410-receive-pack.sh @@ -51,4 +51,12 @@ test_expect_success 'with core.alternateRefsCommand' ' test_cmp expect actual.haves ' +test_expect_success 'with core.alternateRefsPrefixes' ' + test_config -C fork core.alternateRefsPrefixes "refs/tags" && + expect_haves one three two >expect && + printf "0000" | git receive-pack fork >actual && + extract_haves actual.haves && + test_cmp expect actual.haves +' + test_done diff --git a/transport.c b/transport.c index e7d2cdf00b..9323e5c3cd 100644 --- a/transport.c +++ b/transport.c @@ -1341,6 +1341,11 @@ static void fill_alternate_refs_command(struct child_process *cmd, argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path); argv_array_push(&cmd->args, "for-each-ref"); argv_array_push(&cmd->args, "--format=%(objectname) %(refname)"); + + if (!git_config_get_value("core.alternateRefsPrefixes", &value)) { + argv_array_push(&cmd->args, "--"); + argv_array_split(&cmd->args, value); + } } cmd->env = local_repo_env;