From patchwork Tue Aug 10 11:46:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428721 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 5E9B0C4338F for ; Tue, 10 Aug 2021 11:47:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A99E60E09 for ; Tue, 10 Aug 2021 11:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240267AbhHJLsB (ORCPT ); Tue, 10 Aug 2021 07:48:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240346AbhHJLra (ORCPT ); Tue, 10 Aug 2021 07:47:30 -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 B4341C061798 for ; Tue, 10 Aug 2021 04:47:06 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id f3so10001452plg.3 for ; Tue, 10 Aug 2021 04:47:06 -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=IHeFSdmlvW+yoS8FzEgnzH+iAl6gP8Vkd6+v9xM7+JI=; b=Hy2xSueiy9hbRzX4AW/2TFI/o/lMe3tQuqPxnv77VFyFnLi28YKE3MriErafKdJlZd R4E/SWdT9D/ikUthyZ7WTxsPPjCkSVd/eOHVWTXhq9zsCJEA4HdQox/i07ihq0mY0WIj lDO66vsbI6ZyNMRNTcKaG9fuNLydvg5geqSUkNthHQg/5kiqrFMRXuCcHbuIx0pWQ3hT jEx3f5DsoY1lteVVmsItx69m11Lc/6bn29V4kZ0p/4CNZxz6ItO/ieRp4JEsLZbokiGm zm5W75N/GMdvahNLjCygHlD1aCIBEGWtcZOTbuw4Z8JgBU3vev9TuuW5GAEtIk593tz3 qdmg== 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=IHeFSdmlvW+yoS8FzEgnzH+iAl6gP8Vkd6+v9xM7+JI=; b=Z+kr+IxFabD2ErDrZ+vJlnuuqQq4lq5K2KoGT7hp1+zoryYv135zqRueDmF1BtzIkh Hugx6pOSLFsZdlvk/701p1pYnQZ55BW6gQ3yY0qgUZMA4aXY3/v/1CBwjm+yE4sYYRFh fQP+y2X0+ikhFbLIM0aXfnb/imw/NUzi5T+CIcDLLxB5kQ0oaVytJbxviV0v9DFJgbtp mqHyXy3IDEbfdLXw5eT9nB6i43Fv1W3RfY4QnixdnsknjhuUsYjUoBsV/lIQ0X5G7gnE vNwls1U8ApMyuj3J8kqTvSLO4P0Q8RfFyDghM8YI4auRNKLnDK6Qr1QJsudJ80Ocijr+ LwUw== X-Gm-Message-State: AOAM531D8VAUxmpRycVKg3XZ9gYi1NoWuTR4E5xxA39QfgC4WB/9oqTl vN//HpnZmWoMl5xmh9p7+Ow= X-Google-Smtp-Source: ABdhPJzZNMpFp4E0y3u9+l9lGxB0u5gziSFg+nxq6beGT4J8UeyDuO7rIn9gRTxLrP1EWp6H9s0NhA== X-Received: by 2002:a05:6a00:791:b029:3be:500a:2017 with SMTP id g17-20020a056a000791b02903be500a2017mr28651021pfu.44.1628596026278; Tue, 10 Aug 2021 04:47:06 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47: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 v5 1/9] submodule--helper: add options for compute_submodule_clone_url() Date: Tue, 10 Aug 2021 17:16:33 +0530 Message-Id: <20210810114641.27188-2-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-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. We also rename the local variable 'relurl' to avoid potential confusion with the 'rel_url' parameter while we are at it. 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 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6891480013..d850b30fce 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -590,24 +590,28 @@ 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 *remoteurl, *resolved_url; 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)) { - 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); + resolved_url = relative_url(remoteurl, rel_url, up_path); free(remote); free(remoteurl); strbuf_release(&remotesb); - return relurl; + return resolved_url; } struct init_cb { @@ -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 Tue Aug 10 11:46:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428725 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 0BE29C432BE for ; Tue, 10 Aug 2021 11:48:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E55A16023E for ; Tue, 10 Aug 2021 11:48:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240311AbhHJLs0 (ORCPT ); Tue, 10 Aug 2021 07:48:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240360AbhHJLrl (ORCPT ); Tue, 10 Aug 2021 07:47:41 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EC56C061384 for ; Tue, 10 Aug 2021 04:47:11 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id bo18so10608661pjb.0 for ; Tue, 10 Aug 2021 04:47:10 -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=fy1OcdMEKc2d4JvJGoAPeVHxTGq5FJ+Qqo302IldmMM=; b=gMWRu6xCK65rT+BzZIn7QKSv8RFGVztMafhzToaljuBGaFA79bPo6eSQfiXTR7ufzY wHTc0q63/yZ/LCYYN4HDXJyY9zpyBZlIO9XenvCvfEd4THoDZvvxgefQbPYDFLBHwG5f R25tGxCY7gKmc+T/bks7pgF1dkI629wDJMgDXRlxxQkxa0rqyGTx61fBpAtyH9d8DQw/ 73UrFePt8mO4uOVhaQoI6WB7845xTxiR7XaPDeF6nnTvmnNo/g3fHc+Qb/ky/dMuKGxW lrEfQDy9SmKvjpKNA3HkbhtEUNgjMd4+hg81SG9FwCf38TairkwKPAIAywogig+rT6yM qAWA== 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=fy1OcdMEKc2d4JvJGoAPeVHxTGq5FJ+Qqo302IldmMM=; b=OCsYoyAqfIe6WE8mCrLr6QzjEJdWx+hFifIWiTs0iUttNKumiJGE1v0MDK2bFLDQzJ a4oP/IRbJAqC4Pei8j4m+89EcfzZ741GtQQfMjM4sLCGLzpkpcVZcaAWogVsfThBs5ef ExfDWgP/giwXiGeZQVUDRb4nVJx/SiYvUwU74qf4QG+ULSH7Fa8OapB0PIXTj6I+SnGS TDNmE5Ly1nLdeaWLuXkG8LqoivWc2AyIB8GEGgLtY0w4TSBMSwtZ+0wtz8MriELIBeY6 HdfcshsdNRo8OmBtl86is5h7HJ6INdPNCpZFhtaR8aoWRhcJFIaV214FoTSb4MWEGAu1 Mk9g== X-Gm-Message-State: AOAM5317X5itqUs2yXrFrY9sm/U8Y4j48xznTEK2/sJI7dhaqFaaZD0I k0Na7LUazLUWuWXCu3Jf4OQ= X-Google-Smtp-Source: ABdhPJwfeYUwPrnHLhDL0c42eLB/3ulCdFiywEhBWy9InWw7FK72CbY8z4TZui8G8Q0fTJOyiDpehg== X-Received: by 2002:a63:1d5c:: with SMTP id d28mr600417pgm.143.1628596030579; Tue, 10 Aug 2021 04:47:10 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47:10 -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 v5 2/9] submodule--helper: refactor resolve_relative_url() helper Date: Tue, 10 Aug 2021 17:16:34 +0530 Message-Id: <20210810114641.27188-3-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-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 d850b30fce..fe126cdee9 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, *resolved_url; + 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(); + } + resolved_url = relative_url(remoteurl, rel_url, up_path); + + free(remote); + free(remoteurl); + strbuf_release(&remotesb); + + return resolved_url; +} + 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, *resolved_url; - 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(); - } - resolved_url = relative_url(remoteurl, rel_url, up_path); - - free(remote); - free(remoteurl); - strbuf_release(&remotesb); - - return resolved_url; -} - struct init_cb { const char *prefix; unsigned int flags; From patchwork Tue Aug 10 11:46:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428723 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 B080CC4338F for ; Tue, 10 Aug 2021 11:48:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91A266023E for ; Tue, 10 Aug 2021 11:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235202AbhHJLsZ (ORCPT ); Tue, 10 Aug 2021 07:48:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240365AbhHJLrl (ORCPT ); Tue, 10 Aug 2021 07:47:41 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CA5FC061387 for ; Tue, 10 Aug 2021 04:47:15 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id l11so9000683plk.6 for ; Tue, 10 Aug 2021 04:47:15 -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=v1gRep377kazGCVux9LgpDgLFk9zmRefTC/yi5pLJEc=; b=ABj5SqRTUePCR44CR6oBbHloQNfzzeDj68NOD0QpSdZ8x7mrDDpS8dJuJBu8CdTns/ t1SIptJBRwlegxIaKtHbkOtuES7458oUfM2dLNit4MMPtiH+83sXXzoEgE0FkJdMyWwg 9iJlAkwAMxgZOpHGeeAJbIPkh0D5Fd//DztK5mkF2g92tSW2ao802q9MAyP2Psxn0MME 6t6lnoL1df00S6k8SWZW0h9mbdsfsR+LNUiStwGURq2V9qrlJGsLdV0lDLX3rzL+MPNc Nu/VtTeY0RMG+Vh9xEhixT7tbXPjLOfQXtiZMurTOR6nv7kGWd7JDsrdViljHYssKyGZ i/aQ== 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=v1gRep377kazGCVux9LgpDgLFk9zmRefTC/yi5pLJEc=; b=cS3cPpZZKFjquy2wQrOEFWJ5MwKx62S5uygVRP0hpZZULpR9gLEJtwNpyyS/1HiBLG CMoRPTeoal6RiDhMLR/8geyXFBzUMPeGxsro9JJ6H2nAmNyfKZvTxMmVvy+D3Q1tny4o LiayRrdvv6GPyOKCmJr6a+KldUoYXkz2ovjHSfM4t7FkMBe8vclR/NkNXm8P7fMQtezp AaTrPFICTujfEd/fYpvdvyhNMCOJ13oermw1VIn73rgIGQduOLxRIgYu/2dAphhw7vRC vG3/EKX8KMBKmfgFYN7B0g/Tp+gV+8gfPsarwpGErYi9UqnBKdG/ALqN5zHRJr3QCVLl a2cw== X-Gm-Message-State: AOAM531KuvJP3D37Wpxh8/AIkOT73EI/1mgLHzGZCPT6xfYJGrMTeZ9C Z2EoPh/Pv7zzPbEHoTmBwAg= X-Google-Smtp-Source: ABdhPJxMmCNSdo0X6qbdMU3Nop1ZGU/6YtQP4/48md3jR76ri+t040RaFz7rua/qNgcCfa16fkKfvw== X-Received: by 2002:a17:902:e88f:b029:12c:c949:36dd with SMTP id w15-20020a170902e88fb029012cc94936ddmr14747252plg.84.1628596034891; Tue, 10 Aug 2021 04:47:14 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47:14 -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 v5 3/9] submodule--helper: remove repeated code in sync_submodule() Date: Tue, 10 Aug 2021 17:16:35 +0530 Message-Id: <20210810114641.27188-4-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-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 fe126cdee9..da77248948 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 Tue Aug 10 11:46:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428727 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 4BD1DC4338F for ; Tue, 10 Aug 2021 11:48:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D9B260EBB for ; Tue, 10 Aug 2021 11:48:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240340AbhHJLs1 (ORCPT ); Tue, 10 Aug 2021 07:48:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240324AbhHJLrr (ORCPT ); Tue, 10 Aug 2021 07:47:47 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6CFCC0617A5 for ; Tue, 10 Aug 2021 04:47:19 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d1so20655478pll.1 for ; Tue, 10 Aug 2021 04:47:19 -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=0+UUKksn3KuDWhIprdDIn5xVbdTLguTDRUt9PvuESEI=; b=VYdtQ3yxSEkLTBk5bJ3Ny4XqnZu4tB8yGu2LPqrJ//bJI4ZNdbfrH/ispC1cdC7kaJ H1LloUY59uD280JVwbwnephE6TAtRrKLS2FgS6+wdTMH8KxMEzPNwfkla3tMdqMNHBKE +7aK4YJA4VBiQBxZR0z8GaB5u0d0KwvVWFDVc66WK1dBHAvqGQGL1at2YcPmzMcm4y8Y mOf9OXav2Wo1HWQHpLNEurQmMUC4ny76OB7f8+CWSIZIuwG5eywzBhPV1Om6nvOXOQvy 9zPDHOyKQFxPlVJYKm+aCg/c+RNYcYS0BEU8awXpLtIb0r6gGZRoo9Vk5Xy3M3MLFdvV YkTA== 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=0+UUKksn3KuDWhIprdDIn5xVbdTLguTDRUt9PvuESEI=; b=R+HEOIP5JEDA9NM4dnaHiz4iDMdrI523Aa7xe63Eq7kG4rRgCAbrosxqz2S0TJt33m gfZBqBf/m/NZCONs/pNJk12uEqF7djqFRXFiJLnV3SWjgz5SoJ5YUbd0EBHa/sn6bpAN PQIonLnBLlY7NH3B/w3gQGkxlzc/opAtLZkL1lY0CyylGGbukPLGvEx4Yy8dsvKJPP65 dEgvvbBLmRUDotjlCDdM88oK+7B743g6S/f58sW+CcFyGk/bKKl0awacP83sZQ/jOAFn mCeg1KqeAvJFFHGlACdGwnxNvU8kj+7e3aqY1cDDDKmFYOihjQTOYpuKDcGcBy9pqFkQ KP1Q== X-Gm-Message-State: AOAM532mMmWZ7c1XVZyIG3rIAIK5bwJRgWCf7jMcA6wPoUtAxJy6n5mq 7WgiQdXHBc5q1taR+AlmsyY= X-Google-Smtp-Source: ABdhPJx2GDRe+i3PN+GFIc5Zk49xjacrmwOY15FKi+veC/zjuriT73Sid09dN+z4PwpTsFgkR0I6Kw== X-Received: by 2002:a63:1e5c:: with SMTP id p28mr224146pgm.89.1628596039214; Tue, 10 Aug 2021 04:47:19 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47:18 -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 v5 4/9] dir: libify and export helper functions from clone.c Date: Tue, 10 Aug 2021 17:16:36 +0530 Message-Id: <20210810114641.27188-5-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-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 | 11 +++++ 3 files changed, 127 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..63ff04f5ac 100644 --- a/dir.h +++ b/dir.h @@ -453,6 +453,17 @@ 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" + * http://example.com/user/bar.baz => "bar.baz" + */ +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 Tue Aug 10 11:46:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428729 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 B9600C4320A for ; Tue, 10 Aug 2021 11:48:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A140860E09 for ; Tue, 10 Aug 2021 11:48:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240342AbhHJLs2 (ORCPT ); Tue, 10 Aug 2021 07:48:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240376AbhHJLrt (ORCPT ); Tue, 10 Aug 2021 07:47:49 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF495C0617B0 for ; Tue, 10 Aug 2021 04:47:23 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id fa24-20020a17090af0d8b0290178bfa69d97so4954573pjb.0 for ; Tue, 10 Aug 2021 04:47:23 -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=eGEdBEPWd+MQvTsTnDYtNlUTSV97rm3VzjlgY+P5f5U=; b=FDCOqIrIttFhZ3dMpmQc/oJENHz0I8D63wxm3Hpmwuw87dihn2QuifCTJQeBffHWLw ciPTWfCBnVALfvskkF8fTEe0b2ucOIMMH4XfquIWUVJDs32Hr8HyV4CKu4maoxkxO3V+ xXU0Z9iv+eetfygnvZnDAntOPC7IK8nce714xo8EHgUIMXhym7Urc52f6XNC6CNawV37 Q3hdEYmo7DQgzAEGxOIydI6cOk8S0XYlRfGZ3rU/oheLVH5Nfta8PRj4RxbbomYesgWC PctQKwLEONuz1CRhb7n/buJkCEllQRYHeCxgMK5+tAgFqPOhC0PLJ6+4wHRma9RLNdde z3OQ== 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=eGEdBEPWd+MQvTsTnDYtNlUTSV97rm3VzjlgY+P5f5U=; b=oe4N1m3zzKVmrQIlO3r4z9v2kEZ0u4xQjoZBZ5VNBRwKD2t9MtmQ25dURFgRFfusWO 6IOpbqcAaRgbztlIVBTpS4Qf3LphoC57cdJxTnfHTtrkAuQV2IGbsD5IuQU3XPsAS7B/ D/20SQou0meV2VpWpu99SGamuKK/NrAN7T3Bi4qNmBkYd7UProUUMR7i/hkkVA0nWAoq fAP8zgu9odk7hgJk0oRthse5Z04DEfPLdMRHKes6dXkXjxhI7ixMuO4dQiCeG7XsMF6y m2/sQWw9NzO29eQeWEwndJuDcTqQ/iCWGeLUfUz9mfD491rBpGiJghX9c48QaQEpvLoV Tw5w== X-Gm-Message-State: AOAM5301Ez+VD3pqlyIFa0ZORYxTM2/xhn/ME01SOPoDBXe595UyrsJ9 ZH06YkXS0z4iqHUfCSo2zrVp8ekTtiQMxQ== X-Google-Smtp-Source: ABdhPJzLK6ow2zT7FusJNce10xjn63OAJa5Odn/MNeFfsOtjUuxusguW2Ddxb+wwWDGO8trlOV4AJA== X-Received: by 2002:a62:9712:0:b029:3be:3408:65a9 with SMTP id n18-20020a6297120000b02903be340865a9mr23361839pfe.63.1628596043501; Tue, 10 Aug 2021 04:47:23 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47:23 -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 v5 5/9] submodule--helper: convert the bulk of cmd_add() to C Date: Tue, 10 Aug 2021 17:16:37 +0530 Message-Id: <20210810114641.27188-6-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-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 da77248948..bbc5b4d9fd 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 Tue Aug 10 11:46:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428731 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 AB96BC4338F for ; Tue, 10 Aug 2021 11:48:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E91B60E09 for ; Tue, 10 Aug 2021 11:48:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240369AbhHJLsc (ORCPT ); Tue, 10 Aug 2021 07:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240378AbhHJLrv (ORCPT ); Tue, 10 Aug 2021 07:47:51 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4663BC0613D3 for ; Tue, 10 Aug 2021 04:47:28 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id q2so20616973plr.11 for ; Tue, 10 Aug 2021 04:47:28 -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=wbOFHg/LUZHa705OksnmWu/rR+vSdZbUpTXbCqEHrdE=; b=OVPQiL+AEQsFcI44IjsArc7uFEHMkmnpWheDvEZUYjocnjuAbVlhhHF0vJ2XqdTyzk moBeX0pqS6Zdj5nEmQKAUztLpN5EObLW40ZsRx8oqztByKv+KrmYeAT/m1e+NCNEw8pD ZSasb//R4FlZTu8XViIwwKtULjAnt5cNDe7KJ7kYrsZ71WzDN+d7x9jckbLAf1ubGBT6 zJm8aWM7qt1NWBK5w6NydhITpuZLV/Qp+tmbnRfx8Ur5sKWnfRbUhLD6Z8EA2sN4H44x PChF3750baOh4b0eXYbRg0SlzPdvRWPABv/azqjgsMVAuY2E8EtsMYLYSkAMBSvROint z4BQ== 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=wbOFHg/LUZHa705OksnmWu/rR+vSdZbUpTXbCqEHrdE=; b=Y0mtShw7qmk4TJD/tW4/Wo11FOGa37SlNZTAzJKM8gN/EKe+AmcOCACcoxJEnfMRiK bALvpGurzar8OgRB5avaGAqKgLt5vMDkknnCC5nbbcyG46GeupST9TbB+pOHW4Rzl2D1 jcKOlhyMSeSSTfdd4nTfvxYR0IA9vP0sdnkYvl9mrnWIZAPxaQbpOzSpB5L4tYYoSPZi KOWaqxnNOHxJPO29X7/Mqamj6YdQnvr1DIYxbbqaNmydM9jVdt6N+oJrKMo/ecOP+qzo WVYleEHPRZXip9f7LksG/72ngKI4EPxkx7B37YJAyEUt7qsUEFNKMck7UDGv4PrVWf3J EB4w== X-Gm-Message-State: AOAM5312Qh+U/VoHdwN6UJfqQBfLfn47Y8znTj1X0xbV0T3FLVXW7lgr UuFdOwxIqBmpGBVU05b50ngRRaEXtw/8EA== X-Google-Smtp-Source: ABdhPJzwOxsqO34SQhz+7pNvhgXvipsjmBfUcdq2kzW3pKqZBLFnTbHTDwG9hkd1PqHC5KqJki6chA== X-Received: by 2002:a63:f011:: with SMTP id k17mr200080pgh.391.1628596047897; Tue, 10 Aug 2021 04:47:27 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47:27 -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 v5 6/9] submodule--helper: remove add-clone subcommand Date: Tue, 10 Aug 2021 17:16:38 +0530 Message-Id: <20210810114641.27188-7-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-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 bbc5b4d9fd..6ab7de7741 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 Tue Aug 10 11:46:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428737 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 35959C432BE for ; Tue, 10 Aug 2021 11:48:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1835660EBB for ; Tue, 10 Aug 2021 11:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240400AbhHJLsi (ORCPT ); Tue, 10 Aug 2021 07:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236753AbhHJLsS (ORCPT ); Tue, 10 Aug 2021 07:48:18 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82E7BC061798 for ; Tue, 10 Aug 2021 04:47:32 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id fa24-20020a17090af0d8b0290178bfa69d97so4955146pjb.0 for ; Tue, 10 Aug 2021 04:47:32 -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=YL1IOJ999jNLt5fw3vwXHiPo0WllV4TQ4Lqxx1o34AA=; b=imIhZUycwux4i29/i17a0nnEIGmZoQqCc2ChZS0Mq32k0ac5jciX8Y2QGqUXCvCOVU wuE5lxf1vyeOtgLHHzWVl7BVD6FC9/aKAJ4KFWPAZ7o89pzo592ZMdtMXr91wq3K6W2K mnN+zedAbcPhQjuRFTVGXgi4thH9bqHd7ZvU43l9E7krfgwmZEDAejAaUfyP4/KAmn2S M3hCIAoLoUYpKlpxZpv+jbr+ID6j9/GXIod58+FBWUQNErxCTaoXC/7ttp9bbc8mqTz6 2rACssleDlgImfRv9lCebbD4zResNkb/WqMVZCsv/Nsplg2FsBv29vR0Lb/w6CG7e9Sx x5xg== 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=YL1IOJ999jNLt5fw3vwXHiPo0WllV4TQ4Lqxx1o34AA=; b=fTkBE3jTNrZhr7LcRUvoYi6VvQer4bqrRlp9mhbRjbabzIL1YqpCJxiCo6/NYsypmS gZg76JCEIhwiI1rtGcTrd0VuDsxvPb26BfvLzfy9AY/ZqaQzgz2HZpNQ6DPKvSkzMJZU TbgNwW1WT9qTZn2Q4qkwvJpQpESpRZnfo83Cfqhxj/UivMLMdOa8+VeHWqHjVeszqj2o hehaPNDhomaQKCMLu9EAPjtaKbGM+KFRwDRldFMvIfPPoxvTw9YsC0gIdDXdBsaBs7g7 CizSCBLFxBH+yfCwlwWtr6Jv4iblS+XKrghd2wpVPTXNHZ0V7EHHdyhVznrfaMh0wLCE Hehg== X-Gm-Message-State: AOAM531v/vz3Y/3swKmnnObMxb7sdP9RGwCeEYlXpqvMw188my5YC0j1 uIIFE3JlhWS/3efNcCZo7Jg= X-Google-Smtp-Source: ABdhPJzr5CuJSurWdPcoLwfD7UQyyIFFhW/eOBlWKebKBENPxdEZyXze/KWihrYY8mhsiwfu8IiHIQ== X-Received: by 2002:a62:8451:0:b029:3cd:ed80:1521 with SMTP id k78-20020a6284510000b02903cded801521mr2059122pfd.51.1628596052120; Tue, 10 Aug 2021 04:47:32 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47:31 -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 v5 7/9] submodule--helper: remove add-config subcommand Date: Tue, 10 Aug 2021 17:16:39 +0530 Message-Id: <20210810114641.27188-8-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-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 6ab7de7741..0baff16686 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 Tue Aug 10 11:46:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428735 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 22139C4320A for ; Tue, 10 Aug 2021 11:48:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 014EF60F41 for ; Tue, 10 Aug 2021 11:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240420AbhHJLsk (ORCPT ); Tue, 10 Aug 2021 07:48:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240276AbhHJLsS (ORCPT ); Tue, 10 Aug 2021 07:48:18 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3F89C0617B9 for ; Tue, 10 Aug 2021 04:47:36 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id w14so2114471pjh.5 for ; Tue, 10 Aug 2021 04:47:36 -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=3Nrjb+lXCWBWyHgQW9ErD/EwJnaxHdeMQa1Au2UG9Fc=; b=HuQvdK8s7x30ZxdSEwurxS5FpFNAIpmbL4joVuTb6OFERo5VuCik7zXlILHkPOsEdE AlDHZBr5DQHi9EE9Ey0yObkmwCmCni1eL5+vIVlllsJe9Yr580RQbO+ozQ/WXuNKV7wT 2yvWeIQF4F5BIvhf+xcxubpK0wraAJ2Q1soqkHkIn3HvH0ZiiL8nh08eWcl8nyq6U/So V1johtfyWsuY7b08wlFfAYlYH66cKdLozIsdumDXX13xxvpWoiZAtxQghwLFn1RGddew XLfARL3t4IVUYPEnusSFBxvVcLDtU+qhNtThvKp+0FUvCbDDYKKBIFGDYC5t167lYyaq P4hg== 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=3Nrjb+lXCWBWyHgQW9ErD/EwJnaxHdeMQa1Au2UG9Fc=; b=UyczfQIPNPUbZqxSn7mE6pAFZ3vE7lyMpWodZoZIRePpW8WZzKIr5zBV5ZfGKv3bcL 9v0CA0uekz4qDJlXgxCsUSEhBpeaYr9wGiDs9u9lBMbsnmwBW824kzvRdZr5ZFbyHohy 5uSkcUaVg6g/JeAA+wnKBykg0CQvVWOATBEhW6vVb/PGmgn8PbHTfL/zZJnGoOCGWF49 w506182cjtKEwgYo7GAAmqvVDxhK0bQ7IG9AoaEsqxye6Rr1oSYcFblHlhaSkxNMAk6o iO6HJU1Kk7S5arnVe+PBD3hXogJSYwExvXnPAbNKa8zNLYGuTh1AnJCUnsvmYdPLzaFL RTEA== X-Gm-Message-State: AOAM533a2NJBXvTzlbsVom3rOot1FXawbMechJRh3yyR4uNgiveNW0qD HM+xDx0bBDlfJCUlm0pvSOF+jGNgRYYbsA== X-Google-Smtp-Source: ABdhPJwBG7h+h40Bb2/4Oj0BrPmnH+A05eE2mZfcNnWZO0arTRtHlTMCRAt0po/0RxVN2UjA9rY+dw== X-Received: by 2002:a63:5925:: with SMTP id n37mr1135700pgb.251.1628596056476; Tue, 10 Aug 2021 04:47:36 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47:36 -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 v5 8/9] submodule--helper: remove resolve-relative-url subcommand Date: Tue, 10 Aug 2021 17:16:40 +0530 Message-Id: <20210810114641.27188-9-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-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 0baff16686..65591e47eb 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 resolved_url; } -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}, From patchwork Tue Aug 10 11:46:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12428733 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 45CF3C4338F for ; Tue, 10 Aug 2021 11:48:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AD296023E for ; Tue, 10 Aug 2021 11:48:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240388AbhHJLsh (ORCPT ); Tue, 10 Aug 2021 07:48:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240282AbhHJLsT (ORCPT ); Tue, 10 Aug 2021 07:48:19 -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 5F766C0617BD for ; Tue, 10 Aug 2021 04:47:41 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id 28-20020a17090a031cb0290178dcd8a4d1so1749710pje.0 for ; Tue, 10 Aug 2021 04:47:41 -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=5WMd2yqKqr7Qv5eGHfw13m9TryrKC0E1cGLSWKSXxRU=; b=pQ/XSvkrYWDu4RcwAIJXuK6rBrGXBmhjcg35yW4iLAniJFIKsuInGw7NUyhTJMPuew yXShcJ0ROVgXV8S9sLj+EwURBMm0zk2o69/vHZODqQ6X65ZxjOhftQNdP2APongRKfvj mU4WXP4g+GjcqyHV5g+cPtb74eHNy78rtwD0iNDE/01nkBOdAUgqJAQGXijhwnJkA6Li bLT2g3TkResZ/9S56puT51ScxwGGyKTRu/lw2N2lRlIVesXAr7Ul2G4EeZkt6qK1Zn8X 314F1c0Iib2vxRfvyChWzc/3Dx2vqxpTGRY0sUyP/+LIUmmJWy8hpKsWFXVd/T89yGJi CAWg== 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=5WMd2yqKqr7Qv5eGHfw13m9TryrKC0E1cGLSWKSXxRU=; b=imTWrHmxAdQmckJrLDgGcil8cQXElfq7T4GK19ouoKI/yxuFPt0fVB34Uw9MDAVqd2 zd29y0EKNA58jkTtka7jgR1nKlni3b8XZsrLfofMamg6JmwI2usaaFOR1qRMQOE4uItc EkrkmNNdWLFLqj7bpIZaTdT0YrYfc8KqLuMHQszc9pwRJmW4e319bVZycCJJ7Rj3xUMH CfIySyiQdbgK7a/3v+lFfsxD+L3Uwb0AA7g3Yi6Oi+ezx+eQF9zmfi3rJa0W2OwohCIf HSTe0f+cI0HiYrTHannwdxdneTU7FtASsWWRmrrlt4G4tTfr+1K1teBL/COx/IqrmpyG S9UQ== X-Gm-Message-State: AOAM530beNX9IQ74WIZ82wu3TJr8Ho4msASYiBnxHMYxIUfs5KqqUQ/b W3lClFhBz6Res6EbvG8PY7Y= X-Google-Smtp-Source: ABdhPJyv2fy7U3fifZXjrNzmxwycB5CupSTfZBv0bY5Gb5f88lTKfifzNb+yrRKGNMCMECuvZFeSSQ== X-Received: by 2002:aa7:8148:0:b029:31b:10b4:f391 with SMTP id d8-20020aa781480000b029031b10b4f391mr22580536pfn.69.1628596060773; Tue, 10 Aug 2021 04:47:40 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id g19sm12410232pfc.168.2021.08.10.04.47.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Aug 2021 04:47:40 -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 v5 9/9] submodule--helper: rename compute_submodule_clone_url() Date: Tue, 10 Aug 2021 17:16:41 +0530 Message-Id: <20210810114641.27188-10-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810114641.27188-1-raykar.ath@gmail.com> References: <20210807071613.99610-1-raykar.ath@gmail.com> <20210810114641.27188-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Let's rename 'compute_submodule_clone_url()' to 'resolve_relative_url()' to make it clear that this internal helper need not be used exclusively for computing submodule clone URLs. Since the original 'resolve-relative-url' subcommand and its C entry point has been removed in c461095ae3 (submodule--helper: remove resolve-relative-url subcommand, 2021-07-02), this rename can be done without causing any confusion about which function it actually binds to. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/submodule--helper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 65591e47eb..5ab4e17e75 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -199,7 +199,7 @@ 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) +static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet) { char *remoteurl, *resolved_url; char *remote = get_default_remote(); @@ -634,7 +634,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, NULL, 0); + url = resolve_relative_url(oldurl, NULL, 0); free(oldurl); } @@ -1355,8 +1355,8 @@ static void sync_submodule(const char *path, const char *prefix, if (starts_with_dot_dot_slash(sub->url) || starts_with_dot_slash(sub->url)) { 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); + sub_origin_url = resolve_relative_url(sub->url, up_path, 1); + super_config_url = resolve_relative_url(sub->url, NULL, 1); free(up_path); } else { sub_origin_url = xstrdup(sub->url); @@ -2098,7 +2098,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, NULL, 0); + url = resolve_relative_url(sub->url, NULL, 0); need_free_url = 1; } else url = sub->url; @@ -3025,7 +3025,7 @@ static int module_add(int argc, const char **argv, const char *prefix) "of the working tree")); /* dereference source url relative to parent's url */ - add_data.realrepo = compute_submodule_clone_url(add_data.repo, NULL, 1); + add_data.realrepo = resolve_relative_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 {