From patchwork Tue Oct 2 02:23:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10623001 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 C83C414BD for ; Tue, 2 Oct 2018 02:24:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A772A285F9 for ; Tue, 2 Oct 2018 02:24:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AED8286DC; Tue, 2 Oct 2018 02:24:06 +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 25E89285F9 for ; Tue, 2 Oct 2018 02:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726646AbeJBJEr (ORCPT ); Tue, 2 Oct 2018 05:04:47 -0400 Received: from mail-io1-f41.google.com ([209.85.166.41]:43714 "EHLO mail-io1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbeJBJEq (ORCPT ); Tue, 2 Oct 2018 05:04:46 -0400 Received: by mail-io1-f41.google.com with SMTP id y10-v6so535631ioa.10 for ; Mon, 01 Oct 2018 19:23:56 -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=OQgT2c6ua6oyG5TiuGqSbckjjne7kiPH4R3WOoqUMwNh3vZygilfyfK7trr6CnzP6M u3EJzN11DSiMcJdwN8+z0ftMnqGlrFTnjuWPb3t22U3+DpDuOI/HJ+JCEiSzMDn3cYdE k2BFAh5neTV7391ZykK5oOUu3160r1tvbuYWP3dnUt8DWTRRb1QGdN0t0xyegWHy//OY 8YF3FOqFXqOZx5VtEyIPIGpyC8Kbszasf/+RZ8di7dwE/egvIiQ9D3cB8ouQOEsgAkKX KKJY0McA6mnvmxnlTGaHbuRNS2HvT2u36gUirE4g08/FHpcvKj9PSUe7+NqaJSt6DqrF /MjQ== 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=pCFumSNUl37GE10kHz8UQFLcNYQUVVl8AzXN3f9o5Szkuo6Yx1hnCT2S8KEpM/FDkk 46s8R5pRkAenlWMjPhSMSDjKOMUKH5l0jdwXZOQgJjyLyJ1qdirB7DdfilmlvgtwYxWb /+7MzjFXiNzmH7tQ6shzw7XB/I8+4EV3a7ovEQs+7kUL9DIUaYtsjxyAyxzPs/0+KlXQ Zbvh5OUtrLA4jPabLV0L+ZVn71udcUYJXIHztri9dCjVqzlF52t7xuSRFWqIHtwq2CJU WhLkQ+a4X7X5LWWfI1lyFK35a6UP93W7ort87jW+hvyf2L3uua6+aVLJmVVdsyx+ugQF 0aDg== X-Gm-Message-State: ABuFfoi2qpWdIAeVXUpDI5shaWRmDf2M9GR7SZbtXNO4aP/rv/LeiKXG nBUbmkXpgbAw2d/UZIu8mGNIgQNUPBkXeg== X-Google-Smtp-Source: ACcGV60goZ5ATRcubdXNEQ9N+GPgL3zjixl4UCoqqyyogwSne8UAmmH1+AnrXP+MP1vacxsn1ruWpg== X-Received: by 2002:a62:c8c3:: with SMTP id i64-v6mr14324649pfk.183.1538447035664; Mon, 01 Oct 2018 19:23:55 -0700 (PDT) Received: from localhost ([2601:602:9200:32b0:e958:2ad1:68d0:890f]) by smtp.gmail.com with ESMTPSA id g62-v6sm23846036pgc.22.2018.10.01.19.23.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 19:23:54 -0700 (PDT) Date: Mon, 1 Oct 2018 19:23:53 -0700 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com Subject: [PATCH v4 1/4] transport: drop refnames from for_each_alternate_ref Message-ID: <491f258f5080465c6f4feb9958487595368d286e.1538446826.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 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 Tue Oct 2 02:23:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10623003 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 1717A1926 for ; Tue, 2 Oct 2018 02:24:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9AD5285F0 for ; Tue, 2 Oct 2018 02:24:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDBC6285F9; Tue, 2 Oct 2018 02:24:06 +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 515C82861C for ; Tue, 2 Oct 2018 02:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbeJBJEt (ORCPT ); Tue, 2 Oct 2018 05:04:49 -0400 Received: from mail-io1-f51.google.com ([209.85.166.51]:42508 "EHLO mail-io1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbeJBJEt (ORCPT ); Tue, 2 Oct 2018 05:04:49 -0400 Received: by mail-io1-f51.google.com with SMTP id n18-v6so538482ioa.9 for ; Mon, 01 Oct 2018 19:23:59 -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=xOQSed5pj6xZnl+rsGV7ltkyqzLk5qNuxeaUFJh/Q1Vtid1inRil0Hg0vfkxaZaGkL vndDh4ew8fc33BsgmT9mbigPH3WIpEje48xHPH3QX4tH0eK/GeXGCWQwFQj3u2KM+iCq sK0Y4jkgKfah8tx1HJNq00Qdz2/phkVaCbaJrAE44bX0m6JhWtdpxYCt278OSaSYIRvE c44hqS+fgXJAGFQrTvZ2IvfhoYqZ0GC3mCszLIZYNULMLiWu7TuoxdO5pb7NK8+D0SfJ VIO9O8Ed6QXFln04EAX4vv3N7WWbtO3q7vRHGb5oZ9Y4kkmVe9pI1MIfr2e0NK/NUDW4 pU0w== 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=DkrOCafH3fBTJaQY+/Npc/3F1zldCadLmQgDO2/UlpYTFjewld06+t76dilzOQrlrR 6DkP/Ha+IyOJKPdA+asmpq71gIw2tKNB44mi/2yTHLkQ3elXTtMqva3NN6c1OEAU5xyv F8ywldGvXHpi1Dazafaxg04oDmqWwfZAdenNVkm6v6UImNjZShTK10WPUa1UcWvcth/L cCxevUNION4vbNSzBOkc18R7po3cP4/OJ/UGI0lexCMHB5DWtnkCZbZ25dHiEmIDc+h0 kMvO4UBPHDPrAxDoBVWV8zh+4M2roTZQ5cIwCdIm7aHmv9uPflCfk666znuYm756e0PL lJnw== X-Gm-Message-State: ABuFfojv7GjDunybYQ2xtIIIgiIM4PU6g/rrBIfhmIuGwU30G7UCSAlL TaqjFDIk0FX/RPNUM4H3G1uKqO3bQQQbqQ== X-Google-Smtp-Source: ACcGV62xnrhi3kDfvMWhgmMtvJhjeesQV1LP/cn+5kPbbH9JRBEuIwr52MLIANmw2vv5oz1rgN3rEQ== X-Received: by 2002:a62:6cc4:: with SMTP id h187-v6mr14409783pfc.158.1538447038237; Mon, 01 Oct 2018 19:23:58 -0700 (PDT) Received: from localhost ([2601:602:9200:32b0:e958:2ad1:68d0:890f]) by smtp.gmail.com with ESMTPSA id l16-v6sm27830301pfj.179.2018.10.01.19.23.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 19:23:57 -0700 (PDT) Date: Mon, 1 Oct 2018 19:23:56 -0700 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com Subject: [PATCH v4 2/4] transport.c: extract 'fill_alternate_refs_command' Message-ID: <6119de15f2ba56e093c60a41990db740f3904d54.1538446827.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 Tue Oct 2 02:23:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10623009 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 B8571175A for ; Tue, 2 Oct 2018 02:24:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95DF5285F0 for ; Tue, 2 Oct 2018 02:24:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A797285F9; Tue, 2 Oct 2018 02:24:08 +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 721E628681 for ; Tue, 2 Oct 2018 02:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726699AbeJBJEw (ORCPT ); Tue, 2 Oct 2018 05:04:52 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:40453 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbeJBJEv (ORCPT ); Tue, 2 Oct 2018 05:04:51 -0400 Received: by mail-io1-f67.google.com with SMTP id w16-v6so544284iom.7 for ; Mon, 01 Oct 2018 19:24:01 -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=blRkCCa7jL7XzjUtbh8l5A7KQ8skfIx6dW2/MvHuV1g=; b=UCJz6nI5Fxt/UCZjs8Vk+gRN8x+CuRpWUWYlc1R5yyj323dX2m8Du0eX7MkH3L7tKl 2CRxZ28W2sIicB44XkycikSC77UjCh0CBLL0wpMX+xjO3gn4Afv1cpf9uXlDQuJ2ez7s pEV89zIXeRwBnp/p/Az66+JwA6Q3uhHE4EM8UjVrJcwu+IdTa5/lr7BMrMbEvbg5RX3e 9I/FcJ5a3TqJSu0MH2ACq8VfsaeW6KGucuD5f0SmaPqeikXWiu9ErqLfJ8aS89mVrNW9 xPnpKhFvYNdGZosdedzQT2wrPkGuwnmrvinVGDn6QW9+2vlfvnxqc4+gyzsxncFgxF7S JbQw== 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=blRkCCa7jL7XzjUtbh8l5A7KQ8skfIx6dW2/MvHuV1g=; b=FpmMofeF+hJnRPf+c88auVHEKCcajNnUZt7p+DxXccd7RttgNs1lUcem/+fITDjN9l 7o9Yo5ADcPr70m4zMf6wbJg9UhuCRrQ2wzUCnLhNyAgmCgrkjUjR77PZYZMgxhH3cZ7J O0vF611hWIZUncRkjdS9GnspmvsAiZ9JgNlm8RE2Mey4MWJ0qjTXNy5I2SfoZLvJsHk2 FhfIJGzY5fcUC4C8sOG5OHS6qD5Vx/hFiDM99lE353ioit3hpPycz+Elt9hyQs6TeEcl GEWSYJruPc/N3HHEj5JbfSreU5Rjt4F924OvcRyUK9Q1liDY1g2bNpa3APyjgp7ewCc6 Bz9A== X-Gm-Message-State: ABuFfog3NTfMeHaL7gCfCla0nPepC4Ozb3/46eY2x1vH42OLjQPpWN22 zsTrsli08ZQB5O+ubpU37iR71V0DNBI89w== X-Google-Smtp-Source: ACcGV62jLKR9CvjuORIgmhl7AU1hyIErvAQN5dBETz4w9JbYDw787VIN1jHUCFE/c8GM1py3w1+1mQ== X-Received: by 2002:a17:902:64c1:: with SMTP id y1-v6mr14005318pli.301.1538447040684; Mon, 01 Oct 2018 19:24:00 -0700 (PDT) Received: from localhost ([2601:602:9200:32b0:e958:2ad1:68d0:890f]) by smtp.gmail.com with ESMTPSA id h19-v6sm28878222pfk.71.2018.10.01.19.23.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 19:23:59 -0700 (PDT) Date: Mon, 1 Oct 2018 19:23:58 -0700 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com Subject: [PATCH v4 3/4] transport.c: introduce core.alternateRefsCommand 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 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 | 16 +++++++++++++++ t/t5410-receive-pack-alternates.sh | 33 ++++++++++++++++++++++++++++++ transport.c | 19 +++++++++++++---- 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100755 t/t5410-receive-pack-alternates.sh diff --git a/Documentation/config.txt b/Documentation/config.txt index ad0f4510c3..ac0577d288 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -616,6 +616,22 @@ 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)'`). ++ +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 --format='%(objectname)' refs/heads`. ++ +Note that the configured value is executed in a shell, and thus +linkgit:git-for-each-ref[1] by itself does not work, as scripts have to handle +the path argument specially. + 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 Tue Oct 2 02:24:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 10623005 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 477EC17E0 for ; Tue, 2 Oct 2018 02:24:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 264FD285F9 for ; Tue, 2 Oct 2018 02:24:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AE782861C; Tue, 2 Oct 2018 02:24:07 +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 926D428684 for ; Tue, 2 Oct 2018 02:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726709AbeJBJEy (ORCPT ); Tue, 2 Oct 2018 05:04:54 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:55987 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726715AbeJBJEy (ORCPT ); Tue, 2 Oct 2018 05:04:54 -0400 Received: by mail-it1-f196.google.com with SMTP id c23-v6so1291242itd.5 for ; Mon, 01 Oct 2018 19:24:04 -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=B7lGpwVzoTTTl71QZYzO24ADdLeKcqQoJ9sWAkF4ea4=; b=LIoyRAY3X/+bByf5JIuVNNd2k6SgbzO6d/mR5yQgojrmLCGoq1Df/+cImYBO+bdP2x AVrhOSE3kXwC/3keTdbTEr2Ted70ZlIOrNj7aNbmlCyj4NliDhwjT7sV1COVomB2Ykd0 0aOcWePmCPyugIej4UrIZfqZo952RpKV9mi/Z3j4//UharKkdVzmseX9YQhctwyXbnJk IuQjxecQ/FlfdmrHr35AnP9STN5ppBK+pyssL69dIBf4EwqzMBPyJl6cR5n0+uZYWzz7 r9lMbHQMPXLzHo2tQ5IdjxyTlSA5iftHTRJmNBFq+A3Rb8wilJ2yzsBIC28CnoELY/RR ppZA== 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=B7lGpwVzoTTTl71QZYzO24ADdLeKcqQoJ9sWAkF4ea4=; b=eXIlnuGAQq9FNQtFkrQH+Li5bDMgvp+m7PRxYtQxVhnj/L4nlYDAqJkfu78z0Ai77U s5s0VIV8mG1SdCH6QxyGJMK3toSremED1fjxXZNBYnBW7CJ/i66b/aYqVkCC0o09Hlms GxpklTYkIDHvsiaGzsyICHERj0iBRGYF0OwD+tXKfIugaetiY5bc15Vn6/Jy2gtU063D fgbJOeRNeQDyyOG3Hq3scCZ0o70qTWiXYs/UCAPrlYbhgzEk6Vm3toloC1tse1ViTKbs ZTpUnSLPQYwFA9+HNDlG8FhqfKfUnsg7Ov/dRdxN8ZTYDzPqJ1MWAk7ePAyMGl7K6hWu UUZQ== X-Gm-Message-State: ABuFfojx6Rx6wGTkJCxoHY5+TxkERLzxijO1tzvMYvnR8uFQnlTVBJbN fr409QAkTpWNF38EdtnOCDHi3jbLowJhxQ== X-Google-Smtp-Source: ACcGV63T5vFnXq9UG1p2vuu7sXlin4B7oihGK80kaJ1bGLLclfKdQNoUsgYPKaKKhIJVFvqPTod30g== X-Received: by 2002:a63:2441:: with SMTP id k62-v6mr12719931pgk.26.1538447043228; Mon, 01 Oct 2018 19:24:03 -0700 (PDT) Received: from localhost ([2601:602:9200:32b0:e958:2ad1:68d0:890f]) by smtp.gmail.com with ESMTPSA id t4-v6sm2545596pfh.45.2018.10.01.19.24.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 19:24:02 -0700 (PDT) Date: Mon, 1 Oct 2018 19:24:01 -0700 From: Taylor Blau To: git@vger.kernel.org Cc: peff@peff.net, gitster@pobox.com, sunshine@sunshineco.com, sbeller@google.com Subject: [PATCH v4 4/4] transport.c: introduce core.alternateRefsPrefixes Message-ID: <0d3521e92a55377d3e37ecd24ff7667dab50d61d.1538446827.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 ac0577d288..1dc5eb3cfa 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -632,6 +632,13 @@ Note that the configured value is executed in a shell, and thus linkgit:git-for-each-ref[1] by itself does not work, as scripts have to handle the path argument specially. +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..94794c35da 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;