From patchwork Thu Aug 5 07:19:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420459 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 1BDFCC4338F for ; Thu, 5 Aug 2021 07:19:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0454F60F94 for ; Thu, 5 Aug 2021 07:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238133AbhHEHT5 (ORCPT ); Thu, 5 Aug 2021 03:19:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbhHEHT4 (ORCPT ); Thu, 5 Aug 2021 03:19:56 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E39DC061765 for ; Thu, 5 Aug 2021 00:19:42 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id j3so6005003plx.4 for ; Thu, 05 Aug 2021 00:19:42 -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=nJ4odmCXpdqL1/WqB33t8kdsaNVDRhiH01Gb3gn18byW5IJWoLKDRLLJqjE3SwJMix GrDA7Xb0b3pbDbNHMAIzATI5xbujRyMXHCZqTsM3JSDj7VMnK0t/gDLGAc2LEAhm57KW 8nOBTI7KvVGIe/G5f+405Rr52wLUqhP8p7TF9X9UlAD/ppMBnaT4bPUkqSU7k8PglIot +5EAk1oblZVgKFZH4F+XHl94JeuALifFtpt1TJs5UIOtO8rmSiMdvNRWQ7V2t1qxTYp3 /iIPkwQ1w5H0UEpVaPEX2uPhPV6JzbR0ZzRyLo6sgnYq1X4A2MRdyGfm0mQNgVDzNkr1 aEdw== 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=q75quKcNeodNZ9KYmUVu6uMGSVNd9pNvthgQjgP0mezGaGiof9dXKSMyxMkXbB1mI2 Zfvd/js17wNxAiCYDAZmkagiDMmgn+w/vwAfGjyyKnf4OLcgw/k1wFmZnotMVcDzg5Eb poYPAW1IR8XW4lrEjDh9rcHRgFxrvhgLU9AJT/rGGzVjtM1A9q2vjIUQVEPrnMtitfnA zK3E2QJP9upC8Ufn+Ry5vbSTaKPLEKfJnB+xmoCqN/inVdJjjw+3TKqMQnu/Xnp77LJQ kTbmprtW4R2RkN8OSa720AhekIt+1ChtvbLM7L8EHNJ0YyIoHb5efpIZwSUfx0ltkAEu DSew== X-Gm-Message-State: AOAM530YYR8iDWCVXn27dMI8Datlo113zcavtFQ35y1sbv4BbwRJq1A9 g38YXpknvEENhGdezlqF4Zye9lvGuEtPldJl X-Google-Smtp-Source: ABdhPJwZEnp9ajPtilNC+gFpMdcJ6Zf7k7rC1W97eMWCD3RRi5FUZVvK4zYQ/jJ1fU8nWwbpZ5qIWA== X-Received: by 2002:a17:90a:8b81:: with SMTP id z1mr3277343pjn.82.1628147981492; Thu, 05 Aug 2021 00:19:41 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id p17sm8569603pjg.54.2021.08.05.00.19.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:19:41 -0700 (PDT) From: Atharva Raykar To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , "Emily Shaffer" , "Jonathan Nieder" , "Junio C Hamano" , "Christian Couder" , "Shourya Shukla" , "Kaartic Sivaraam" , "Eric Sunshine" , "Prathamesh Chavan" , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , "Rafael Silva" Subject: [GSoC] [PATCH 1/8] submodule--helper: refactor resolve_relative_url() helper Date: Thu, 5 Aug 2021 12:49:10 +0530 Message-Id: <20210805071917.29500-2-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805071917.29500-1-raykar.ath@gmail.com> References: <20210805071917.29500-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:19:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420461 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 2C204C432BE for ; Thu, 5 Aug 2021 07:19:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 052F06105A for ; Thu, 5 Aug 2021 07:19:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238345AbhHEHUC (ORCPT ); Thu, 5 Aug 2021 03:20:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238268AbhHEHUB (ORCPT ); Thu, 5 Aug 2021 03:20:01 -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 95EDFC061765 for ; Thu, 5 Aug 2021 00:19:46 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id s22-20020a17090a1c16b0290177caeba067so12797160pjs.0 for ; Thu, 05 Aug 2021 00:19:46 -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=bmBUKmCfXiv1SFldvDOjgSh2B/hdvWGWmPhi9CRoxW4cgFHIfSaO1RZkahDJ0d0LhM WkjdHmnZqT0C2rMMchJWQhdyrMNRAt/5K3/ggoA3S9NKJ7AlKxjSjYQLHvL9f3wVrY5N aBFH3fxeYVu0sdAF0qipLV8VHu0ffOUUdDQL0cTnEBoPSsS6VA97KIg1RB1QywAkKJsf H47KGFz4AwZhfPWdUWnwDeWAnzijiZafEAiUubxRsplARqsVFKP9VDVBb4ASg7BOPnDT 7iSp0GhBjz3QQwWEM2+mfs3qtGCsaISiDYgoA39FRwThfNyR8zU50BmPd64UXRZoJFCP 0THA== 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=VskU58NqWaEoJvHw3UCbHFD19PfkqVzX8hwAIzh+CqZkAaNxy2fyG4GNLKR80INxeo wtWU4BpkfPMpZJuCEXc/qDfYVy/wwkrAQiM9ih9F6CXFq9UjKJKinpHbJeWSQCStmBPQ GFyXYVhqdOCFeIobXRy6l4reiV1Q8zi0oKfxXwVaeGpCOi2MPRmu5lY3N/CXmQ/PSEXh 5Rs2a/I9AyUf5QTEHvTyDSpd8+lj4517ri1FJnK7KH2FpERuEIHy6x85ZYrnYv84xtP+ Vm1qouWtEFOmjZIyow9wIGwhVTB/QqSrhiCI0/czd21GjztYkTTa+N59puW4uDH0+3Va PpAw== X-Gm-Message-State: AOAM530Wk5ZEUEEpjrJrgMMmMihAMVKDHTXrXUsQdYWBTRmogvDyyF58 U2WgFHqk0A/Qk01gqYN/QD0mnYJcniK9itIs X-Google-Smtp-Source: ABdhPJzd07xDFIgGjSHDei3j45QMpEZwpnjSyX8GLDeoWW6dAWi2arO6af5Jl6Gt6+GJDCL8AJ7JRg== X-Received: by 2002:a62:7f0e:0:b029:3af:e2a6:f838 with SMTP id a14-20020a627f0e0000b02903afe2a6f838mr3692631pfd.7.1628147985985; Thu, 05 Aug 2021 00:19:45 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id p17sm8569603pjg.54.2021.08.05.00.19.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:19:45 -0700 (PDT) From: Atharva Raykar To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , "Emily Shaffer" , "Jonathan Nieder" , "Junio C Hamano" , "Christian Couder" , "Shourya Shukla" , "Kaartic Sivaraam" , "Eric Sunshine" , "Prathamesh Chavan" , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , "Rafael Silva" Subject: [GSoC] [PATCH 2/8] submodule--helper: remove repeated code in sync_submodule() Date: Thu, 5 Aug 2021 12:49:11 +0530 Message-Id: <20210805071917.29500-3-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805071917.29500-1-raykar.ath@gmail.com> References: <20210805071917.29500-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:19:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420463 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 0E5C6C4338F for ; Thu, 5 Aug 2021 07:19:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5D1360F94 for ; Thu, 5 Aug 2021 07:19:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238355AbhHEHUG (ORCPT ); Thu, 5 Aug 2021 03:20:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238268AbhHEHUG (ORCPT ); Thu, 5 Aug 2021 03:20:06 -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 A523FC061798 for ; Thu, 5 Aug 2021 00:19:51 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id mz5-20020a17090b3785b0290176ecf64922so12705709pjb.3 for ; Thu, 05 Aug 2021 00:19:51 -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=FUh49Nen6+XXGWm203BeVIWyhspkj6R2+5R95vtWrC9yujGzjKgY5y/VnCJJZvchbU nHFpKh7PoK/ka6GPzDYarWMb4JeDLMqLWMMq3hvDJKqLCoFRv+9bLWrD2MX3Mm9k0o0h EG0s23/D0Jiw3B7QIR6B55GVKz+RpM4+h3QmQ1anrFRe3S5xevjqI8fT2jzDKtUMpneG K0X0gi2mmyFLUGkniRYEdKU6P1q3an5qJbD1nUoVnpfMbKLR4H+wMNUsyQwVUEYlm+Oz 6hnesAVaqzuts4lrZcmKIQoNaRBsFbYWkSDOOG7SzVIswZHrApgS/jJq72TepEvHiZ7m 9jcQ== 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=jvF8cgBJ0Un0fDhbuXW4SHsNWj7+AcqzB/JmmtvPJx1e+HZudrFPyOVLlI6tLriSek 56kcWkZIP/5Jg4fRavrcvAEeVjZii04H8N91uSH9RalFszvthDMy1TlYtpc/0Pd4L6Dv 9X6v8Iettkvqx6YURtwuxFxFMnJaXl8G6S0irMqLaDbjD/NY81g0iGGAiY2RoP7Ip0XY xivoYWXgpmGYmeQd08utZEwe0VnQXLl8QarWEwbWacp9lue85ZLDaLtVPTc6pEnzPnOi H0pVYoMIKS0Kv6GUT9/zZSO0OR14hmDLHB221765xVlthadqQk1z2chDk3VZxX1PDRhG lZ4A== X-Gm-Message-State: AOAM533Kg0Myl82kgtqAVoJfBdfqKeBb9If4RBcHHUFzj7B2jP7PXcj3 bFPXiwi5H17yKK6vohxVht06MxOcKsOMWk0+ X-Google-Smtp-Source: ABdhPJw6hmZFHuwIXUW5T8FAev7VU6bUzdoOl2ufbJhwj3JNCs1wTAG1jZGTi79SFIkzXpPQfdsRCw== X-Received: by 2002:a17:90a:2c0c:: with SMTP id m12mr1847948pjd.107.1628147990944; Thu, 05 Aug 2021 00:19:50 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id p17sm8569603pjg.54.2021.08.05.00.19.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:19:50 -0700 (PDT) From: Atharva Raykar To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , "Emily Shaffer" , "Jonathan Nieder" , "Junio C Hamano" , "Christian Couder" , "Shourya Shukla" , "Kaartic Sivaraam" , "Eric Sunshine" , "Prathamesh Chavan" , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , "Rafael Silva" , Shourya Shukla Subject: [GSoC] [PATCH 3/8] dir: libify and export helper functions from clone.c Date: Thu, 5 Aug 2021 12:49:12 +0530 Message-Id: <20210805071917.29500-4-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805071917.29500-1-raykar.ath@gmail.com> References: <20210805071917.29500-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:19:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420465 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 5C71DC4338F for ; Thu, 5 Aug 2021 07:20:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CAE260F94 for ; Thu, 5 Aug 2021 07:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238398AbhHEHUN (ORCPT ); Thu, 5 Aug 2021 03:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238484AbhHEHUK (ORCPT ); Thu, 5 Aug 2021 03:20:10 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB583C061798 for ; Thu, 5 Aug 2021 00:19:55 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id t7-20020a17090a5d87b029017807007f23so9527341pji.5 for ; Thu, 05 Aug 2021 00:19:55 -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=sZSVzor1dJB8JD6LMVhxFQ0RTD/DPyLav1E7ti/pgKMmJIgyr9hgXGGSJuVz0D5Mul dccEUNoPYwTnwsbzniiB3N7ddaHh08A14K6MC5UlE4f3YFSUOHyyDfQP3rxd/9uUKG4p pVr1TPJDarHTlZSy42SJTK4wKa6nBXLnYE9jujAqsmU0UzyxdG0aTl3XIuIWuueYiR5F GsTUZ3my6VSNF6/i7fIeDc5sBCbniezwuEpt2d1cRjangn7ySHFKS82dzqwKP6fRFYsD f9a8djeHlZfCgG6gtdRiFncaXWZbDyLtoLkKrCTNNyy20C9GshxmguWDjy4Hw7zcGp9M n4Zw== 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=JJoduZbPJ+z6MfR5V+AwcjPEVA9rpYS/ZnUhYGem8ANV/ZBgZB6XsrOcPu3JExnsmH oksWDmVCdcVNu/iFG7+ckDKwyyknMu1WeoMlbQSTI0FV+hvNoLtj2CD1Q+IR6UTy+1Q3 P6cZli49HkxK/iWGWZakh6bEeDoPVe/z7hhggDXJKPAuimjK1L69z9fovgl6qXShNEtL Mwk6gFLRLglXE7PD6rpifJUZR5GV8hkOWPBHWyDNaA/5kysO8kFoL/8G0WPtDLxZ7XXT eUYlsSbFhRg8LGk7R88ivnSAIgtzG/Cscr7Oq83KJF6Kbj8NTdeQWu3WtL/EBVHIyyZ2 mLXQ== X-Gm-Message-State: AOAM5329O9Y9WBE/q4Wtwv4Cv/tWxHzgy9mxXlSupuzUSPRh+kC8MFvM LcokSyvld3lzXYW+MSRspdXe+9u5SH/NBleL X-Google-Smtp-Source: ABdhPJyY/XOkMb+g0uZq+hTjC3VNprrmQJXbDyuJq+2kfT0Wf7F1fvpvONTwXs6d0bkvTR+lxi8TyQ== X-Received: by 2002:a63:cd4c:: with SMTP id a12mr694975pgj.449.1628147995309; Thu, 05 Aug 2021 00:19:55 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id p17sm8569603pjg.54.2021.08.05.00.19.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:19:55 -0700 (PDT) From: Atharva Raykar To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , "Emily Shaffer" , "Jonathan Nieder" , "Junio C Hamano" , "Christian Couder" , "Shourya Shukla" , "Kaartic Sivaraam" , "Eric Sunshine" , "Prathamesh Chavan" , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , "Rafael Silva" Subject: [GSoC] [PATCH 4/8] submodule--helper: remove constness of sm_path Date: Thu, 5 Aug 2021 12:49:13 +0530 Message-Id: <20210805071917.29500-5-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805071917.29500-1-raykar.ath@gmail.com> References: <20210805071917.29500-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:19:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420467 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 8830DC4338F for ; Thu, 5 Aug 2021 07:20:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C8CF60F94 for ; Thu, 5 Aug 2021 07:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238268AbhHEHUS (ORCPT ); Thu, 5 Aug 2021 03:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238478AbhHEHUQ (ORCPT ); Thu, 5 Aug 2021 03:20:16 -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 7E253C061765 for ; Thu, 5 Aug 2021 00:20:00 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id j1so6708997pjv.3 for ; Thu, 05 Aug 2021 00:20:00 -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=Bozlcm0KPQPJaxWSB1aaxVtVgT4r4lj4pp+ePFcqFprHc37jFIeBy8BheMKIFDmKCw 7mJXBXWbyBSKSOc0nIN9o4+LR4+Fzfu0kLXgAKbrskWWTwnhm30oRlR4bnj3/HY7yBv1 OXLlwVwuzppYPYPzC2ZFqLqat6kHdv2FR1qrCERERXNX4Rn7aH5Yy1EurpYNY19yL670 F3XnOKOPuDifLR1ObiDr7DM0e5yThhNHKMLVvjWSR4jNy88heYRbARxTI9hCHF1sccpg ZNABtArO3RqJR0bTdW67Ra0dtCdNnMoPhTdMr8ZG/RkdL7v1o0ouYybvDJonjKtkLWv5 R8bw== 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=SOxiyewZ8fSvlOJm1rrwcaAbnbddoHHaY+QQeRAxen2KQg5T3bmDUzibSx1O9kG4NH bZwobrZvnnZDH/z1iloga7oIibWw6bq6/iG4UhPcl//1ufaf8s66LkKdItz/I7a3re8v I0buwojRLKKp8dIjwW1mW9Ai/7q7NEzLGjyE5/6LXDZWeQweah7FUbbbVZbxo088lG3w OsgNEMZ4t7aopxbY+qtg+LERc2LOkinaigwQ2uq2mVG0baGa7vR/I9i0e3e9/iJJR9gu qJziajcwSIdu0MOR3/jGYdOkr0w3DSG86mAWGrXn95f0YNSRSN1hWkP1m6DkWThJ9kfs Lx+Q== X-Gm-Message-State: AOAM532tM0KC5MvTm7rze2I4R0wq47oMxk4DYCLbs5VejsVOWuhEO34C l+MJXlcg4DwWyeXNYrdviUla9G7+cW9ZDW9V X-Google-Smtp-Source: ABdhPJyXVhl++hdJF0fOLb67WvTDDYNuAiqEH+NcNEUa73mZR4050BxPUTadRhcIw0AQ+0q8zYv8xg== X-Received: by 2002:a63:1d47:: with SMTP id d7mr84895pgm.44.1628147999883; Thu, 05 Aug 2021 00:19:59 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id p17sm8569603pjg.54.2021.08.05.00.19.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:19:59 -0700 (PDT) From: Atharva Raykar To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , "Emily Shaffer" , "Jonathan Nieder" , "Junio C Hamano" , "Christian Couder" , "Shourya Shukla" , "Kaartic Sivaraam" , "Eric Sunshine" , "Prathamesh Chavan" , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , "Rafael Silva" Subject: [GSoC] [PATCH 5/8] submodule--helper: convert the bulk of cmd_add() to C Date: Thu, 5 Aug 2021 12:49:14 +0530 Message-Id: <20210805071917.29500-6-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805071917.29500-1-raykar.ath@gmail.com> References: <20210805071917.29500-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:19:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420469 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 A0911C432BE for ; Thu, 5 Aug 2021 07:20:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F88760ED6 for ; Thu, 5 Aug 2021 07:20:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238428AbhHEHUU (ORCPT ); Thu, 5 Aug 2021 03:20:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238303AbhHEHUT (ORCPT ); Thu, 5 Aug 2021 03:20:19 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2FAFC061765 for ; Thu, 5 Aug 2021 00:20:04 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id q2so5968115plr.11 for ; Thu, 05 Aug 2021 00:20:04 -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=YNwLasq9X03Mmba26ayuj9zJEFxT0NBjzAJmFw7/tgwUswXM1VUFwORNC4LOa3DAgQ 7XUrwvFK8ul34xbrALsOisUkI3SF+YdPNFOip+Q4cwMNEiQfLAArQsR2cpaX6EhwWbPp aDFS4cy/R9MjDYKvNlVymn3X/SraM+vkZanPnXfTwets2FQAur0sQBM3/JJAjjR0ozu8 b58jUGmqWyTPNwtXYg8Ozff2ivZ2Q1e8TmGBFOUvh3Quh1med13Pb/oxVCP6DKdFAK9K a7horlEh74PcxA5L9ICCQXKoDRj4eY9ku5YFmwDkROnmKg9uo8n2naXPHq3BeWaEg6Nv 9VsA== 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=Ip8xM2lHkJUQItGefZ/Br/DnM7/fuNKw+vj5ZCQytVfaMdFFZ4y5oSrOe6jPgLDK1J 70m9KDROBO+bVbqg76oBhgQy16DEBk7ESWQ96HzOmgYjtpVR83uecnsnNI5SFg5h5KSZ 8+UqxzH716oirDuyzNp0LJ6qHDJ4mRvpF9A+oFGlb8Nr8tBjj56mw3dRBhkwJIRQRPpU awfmax4Q0wZ/MMUAmm936Yav2QR6tm0CKIQ31s/zSDm0meHkPyerF32wN6qRZ86R//fC j3kNwFSM0+47OJtmNmg3I1N8HhAR6HwSa/WRinqqPEwLpdnx3+erJNHZvz7tAk2On4hc kaTQ== X-Gm-Message-State: AOAM533Ri3D/gaAtl+gkFHAp28kmzowLDfmVwMoqphnj0piMDhrv4sjx QkAJ45ZokKXRsfdMAnJaulBH5rQrMUzw+8Er X-Google-Smtp-Source: ABdhPJwpzovu/x9nOGk/X6zA0SVm3NknuUXNrztNl+huRF3zGuR5hSR0sWN1hBz+m589bRmQjtElJg== X-Received: by 2002:a17:902:c115:b029:12c:50d1:ebde with SMTP id 21-20020a170902c115b029012c50d1ebdemr2716266pli.67.1628148004204; Thu, 05 Aug 2021 00:20:04 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id p17sm8569603pjg.54.2021.08.05.00.20.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:20:03 -0700 (PDT) From: Atharva Raykar To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , "Emily Shaffer" , "Jonathan Nieder" , "Junio C Hamano" , "Christian Couder" , "Shourya Shukla" , "Kaartic Sivaraam" , "Eric Sunshine" , "Prathamesh Chavan" , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , "Rafael Silva" Subject: [GSoC] [PATCH 6/8] submodule--helper: remove add-clone subcommand Date: Thu, 5 Aug 2021 12:49:15 +0530 Message-Id: <20210805071917.29500-7-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805071917.29500-1-raykar.ath@gmail.com> References: <20210805071917.29500-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:19:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420473 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 C0FFCC4320A for ; Thu, 5 Aug 2021 07:20:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A96F5610CC for ; Thu, 5 Aug 2021 07:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238478AbhHEHUb (ORCPT ); Thu, 5 Aug 2021 03:20:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238519AbhHEHUX (ORCPT ); Thu, 5 Aug 2021 03:20:23 -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 35BDCC0613C1 for ; Thu, 5 Aug 2021 00:20:09 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so12741295pjr.1 for ; Thu, 05 Aug 2021 00:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7PeTlolYUUEdH50YFM+tYWul3tHUIpiVifHEE94XnWs=; b=mZFhmqG0tTcaSJGYzkPnsztugTDlAOJEr3JxgwPSQpL/QmXqlRfciJi/hiwUkaG3Xc jOALrxkepY6zXQcHIqIcvOAwnCZLMCxJw5TEdkdkE9mTkG2Ykeo1MxBJv9Er/qTs1kAa nc8gQlV3E5tiSVkC9xHpF9rQZSiIlLlOSOstHLls2TVmHx1ZeDKc50TP1mlvJk1O4qvn vk3n0cHq90P580PCh2ExE2Kz4BqVKhcaA5OPOVDY34uSVXrQn05Cy61aC/AEDeFLYaQw 8FfHBlLy1tqE75estXMHojnzHI7ZyrHjtFzW+BCrwqIAyihX0Ry2imakkhgffxtHWuJy kGLQ== 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=tjxA2p48UUMxcBf5Nzvk+4UE8YUt+y7qzsqkoEYGLuSUIyft220HbwZ7iyXHQa+0L1 RHzQt8uGrJ4YmiyP6Gk8i0okdMhk9IAyFicL0vu09e67R3VitPYo6iFk+jLB9fboKs2s RwbXnVEehaiM2IbpX5+coyXKp2wz4s6lZv0/GPQ0WLy7AaRnukeVu/aRG7i56VyNf3LN iShyrzesQj/Lu9JtBOJ7qVnLujbWNJQjAdBxkTClsI6Mpd86edNQLfZyRee3HPmRN3eJ LPWAm53EfmRaT2qzDkTLPZAYC6AXWqU3yBoreeRRTrWn1/X+btE+RGisEw8WXzNSbhr8 cl0w== X-Gm-Message-State: AOAM531M+bikMTyRCxIy48sC358uvDWUkjhxTYUxZgkPwGENrPGmBYuW AOpNoBc0p2kTY4H+0v6+RaPhPR9ZothRBDYu X-Google-Smtp-Source: ABdhPJxGKZJ8gLSueaoDgq738rVzBXscLcGx5B4w9foDAYXiz6A3qqtGzZnOXf0iqbJJZN+Fh66+xQ== X-Received: by 2002:a17:90a:ea82:: with SMTP id h2mr3286480pjz.99.1628148008628; Thu, 05 Aug 2021 00:20:08 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id p17sm8569603pjg.54.2021.08.05.00.20.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:20:08 -0700 (PDT) From: Atharva Raykar To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , "Emily Shaffer" , "Jonathan Nieder" , "Junio C Hamano" , "Christian Couder" , "Shourya Shukla" , "Kaartic Sivaraam" , "Eric Sunshine" , "Prathamesh Chavan" , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , "Rafael Silva" Subject: [GSoC] [PATCH 7/8] submodule--helper: remove add-config subcommand Date: Thu, 5 Aug 2021 12:49:16 +0530 Message-Id: <20210805071917.29500-8-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805071917.29500-1-raykar.ath@gmail.com> References: <20210805071917.29500-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:19:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atharva Raykar X-Patchwork-Id: 12420471 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 BAB67C4338F for ; Thu, 5 Aug 2021 07:20:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9896F60ED6 for ; Thu, 5 Aug 2021 07:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238303AbhHEHUc (ORCPT ); Thu, 5 Aug 2021 03:20:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238513AbhHEHUb (ORCPT ); Thu, 5 Aug 2021 03:20:31 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 984DEC06179E for ; Thu, 5 Aug 2021 00:20:13 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id l19so6782137pjz.0 for ; Thu, 05 Aug 2021 00:20:13 -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=BGmcfAtzdJWICbC9IrGyAExp1EODVK5J6uFLNn6oadhz82fU0MWGQGAUq7eYGifHpD PqMN61lvoU3l4lyhy+yOaYDSxUU229JkqHqcTsqnK+XYUzpkyzogCfN5V9l8mWv8DT3s o0RF0LTbBHV17dJjQ08hb1HkgoaG4hq1Ogh4IJ6dcG0wAFHwid4vjQJzePp1UBiGBTr1 ANysse5IGIx0xZlpxooKc5q8wGEeIuq7kQtl+TeQXT47zxmosxG0l+SkxqElvlYffil9 Gr8rnbazbGzRlB5DSawCdiud8RYozkHRslWjBdUE6+SjImNqsAiUuzefE0ugyWVXjQ8u AkTw== 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=X9S32YQq4693Y+o4nqk6GHv4x4SV0XIzZ2NHXlKaV/Eo5Vh+diIPRi4TjXAtKouas5 Swymv5YFRSkqLabljfn4zbSbFCQY8WL2w3l7S8iIOmXJ2uqddc3ySmGrZxvzfufkpft+ oZaU2o6QBnCt3Al+oBJNzqOp92MHiCFB0Js/ufvWUHMYz2ufNSz4bTTUgkldniRTRVlH oJC53YJ1jBZS6nhaaAGuIpsZsuRmdZpQoT4G/XnWVnxozPWz12Ua/bxY1pVBMVd2jnGf ntVCz9LkipqC2Pjcf1hyomqwmoAj8n73SbqCkYIvHd9Zf7sz2uXLJpPyNhlChQ2X85js gAcQ== X-Gm-Message-State: AOAM532M4s/7/A43UdvYK0cS+l+cOeSj1FQyH++Ao4ALh9FvGDl5myCT +og+hPRkLFBO0A3DUXmtm8Tx8sdLFSNNqzxo X-Google-Smtp-Source: ABdhPJydPDAMdBx9Prd+WaqF1aBqr3m9WRiqa73uuqlW7D32/KDdn+uy6+a/QudFmUjAVd5lRjyUWQ== X-Received: by 2002:a17:902:8ec2:b029:12c:dc6d:4e31 with SMTP id x2-20020a1709028ec2b029012cdc6d4e31mr2785896plo.80.1628148013037; Thu, 05 Aug 2021 00:20:13 -0700 (PDT) Received: from atharva-on-air.Dlink ([119.82.121.47]) by smtp.gmail.com with ESMTPSA id p17sm8569603pjg.54.2021.08.05.00.20.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Aug 2021 00:20:12 -0700 (PDT) From: Atharva Raykar To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , "Emily Shaffer" , "Jonathan Nieder" , "Junio C Hamano" , "Christian Couder" , "Shourya Shukla" , "Kaartic Sivaraam" , "Eric Sunshine" , "Prathamesh Chavan" , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7Ru?= =?utf-8?b?ZyBEYW5o?= , "Rafael Silva" Subject: [GSoC] [PATCH 8/8] submodule--helper: remove resolve-relative-url subcommand Date: Thu, 5 Aug 2021 12:49:17 +0530 Message-Id: <20210805071917.29500-9-raykar.ath@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805071917.29500-1-raykar.ath@gmail.com> References: <20210805071917.29500-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},