From patchwork Sat Aug 7 07:16:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12424183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B320C4338F for ; Sat, 7 Aug 2021 07:16:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2ACEE61163 for ; Sat, 7 Aug 2021 07:16:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbhHGHRP (ORCPT ); Sat, 7 Aug 2021 03:17:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231408AbhHGHRO (ORCPT ); Sat, 7 Aug 2021 03:17:14 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94D96C061798 for ; Sat, 7 Aug 2021 00:16:57 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id nh14so20075079pjb.2 for ; Sat, 07 Aug 2021 00:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FUGNEGv5b7iiJ5jGiHKZnJPiC1v9derrDbJFJLo+EPU=; b=Kdt7HDsVpmS8nbeCSK5xzDIocFX5MWN1i9b0N0rHgH1oAE6/Z9M/V5h6TH+30zWCUO w/8g8st/D153LDOq0vWYfJJOMTFZp5+8Shqac+8DiTHhCtc1mPO/yCB//R4XP4VSd1nS fmaWZF9PVD40tqHIm0t3I+3Zq70ZtpbDOtwyGdHt8R65Cw5BzwV6i8zCX9dRaiFgUqIP 45Ksn6LU5LZo/w4++xVC16Rsk8DkC60hiIV3k9OwC5As565GIuXqTolooa/N5eA68bye aL6sZsiGeccbPEqvpZrhtySWLhiOgIAvIyiFnFf2v6NX9QISf9ryktGr8Uv52jiY4u3p lu2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FUGNEGv5b7iiJ5jGiHKZnJPiC1v9derrDbJFJLo+EPU=; b=eYLavFfZxfv70loxOPbwwUvTyWRcgbqqxCaYvYgzi6V6OlOK0O3HBY1bDoRgMiEDlg m5lIsQ/v0Qy+Y8n9ERuIabGziJevpw/PCIf8wgcRhMUaa6z4P61y+LXFnKF3ji9b/Imw Dv1+fpOqVsEc8S53ChKCn8xAqA40RStOwlpH/ZYoH0SvA64QfBig4HIKCHtKrNus0cLj BZV8WzwzfPbij8fgnMFpmp63upu4TlRec8/1M3VdcyqzLD/AKAW5w0FygrBAB+7ZTaLG g3hE58T4RLcpCaJhrM9cOlz4CYm/h5zRi08ZTZEDvOxLokwed8RRMBpXo8Mf6NGX+0re GSaw== X-Gm-Message-State: AOAM532N+YDoZikfZ7jZzzCE/1x+P5VO/wd6ZYXC71+vjJzE4nSmJmTi 8tgJmWO//QQAWfNa8bYUtsc= X-Google-Smtp-Source: ABdhPJzxZ7C4iFIt2zkTHT8JfA4QdafgzKmny+WsXxBi6MmvBVeoFGWRrdIWuUopEf0qQijx5XDDcA== X-Received: by 2002:a63:bd41:: with SMTP id d1mr201072pgp.306.1628320617183; Sat, 07 Aug 2021 00:16:57 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b15sm14604981pgm.15.2021.08.07.00.16.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Aug 2021 00:16:56 -0700 (PDT) From: Atharva Raykar To: raykar.ath@gmail.com Cc: avarab@gmail.com, christian.couder@gmail.com, congdanhqx@gmail.com, emilyshaffer@google.com, git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com, kaartic.sivaraam@gmail.com, pc44800@gmail.com, periperidip@gmail.com, rafaeloliveira.cs@gmail.com, sunshine@sunshineco.com Subject: [GSoC] [PATCH v4 1/8] submodule--helper: add options for compute_submodule_clone_url() Date: Sat, 7 Aug 2021 12:46:06 +0530 Message-Id: <20210807071613.99610-2-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807071613.99610-1-raykar.ath@gmail.com> References: <20210806120147.73349-1-raykar.ath@gmail.com> <20210807071613.99610-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Let's modify the interface to `compute_submodule_clone_url()` function by adding two more arguments, so that we can reuse this in various parts of `submodule--helper.c` that follow a common pattern, which is--read the remote url configuration of the superproject and then call `relative_url()`. This function is nearly identical to `resolve_relative_url()`, the only difference being the extra warning message. We can add a quiet flag to it, to suppress that warning when not needed, and then refactor `resolve_relative_url()` by using this function, something we will do in the next patch. Having this functionality factored out will be useful for converting the rest of `submodule add` in subsequent patches. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/submodule--helper.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6891480013..2d2d8ac637 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -590,7 +590,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) return 0; } -static char *compute_submodule_clone_url(const char *rel_url) +static char *compute_submodule_clone_url(const char *rel_url, const char *up_path, int quiet) { char *remoteurl, *relurl; char *remote = get_default_remote(); @@ -598,10 +598,14 @@ static char *compute_submodule_clone_url(const char *rel_url) strbuf_addf(&remotesb, "remote.%s.url", remote); if (git_config_get_string(remotesb.buf, &remoteurl)) { - warning(_("could not look up configuration '%s'. Assuming this repository is its own authoritative upstream."), remotesb.buf); + if (!quiet) + warning(_("could not look up configuration '%s'. " + "Assuming this repository is its own " + "authoritative upstream."), + remotesb.buf); remoteurl = xgetcwd(); } - relurl = relative_url(remoteurl, rel_url, NULL); + relurl = relative_url(remoteurl, rel_url, up_path); free(remote); free(remoteurl); @@ -660,7 +664,7 @@ static void init_submodule(const char *path, const char *prefix, if (starts_with_dot_dot_slash(url) || starts_with_dot_slash(url)) { char *oldurl = url; - url = compute_submodule_clone_url(oldurl); + url = compute_submodule_clone_url(oldurl, NULL, 0); free(oldurl); } @@ -2134,7 +2138,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) { if (starts_with_dot_slash(sub->url) || starts_with_dot_dot_slash(sub->url)) { - url = compute_submodule_clone_url(sub->url); + url = compute_submodule_clone_url(sub->url, NULL, 0); need_free_url = 1; } else url = sub->url; From patchwork Sat Aug 7 07:16:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12424185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D742AC4338F for ; Sat, 7 Aug 2021 07:17:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B463B610C7 for ; Sat, 7 Aug 2021 07:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231474AbhHGHRT (ORCPT ); Sat, 7 Aug 2021 03:17:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbhHGHRT (ORCPT ); Sat, 7 Aug 2021 03:17:19 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD516C0613CF for ; Sat, 7 Aug 2021 00:17:01 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d17so10184365plr.12 for ; Sat, 07 Aug 2021 00:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z0dczKJTO5baTemhmXZeMRVP4jza28YNvT8kLN9WZLY=; b=Ke+/A6wjvbg5a+cTq4tdjo8RUZTAmZFC7JdH0YcA6UAYyakq5xTyxfg34kqajGRzFW zwreQlS/TawOH7Ws0ExidFb/cOvlhyWCMACWhoVviAw4/mOODwQSoOoXAjT/HI3d0Dqe 7nG6ohzZAtgqNGcl4d6TLB2APNdB61pY1kmXAnvsdVAt3hhNd+3yK6FpgCvFhtcD1P4J tQavKmdosHzcXd1cYI5LyNuKDg0630qsLaRVsE4c03EzC1P/9uD4VTd0DFX2HFGD0q2z F7mfDsdg0uorhS/AQeipGwXpJ8FUInpd448mNVXdip+JKlK+yM6IYvTL2TwSt6ZFaXtC ngAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z0dczKJTO5baTemhmXZeMRVP4jza28YNvT8kLN9WZLY=; b=p/vKveH6QtaWJFIKACveTRrhqIProKgmpTw625/Ir9OavDhEtjAptvJxjUOkjXsLeu N4MayLHxwuamgazyqWPLWo3T2LugByoHmHMBdl0m8BEK0MsQWILiUCnMYvR2o9nYsp6r GDueLQJwojKMe2wy2pJ+IZ4MBwoyL06fvqIzB3OZn1f+OhKR0aHGfmHe/OV1W7dI+eOX 3UvmLu9U7+gRqXsNiDlGuh6Cs74YdVWC7R6yjl07lcK9egQ0uTQBAEe33T8UVEA0VB3y 72b5wjrxHpPPmgKSKyZBDpfecXfk5uVgk1jtGKfqcpLOoVH3L3z6UGKJEK7cif/6r1K0 SV7g== X-Gm-Message-State: AOAM532Z+iECjbTF0ax0KYgeQ6XGefpE40wOGvhzmL7wlIe77ZuHtWQ6 9Vt2sebvYVwN59/omSranIM= X-Google-Smtp-Source: ABdhPJwsJNrLZH5/hSY5o2C5lz0kZ9AadXppwJqBa4qZ+Eapc7D2q3Mor6XSZ+xLei6pZ2cBMfNt7w== X-Received: by 2002:a63:5244:: with SMTP id s4mr58019pgl.267.1628320621268; Sat, 07 Aug 2021 00:17:01 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b15sm14604981pgm.15.2021.08.07.00.16.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Aug 2021 00:17:00 -0700 (PDT) From: Atharva Raykar To: raykar.ath@gmail.com Cc: avarab@gmail.com, christian.couder@gmail.com, congdanhqx@gmail.com, emilyshaffer@google.com, git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com, kaartic.sivaraam@gmail.com, pc44800@gmail.com, periperidip@gmail.com, rafaeloliveira.cs@gmail.com, sunshine@sunshineco.com Subject: [GSoC] [PATCH v4 2/8] submodule--helper: refactor resolve_relative_url() helper Date: Sat, 7 Aug 2021 12:46:07 +0530 Message-Id: <20210807071613.99610-3-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807071613.99610-1-raykar.ath@gmail.com> References: <20210806120147.73349-1-raykar.ath@gmail.com> <20210807071613.99610-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the helper function to resolve a relative url, by reusing the existing `compute_submodule_clone_url()` function. `compute_submodule_clone_url()` performs the same work that `resolve_relative_url()` is doing, so we eliminate this code repetition by moving the former function's definition up, and calling it inside `resolve_relative_url()`. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/submodule--helper.c | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 2d2d8ac637..f4b496bac6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -199,33 +199,46 @@ static char *relative_url(const char *remote_url, return strbuf_detach(&sb, NULL); } +static char *compute_submodule_clone_url(const char *rel_url, const char *up_path, int quiet) +{ + char *remoteurl, *relurl; + char *remote = get_default_remote(); + struct strbuf remotesb = STRBUF_INIT; + + strbuf_addf(&remotesb, "remote.%s.url", remote); + if (git_config_get_string(remotesb.buf, &remoteurl)) { + if (!quiet) + warning(_("could not look up configuration '%s'. " + "Assuming this repository is its own " + "authoritative upstream."), + remotesb.buf); + remoteurl = xgetcwd(); + } + relurl = relative_url(remoteurl, rel_url, up_path); + + free(remote); + free(remoteurl); + strbuf_release(&remotesb); + + return relurl; +} + static int resolve_relative_url(int argc, const char **argv, const char *prefix) { - char *remoteurl = NULL; - char *remote = get_default_remote(); const char *up_path = NULL; char *res; const char *url; - struct strbuf sb = STRBUF_INIT; if (argc != 2 && argc != 3) die("resolve-relative-url only accepts one or two arguments"); url = argv[1]; - strbuf_addf(&sb, "remote.%s.url", remote); - free(remote); - - if (git_config_get_string(sb.buf, &remoteurl)) - /* the repository is its own authoritative upstream */ - remoteurl = xgetcwd(); - if (argc == 3) up_path = argv[2]; - res = relative_url(remoteurl, url, up_path); + res = compute_submodule_clone_url(url, up_path, 1); puts(res); free(res); - free(remoteurl); return 0; } @@ -590,30 +603,6 @@ static int module_foreach(int argc, const char **argv, const char *prefix) return 0; } -static char *compute_submodule_clone_url(const char *rel_url, const char *up_path, int quiet) -{ - char *remoteurl, *relurl; - char *remote = get_default_remote(); - struct strbuf remotesb = STRBUF_INIT; - - strbuf_addf(&remotesb, "remote.%s.url", remote); - if (git_config_get_string(remotesb.buf, &remoteurl)) { - if (!quiet) - warning(_("could not look up configuration '%s'. " - "Assuming this repository is its own " - "authoritative upstream."), - remotesb.buf); - remoteurl = xgetcwd(); - } - relurl = relative_url(remoteurl, rel_url, up_path); - - free(remote); - free(remoteurl); - strbuf_release(&remotesb); - - return relurl; -} - struct init_cb { const char *prefix; unsigned int flags; From patchwork Sat Aug 7 07:16:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12424187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF0D4C4338F for ; Sat, 7 Aug 2021 07:17:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 94F6960F0F for ; Sat, 7 Aug 2021 07:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231499AbhHGHR0 (ORCPT ); Sat, 7 Aug 2021 03:17:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231497AbhHGHRX (ORCPT ); Sat, 7 Aug 2021 03:17:23 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B926DC0613CF for ; Sat, 7 Aug 2021 00:17:05 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id a8so20034059pjk.4 for ; Sat, 07 Aug 2021 00:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bC3LVEeg6ZqTUnpofrbrencrwjSmmnhJTnEsJIT6aqw=; b=gvNirxZfcgRkZFynvBfciuv++Kq53b96JgRrnUmrbZcMN41bnT7jjhsytvRg2R/kVV X5QyifWC6/fyBsGn7Da1ZMyZoXCtJ6jVkelNk4qlUX+YBrlmx8oatFxZh2iMut6HGULj GFURLljQJh6O5C2gVh0V0G4TO9KGU0Zsv8/Yo9dzkC52OHXwupdz4PoRpXhHi1cRXvGI 99dufatIl/kByPz6d3c6YZZWq8jV8+StjBQXPnl2QL4oZ9kEj8oAniy504FtvhCINoPo fzrF3G08oFxsWopkz5G7fx7Lo1M7UllcPufBDUQmvqV7h4HuWHaRZZFVqWetmlg34lzb 0/qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bC3LVEeg6ZqTUnpofrbrencrwjSmmnhJTnEsJIT6aqw=; b=VAuOtJV91MIgGtPw862SW0PrMzlKswZRXKfvGVHKpgcxS/UfUklCOcE7zCx1IWsj9c GhIBAsPsiHTEywnJlWR3J0nj+eduzpgsSWXxs3nhPA6daFTAF6C3JRiNJk6N0uiQaXEH mz6YR/8muYvfS6aM24/iElao2LBHpHI2pUmloTOPbVx0JruMxfEaAgUYIZrEDGGeqHgR iNhCjeIxInFbk8Es6DrGtctrl2qxtIxsF6uKD83HM+LDLA0Ide0ni92Olrw3MMEl/MpS x/6JAB000hdDVTKt2IpTQEUJNRH1aruNQ7XO4d3ho8j/7902VY6bOz/Bfodsrsed43P7 00pg== X-Gm-Message-State: AOAM5339UdgQRgoHHa3nkAJPGrfKguHTX3h1KHg2M1m5R6fOQ4nnHs6b obN4S8Fup6wg6+rt/9b4R+E= X-Google-Smtp-Source: ABdhPJzxrLEGsM7K1mcbu1ZIGBX+ZqXhsMOIpc0Ym69y6hXbx6GZaJ7QNA9oFinV6hRSxnv09A9K7w== X-Received: by 2002:a63:e14c:: with SMTP id h12mr183778pgk.431.1628320625383; Sat, 07 Aug 2021 00:17:05 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b15sm14604981pgm.15.2021.08.07.00.17.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Aug 2021 00:17:05 -0700 (PDT) From: Atharva Raykar To: raykar.ath@gmail.com Cc: avarab@gmail.com, christian.couder@gmail.com, congdanhqx@gmail.com, emilyshaffer@google.com, git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com, kaartic.sivaraam@gmail.com, pc44800@gmail.com, periperidip@gmail.com, rafaeloliveira.cs@gmail.com, sunshine@sunshineco.com Subject: [GSoC] [PATCH v4 3/8] submodule--helper: remove repeated code in sync_submodule() Date: Sat, 7 Aug 2021 12:46:08 +0530 Message-Id: <20210807071613.99610-4-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807071613.99610-1-raykar.ath@gmail.com> References: <20210806120147.73349-1-raykar.ath@gmail.com> <20210807071613.99610-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This part of `sync_submodule()` is doing the same thing that `compute_submodule_clone_url()` is doing. Let's reuse that helper here. Note that this change adds a small overhead where we allocate and free the 'remote' twice, but that is a small price to pay for the higher level of abstraction we get. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/submodule--helper.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f4b496bac6..9b676c12f8 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1373,20 +1373,10 @@ static void sync_submodule(const char *path, const char *prefix, if (sub && sub->url) { if (starts_with_dot_dot_slash(sub->url) || starts_with_dot_slash(sub->url)) { - char *remote_url, *up_path; - char *remote = get_default_remote(); - strbuf_addf(&sb, "remote.%s.url", remote); - - if (git_config_get_string(sb.buf, &remote_url)) - remote_url = xgetcwd(); - - up_path = get_up_path(path); - sub_origin_url = relative_url(remote_url, sub->url, up_path); - super_config_url = relative_url(remote_url, sub->url, NULL); - - free(remote); + char *up_path = get_up_path(path); + sub_origin_url = compute_submodule_clone_url(sub->url, up_path, 1); + super_config_url = compute_submodule_clone_url(sub->url, NULL, 1); free(up_path); - free(remote_url); } else { sub_origin_url = xstrdup(sub->url); super_config_url = xstrdup(sub->url); From patchwork Sat Aug 7 07:16:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12424189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A349AC4338F for ; Sat, 7 Aug 2021 07:17:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81B2F61163 for ; Sat, 7 Aug 2021 07:17:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbhHGHRc (ORCPT ); Sat, 7 Aug 2021 03:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbhHGHR1 (ORCPT ); Sat, 7 Aug 2021 03:17:27 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00179C0613CF for ; Sat, 7 Aug 2021 00:17:09 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id u5-20020a17090ae005b029017842fe8f82so12184373pjy.0 for ; Sat, 07 Aug 2021 00:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z3c3jAhcABfuJhK3t0XzvawmavSKzTDTc4wbhv+5x/I=; b=eIqTgTzxEc/Ns5Kj19ZLV8l42naG7cfQMbU49F7LfBq4lnW05T9VLEsCQ+zketbCOh T4gSYodYubDvYJQnzYOvzO0xpFs3SId/ODMem9/BGJkwVF47EPhnEo6tl5ag69/EHU1i f6xlf0vuOWF/dfyBCO4IPhpn5u1i1xyb/mrxiJg2RA8OXJ0R8YdeVMt6wP96GurE/Lqg kf6x6ZbscPat/xryLWeV9U6hRb6b957tzlm47BAHhLyiL09qRXxWt22Z20inNNZ2ojmw Q6UfW/pyBk/fnamHibx2f2gPK/3+P9tpicSLKVToRozjAJmsisN9qWOfEmPI6gQeh5PV N7IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z3c3jAhcABfuJhK3t0XzvawmavSKzTDTc4wbhv+5x/I=; b=H/tYFIr1CbrfQwIdn5aDkhAA8gJsFtcgQXEr7tzwliUSg9GNrNCqbtQm3JGPT357JE 9GLsPguwRnBbFnOtTmO+aEEPnV2lcYZy7zTlI7322frEL4wCdLts9FmaWWwefWDmJWIU locw9tiOk6QSITXFxqWqqoJXMzLUjLVkAGDV98ndjyVRO456HphHLnD9sx7g8qBPaxoi hDqz4bzN2sqMZDLsVOKI75oBqFlWGMMYncMS6serFk3GpO6lbIftf+EoA31l2wbeasuZ TOFmFDvamwjWOE4T45xW0RdV/q/qX+203LrWg5f3keoyuocWdS4bg9eqtauICSX5Nqlq JZrA== X-Gm-Message-State: AOAM533B5wZQ2LLTnCR025fGyjp3O9/B0oPNQsnWIakxjdekU2nIkXjq U6nU3fEy0ej6MjTD7P9l/M4= X-Google-Smtp-Source: ABdhPJycxS2ziYDlYhHyUt+/YVtdTRAbzi4p6XPTwtLNDfn7Xj3UmEb0Nl2g0eXjKiJY5sO1igSxXA== X-Received: by 2002:a63:5908:: with SMTP id n8mr447848pgb.202.1628320629545; Sat, 07 Aug 2021 00:17:09 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b15sm14604981pgm.15.2021.08.07.00.17.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Aug 2021 00:17:09 -0700 (PDT) From: Atharva Raykar To: raykar.ath@gmail.com Cc: avarab@gmail.com, christian.couder@gmail.com, congdanhqx@gmail.com, emilyshaffer@google.com, git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com, kaartic.sivaraam@gmail.com, pc44800@gmail.com, periperidip@gmail.com, rafaeloliveira.cs@gmail.com, sunshine@sunshineco.com Subject: [GSoC] [PATCH v4 4/8] dir: libify and export helper functions from clone.c Date: Sat, 7 Aug 2021 12:46:09 +0530 Message-Id: <20210807071613.99610-5-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807071613.99610-1-raykar.ath@gmail.com> References: <20210806120147.73349-1-raykar.ath@gmail.com> <20210807071613.99610-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org These functions can be useful to other parts of Git. Let's move them to dir.c, while renaming them to be make their functionality more explicit. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/clone.c | 118 +----------------------------------------------- dir.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++ dir.h | 10 ++++ 3 files changed, 126 insertions(+), 116 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 66fe66679c..5ba24b7ae7 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -217,120 +217,6 @@ static char *get_repo_path(const char *repo, int *is_bundle) return canon; } -static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) -{ - const char *end = repo + strlen(repo), *start, *ptr; - size_t len; - char *dir; - - /* - * Skip scheme. - */ - start = strstr(repo, "://"); - if (start == NULL) - start = repo; - else - start += 3; - - /* - * Skip authentication data. The stripping does happen - * greedily, such that we strip up to the last '@' inside - * the host part. - */ - for (ptr = start; ptr < end && !is_dir_sep(*ptr); ptr++) { - if (*ptr == '@') - start = ptr + 1; - } - - /* - * Strip trailing spaces, slashes and /.git - */ - while (start < end && (is_dir_sep(end[-1]) || isspace(end[-1]))) - end--; - if (end - start > 5 && is_dir_sep(end[-5]) && - !strncmp(end - 4, ".git", 4)) { - end -= 5; - while (start < end && is_dir_sep(end[-1])) - end--; - } - - /* - * Strip trailing port number if we've got only a - * hostname (that is, there is no dir separator but a - * colon). This check is required such that we do not - * strip URI's like '/foo/bar:2222.git', which should - * result in a dir '2222' being guessed due to backwards - * compatibility. - */ - if (memchr(start, '/', end - start) == NULL - && memchr(start, ':', end - start) != NULL) { - ptr = end; - while (start < ptr && isdigit(ptr[-1]) && ptr[-1] != ':') - ptr--; - if (start < ptr && ptr[-1] == ':') - end = ptr - 1; - } - - /* - * Find last component. To remain backwards compatible we - * also regard colons as path separators, such that - * cloning a repository 'foo:bar.git' would result in a - * directory 'bar' being guessed. - */ - ptr = end; - while (start < ptr && !is_dir_sep(ptr[-1]) && ptr[-1] != ':') - ptr--; - start = ptr; - - /* - * Strip .{bundle,git}. - */ - len = end - start; - strip_suffix_mem(start, &len, is_bundle ? ".bundle" : ".git"); - - if (!len || (len == 1 && *start == '/')) - die(_("No directory name could be guessed.\n" - "Please specify a directory on the command line")); - - if (is_bare) - dir = xstrfmt("%.*s.git", (int)len, start); - else - dir = xstrndup(start, len); - /* - * Replace sequences of 'control' characters and whitespace - * with one ascii space, remove leading and trailing spaces. - */ - if (*dir) { - char *out = dir; - int prev_space = 1 /* strip leading whitespace */; - for (end = dir; *end; ++end) { - char ch = *end; - if ((unsigned char)ch < '\x20') - ch = '\x20'; - if (isspace(ch)) { - if (prev_space) - continue; - prev_space = 1; - } else - prev_space = 0; - *out++ = ch; - } - *out = '\0'; - if (out > dir && prev_space) - out[-1] = '\0'; - } - return dir; -} - -static void strip_trailing_slashes(char *dir) -{ - char *end = dir + strlen(dir); - - while (dir < end - 1 && is_dir_sep(end[-1])) - end--; - *end = '\0'; -} - static int add_one_reference(struct string_list_item *item, void *cb_data) { struct strbuf err = STRBUF_INIT; @@ -1041,8 +927,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (argc == 2) dir = xstrdup(argv[1]); else - dir = guess_dir_name(repo_name, is_bundle, option_bare); - strip_trailing_slashes(dir); + dir = git_url_basename(repo_name, is_bundle, option_bare); + strip_dir_trailing_slashes(dir); dest_exists = path_exists(dir); if (dest_exists && !is_empty_dir(dir)) diff --git a/dir.c b/dir.c index 03c4d21267..6d26db3189 100644 --- a/dir.c +++ b/dir.c @@ -2970,6 +2970,120 @@ int is_empty_dir(const char *path) return ret; } +char *git_url_basename(const char *repo, int is_bundle, int is_bare) +{ + const char *end = repo + strlen(repo), *start, *ptr; + size_t len; + char *dir; + + /* + * Skip scheme. + */ + start = strstr(repo, "://"); + if (start == NULL) + start = repo; + else + start += 3; + + /* + * Skip authentication data. The stripping does happen + * greedily, such that we strip up to the last '@' inside + * the host part. + */ + for (ptr = start; ptr < end && !is_dir_sep(*ptr); ptr++) { + if (*ptr == '@') + start = ptr + 1; + } + + /* + * Strip trailing spaces, slashes and /.git + */ + while (start < end && (is_dir_sep(end[-1]) || isspace(end[-1]))) + end--; + if (end - start > 5 && is_dir_sep(end[-5]) && + !strncmp(end - 4, ".git", 4)) { + end -= 5; + while (start < end && is_dir_sep(end[-1])) + end--; + } + + /* + * Strip trailing port number if we've got only a + * hostname (that is, there is no dir separator but a + * colon). This check is required such that we do not + * strip URI's like '/foo/bar:2222.git', which should + * result in a dir '2222' being guessed due to backwards + * compatibility. + */ + if (memchr(start, '/', end - start) == NULL + && memchr(start, ':', end - start) != NULL) { + ptr = end; + while (start < ptr && isdigit(ptr[-1]) && ptr[-1] != ':') + ptr--; + if (start < ptr && ptr[-1] == ':') + end = ptr - 1; + } + + /* + * Find last component. To remain backwards compatible we + * also regard colons as path separators, such that + * cloning a repository 'foo:bar.git' would result in a + * directory 'bar' being guessed. + */ + ptr = end; + while (start < ptr && !is_dir_sep(ptr[-1]) && ptr[-1] != ':') + ptr--; + start = ptr; + + /* + * Strip .{bundle,git}. + */ + len = end - start; + strip_suffix_mem(start, &len, is_bundle ? ".bundle" : ".git"); + + if (!len || (len == 1 && *start == '/')) + die(_("No directory name could be guessed.\n" + "Please specify a directory on the command line")); + + if (is_bare) + dir = xstrfmt("%.*s.git", (int)len, start); + else + dir = xstrndup(start, len); + /* + * Replace sequences of 'control' characters and whitespace + * with one ascii space, remove leading and trailing spaces. + */ + if (*dir) { + char *out = dir; + int prev_space = 1 /* strip leading whitespace */; + for (end = dir; *end; ++end) { + char ch = *end; + if ((unsigned char)ch < '\x20') + ch = '\x20'; + if (isspace(ch)) { + if (prev_space) + continue; + prev_space = 1; + } else + prev_space = 0; + *out++ = ch; + } + *out = '\0'; + if (out > dir && prev_space) + out[-1] = '\0'; + } + return dir; +} + +void strip_dir_trailing_slashes(char *dir) +{ + char *end = dir + strlen(dir); + + while (dir < end - 1 && is_dir_sep(end[-1])) + end--; + *end = '\0'; +} + static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up) { DIR *dir; diff --git a/dir.h b/dir.h index b3e1a54a97..a4a6fd7371 100644 --- a/dir.h +++ b/dir.h @@ -453,6 +453,16 @@ static inline int is_dot_or_dotdot(const char *name) int is_empty_dir(const char *dir); +/* + * Retrieve the "humanish" basename of the given Git URL. + * + * For example: + * /path/to/repo.git => "repo" + * host.xz.foo/.git => "foo" + */ +char *git_url_basename(const char *repo, int is_bundle, int is_bare); +void strip_dir_trailing_slashes(char *dir); + void setup_standard_excludes(struct dir_struct *dir); char *get_sparse_checkout_filename(void); From patchwork Sat Aug 7 07:16:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12424191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88FD1C4338F for ; Sat, 7 Aug 2021 07:17:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68E0261184 for ; Sat, 7 Aug 2021 07:17:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231510AbhHGHRe (ORCPT ); Sat, 7 Aug 2021 03:17:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbhHGHRd (ORCPT ); Sat, 7 Aug 2021 03:17:33 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15864C06179B for ; Sat, 7 Aug 2021 00:17:14 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id bh7so1403972plb.5 for ; Sat, 07 Aug 2021 00:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5/HhBsyyhx4TFhbeDyvqD34pBNyQDMh39jjhl5b5lbs=; b=M8mqtdOa+iw6mdCgmk5ACGjRhf2GEClbWpGqIZeGavz6PUekmNsD8rSev8GwmjODn7 UAmht4nTwE0M5e7u8+YVsRYbFMhib2+eSSK2ymQMirCMGxJpJ6jJTJziUBQxVA8Nlgle mhn+VnCazXKUrPQziimXfejXhsPez80BgFmdKTVHGChDMYropNL84C7nXZNc9g2Ba1NW UW7La4gkz7P9s2ndX5zfcDC9+WL1nn3k/HDxjfk3qQVw0YJUbMw7H2RHcAKqqYqGmsWz qch93WCEzsYlPpyWxR3Kl9gNrxmFHfDZArGEWFh39hj2BCj89Mi5F4E6kwJh6RZ2X94n RaiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5/HhBsyyhx4TFhbeDyvqD34pBNyQDMh39jjhl5b5lbs=; b=XwdsYU/RpRoVqW24PlK+HwPFAq/zOLFUTg65G2P1pAq9N9F+v2JwBwJcyIDuGsJU50 ncBR3nzddoagp/JQzHilC9BF4AUan6dP2Te+ZhVVT3XZKOKP/0Dvtt+Gz661wBD/0nwe x7oDuUhMgmnmIVEamWaobJu/sG4/5l2CzvKAajs8+CVdlpADwE+brjrvSa1lZqKQngsK iZ7YILgv68/I7nuzq8fUKiW6sgG4NvddzYb/qh3w0yWCDElzDqm9veFkL5xMZoSfY8Ze FLHxbH2xTeZ7yN9oHnV9T4FFSS+GZu4RVZM3gk6rx5AgQXT4NBczg6blidEjm292d4J+ Ll9w== X-Gm-Message-State: AOAM531j7srppswnDatWBdYpfJlamO5Uo7mNI43Y0lZq+w0O6WhgFU1h nyCfG3nN1JPV1csON2R/eUvv/29y5QJopQQg X-Google-Smtp-Source: ABdhPJyybxwvbkZkDz8acOOkMCFvjGKEk520m/Gy+uLmQ1xgYrURmiexTnZtzWhFht3ZR6uGumsM1Q== X-Received: by 2002:a17:90a:9f91:: with SMTP id o17mr24585892pjp.29.1628320633645; Sat, 07 Aug 2021 00:17:13 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b15sm14604981pgm.15.2021.08.07.00.17.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Aug 2021 00:17:13 -0700 (PDT) From: Atharva Raykar To: raykar.ath@gmail.com Cc: avarab@gmail.com, christian.couder@gmail.com, congdanhqx@gmail.com, emilyshaffer@google.com, git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com, kaartic.sivaraam@gmail.com, pc44800@gmail.com, periperidip@gmail.com, rafaeloliveira.cs@gmail.com, sunshine@sunshineco.com Subject: [GSoC] [PATCH v4 5/8] submodule--helper: convert the bulk of cmd_add() to C Date: Sat, 7 Aug 2021 12:46:10 +0530 Message-Id: <20210807071613.99610-6-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807071613.99610-1-raykar.ath@gmail.com> References: <20210806120147.73349-1-raykar.ath@gmail.com> <20210807071613.99610-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Introduce the 'add' subcommand to `submodule--helper.c` that does all the work 'submodule add' past the parsing of flags. We also remove the constness of the sm_path field of the `add_data` struct. This is needed so that it can be modified by normalize_path_copy(). As with the previous conversions, this is meant to be a faithful conversion with no modification to the behaviour of `submodule add`. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Helped-by: Kaartic Sivaraam Mentored-by: Shourya Shukla Based-on-patch-by: Shourya Shukla Based-on-patch-by: Prathamesh Chavan --- builtin/submodule--helper.c | 165 +++++++++++++++++++++++++++++++++++- git-submodule.sh | 96 +-------------------- 2 files changed, 166 insertions(+), 95 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9b676c12f8..3aa3ae8b61 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2748,7 +2748,7 @@ struct add_data { const char *prefix; const char *branch; const char *reference_path; - const char *sm_path; + char *sm_path; const char *sm_name; const char *repo; const char *realrepo; @@ -3046,6 +3046,168 @@ static int add_config(int argc, const char **argv, const char *prefix) return 0; } +static void die_on_index_match(const char *path, int force) +{ + struct pathspec ps; + const char *args[] = { path, NULL }; + parse_pathspec(&ps, 0, PATHSPEC_PREFER_CWD, NULL, args); + + if (read_cache_preload(NULL) < 0) + die(_("index file corrupt")); + + if (ps.nr) { + int i; + char *ps_matched = xcalloc(ps.nr, 1); + + /* TODO: audit for interaction with sparse-index. */ + ensure_full_index(&the_index); + + /* + * Since there is only one pathspec, we just need + * need to check ps_matched[0] to know if a cache + * entry matched. + */ + for (i = 0; i < active_nr; i++) { + ce_path_match(&the_index, active_cache[i], &ps, + ps_matched); + + if (ps_matched[0]) { + if (!force) + die(_("'%s' already exists in the index"), + path); + if (!S_ISGITLINK(active_cache[i]->ce_mode)) + die(_("'%s' already exists in the index " + "and is not a submodule"), path); + break; + } + } + free(ps_matched); + } +} + +static void die_on_repo_without_commits(const char *path) +{ + struct strbuf sb = STRBUF_INIT; + strbuf_addstr(&sb, path); + if (is_nonbare_repository_dir(&sb)) { + struct object_id oid; + if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) + die(_("'%s' does not have a commit checked out"), path); + } +} + +static int module_add(int argc, const char **argv, const char *prefix) +{ + int force = 0, quiet = 0, progress = 0, dissociate = 0; + struct add_data add_data = ADD_DATA_INIT; + + struct option options[] = { + OPT_STRING('b', "branch", &add_data.branch, N_("branch"), + N_("branch of repository to add as submodule")), + OPT__FORCE(&force, N_("allow adding an otherwise ignored submodule path"), + PARSE_OPT_NOCOMPLETE), + OPT__QUIET(&quiet, N_("print only error messages")), + OPT_BOOL(0, "progress", &progress, N_("force cloning progress")), + OPT_STRING(0, "reference", &add_data.reference_path, N_("repository"), + N_("reference repository")), + OPT_BOOL(0, "dissociate", &dissociate, N_("borrow the objects from reference repositories")), + OPT_STRING(0, "name", &add_data.sm_name, N_("name"), + N_("sets the submodule’s name to the given string " + "instead of defaulting to its path")), + OPT_INTEGER(0, "depth", &add_data.depth, N_("depth for shallow clones")), + OPT_END() + }; + + const char *const usage[] = { + N_("git submodule--helper add [] [--] []"), + NULL + }; + + argc = parse_options(argc, argv, prefix, options, usage, 0); + + if (!is_writing_gitmodules_ok()) + die(_("please make sure that the .gitmodules file is in the working tree")); + + if (prefix && *prefix && + add_data.reference_path && !is_absolute_path(add_data.reference_path)) + add_data.reference_path = xstrfmt("%s%s", prefix, add_data.reference_path); + + if (argc == 0 || argc > 2) + usage_with_options(usage, options); + + add_data.repo = argv[0]; + if (argc == 1) + add_data.sm_path = git_url_basename(add_data.repo, 0, 0); + else + add_data.sm_path = xstrdup(argv[1]); + + if (prefix && *prefix && !is_absolute_path(add_data.sm_path)) + add_data.sm_path = xstrfmt("%s%s", prefix, add_data.sm_path); + + if (starts_with_dot_dot_slash(add_data.repo) || + starts_with_dot_slash(add_data.repo)) { + if (prefix) + die(_("Relative path can only be used from the toplevel " + "of the working tree")); + + /* dereference source url relative to parent's url */ + add_data.realrepo = compute_submodule_clone_url(add_data.repo, NULL, 1); + } else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) { + add_data.realrepo = add_data.repo; + } else { + die(_("repo URL: '%s' must be absolute or begin with ./|../"), + add_data.repo); + } + + /* + * normalize path: + * multiple //; leading ./; /./; /../; + */ + normalize_path_copy(add_data.sm_path, add_data.sm_path); + strip_dir_trailing_slashes(add_data.sm_path); + + die_on_index_match(add_data.sm_path, force); + die_on_repo_without_commits(add_data.sm_path); + + if (!force) { + int exit_code = -1; + struct strbuf sb = STRBUF_INIT; + struct child_process cp = CHILD_PROCESS_INIT; + cp.git_cmd = 1; + cp.no_stdout = 1; + strvec_pushl(&cp.args, "add", "--dry-run", "--ignore-missing", + "--no-warn-embedded-repo", add_data.sm_path, NULL); + if ((exit_code = pipe_command(&cp, NULL, 0, NULL, 0, &sb, 0))) { + strbuf_complete_line(&sb); + fputs(sb.buf, stderr); + free(add_data.sm_path); + return exit_code; + } + strbuf_release(&sb); + } + + if(!add_data.sm_name) + add_data.sm_name = add_data.sm_path; + + if (check_submodule_name(add_data.sm_name)) + die(_("'%s' is not a valid submodule name"), add_data.sm_name); + + add_data.prefix = prefix; + add_data.force = !!force; + add_data.quiet = !!quiet; + add_data.progress = !!progress; + add_data.dissociate = !!dissociate; + + if (add_submodule(&add_data)) { + free(add_data.sm_path); + return 1; + } + configure_added_submodule(&add_data); + free(add_data.sm_path); + + return 0; +} + #define SUPPORT_SUPER_PREFIX (1<<0) struct cmd_struct { @@ -3060,6 +3222,7 @@ static struct cmd_struct commands[] = { {"clone", module_clone, 0}, {"add-clone", add_clone, 0}, {"add-config", add_config, 0}, + {"add", module_add, SUPPORT_SUPER_PREFIX}, {"update-module-mode", module_update_module_mode, 0}, {"update-clone", update_clone, 0}, {"ensure-core-worktree", ensure_core_worktree, 0}, diff --git a/git-submodule.sh b/git-submodule.sh index 8c219ef382..1070540525 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -145,104 +145,12 @@ cmd_add() shift done - if ! git submodule--helper config --check-writeable >/dev/null 2>&1 + if test -z "$1" then - die "fatal: $(eval_gettext "please make sure that the .gitmodules file is in the working tree")" - fi - - if test -n "$reference_path" - then - is_absolute_path "$reference_path" || - reference_path="$wt_prefix$reference_path" - - reference="--reference=$reference_path" - fi - - repo=$1 - sm_path=$2 - - if test -z "$sm_path"; then - sm_path=$(printf '%s\n' "$repo" | - sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g') - fi - - if test -z "$repo" || test -z "$sm_path"; then usage fi - is_absolute_path "$sm_path" || sm_path="$wt_prefix$sm_path" - - # assure repo is absolute or relative to parent - case "$repo" in - ./*|../*) - test -z "$wt_prefix" || - die "fatal: $(gettext "Relative path can only be used from the toplevel of the working tree")" - - # dereference source url relative to parent's url - realrepo=$(git submodule--helper resolve-relative-url "$repo") || exit - ;; - *:*|/*) - # absolute url - realrepo=$repo - ;; - *) - die "fatal: $(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")" - ;; - esac - - # normalize path: - # multiple //; leading ./; /./; /../; trailing / - sm_path=$(printf '%s/\n' "$sm_path" | - sed -e ' - s|//*|/|g - s|^\(\./\)*|| - s|/\(\./\)*|/|g - :start - s|\([^/]*\)/\.\./|| - tstart - s|/*$|| - ') - if test -z "$force" - then - git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 && - die "fatal: $(eval_gettext "'\$sm_path' already exists in the index")" - else - git ls-files -s "$sm_path" | sane_grep -v "^160000" > /dev/null 2>&1 && - die "fatal: $(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")" - fi - - if test -d "$sm_path" && - test -z $(git -C "$sm_path" rev-parse --show-cdup 2>/dev/null) - then - git -C "$sm_path" rev-parse --verify -q HEAD >/dev/null || - die "fatal: $(eval_gettext "'\$sm_path' does not have a commit checked out")" - fi - - if test -z "$force" - then - dryerr=$(git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" 2>&1 >/dev/null) - res=$? - if test $res -ne 0 - then - echo >&2 "$dryerr" - exit $res - fi - fi - - if test -n "$custom_name" - then - sm_name="$custom_name" - else - sm_name="$sm_path" - fi - - if ! git submodule--helper check-name "$sm_name" - then - die "fatal: $(eval_gettext "'$sm_name' is not a valid submodule name")" - fi - - git submodule--helper add-clone ${GIT_QUIET:+--quiet} ${force:+"--force"} ${progress:+"--progress"} ${branch:+--branch "$branch"} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${dissociate:+"--dissociate"} ${depth:+"$depth"} || exit - git submodule--helper add-config ${force:+--force} ${branch:+--branch "$branch"} --url "$repo" --resolved-url "$realrepo" --path "$sm_path" --name "$sm_name" + git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" } # From patchwork Sat Aug 7 07:16:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12424193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07382C4338F for ; Sat, 7 Aug 2021 07:17:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8C6161163 for ; Sat, 7 Aug 2021 07:17:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231539AbhHGHRj (ORCPT ); Sat, 7 Aug 2021 03:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbhHGHRg (ORCPT ); Sat, 7 Aug 2021 03:17:36 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39088C0613CF for ; Sat, 7 Aug 2021 00:17:18 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id j1so20063278pjv.3 for ; Sat, 07 Aug 2021 00:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r4Ixvdig+iVi+/YHopq/0oQi3oXJRiBED8Nh2SNx8Qo=; b=M9C5mxDy2Gv9ZjD2DtJcoN9z6ywLuAxk5EmqO+LNk9LEez62gtOnGctX9WObPGpAbX wloaDV5VyHvkWiAgsipAeSc5eaAOiLf68oeK8hhuQgAJWWgJiAeUFHLwGBvDd3RoKFx1 bUGJUgjO03csTkFcC4NVyyv3DQq55moYSW+5hxIJWlyHq2YQxH9XZsZyElZ+zQQzJRcG d15dE6/uY8OcP7jsqBuJEs7C4+w1kh3GqDVlZAbx4A6mVcjJP+jAxd/B5hKFqF6nWK3+ MINxDi+jZ8uSF8Kf7DNZGoFSOwNcscoacVPrGWEBLh47VDHb0Fby33H7JCLHyJkVPoiD n3cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r4Ixvdig+iVi+/YHopq/0oQi3oXJRiBED8Nh2SNx8Qo=; b=aGn6JETZhrIYstQavhgeXQqIdWHW5KJ97kz+7QAj07WG0YB9quAmzPMjXZ6jStjCAP I0pTlL30jnNnKXyLXlDwEmzXsaZgAW5Vh9NecpSckA8sFaLu8NQDX3QZkI6RSoug4Vel 9V6hMwgO2SfucHb8RyIwXgyBnWSrwIYLkoPxuTbjsokAiQSjrIhhhYuYKgXNsd1vSHq8 J/Ff6cOCj2MKQTX17pcgkGnhIyOWYuwq3zmaBRnvrNBPyACkT0zfA66/0FnGrrhfwD5V n0DjkDJu8xjQTphy1Jdqo29xCS0T6ZzK4U+4U4MClpU0IK1A3ImTQOS19/7DM5HjR7e+ c9MA== X-Gm-Message-State: AOAM531N4zDFQeqdkCp9ufSrcjEfSAin+ReGq5+7lNGvWsioND4VxqiS ZchD14Zl2reaFMsef9oaOOY= X-Google-Smtp-Source: ABdhPJwcaRjvFUO69xyNfokZhrjaDCLwDZmh3jwPq3/XrdjkXJ7eCq8RHj75s5ji0oulg4seHHnOLg== X-Received: by 2002:a17:90b:2286:: with SMTP id kx6mr25423698pjb.11.1628320637812; Sat, 07 Aug 2021 00:17:17 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b15sm14604981pgm.15.2021.08.07.00.17.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Aug 2021 00:17:17 -0700 (PDT) From: Atharva Raykar To: raykar.ath@gmail.com Cc: avarab@gmail.com, christian.couder@gmail.com, congdanhqx@gmail.com, emilyshaffer@google.com, git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com, kaartic.sivaraam@gmail.com, pc44800@gmail.com, periperidip@gmail.com, rafaeloliveira.cs@gmail.com, sunshine@sunshineco.com Subject: [GSoC] [PATCH v4 6/8] submodule--helper: remove add-clone subcommand Date: Sat, 7 Aug 2021 12:46:11 +0530 Message-Id: <20210807071613.99610-7-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807071613.99610-1-raykar.ath@gmail.com> References: <20210806120147.73349-1-raykar.ath@gmail.com> <20210807071613.99610-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We no longer need this subcommand, as all of its functionality is being called by the newly-introduced `module_add()` directly within C. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/submodule--helper.c | 60 ------------------------------------- 1 file changed, 60 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 3aa3ae8b61..5932438d65 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2860,65 +2860,6 @@ static int add_submodule(const struct add_data *add_data) return 0; } -static int add_clone(int argc, const char **argv, const char *prefix) -{ - int force = 0, quiet = 0, dissociate = 0, progress = 0; - struct add_data add_data = ADD_DATA_INIT; - - struct option options[] = { - OPT_STRING('b', "branch", &add_data.branch, - N_("branch"), - N_("branch of repository to checkout on cloning")), - OPT_STRING(0, "prefix", &prefix, - N_("path"), - N_("alternative anchor for relative paths")), - OPT_STRING(0, "path", &add_data.sm_path, - N_("path"), - N_("where the new submodule will be cloned to")), - OPT_STRING(0, "name", &add_data.sm_name, - N_("string"), - N_("name of the new submodule")), - OPT_STRING(0, "url", &add_data.realrepo, - N_("string"), - N_("url where to clone the submodule from")), - OPT_STRING(0, "reference", &add_data.reference_path, - N_("repo"), - N_("reference repository")), - OPT_BOOL(0, "dissociate", &dissociate, - N_("use --reference only while cloning")), - OPT_INTEGER(0, "depth", &add_data.depth, - N_("depth for shallow clones")), - OPT_BOOL(0, "progress", &progress, - N_("force cloning progress")), - OPT__FORCE(&force, N_("allow adding an otherwise ignored submodule path"), - PARSE_OPT_NOCOMPLETE), - OPT__QUIET(&quiet, "suppress output for cloning a submodule"), - OPT_END() - }; - - const char *const usage[] = { - N_("git submodule--helper add-clone [...] " - "--url --path --name "), - NULL - }; - - argc = parse_options(argc, argv, prefix, options, usage, 0); - - if (argc != 0) - usage_with_options(usage, options); - - add_data.prefix = prefix; - add_data.progress = !!progress; - add_data.dissociate = !!dissociate; - add_data.force = !!force; - add_data.quiet = !!quiet; - - if (add_submodule(&add_data)) - return 1; - - return 0; -} - static int config_submodule_in_gitmodules(const char *name, const char *var, const char *value) { char *key; @@ -3220,7 +3161,6 @@ static struct cmd_struct commands[] = { {"list", module_list, 0}, {"name", module_name, 0}, {"clone", module_clone, 0}, - {"add-clone", add_clone, 0}, {"add-config", add_config, 0}, {"add", module_add, SUPPORT_SUPER_PREFIX}, {"update-module-mode", module_update_module_mode, 0}, From patchwork Sat Aug 7 07:16:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12424195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D0A4C4338F for ; Sat, 7 Aug 2021 07:17:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AA6060F0F for ; Sat, 7 Aug 2021 07:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231497AbhHGHRr (ORCPT ); Sat, 7 Aug 2021 03:17:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231536AbhHGHRj (ORCPT ); Sat, 7 Aug 2021 03:17:39 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67CEDC0613CF for ; Sat, 7 Aug 2021 00:17:22 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id z3so10199903plg.8 for ; Sat, 07 Aug 2021 00:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VerDo6WCLGukMTTzg2NEC3AEcYJXQGjN+FkojerC2vA=; b=B8EvjS/C1DKw51u8oNUYfFkrqEzVbJZnqAAyas97tF0Gy2xq3riUjfO8zsA5FTjw1y Y20+Vip14j499oxfstJB+r91PhGBfb+YiGQHe0c0IFPBkc8cTvPQki+LKC8xz5oWhI9K 4XFth1lc/hrXK5PJMV5ev4xmY7hsyn1rQ1dZRPoFlsRsgtg5V+wykusaf1RjUSGUvH+l dC31JHBK0hx/qRqDwbqZ2rugpmRHU5acm9qbrXti9TpdWDxFdfG+RhlEpfnqDbXKurRK 90fkRyFf+NWuWHTte6bqrQEFAYzdsgtjcXEPBRoTuHWP0nEY6hApOkCYGj9Pae2xCf9T CDYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VerDo6WCLGukMTTzg2NEC3AEcYJXQGjN+FkojerC2vA=; b=ZlKUE8L2l6WEoxa/Srjh6O1+jV8P83u+RYj+niAK5eHJuEvKzPV9YBb6q7xtAzFB7M OHOCBAnpqAjz6IE3B/+40h1nK5Toc9tzN7AyVMkok0UBhcsBzYh6WqlUp7YZzGH/Qgqu 4vUATX8G/wrGS5kDL2C3zK2cAKLuL2IxaCRXCuyX2i1mJzsp4wKzmDINRUQ793s0bO5G 7l6jDeeleeW4yGcGddWgf3c+xuJ0YTr3ny9BmgVUyUi09QBNCnc1ARXmHF9zYY50K5My I2s8IPaCT988fJNm66kjcDEH1w2CSF9hgxsGE1GpxQJe6G4e6X2fjcA9Agaz9HrN2NLZ Ot3A== X-Gm-Message-State: AOAM533B29ZzCfXSGZwLrJ2uDIbrjzHxKfHc/Nb6QlbMr3v6PutXqFZC RAzjasxJMR6RpuVq9FFEzn0= X-Google-Smtp-Source: ABdhPJyt8De0LDqmEgzDYxijnWz6wcsBmbpJ78A3gjNi9AQpNyreAjHgmYXP1dwQ5XoffhDP3DXpfA== X-Received: by 2002:a63:1709:: with SMTP id x9mr1026070pgl.28.1628320642019; Sat, 07 Aug 2021 00:17:22 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b15sm14604981pgm.15.2021.08.07.00.17.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Aug 2021 00:17:21 -0700 (PDT) From: Atharva Raykar To: raykar.ath@gmail.com Cc: avarab@gmail.com, christian.couder@gmail.com, congdanhqx@gmail.com, emilyshaffer@google.com, git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com, kaartic.sivaraam@gmail.com, pc44800@gmail.com, periperidip@gmail.com, rafaeloliveira.cs@gmail.com, sunshine@sunshineco.com Subject: [GSoC] [PATCH v4 7/8] submodule--helper: remove add-config subcommand Date: Sat, 7 Aug 2021 12:46:12 +0530 Message-Id: <20210807071613.99610-8-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807071613.99610-1-raykar.ath@gmail.com> References: <20210806120147.73349-1-raykar.ath@gmail.com> <20210807071613.99610-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Also no longer needed is this subcommand, as all of its functionality is being called by the newly-introduced `module_add()` directly within C. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/submodule--helper.c | 49 ------------------------------------- 1 file changed, 49 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 5932438d65..d526423a0c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2939,54 +2939,6 @@ static void configure_added_submodule(struct add_data *add_data) } } -static int add_config(int argc, const char **argv, const char *prefix) -{ - int force = 0; - struct add_data add_data = ADD_DATA_INIT; - - struct option options[] = { - OPT_STRING('b', "branch", &add_data.branch, - N_("branch"), - N_("branch of repository to store in " - "the submodule configuration")), - OPT_STRING(0, "url", &add_data.repo, - N_("string"), - N_("url to clone submodule from")), - OPT_STRING(0, "resolved-url", &add_data.realrepo, - N_("string"), - N_("url to clone the submodule from, after it has " - "been dereferenced relative to parent's url, " - "in the case where is a relative url")), - OPT_STRING(0, "path", &add_data.sm_path, - N_("path"), - N_("where the new submodule will be cloned to")), - OPT_STRING(0, "name", &add_data.sm_name, - N_("string"), - N_("name of the new submodule")), - OPT__FORCE(&force, N_("allow adding an otherwise ignored submodule path"), - PARSE_OPT_NOCOMPLETE), - OPT_END() - }; - - const char *const usage[] = { - N_("git submodule--helper add-config " - "[--force|-f] [--branch|-b ] " - "--url --resolved-url " - "--path --name "), - NULL - }; - - argc = parse_options(argc, argv, prefix, options, usage, 0); - - if (argc) - usage_with_options(usage, options); - - add_data.force = !!force; - configure_added_submodule(&add_data); - - return 0; -} - static void die_on_index_match(const char *path, int force) { struct pathspec ps; @@ -3161,7 +3113,6 @@ static struct cmd_struct commands[] = { {"list", module_list, 0}, {"name", module_name, 0}, {"clone", module_clone, 0}, - {"add-config", add_config, 0}, {"add", module_add, SUPPORT_SUPER_PREFIX}, {"update-module-mode", module_update_module_mode, 0}, {"update-clone", update_clone, 0}, From patchwork Sat Aug 7 07:16:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12424197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B18A7C4320A for ; Sat, 7 Aug 2021 07:17:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93C4460F0F for ; Sat, 7 Aug 2021 07:17:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231508AbhHGHRt (ORCPT ); Sat, 7 Aug 2021 03:17:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231523AbhHGHRq (ORCPT ); Sat, 7 Aug 2021 03:17:46 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23F1BC06179A for ; Sat, 7 Aug 2021 00:17:26 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id j1so20063660pjv.3 for ; Sat, 07 Aug 2021 00:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=clA24kMKRMcE4dsNXF8NItKQefu2PB5aJzRuAOOWW/E=; b=cXafzQWrL/SjT/lPQR1azaX9SiAFEI9v5zqDqd7XqxLoxUVDCKIXMaDenk93JObFDm Wy7ClBkhTVfU/L8Fociq3TGf8bG/O+B1Bylv5j6i7Eqhu05cEdXoXyPeCrq7xDdy1AOD zk1ki+9IeZGuq7J2ubzLUs9hy4ifaSuN659K1L1ThYoNThdOsak1VN3Hmg6zDH1W4ZQU LJLmfmEwBarcedb3atwxq/tj0mcC7iJIYcionfGZevDgGkiofem3LDUdmuhf1sn57l8r P/oOzaZcFQbhfI/tQc6rHtsM38CktvM0UEVObuLMDQ48ri8VB/8kQsElSdw1VaTRyl5T SvSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=clA24kMKRMcE4dsNXF8NItKQefu2PB5aJzRuAOOWW/E=; b=lLIOz3RsoG5RMUAtKqk3TUEHZZYIiGg6czBUQNe1Mi9DxA79AFo9s+LVXFVNPXFMvW E250r4jWGvX8dl7hrDNZhisokmA5tTQaQuFqtwdEosPyxJUpy4N1uOFT3mqF62N6xyIh USaAtPkhc6xAv6URfdwNatwSkiq6DdhjTKamNJqeqt+Fszk8z2GV6ukWWNJaBymml4+E 7fQ9WT/LvWSVquzvK/SCFcwvPARdn8aG6ansZeyocr1Z11OP1VdTvbTkh0pHU30Gc8KI GcL1ckYsEF07zZa29MxeoNuHTqzEYRHr4NLkBVut30PUF20tb0gdOIf3Rd26RVUT4q4t aKKQ== X-Gm-Message-State: AOAM530ns4WGbsgLICsxwYNhdSLLTfJ6GPp/z3kw9dg4RyALh5xxxNRj jlVnxw1aEnwePQrMwbN6z1U= X-Google-Smtp-Source: ABdhPJx49VKDFOhoivnZmKBQPko5EFqba0qw3udsT0nUZg2K7Qpx9nhflJfcjBXUNzuAWBw3eNr6Pg== X-Received: by 2002:a63:4e0d:: with SMTP id c13mr543586pgb.276.1628320646198; Sat, 07 Aug 2021 00:17:26 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b15sm14604981pgm.15.2021.08.07.00.17.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Aug 2021 00:17:25 -0700 (PDT) From: Atharva Raykar To: raykar.ath@gmail.com Cc: avarab@gmail.com, christian.couder@gmail.com, congdanhqx@gmail.com, emilyshaffer@google.com, git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com, kaartic.sivaraam@gmail.com, pc44800@gmail.com, periperidip@gmail.com, rafaeloliveira.cs@gmail.com, sunshine@sunshineco.com Subject: [GSoC] [PATCH v4 8/8] submodule--helper: remove resolve-relative-url subcommand Date: Sat, 7 Aug 2021 12:46:13 +0530 Message-Id: <20210807071613.99610-9-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807071613.99610-1-raykar.ath@gmail.com> References: <20210806120147.73349-1-raykar.ath@gmail.com> <20210807071613.99610-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The shell subcommand `resolve-relative-url` is no longer required, as its last caller has been removed when it was converted to C. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/submodule--helper.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index d526423a0c..bc123d7aaf 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -223,25 +223,6 @@ static char *compute_submodule_clone_url(const char *rel_url, const char *up_pat return relurl; } -static int resolve_relative_url(int argc, const char **argv, const char *prefix) -{ - const char *up_path = NULL; - char *res; - const char *url; - - if (argc != 2 && argc != 3) - die("resolve-relative-url only accepts one or two arguments"); - - url = argv[1]; - if (argc == 3) - up_path = argv[2]; - - res = compute_submodule_clone_url(url, up_path, 1); - puts(res); - free(res); - return 0; -} - static int resolve_relative_url_test(int argc, const char **argv, const char *prefix) { char *remoteurl, *res; @@ -3118,7 +3099,6 @@ static struct cmd_struct commands[] = { {"update-clone", update_clone, 0}, {"ensure-core-worktree", ensure_core_worktree, 0}, {"relative-path", resolve_relative_path, 0}, - {"resolve-relative-url", resolve_relative_url, 0}, {"resolve-relative-url-test", resolve_relative_url_test, 0}, {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, {"init", module_init, SUPPORT_SUPER_PREFIX},