From patchwork Mon Oct 8 18:09:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10631169 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 24B6614BD for ; Mon, 8 Oct 2018 18:09:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 186F22991D for ; Mon, 8 Oct 2018 18:09:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BCA929930; Mon, 8 Oct 2018 18:09:29 +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 87DD02992B for ; Mon, 8 Oct 2018 18:09:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726461AbeJIBWW (ORCPT ); Mon, 8 Oct 2018 21:22:22 -0400 Received: from mail-pf1-f173.google.com ([209.85.210.173]:38494 "EHLO mail-pf1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbeJIBWW (ORCPT ); Mon, 8 Oct 2018 21:22:22 -0400 Received: by mail-pf1-f173.google.com with SMTP id f29-v6so5869623pff.5 for ; Mon, 08 Oct 2018 11:09:26 -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=iMbBJEIy7CcRrtNLx3aihrhtIKCAy8t6xUB1y+wXPn0=; b=VbuM3/U4qPOI/4iL+tYQnyxZ5HCnkanNtf8gjnAfIzFL9cmvuCakuyqdInMzgv0XSv 5RHZ42yL46dl8N6mpc3wwIgB/PWCDw/wBH1mB6gwjbQmHPeAPySHp798q8CQKl60D2Na 2SzP/whYBReYkyKvSm/ylBdoDlRbsVpOzmupnbz/faBwgZFkeb6Ik5C04WM/oJyGBhV6 dtfyT/Q33R8pMu9rINBdxW8+rKSzpW8lidPv8Oze5rXllZNUv1sBic/6ll4IdKAp2IHR 81CeqqKXHJwCmUgUfv3xyu6YstiGF8czherWs5pLbSXTPeoe2ApPdt2jGUIPVn8Mfjdg h8WQ== 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=iMbBJEIy7CcRrtNLx3aihrhtIKCAy8t6xUB1y+wXPn0=; b=ejlPoEnbWDKlSzzt9EZslCFq22lfCPW+TY1Gb0IZhTFRj76F06NqPj1OLso3m79LCx 05mMPs9hqN1slpTvkpCkHxpD0Ad4ALR5Ot5yMajke0k1cYlw5ZeQDi+54v+sHLYkSHoX siVgcD4UDaF+rCsNsTEs5a47qShwGllmU0MWIkG40e+ZFPsT3grX8lrH96oifcYdYCfe dnemqA1i5xWbmPb4uU2eeVGM6yfjUxecTOXSo1zIAtZET7NvDYf5ix03ZVb0N3W/vVgH YsCmpyyLJgMokLDJWqmTRh0uPz6n6GFlC3ssAVBbDz6LAcitPJ9PmCaEfZk9EaFMgIvM BNxQ== X-Gm-Message-State: ABuFfoiuR+whCV4fgZybMm3RI2Qe5ViKZ4FuPnfnrmFYr1gjSEKnLfFX a++cxd03SUc7YP2mPZQxJBgf3LCdOeA= X-Google-Smtp-Source: ACcGV60v3HSkUxk4mIHZVGw1y+wY8KOF5moCoR1Z2SEGk8A755HDc2HdWvn9bZgrbMiPa1YT6J5Uzw== X-Received: by 2002:a62:8708:: with SMTP id i8-v6mr26181317pfe.150.1539022165196; Mon, 08 Oct 2018 11:09:25 -0700 (PDT) Received: from localhost ([205.175.107.112]) by smtp.gmail.com with ESMTPSA id d186-v6sm24223373pfg.173.2018.10.08.11.09.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 11:09:24 -0700 (PDT) Date: Mon, 8 Oct 2018 11:09:23 -0700 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com, ramsay@ramsayjones.plus.com Subject: [PATCH v5 1/4] transport: drop refnames from for_each_alternate_ref Message-ID: 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 From: Jeff King None of the current callers use the refname parameter we pass to their callbacks. In theory somebody _could_ do so, but it's actually quite weird if you think about it: it's a ref in somebody else's repository. So the name has no meaning locally, and in fact there may be duplicates if there are multiple alternates. The users of this interface really only care about seeing some ref tips, since that promises that the alternate has the full commit graph reachable from there. So let's keep the information we pass back to the bare minimum. Signed-off-by: Jeff King Signed-off-by: Taylor Blau --- builtin/receive-pack.c | 3 +-- fetch-pack.c | 3 +-- transport.c | 6 +++--- transport.h | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 4d30001950..6792291f5e 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -281,8 +281,7 @@ static int show_ref_cb(const char *path_full, const struct object_id *oid, return 0; } -static void show_one_alternate_ref(const char *refname, - const struct object_id *oid, +static void show_one_alternate_ref(const struct object_id *oid, void *data) { struct oidset *seen = data; diff --git a/fetch-pack.c b/fetch-pack.c index 75047a4b2a..b643de143b 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -76,8 +76,7 @@ struct alternate_object_cache { size_t nr, alloc; }; -static void cache_one_alternate(const char *refname, - const struct object_id *oid, +static void cache_one_alternate(const struct object_id *oid, void *vcache) { struct alternate_object_cache *cache = vcache; diff --git a/transport.c b/transport.c index 1c76d64aba..2e0bc414d0 100644 --- a/transport.c +++ b/transport.c @@ -1336,7 +1336,7 @@ static void read_alternate_refs(const char *path, 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)"); + argv_array_push(&cmd.args, "--format=%(objectname)"); cmd.env = local_repo_env; cmd.out = -1; @@ -1348,13 +1348,13 @@ static void read_alternate_refs(const char *path, struct object_id oid; if (get_oid_hex(line.buf, &oid) || - line.buf[GIT_SHA1_HEXSZ] != ' ') { + line.buf[GIT_SHA1_HEXSZ]) { warning(_("invalid line while parsing alternate refs: %s"), line.buf); break; } - cb(line.buf + GIT_SHA1_HEXSZ + 1, &oid, data); + cb(&oid, data); } fclose(fh); diff --git a/transport.h b/transport.h index 01e717c29e..9baeca2d7a 100644 --- a/transport.h +++ b/transport.h @@ -261,6 +261,6 @@ int transport_refs_pushed(struct ref *ref); void transport_print_push_status(const char *dest, struct ref *refs, int verbose, int porcelain, unsigned int *reject_reasons); -typedef void alternate_ref_fn(const char *refname, const struct object_id *oid, void *); +typedef void alternate_ref_fn(const struct object_id *oid, void *); extern void for_each_alternate_ref(alternate_ref_fn, void *); #endif From patchwork Mon Oct 8 18:09:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10631171 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 95C2814BD for ; Mon, 8 Oct 2018 18:09:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89F382991D for ; Mon, 8 Oct 2018 18:09:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E08929930; Mon, 8 Oct 2018 18:09:30 +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 275282991D for ; Mon, 8 Oct 2018 18:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726481AbeJIBWY (ORCPT ); Mon, 8 Oct 2018 21:22:24 -0400 Received: from mail-pf1-f174.google.com ([209.85.210.174]:44675 "EHLO mail-pf1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbeJIBWY (ORCPT ); Mon, 8 Oct 2018 21:22:24 -0400 Received: by mail-pf1-f174.google.com with SMTP id r9-v6so8580610pff.11 for ; Mon, 08 Oct 2018 11:09:28 -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=DV7GU0hije/3MRO0t6GQNPK1JremetfuPFkNeZT3Y/E=; b=Jy1RPBBihw5XXUgVlfNcjZX8/sfeWQUHGaFyS8izvgIGybMyJ2mbgQaV8U5BTWbJzc MLIjsWh2xycFyxQM88Aosb/akzVzWQwx6/sa4BFuMnVF0XBfDX4ZyiGNh+D/ya2Lnv7H kf2ghFrVLC7BIaGcZTdSuhaiT3qGWqvGwpZhArVPzhCBf7QjnUxboK5dzIOL0X5ABQZH duDagpdU79BGJDQCEudr5I9LrnoHO6xphRuVIBdgzjy4l5Q7Gs3WAQ6lTt8VATufxIyr 1mLAHJf8/IT9RtHDnSE1GYUK8ZKZO98SsumHV7ZCIp8/3iCNji4+MUNfjEOZ8o3hYNZP GUlQ== 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=DV7GU0hije/3MRO0t6GQNPK1JremetfuPFkNeZT3Y/E=; b=P2S713UTyvDJ97bGWGA6bjsmHLLUofuY29K57+/J5tkmxBnhJ6dYhrhtYLzGeNBlDI nxIH4Jo9sFJ1iyXtmqOB4uXoPN9acMVUCPNk6RKBFTwHbz3ElGCz+aOggaM2ZWb21mxn pMGjBUDrV2f4tPeec1GwtMbcqcmIFqHSoJUU4FZHAejlrcb1x/WANGgaAit2231aoNWd yiH843Gvpmxf4oWsVnfs95Swd4aXYnSskec61SH+FUrRNFty8HmZI3FhYHZXcpMP6iZe Bao+bEZ4W4zk28Q6HIEbVoeDRqFtbZ37FZrRq5tsxcpnAj6/QSYibKibyG2OiogYl9vh W+cw== X-Gm-Message-State: ABuFfojBJF+SxOXiLFe/gozDmEdPR8KmIJ2wuL7Ni4A8bLvQx2OfyR/X TctAZqWq3IpTdhCUv6+AiRuT/fiD1O4= X-Google-Smtp-Source: ACcGV61VZNE0lNK7jKOZcOA+1LqE5TpPNEbtf8xY87knGVSkS5PmHgp++M2EpZmmNWIIQ5fVN+yk5g== X-Received: by 2002:a63:e00d:: with SMTP id e13-v6mr21878474pgh.114.1539022167349; Mon, 08 Oct 2018 11:09:27 -0700 (PDT) Received: from localhost ([205.175.107.112]) by smtp.gmail.com with ESMTPSA id n63-v6sm15396056pfn.9.2018.10.08.11.09.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 11:09:26 -0700 (PDT) Date: Mon, 8 Oct 2018 11:09:26 -0700 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com, ramsay@ramsayjones.plus.com Subject: [PATCH v5 2/4] transport.c: extract 'fill_alternate_refs_command' Message-ID: <3d77a46c613c1c3d7f1cf161ac12ff6477430958.1539021825.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 2e0bc414d0..2825debac5 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)"); + 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)"); - cmd.env = local_repo_env; - cmd.out = -1; + fill_alternate_refs_command(&cmd, path); if (start_command(&cmd)) return; From patchwork Mon Oct 8 18:09:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10631173 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 F03BE112B for ; Mon, 8 Oct 2018 18:09:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E29352991D for ; Mon, 8 Oct 2018 18:09:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D66DF29930; Mon, 8 Oct 2018 18:09:32 +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 559942991D for ; Mon, 8 Oct 2018 18:09:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726522AbeJIBW0 (ORCPT ); Mon, 8 Oct 2018 21:22:26 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35538 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbeJIBW0 (ORCPT ); Mon, 8 Oct 2018 21:22:26 -0400 Received: by mail-pf1-f195.google.com with SMTP id l17-v6so4362365pff.2 for ; Mon, 08 Oct 2018 11:09:30 -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=OO+NGL0PaPgxh3RgxL9DTPFybWyOW8DwyS8Nrz7R4Ug=; b=Wv2RrVbXjofcv/EMwkT9qKrc/Gp3gE0lSxa0nv0+NR4vRFToY/Qb4XyMyIBA2wYa1M DfnxefLO9W9wgMyDgte3syC09nJF8G8ZbN9SteWt6MXpahgjQeqH7zQMclhkGBSqHrdv GbZvG8X9KsGGEZ8C3qt2VTU/qA8kIVE7G5XfPedf3/8PemSacYF9ie0pvlAy4w0bhw4g dhn9Uz25S2XCjzRWjv/JNlmVASkDnUKY28DPErSmEauH3Gt6/qWXAeLLcYmMVVqoDCOA j3vDMtSXSZPOfeloC7M9PmkVJR2+0To5IhsRp/qUrRFkxdzsZUpJ2h99UctdAH0t3Bwr zP7g== 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=OO+NGL0PaPgxh3RgxL9DTPFybWyOW8DwyS8Nrz7R4Ug=; b=HqSTmV7aMPgTbQlHQqWE3X6/glyw2mUbwR/ZQ9q4V4f0MO3lM5z7NFBN2qWNGU8HM1 Wq0NV9xaaJWowmHu99De+mMRt9oityQ2ttWLYZFVPIJs5LClMWoNvfOER0sH+TGWEPr2 Mwbz8ZME8anmrZs9TFNj+BA376KMNpNwGfc1Rnvv60vM8SnLq9MwF3U13k2a9q2zWjcB YRK779KBFtAowMHzN/Hla5ZTxk+15oPc14BcKeE6NlPn87iWWvCAAKQXCWRVpHipcDKb 5bK+iF+DYL+DxCWlGu7P2w+jmjqI1xgJSGYWLAZzhK1SJdgHXlG6mLbp8ZPjlH0iDiOC zZBQ== X-Gm-Message-State: ABuFfoj96yoDQ4DwOYIvl6leHyd1FV2Yf/XiIQ0sM2u/9kfhlphauZAE HdSvFrn4TbwueyQ10lU0irLQQH9Kkjw= X-Google-Smtp-Source: ACcGV61S/XMwMTADGxUkxHMDPtKZhLNjlBryWLofrPi6/sNlXwDc/ZVsyuX0EfU7QQNh3YWoo4F50w== X-Received: by 2002:a62:6506:: with SMTP id z6-v6mr11666527pfb.20.1539022169364; Mon, 08 Oct 2018 11:09:29 -0700 (PDT) Received: from localhost ([205.175.107.112]) by smtp.gmail.com with ESMTPSA id r1-v6sm25493611pfb.41.2018.10.08.11.09.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 11:09:28 -0700 (PDT) Date: Mon, 8 Oct 2018 11:09:28 -0700 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com, ramsay@ramsayjones.plus.com Subject: [PATCH v5 3/4] transport.c: introduce core.alternateRefsCommand Message-ID: <7451b4872a0fd66d84cbe492fdfe7a9a8e81eab7.1539021825.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 those alternates. For example, 'git receive-pack' lists the "tips" pointed to by references in those alternates 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 (upstream, in the previous example) 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 references the alternate does not wish to send (for space concerns, or otherwise) during the initial advertisement. 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 find the alternate, pass its absolute path as the first argument. Signed-off-by: Taylor Blau --- Documentation/config.txt | 11 ++++++++++ t/t5410-receive-pack-alternates.sh | 33 ++++++++++++++++++++++++++++++ transport.c | 19 +++++++++++++---- 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100755 t/t5410-receive-pack-alternates.sh diff --git a/Documentation/config.txt b/Documentation/config.txt index ad0f4510c3..c51e82d8a5 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 advertising tips of available history from an alternate, use the shell to + execute the specified command instead of linkgit:git-for-each-ref[1]. The + first argument is the absolute path of the alternate. Output must contain one + hex object id per line (i.e., the same as produce by `git for-each-ref + --format='%(objectname)'`). ++ +Note that you cannot generally put `git for-each-ref` directly into the config +value, as it does not take a repository path as an argument (but you can wrap +the command above in a shell script). + 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-alternates.sh b/t/t5410-receive-pack-alternates.sh new file mode 100755 index 0000000000..49d0fe44fb --- /dev/null +++ b/t/t5410-receive-pack-alternates.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +test_description='git receive-pack with alternate ref filtering' + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit base && + git clone -s --bare . fork && + git checkout -b public/branch master && + test_commit public && + git checkout -b private/branch master && + test_commit private +' + +extract_haves () { + depacketize | perl -lne '/^(\S+) \.have/ and print $1' +} + +test_expect_success 'with core.alternateRefsCommand' ' + write_script fork/alternate-refs <<-\EOF && + git --git-dir="$1" for-each-ref \ + --format="%(objectname)" \ + refs/heads/public/ + EOF + test_config -C fork core.alternateRefsCommand alternate-refs && + git rev-parse public/branch >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 2825debac5..e271b66603 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)"); + 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)"); + } + cmd->env = local_repo_env; cmd->out = -1; } From patchwork Mon Oct 8 18:09:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10631175 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 EAE8A112B for ; Mon, 8 Oct 2018 18:09:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCF5C2991D for ; Mon, 8 Oct 2018 18:09:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D18AA29930; Mon, 8 Oct 2018 18:09:34 +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 603F52991D for ; Mon, 8 Oct 2018 18:09:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726563AbeJIBW2 (ORCPT ); Mon, 8 Oct 2018 21:22:28 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41646 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726529AbeJIBW2 (ORCPT ); Mon, 8 Oct 2018 21:22:28 -0400 Received: by mail-pl1-f196.google.com with SMTP id q17-v6so10420047plr.8 for ; Mon, 08 Oct 2018 11:09:32 -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=gVAytk9f9rkr6ixJ8lvF+32eUIQN30kaYtL62ymwnrY=; b=Xsip05ojA+0L2v5CtVysLCrmUdL07iXDELyolluDdXge87jCBupqZJzYw7HWK2M+Vp XElJ6yCoABH+6P/3kvA7vrHrCcrvCdSTbxLvCc6RiyyuFhs4TsP5ZjJEgAXfZ4qWBjQL j2wKVOmLalR9366UAKyqKrEVSqb+JVCHL9cZodzNMJJUPho47nnr7hITCWvB6mOx1pz0 Scxr38mhCdpJ4hlLXYVkV7Xj6/WzCLoY8BA29mtvN1XaMuwCU5pj4bXddbq3q4g9shux cVyzeFadq6cAipkgnjMcnVyK7TJLqDqx24Bx+/N3xYgGKw1t+5ohi1ok5VPWRfXdZCBm Qy1Q== 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=gVAytk9f9rkr6ixJ8lvF+32eUIQN30kaYtL62ymwnrY=; b=qdCirYVKfUgTtgde5Kf29E0jfAO6Oqi84rTaTfBpnQZrE+c/JNaSjWwAo49Nxf4grL u5k9SNJLL6tfbVxvDNb78DmbIA3gsjy+m2ugPhHZn0g6sNPPYUctREefoM2KzZpEzAq1 VVC/5lM8DzBt6mGfq/d64LdftZcEFyj0974OyqZUEm0uluUxFsibqboH9ZgGm9mtnn/r NIXn1uZJj/DWnaPlCgMf9Ux0quTR+DCdLoTqy2edd/b4dDtiT+tX1truKqmJaAam3IXi Kp1/USl7cyWh47/YN2DBvOsxp/tea8DFE1T7p9gVmnO20dkO95wLw/HWV2I6ncYVsBpq gf0A== X-Gm-Message-State: ABuFfoj0NRhyFIGQVdPBfrATEHFanesz12JsU5BC6IRweRXBMjuXmOVA WCis9B1nXMPTzSvhtyll1MIYH76HlFE= X-Google-Smtp-Source: ACcGV63Ahca3c3XrEfvbYOLf+nug/I0ty8UxIePrVa22MIhe7Ag6zMqvD+YgpzmM4o8Kn4cDqGtrWw== X-Received: by 2002:a17:902:7246:: with SMTP id c6-v6mr25273119pll.304.1539022171720; Mon, 08 Oct 2018 11:09:31 -0700 (PDT) Received: from localhost ([205.175.107.112]) by smtp.gmail.com with ESMTPSA id l6-v6sm23995459pfl.169.2018.10.08.11.09.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 11:09:31 -0700 (PDT) Date: Mon, 8 Oct 2018 11:09:30 -0700 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com, ramsay@ramsayjones.plus.com Subject: [PATCH v5 4/4] transport.c: introduce core.alternateRefsPrefixes Message-ID: <28cbbe63f73b14315f8b1b7c7049b1f81f27057f.1539021825.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 ' \ f() { git -C "$1" for-each-ref \ refs/tags --format="%(objectname)" }; f "$@"' 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 --- Documentation/config.txt | 7 +++++++ t/t5410-receive-pack-alternates.sh | 8 ++++++++ transport.c | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index c51e82d8a5..a133a709f3 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -627,6 +627,13 @@ Note that you cannot generally put `git for-each-ref` directly into the config value, as it does not take a repository path as an argument (but you can wrap the command above in a shell script). +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-alternates.sh b/t/t5410-receive-pack-alternates.sh index 49d0fe44fb..457c20c2a5 100755 --- a/t/t5410-receive-pack-alternates.sh +++ b/t/t5410-receive-pack-alternates.sh @@ -30,4 +30,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/heads/private" && + git rev-parse private/branch >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 e271b66603..83474add28 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)"); + + if (!git_config_get_value("core.alternateRefsPrefixes", &value)) { + argv_array_push(&cmd->args, "--"); + argv_array_split(&cmd->args, value); + } } cmd->env = local_repo_env;