From patchwork Thu Aug 5 07:40:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420519 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 A71F3C4338F for ; Thu, 5 Aug 2021 07:41:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83A2D61008 for ; Thu, 5 Aug 2021 07:41:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236177AbhHEHlr (ORCPT ); Thu, 5 Aug 2021 03:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232753AbhHEHlr (ORCPT ); Thu, 5 Aug 2021 03:41:47 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03AD2C061765 for ; Thu, 5 Aug 2021 00:41:32 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id k2so6016433plk.13 for ; Thu, 05 Aug 2021 00:41:31 -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=HN/AJoWhrDEm1RKtjsgcDK0KFjApGPlEmepXkYf1gUQ8ioq15yD7syk7ogCHvJ6lPP h+wrA9KvFQusuYe9JO3xfCr6+Tbrl/Hk1YG6+5KXP2iAkxszbYKuKoDWQE1z2ktQC0tE wSFRA+gyWR8/LSwBk/qHhFRVSURiLNr0Dtcwi1mc2GGuLor4SP59gZhMpUP9OyzkQgTI 0R7gaQiK3+sp0zB4FcHUwETex8rMBnEstyzcr4PMqSOyHiC0T8g7eINMROwve06uruvL 2ao0EfJhzdv7rK2TQn5PIPEIMt3v2UKykZqkz4a7ZkFoBIW5fI9JWcr4OYO4Wns24IWk vw0w== 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=MbvriNig47OLagOkfrTcbDZVkNGGAcuutBuEhaRYKgnKYwMF0r7GPgnTruOuXh7KMw yNNxR8AHOR1Fo2rGlLTdOKIV/TYUiUV3VQW3kywddNmvByaQeGQ7lxnZ93ImI71tnToP dattzR9Vb6yTu0y3PcO9ElCqiakzQcXde/L2EXMoloZdWDtMNKB2H9+4SPTJoC4a9Jua OZRqSR92+/cOCWzeooGa/GrIQQgTFL+GS2jDJNcq1unI96YGEM5Cv3xPK5S/k1EFNy+f VqcY5I6i4Q+GFZK0pc9iKb+SJi2vfA8Ma25IXWYNacmf5+ou+URVJcebNI4XfthR2Mkm Sthw== X-Gm-Message-State: AOAM5301Yemls8mZsePcv0BpZSj178x9pK94iG8ISKoDuMB+gj8vQ/Hl a+JHfXjKn8pt2k2GN7CLfcc= X-Google-Smtp-Source: ABdhPJxfaMT3farVGMXscXyE8YMGeuiZmcG4fzGIF46kgs7hW3MJjx7lxLr0VdyP64iMNUixpuufDA== X-Received: by 2002:a17:90a:ba82:: with SMTP id t2mr13991729pjr.143.1628149291603; Thu, 05 Aug 2021 00:41:31 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.41.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:41: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 v2 1/9] submodule--helper: add options for compute_submodule_clone_url() Date: Thu, 5 Aug 2021 13:10:46 +0530 Message-Id: <20210805074054.29916-2-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-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 Thu Aug 5 07:40:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420521 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 1CEF8C4320A for ; Thu, 5 Aug 2021 07:41:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 014C861040 for ; Thu, 5 Aug 2021 07:41:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238529AbhHEHlw (ORCPT ); Thu, 5 Aug 2021 03:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237793AbhHEHlu (ORCPT ); Thu, 5 Aug 2021 03:41:50 -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 56257C061765 for ; Thu, 5 Aug 2021 00:41:36 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id dw2-20020a17090b0942b0290177cb475142so12809015pjb.2 for ; Thu, 05 Aug 2021 00:41: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=z0dczKJTO5baTemhmXZeMRVP4jza28YNvT8kLN9WZLY=; b=UCruLmf9Dw+gYz9Ybuf6IHAJwXTz2q9P9EcrymL2Z1loyfP3+2xpxWJ6sbbDfq+0+3 +ZUzupwpnrSoGyB6b/+qKBgGrBWZPrCi2eRzgbYWJ1A93hXIhgAwXx+yRB+anbIVvytj LhtMha0oAH0Q+S5euCn7qwW7SNX1AjUD6VlUEhE5Rgwaxy+hpteuv50vZCv4xuMxBODs 6AOoDQo/jBZgcNvrCM9G0xtH757t+4FQvazJq1sUIN13oitO8VnYBf51CZEPA+aoffub XW2egY9rQ2Y0dh+B8WrFAs2YKgDzGd1OTUHIIatB6OKcdXzSdYnF5jhAKtBCkohXAc7M 8tVg== 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=G0L3zZJGmGKBJupIBOTrXzqjQAu09nnCRHRnk3nder7xtzjE2ku2xQrlZZ12YNCqHq IIndsMN5SczPiaWodbnMidfKsV4hvXdlyqJSl+JAsYwt4YbAA9QeuKBYUIujmoMHZ5u5 QBKGM8NLjNo6meN2GKBRT85itngDbKAEKgfX0l7x4N13ID2BXe/eem6139naS+G8s9be Bjzk6WPmBXO5tLXhMlkY6z6KNxif9Eu3yT0YGrFCV0KTdhNwBjovt3Y4V/4+zUJ7FnLY EurkP3kjnaCC9CgeB3MKbwgnTqCMnfFIz4tLZQiUmNkTVm6zh2su82w5Y3qiGc7WEW0M oOUQ== X-Gm-Message-State: AOAM533fhf/6hu2GK2PT8rqXYKuzTiyYv6UWNwn9PHofrYxdjySOoh+d LrI7jx9YZonZjBqJLQ3SAqg= X-Google-Smtp-Source: ABdhPJwIQxyyW1Vv7cw12Lwsxkzk5qutrOX1ykuSKB7wmM5i8pYaDGnuLaxqEFopsh8pqoIU87tUYA== X-Received: by 2002:a17:90a:b795:: with SMTP id m21mr3349045pjr.143.1628149295958; Thu, 05 Aug 2021 00:41:35 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.41.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:41:35 -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 v2 2/9] submodule--helper: refactor resolve_relative_url() helper Date: Thu, 5 Aug 2021 13:10:47 +0530 Message-Id: <20210805074054.29916-3-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-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 Thu Aug 5 07:40:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420523 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 0548EC4320A for ; Thu, 5 Aug 2021 07:41:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2D3161008 for ; Thu, 5 Aug 2021 07:41:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238555AbhHEHlz (ORCPT ); Thu, 5 Aug 2021 03:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbhHEHly (ORCPT ); Thu, 5 Aug 2021 03:41:54 -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 8E9A7C061765 for ; Thu, 5 Aug 2021 00:41:40 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id t7-20020a17090a5d87b029017807007f23so9596425pji.5 for ; Thu, 05 Aug 2021 00:41:40 -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=2A4eYVaTTM9VZxd7hC9YXxEmUa+bNfFFszvXpQKiZlA=; b=FLMHg7/tZFQ3Ou1CvVLbqtC5tRpOz7xPIY/Nwrj3ANf4MJQ0kjXquE3duiJZxaogHl PVkBxSxdX3Z61M0+AT/IVJMLGKOK/GGzzptQGiUR9Hjb1Ntu0e73+uOrA+oVVnumMfcr vKAhXbEYIVAx288gq/osrTGMks4e+a1fHktAjEyr1d4ZnvdP2r0mDsGd6TVl4+s00kU8 3hjnmmfJIp7UD8x57Oorhrgy5t/L87BA5rT2fkrtQ/MsdhoIZjnIDNheS8Mcpl9w7xRZ 9fUOEXrM2I1GE3CXo7B2rPhhypXsZUuZ8Qkf6g4Lm/mYRduDDjiKwsl6PvdXSZQ9eDl3 2T+w== 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=2A4eYVaTTM9VZxd7hC9YXxEmUa+bNfFFszvXpQKiZlA=; b=o8ymELKriaNL+skONmvw5jfVr/+W5VPjMj+108L80sAntyD926J6Gq55nPFQBkRJq1 xNeIfW9bual8wo4HcGvZ6dNmsi9RHwl9OJ/lTOZVdqwXRnmjUgIg3Tp2qCQ41Vj+ro2d Rpx0IoWFEG53Q2zYi5lpnKsNDJIJ/EDDBHgunJym/26j1sIJzuQ2iwlUrISWhxDz81t8 EXNeGbnHl14F7lFQkkyuhMXhmfA0c8wsle/jshkhAoPjhgAVTpeWckU+bY1qNoZSCIoO BAHVI70iivdjkYRKOXPxTpsyX/KnGFnrzB+jTfKwL58I4CiJLxD3F4BqMq6bHBvq11dg lGQg== X-Gm-Message-State: AOAM530PaTSx+yX5IC+NQo4YXBWLIWCl9VVNsK9e3HuCy6jKvtooKoXl RhY+k3dKffkTk0P5Pb9F6iI= X-Google-Smtp-Source: ABdhPJz1uZDrxBBk94RyZjI6H8StuqogJkHdKFxRdsUiq+Qtch2T9uTinBWpYTojz+sj3Wu/8KsMdg== X-Received: by 2002:a63:9c5:: with SMTP id 188mr1632328pgj.187.1628149300214; Thu, 05 Aug 2021 00:41:40 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.41.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:41:39 -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 v2 3/9] submodule--helper: remove repeated code in sync_submodule() Date: Thu, 5 Aug 2021 13:10:48 +0530 Message-Id: <20210805074054.29916-4-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-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. 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 Thu Aug 5 07:40:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420525 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 331E7C4338F for ; Thu, 5 Aug 2021 07:41:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1463861040 for ; Thu, 5 Aug 2021 07:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238645AbhHEHmE (ORCPT ); Thu, 5 Aug 2021 03:42:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232753AbhHEHmC (ORCPT ); Thu, 5 Aug 2021 03:42:02 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 467F2C06179B for ; Thu, 5 Aug 2021 00:41:45 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so12810407pjr.1 for ; Thu, 05 Aug 2021 00:41:45 -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=bbLs9x3o5zCDEnUgVGn73d6DqvV7gyijtRaOLcYmCAs=; b=Pmuj5v+1vsKScVkhpZ42tr5kumGldGcFt5BvNkidcoVEavrju5srlXWgJz8ubG1v6q CxUd4S3iIMw8+x5p/RlydL4FZbo7yKE6AjmON25iLeM51lyOPhd3kn5b1zFMaUcsw8z6 wto1mZVkz8KEuCeuZAWeQOspoe3VpYYvhqBiOvkpiXr/39qX89iWdbvAzCj/rggnQiCG YxXSJ79lKeKPgOvzGFt6i85PYpAJCXdUPtF+dYAEQBEEv+oq4dEcWqPmX7T3aNK8vOOg obblhJvJb1Wcpli56myncwzaXqjPWHM7sBQZhMXfn6rniKZEGAjtnq1oBMiR+RFEqwSI ppbg== 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=bbLs9x3o5zCDEnUgVGn73d6DqvV7gyijtRaOLcYmCAs=; b=IHgQJyA4A3kff4ftNHtmNDKi+9r9KWzN8VXVym3ADnSgP3y59eaKnHSlH4f3uiyN4D jhsS3IhgzA2rc/r8L1Zpt/sdWu6Kkb6ep44VtMizXbXK4gNMetwUKvnSvWAEc420SWdT z1dx0hfFE56AmNiF8dpoem47pRW7fQn6+3tsSlvaDOzNhtgf6Bg8Vq4TbYryQdcBaW0j rQVAHQSk5PgWEo9dOuLQ16LkThEtwRtqUSUl8xytU8TzE/8zTzQD/d4mrmafQEJJoPNA 7g94oCMoy0nsK9ZFdZOYMWtIQGYssQWMf0Ell4Ymc6mpY6jCHHiOstb843WGVwbFDuQ7 /Cvw== X-Gm-Message-State: AOAM533pRbVL3daANPFT+/Hzdu6e6HkSDXLq8hZ8jGbwr7dYlOfQASkU PI0ZvSfZ1UqKSK9iNBp8oSM= X-Google-Smtp-Source: ABdhPJwcAKLNAOxzfZ/j/F86KhvSkR+2o6y7cdTORhnR2Zi3/elrdNA/5N7UNR0Dtd2P3fj/YLsrUg== X-Received: by 2002:a17:90a:f486:: with SMTP id bx6mr3349807pjb.26.1628149304826; Thu, 05 Aug 2021 00:41:44 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.41.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:41:44 -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, Shourya Shukla Subject: [GSoC] [PATCH v2 4/9] dir: libify and export helper functions from clone.c Date: Thu, 5 Aug 2021 13:10:49 +0530 Message-Id: <20210805074054.29916-5-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-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 | 3 ++ 3 files changed, 119 insertions(+), 116 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 66fe66679c..b9b59a838f 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 = guess_dir_name_from_git_url(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..84b47c4dbc 100644 --- a/dir.c +++ b/dir.c @@ -2970,6 +2970,120 @@ int is_empty_dir(const char *path) return ret; } +char *guess_dir_name_from_git_url(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..76441dde2d 100644 --- a/dir.h +++ b/dir.h @@ -453,6 +453,9 @@ static inline int is_dot_or_dotdot(const char *name) int is_empty_dir(const char *dir); +char *guess_dir_name_from_git_url(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 Thu Aug 5 07:40:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420527 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 688AEC4320A for ; Thu, 5 Aug 2021 07:41:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4804261040 for ; Thu, 5 Aug 2021 07:41:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238610AbhHEHmF (ORCPT ); Thu, 5 Aug 2021 03:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237044AbhHEHmD (ORCPT ); Thu, 5 Aug 2021 03:42:03 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CFA0C061765 for ; Thu, 5 Aug 2021 00:41:49 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id e2-20020a17090a4a02b029016f3020d867so7357714pjh.3 for ; Thu, 05 Aug 2021 00:41:49 -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=wW5DjSZqp+Dhl/nWLGRg6nwqM/EOuy5TG7n2/Uyyfww=; b=ZLfjG2/zjkwY286Qny9dWQ1yIiq91g60SRu5W6DGLhT+J/t6zi38lYd9eq0VQYYyDE 9vQEgrXaCr14yn0CvbkKDWfPmU2mGGOKDqH80QM6Ptf7DVqSOk8A8hvOsI3hWZib+D0z zKQ7kxQ8mgsPyowpo/vJrf+1jCH3csadPFRc7LxaXUhlTQbxCouBdzx7RHJ/JmFD8etw n18AMTTQq9pDgN8qDeBdBHb1tKPGbO+XHTWweN0mlXWFzcTg06o9JVBgH0d35p3e6ApF aqI279WNVZzmgIWMhb4uaeJkCtGIzLxlhCBpyCD25H+vNQ3F2PaxT6tbNMr/gNgY6bHg JzQw== 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=wW5DjSZqp+Dhl/nWLGRg6nwqM/EOuy5TG7n2/Uyyfww=; b=FTir4uwEqAx2f1r/9n/ShoJlRA7TORm1umORfloLHQEBO9IS6TyqkpfqN8Wrw5Fpi4 GeGRv852irthrTXDt7IAM5KLuxmPDpOEtCS8lzIIwVKHkquHsv52ZVbp7/c9YigQtX+1 Mpbu4J/INOfSvWESeTimwCoKbSHwE8gJ3HB2haPsO7+L5VSMBncCMIh7IzyEiJuo7pGR LNA304xVSbZ+oW9I9aSjIN0uB+7a1c67VrPGKmrYw9se7ruyp8pfwGXL+sFAOOfIYawg MNblEcMOHyt6Pi1adj3l8K9Qi/8nlTwfmlZFjX5bkxuOqnnBFyWvfZ/o9g7Jzd+4vg1r AP8A== X-Gm-Message-State: AOAM531W5ZV4YPDY5DyWu7KUg38SkNWNIaHxSCBOgvt+IqLlMe7fWGXv CtCc0KM5ywxLLJmEKfa5OE8= X-Google-Smtp-Source: ABdhPJzTN5juhzZGLJvJfYO8SEIhL6W2Ei+HaWe0tHJL3XeA+iq7BLtzNy2ob4QQR0VF8apbc05ovg== X-Received: by 2002:a17:90a:a883:: with SMTP id h3mr3449242pjq.226.1628149309003; Thu, 05 Aug 2021 00:41:49 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.41.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:41:48 -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 v2 5/9] submodule--helper: remove constness of sm_path Date: Thu, 5 Aug 2021 13:10:50 +0530 Message-Id: <20210805074054.29916-6-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-1-raykar.ath@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This is needed so that it can be modified by normalize_path_copy() in the next patch. Signed-off-by: Atharva Raykar Mentored-by: Christian Couder Mentored-by: Shourya Shukla --- builtin/submodule--helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9b676c12f8..99aabf1078 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; From patchwork Thu Aug 5 07:40:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420529 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 0D040C4338F for ; Thu, 5 Aug 2021 07:41:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8F1861008 for ; Thu, 5 Aug 2021 07:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238654AbhHEHmL (ORCPT ); Thu, 5 Aug 2021 03:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238648AbhHEHmI (ORCPT ); Thu, 5 Aug 2021 03:42:08 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC074C061765 for ; Thu, 5 Aug 2021 00:41:53 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d17so6024478plr.12 for ; Thu, 05 Aug 2021 00:41:53 -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=a9OTKrqV7Ovyd4inRxW0ZR34NlvzqBi2hYKmbgmVkjI=; b=p0r47VROMEmF2RG9wgJ3mlFFf4+S9zHPkT+OG6oTH/LO8wEJU8eggq6+np0TNpdX+Q 8oZbxC07XH5mFA+hn01Xy2vUP6RUPn7tIz/mD3lBHaaj1pJdDcumAt4aBUCjT+tjy6qg ++zo//QMgDCUBy3tqE2XxxlneQNIBbpUqnNEO+2AUU5EfMKZnCJSbOFekPxLF3DuZL6I VUWibTSguJ1WG0f8KbDMYqhuHGXCIkmz/1YxA2+P7dcvyWXcJCz/+7rkz6SBOrew+utC UUC49iN+GnDmwBcCFF6gyMyndrk9kOTP2ew2MG/oQMbUVKaefZHBHcgkgymGQE/Ztuc8 VzwQ== 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=a9OTKrqV7Ovyd4inRxW0ZR34NlvzqBi2hYKmbgmVkjI=; b=fD3BKIQeXsfOgZGSW2yNJO3es5KqSaftMPXBRtaFuC5gXv0ivoSsfao068BoYxzSCu aeqF2CO6hsuz2h2tQZlMcJWSHSiMqWGHFPy6tI3vHWR5P/jojUyCllCW+ttbbRYCsJ5E 4x+K+8zuUU6K/kDZQSqCpPqyn4q8GKCC1nqg6rYOSj+/YLoUK47003m/9zuxNozw98TU /APYtkur3DOo/ILhDYUAZE4X3Kop4lqEc83+ylessnUzVpXTePGrNb3KBXAMn0SpKPnB dj5sQxWxTZJh2VbNRvnJdBbotPp8+rUEkivaWBDcv+xuxQZXiEgJpLJGsS50D23QLWJY CvXA== X-Gm-Message-State: AOAM530cjLjk9EJWyMXAjby3v10YMMvQkSWVA7ubJPM/foOqf4nuE3jW GQz9CURdmfgXjjfALTsdexCEJYdcJZPdrBYC X-Google-Smtp-Source: ABdhPJwP4w+uHGp4GP6mENwSqF+ciTQhsnIVc8vqN9DPwi+vDiBzJiwfE7ueiNs1iO9w/YozI3wZDg== X-Received: by 2002:a63:6ca:: with SMTP id 193mr1221528pgg.265.1628149313216; Thu, 05 Aug 2021 00:41:53 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.41.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:41:52 -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 v2 6/9] submodule--helper: convert the bulk of cmd_add() to C Date: Thu, 5 Aug 2021 13:10:51 +0530 Message-Id: <20210805074054.29916-7-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-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. 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 | 160 ++++++++++++++++++++++++++++++++++++ git-submodule.sh | 96 +--------------------- 2 files changed, 162 insertions(+), 94 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 99aabf1078..05ae9ebe50 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3046,6 +3046,165 @@ 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 = guess_dir_name_from_git_url(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); + 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)) + 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 +3219,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 Thu Aug 5 07:40:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420531 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 96E85C4320A for ; Thu, 5 Aug 2021 07:41:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B3AD61029 for ; Thu, 5 Aug 2021 07:41:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238184AbhHEHmM (ORCPT ); Thu, 5 Aug 2021 03:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238627AbhHEHmL (ORCPT ); Thu, 5 Aug 2021 03:42:11 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9458C0613D5 for ; Thu, 5 Aug 2021 00:41:57 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id ca5so6758292pjb.5 for ; Thu, 05 Aug 2021 00:41: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=s9wD3p/s/nP5k2Pl25OVVZ4hei8Nernjc4lgNCXspgI=; b=S29nGuSs2Ucf+qlIbt/4EVyyD7A1UCzGrOq9icMP45TkkxZuxrfrlJXNW93yQ5aisz iVYU2egXtdhcER5pmYoyTsBbhp9PlQG8r6Pa9FhVj7Na6LjOEKPf6LtYkjX850OeJfQd BztdYyiBGcjpnNWAdQplm0vwwK5i+FPv3C6ZiG6QvVwwjCi2x1QYYn6txxicymWP5uY9 yk5acXY8QqDexWES+eTg35xL3c+XOBT1/3TmfGjh2d9PiDYgV5bIxysjfoGhQUPN6wPZ mqwbMGz64YsPPzpfjtKWZsh97ACrxhItffpoRINzfByP7Qm+6gFLUINTCZ3/jjK6QxW9 i9vQ== 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=s9wD3p/s/nP5k2Pl25OVVZ4hei8Nernjc4lgNCXspgI=; b=cDE6s3TejFDkhQLyBg7vd6is00FkGCotyehKjjs5XKibCWqrKUy1Lk8gJ9CK1O4IUp rPo+R8Fzsu/GP4CqtTXUqQk9f0pMnB40p6bL0zdcJjxbBRdyJjKqiK/TYFiFKdqDSp20 yFGPVP6IHkm/KaNH/Qjxtrx3cqIUKePPob/cze5GY9CI48LP6J9ExvR7q4YKFrSwTg0S NeoQP2+GNOyBONJuW44rkHUqLyCS2LTLxMfZQad2sDxXALphEJrMeCH4nfHk9sZT4zJG GYN0l5LCaPWEkfi3VRD8aM45Rv6zEY7dJAjtR+vg+surmXXh6qO+3Jkb7EE+W59lYgcw hhbQ== X-Gm-Message-State: AOAM531xVRZ2rlr2neOkvSd84HpYySklsidQYOg0uqPFqFsRkgHTOD0Y XiQehnuJij8+lI8n2OqatDA= X-Google-Smtp-Source: ABdhPJymwzO7VjLephxWeys+sOr4H9fkqciOyRXmtLtMkKVpeFRSh9z1Li3F8jp3eYC5/6aTECBa7A== X-Received: by 2002:a63:5855:: with SMTP id i21mr768361pgm.77.1628149317498; Thu, 05 Aug 2021 00:41:57 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.41.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:41:57 -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 v2 7/9] submodule--helper: remove add-clone subcommand Date: Thu, 5 Aug 2021 13:10:52 +0530 Message-Id: <20210805074054.29916-8-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-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 05ae9ebe50..700cc8bbeb 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; @@ -3217,7 +3158,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 Thu Aug 5 07:40:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420533 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 BC823C4338F for ; Thu, 5 Aug 2021 07:42:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 650A161040 for ; Thu, 5 Aug 2021 07:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238519AbhHEHmV (ORCPT ); Thu, 5 Aug 2021 03:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238677AbhHEHmQ (ORCPT ); Thu, 5 Aug 2021 03:42:16 -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 05DDBC061765 for ; Thu, 5 Aug 2021 00:42:02 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id t7-20020a17090a5d87b029017807007f23so9597600pji.5 for ; Thu, 05 Aug 2021 00:42: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=7PeTlolYUUEdH50YFM+tYWul3tHUIpiVifHEE94XnWs=; b=JnivifsYZUEUV/2feaQTrBMAa6DgmCeb9JnrRpCzlWpy+CLtFParqfPDcxWkw1RTqe itFJYHCVaTGZrbw+MwhmRi4KVN5IkpSTndLyi4aEFS+ZW6/zSFIqvGFX/GmS3GTvNnNy Vw8vlDjujhYF79ArSH0FmySJ2CgT7WooiRB5D2be4cvJ7pO+rRSQ4C70E3YSaI9fxf8M LGvmqjkCFOjjTV0ysOCT6VPCm6M50bFtDn7m1iFNSd/7i/iJSTSLoKG0I67DprcaY06M pYN3h6hJzUioITvF1RacbLkdERWjicWoWrxskM979L1M0H+s160rcypNGLotEczIreB6 KjPQ== 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=7PeTlolYUUEdH50YFM+tYWul3tHUIpiVifHEE94XnWs=; b=fz6tCLs+j/6P3mlJC9DMhNevKpughqegbPsmzkIP6WzGWhB5CLryghg8iEqMoDt1Si 2zxwVaYHOeD4Ej8038xLC1Sb+gi8s9wPvCEgb2lZhvjlxgMaOFlcOAH8M92/eyF2KgZE US3rroKDdt6OImAgtUBEjvWA3FZk97vk+mnVziQ7WUQr5+cdR6vIYytjGe0TVxOxQlGn XXGME+5QNL/hAAS6ISxJo8ScPJ0YtIqCp7mqwbi6j3fIIBxQhip2SQJDHEnHEa9v06GR nRO3gEMNZAUw7KfRXs2rMHvbUISSG00jQwIW9WqabgAEoDW1aULJguBLjld20HO0py0P HmAw== X-Gm-Message-State: AOAM533YdSbB3zFS4tyouNUTykbP3uGjkKtrvahOwXm6xAqKqv9mmeYJ OySYMsZ8JhcYLuhkgZ8njJM= X-Google-Smtp-Source: ABdhPJwgOmY+oTxtadJdUo0QBiU5pZ7tZjR6kdsUWTw99pcetIzF/3QBNVnY4hE9OB9eNhKlV5D4pw== X-Received: by 2002:a17:90b:80c:: with SMTP id bk12mr3471778pjb.69.1628149321582; Thu, 05 Aug 2021 00:42:01 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.41.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:42:01 -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 v2 8/9] submodule--helper: remove add-config subcommand Date: Thu, 5 Aug 2021 13:10:53 +0530 Message-Id: <20210805074054.29916-9-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-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 700cc8bbeb..da83e8e2a5 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; @@ -3158,7 +3110,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 Thu Aug 5 07:40:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420535 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 DDFCBC432BE for ; Thu, 5 Aug 2021 07:42:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFDA961040 for ; Thu, 5 Aug 2021 07:42:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238660AbhHEHmW (ORCPT ); Thu, 5 Aug 2021 03:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238667AbhHEHmV (ORCPT ); Thu, 5 Aug 2021 03:42:21 -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 35103C061798 for ; Thu, 5 Aug 2021 00:42:06 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id dw2-20020a17090b0942b0290177cb475142so12810581pjb.2 for ; Thu, 05 Aug 2021 00:42: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=e+6OCMo+DlGa2QWoBAGf75KRxMzKVKH6/dy+1rWuxBU=; b=TKnTKrrVLQrwBvYN42QUDBkk5D+R1zisPKHN5jS5FeLErLaxsWyakIFWcm2y77T3kD bYEusfqQg6KRE/8zdcd+T4DYT19JxEWeXkGSTiNPERZK3pRJD6Y1RhjJoeLvnmVnj2pU KWLtl1tTAk58eyDQUUxoIL7S2afPX08LncRvSJPuiE1z/VC5tBZ+lZKgOfBKjGXEX1Q9 PJJbvHhhWShJqmUTTFNStVDwVrHnGGobpGgaVho3+DJsr2zd6ZNeDl6pka4UkLBVspHa v0N3r2lAkN85iDoz19jlIkEOCC5QHotfYk0ZD65CBkTMUzy0aVBppAddiwBVvoyCkbxI sfTw== 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=e+6OCMo+DlGa2QWoBAGf75KRxMzKVKH6/dy+1rWuxBU=; b=RaGgiCjQzbiFnlXT/ANHEmbe1KOPMlH0d9wHyVYSKhu3gXJEfeonF4bXr+RjgxnK62 F7QjhT0LB6tAkwSCx5WRYR6fM5XZf9C2jblka8EjgBoTP9AZ37qXzfkWedwxlOw4WDYn z9NKkTv16CHO9ak8OKLIFFR1ORn8G0RnTWIwFzoA4fUyTa5VtG8MCE7TLgu6BmfNeH1d ETwQKZzW6twezp0J/Uy64+zGEKfJx1rKjcdL+20X9JzKFUkDQ/Q6iQGz5zL/N7shshqT G8eua3brFwwlp/Ij7N6E+N+XrPH20Wj0jyNGku+XIuvY7EVMgdqnDCMJ5rNql9+WhzXG 7Vlg== X-Gm-Message-State: AOAM532jbpc5Zm3r1xAdMsI1AuYXJD0JirX2rX2fgIch7OHoSH2n82tN uHGn1v+5R/lG5sWO877WuZk= X-Google-Smtp-Source: ABdhPJyq+7FJ5c1EUkggKmUeOK7NYcgFHRWcaQqTvmPujYxaS1DhxaczPEbebboc5H5NV0XPuUIRvA== X-Received: by 2002:a17:90a:6e07:: with SMTP id b7mr13877674pjk.1.1628149325824; Thu, 05 Aug 2021 00:42:05 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id b2sm4885153pjh.18.2021.08.05.00.42.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:42: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 v2 9/9] submodule--helper: remove resolve-relative-url subcommand Date: Thu, 5 Aug 2021 13:10:54 +0530 Message-Id: <20210805074054.29916-10-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805074054.29916-1-raykar.ath@gmail.com> References: <20210805071917.29500-1-raykar.ath@gmail.com> <20210805074054.29916-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 da83e8e2a5..514891a22f 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; @@ -3115,7 +3096,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},