From patchwork Thu Jun 30 22:11:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902298 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73690C433EF for ; Thu, 30 Jun 2022 22:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229884AbiF3WMB (ORCPT ); Thu, 30 Jun 2022 18:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbiF3WMA (ORCPT ); Thu, 30 Jun 2022 18:12:00 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7227C5721E for ; Thu, 30 Jun 2022 15:11:58 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id h18-20020a170902f55200b0016a4a78bd71so295715plf.9 for ; Thu, 30 Jun 2022 15:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LVTHjkAYlaiepUv4M45wNpA3phOsy2EDVQqr3hLaclQ=; b=leA1SaCrJgxU6EQt+ozatNOXwpHs96PMHSWl7iQz9/di7+cv9qRtZXLRlj4uf+C3W/ F/2+AYLdhwWfNi2RztVESLLX5F9VvJL1y4Yb1QJqHmc/6WKzF6PobhWian1iylrC4sMn beKNNjiMZn3WFbFbT0oAUqHR0Zyo118VsbU4GqNMZbCL3vInsDJRC0cs4xUKExWDtFLV ne9AfQzTG9YRyxqS5UhkSZfUOHOXO7Fi/AVHERXvIy8uOz5PuMPzsxHsrAvvnf5K4z2c 7fOofVlq09nuCAVrMk2qvYvv+f/LISLeJilyMOo34RA2Y+mTSzmdavjYQXyx+IUbmTUR UUPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LVTHjkAYlaiepUv4M45wNpA3phOsy2EDVQqr3hLaclQ=; b=WW9lsGzb3STqRAlAR3rZToufU6yhwtZlrSIoBqLRg++ynIL0qawWh9X+tzmUq/Gjc7 Mr1+kvTufAOgP9RC+pxgiMkj/9Tgh45heUE9DWsxiJZY5nyxGKxJfi8dT5Y9TiGkxFNR 6DZRqIadrZ02Slnyv7NHzHcsynyj0rIhmkTQbB21lp730VKZLBIkeUjDFwHbmlKP78sC ARvD9mkRWjQt3tJAH+bnW58lbQ9oPQepfmFU5GuvKU8ug8MV/MWQdiAuPBKv+GuzycHG LE9ioJOaofKtnPk9ZUm0dg9Yqm2Js+5HdwctpVSgi0FDIXs0bK7TcMXN/PjUB8FaEXPM p9Sg== X-Gm-Message-State: AJIora/B9LxXKzhTeycOOyBBzlOd7lpgWzwpwsZeXMHT9ButsLdxxD8O ljO8PQwOKZv5OUvdDfRvgXvEXj8xqPr2oPW/FYbjNNvIZdbbCFnjAkUiwYmnGg6RvvIiiYMw9Nx rVqwewj/K+tabKt+dWwBjS+D0aV82Bcayxao4N8QhLoZn9lKi+xz19GD+Pw3TF+A= X-Google-Smtp-Source: AGRyM1u0cyLncqrojKO2lnsju1c/zZts7bQskFdvTI9mW7CXD+bRBpQvP0OTlTSBfsIIPdP1aPeU48jOJSBHHw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:15cc:b0:525:8b07:71c3 with SMTP id o12-20020a056a0015cc00b005258b0771c3mr17840363pfu.57.1656627117829; Thu, 30 Jun 2022 15:11:57 -0700 (PDT) Date: Thu, 30 Jun 2022 15:11:42 -0700 In-Reply-To: <20220630221147.45689-1-chooglen@google.com> Message-Id: <20220630221147.45689-2-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v3 1/6] submodule--helper update: use display path helper From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There are two locations in prepare_to_clone_next_submodule() that manually calculate the submodule display path, but should just use do_get_submodule_displaypath() for consistency. Do this replacement and reorder the code slightly to avoid computing the display path twice. This code was never tested, and adding tests shows that both these sites have been computing the display path incorrectly ever since they were introduced in 48308681b0 (git submodule update: have a dedicated helper for cloning, 2016-02-29) [1]: - The first hunk puts a "/" between recursive_prefix and ce->name, but recursive_prefix already ends with "/". - The second hunk calls relative_path() on recursive_prefix and ce->name, but relative_path() only makes sense when both paths share the same base directory. This is never the case here: - recursive_prefix is the path from the topmost superproject to the current submodule - ce->name is the path from the root of the current submodule to its submodule. so, e.g. recursive_prefix="super" and ce->name="submodule" produces displayname="../super" instead of "super/submodule". While we're fixing the display names, also fix inconsistent quoting of the submodule name. [1] I verified this by applying the tests to 48308681b0. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 21 +++++--------- t/t7406-submodule-update.sh | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 389b900602..db2d5ab799 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1947,30 +1947,23 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, const char *update_string; enum submodule_update_type update_type; char *key; - struct strbuf displaypath_sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT; - const char *displaypath = NULL; + char *displaypath; int needs_cloning = 0; int need_free_url = 0; + displaypath = do_get_submodule_displaypath(ce->name, + suc->update_data->prefix, + suc->update_data->recursive_prefix); + if (ce_stage(ce)) { - if (suc->update_data->recursive_prefix) - strbuf_addf(&sb, "%s/%s", suc->update_data->recursive_prefix, ce->name); - else - strbuf_addstr(&sb, ce->name); - strbuf_addf(out, _("Skipping unmerged submodule %s"), sb.buf); + strbuf_addf(out, _("Skipping unmerged submodule %s"), displaypath); strbuf_addch(out, '\n'); goto cleanup; } sub = submodule_from_path(the_repository, null_oid(), ce->name); - if (suc->update_data->recursive_prefix) - displaypath = relative_path(suc->update_data->recursive_prefix, - ce->name, &displaypath_sb); - else - displaypath = ce->name; - if (!sub) { next_submodule_warn_missing(suc, out, displaypath); goto cleanup; @@ -2060,7 +2053,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, "--no-single-branch"); cleanup: - strbuf_release(&displaypath_sb); + free(displaypath); strbuf_release(&sb); if (need_free_url) free((void*)url); diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 06d804e213..f0408c5cc4 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1116,4 +1116,60 @@ test_expect_success 'submodule update --filter sets partial clone settings' ' test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter ' +# NEEDSWORK: Clean up the tests so that we can reuse the test setup. +# Don't reuse the existing repos because the earlier tests have +# intentionally disruptive configurations. +test_expect_success 'setup clean recursive superproject' ' + git init bottom && + test_commit -C bottom "bottom" && + git init middle && + git -C middle submodule add ../bottom bottom && + git -C middle commit -m "middle" && + git init top && + git -C top submodule add ../middle middle && + git -C top commit -m "top" && + git clone --recurse-submodules top top-clean +' + +test_expect_success 'submodule update should skip unmerged submodules' ' + test_when_finished "rm -fr top-cloned" && + cp -r top-clean top-cloned && + + # Create an upstream commit in each repo, starting with bottom + test_commit -C bottom upstream_commit && + # Create middle commit + git -C middle/bottom fetch && + git -C middle/bottom checkout -f FETCH_HEAD && + git -C middle add bottom && + git -C middle commit -m "upstream_commit" && + # Create top commit + git -C top/middle fetch && + git -C top/middle checkout -f FETCH_HEAD && + git -C top add middle && + git -C top commit -m "upstream_commit" && + + # Create a downstream conflict + test_commit -C top-cloned/middle/bottom downstream_commit && + git -C top-cloned/middle add bottom && + git -C top-cloned/middle commit -m "downstream_commit" && + git -C top-cloned/middle fetch --recurse-submodules origin && + test_must_fail git -C top-cloned/middle merge origin/main && + + # Make the update of "middle" a no-op, otherwise we error out + # because of its unmerged state + test_config -C top-cloned submodule.middle.update !true && + git -C top-cloned submodule update --recursive 2>actual.err && + grep -F "Skipping unmerged submodule middle/bottom" actual.err +' + +test_expect_success 'submodule update --recursive skip submodules with strategy=none' ' + test_when_finished "rm -fr top-cloned" && + cp -r top-clean top-cloned && + + test_commit -C top-cloned/middle/bottom downstream_commit && + git -C top-cloned/middle config submodule.bottom.update none && + git -C top-cloned submodule update --recursive 2>actual.err && + grep -F "Skipping submodule ${SQ}middle/bottom${SQ}" actual.err +' + test_done From patchwork Thu Jun 30 22:11:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DE8EC433EF for ; Thu, 30 Jun 2022 22:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbiF3WMC (ORCPT ); Thu, 30 Jun 2022 18:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbiF3WMB (ORCPT ); Thu, 30 Jun 2022 18:12:01 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01B2557221 for ; Thu, 30 Jun 2022 15:11:59 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id f8-20020a17090ac28800b001ed312c6fe1so348263pjt.8 for ; Thu, 30 Jun 2022 15:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Uc1wUpswlB7QI5C9LKGx9uW0ov7hkTrcI9ayvPeZMG8=; b=M3BalLDQE+9d8+AzTtW2WU2jmDsmMKo2J8TCjT9nUe/ow8GnUavcB7XKyeOsdrxEam /3NkhF62jJMdqwbFwhQ5tfPauUKa/2vWFWE1FvwTERsuyK68bMq+EBMpTtsjBVBAnLrY gw2GNOUKQtE6uXorG61y6Bgz2yu8IOnGTHbJonUCwMSS2E8jNxl6PIJzyaSQwYcP4un8 a1tCC+LQKHGf8rr1vh2vsJOf2hGD+QMWgvtx/AP426ULsLlR9ZocXyYAXMFIJC5p1r4S xIo7B5EtFdnXsv9TQMqvvgFbjcZBSvViuDEnWYwuxYN1BJreC5J811qRuzxBvgyCQQgI 3k/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Uc1wUpswlB7QI5C9LKGx9uW0ov7hkTrcI9ayvPeZMG8=; b=4NUF5rvEvL8SKKzK1F5JT0Op0XZ2NSI/EzcGxPVedJTM0snEK6l1qJnraPHbVtpe/V xNM/um3jSa7LsRV6/D9IZPUUX54mxrEkT+n0TKIIaFGcE9P3ttYsfMN5eHMpppp53Fdk S+NZJzEWMm56//mnM7SNd67zGXSsuPsHYUhAIl1XMOKSwzo6abbQshmXT4ZmT6xje6hv mJsQ6qyR9N3qALVixEEQPM+SGSkRRGCIux2Ofk16RP8BnKeMFj7kAZM2rkV9WmZfN+7x ejJiTfP66G7FY5A8ZY/0sXNZbJmKeWP1HYvoIr2ry7qlvgJphgt+6s0IDLX56ITJoWNI Ux4g== X-Gm-Message-State: AJIora/xY21OjMTYrqkdjb+Sc7LICPbtvp5MOE0aHY/O1MvodJ1Ufjpw R2n2pTqTKgvd8qf0wv9cQkmbS4LyL7Nt/1eW8fOt6TWrosxt6mLn3MZrV5oROQvBjJl2/TaVHgT nVjDsc8YvmOnZkZm0Miwy6eU6FmYaT7FhQKEIMbFcRoq/yuMzji61rXvfudZyTsM= X-Google-Smtp-Source: AGRyM1sBCrFa4EjQbMzmL2+VOGx/nSfrm8TiPXW6sO7FOtdq95yVamK6qdrPXXnXs1w/4ydO4im8Dyn5Py/JEA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:aa7:9206:0:b0:525:1068:c026 with SMTP id 6-20020aa79206000000b005251068c026mr18029809pfo.52.1656627119643; Thu, 30 Jun 2022 15:11:59 -0700 (PDT) Date: Thu, 30 Jun 2022 15:11:43 -0700 In-Reply-To: <20220630221147.45689-1-chooglen@google.com> Message-Id: <20220630221147.45689-3-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v3 2/6] submodule--helper: don't recreate recursive prefix From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org update_submodule() uses duplicated code to compute update_data->displaypath and next.recursive_prefix. The latter is just the former with "/" appended to it, and since update_data->displaypath not changed outside of this statement, we can just reuse the already computed result. We can go one step further and remove the reference to next.recursive_prefix altogether. Since it is only used in update_data_to_args() (to compute the "--recursive-prefix" flag for the recursive update child process) we can just use the already computed .displaypath value of there. Delete the duplicated code, and remove the unnecessary reference to next.recursive_prefix. As a bonus, this fixes a memory leak where prefixed_path was never freed (this leak was first reported in [1]). [1] https://lore.kernel.org/git/877a45867ae368bf9e053caedcb6cf421e02344d.1655336146.git.gitgitgadget@gmail.com Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index db2d5ab799..c104b1a023 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2418,9 +2418,9 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); strvec_pushf(args, "--jobs=%d", update_data->max_jobs); - if (update_data->recursive_prefix) - strvec_pushl(args, "--recursive-prefix", - update_data->recursive_prefix, NULL); + if (update_data->displaypath) + strvec_pushf(args, "--recursive-prefix=%s/", + update_data->displaypath); if (update_data->quiet) strvec_push(args, "--quiet"); if (update_data->force) @@ -2516,14 +2516,6 @@ static int update_submodule(struct update_data *update_data) struct update_data next = *update_data; int res; - if (update_data->recursive_prefix) - prefixed_path = xstrfmt("%s%s/", update_data->recursive_prefix, - update_data->sm_path); - else - prefixed_path = xstrfmt("%s/", update_data->sm_path); - - next.recursive_prefix = get_submodule_displaypath(prefixed_path, - update_data->prefix); next.prefix = NULL; oidcpy(&next.oid, null_oid()); oidcpy(&next.suboid, null_oid()); From patchwork Thu Jun 30 22:11:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F131EC43334 for ; Thu, 30 Jun 2022 22:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbiF3WMP (ORCPT ); Thu, 30 Jun 2022 18:12:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbiF3WMD (ORCPT ); Thu, 30 Jun 2022 18:12:03 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 983535721E for ; Thu, 30 Jun 2022 15:12:02 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id a19-20020a17090abe1300b001ecae1011fcso2009718pjs.0 for ; Thu, 30 Jun 2022 15:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7FPH+Z1TPp843C1JN+zunsLTn/GaqmHSFrL8aHYJeQU=; b=iWPIiztB/yN9gbEIozx1hy2OKNUVAKAu6Zry0TBxfNxH6X3KCKCfGtjN3jBQ9jmynR +Z0BfdNy1ViBY+38o6h5SygRTqg9yCAIIb2OS4sw9Po8SRphs0gkylyvIH/7Cx8WlD5o zJ8QqBozSSsC/xRiOsWPax6mCrVcp79XKPev5UE9creqxRGdlmLvwiROiZGcnyqEai4w 78TkQb73Fb/ZQFGj3IRbYt6442Z6D/3JnE2dBuxtfrFseE7aK3Bz+Udh7WhLld5n+Aji wEmapyI5Hxih9DlJq8N5nuEhpbbc5trpaJoqZDRh7wB/StU36t7vHuMN6HgN50jDJCa3 fEDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7FPH+Z1TPp843C1JN+zunsLTn/GaqmHSFrL8aHYJeQU=; b=tw691pPD2g64v0nTZcZXRfiSvGUU7Nuysgv1TwK987GWVoyPnNzxtztbTpL6ts/rBU Mrq4Yzaxmu+0UA36o+3+3t7Pi488LpiU9YhXZ80X7IjGWnnljFCfgazsztgMTDKgFX1i NPoeSo+I8uFxM5IDg2ALppZ4+aPgi0CLRd2VfmlCOu0COGUuvL7qtBQzVbardM+TpVld Ks3CrLbBAc2af6S2d02a8te/6srmc/ebzrA9Y0uU6zdkyAodZcGM+YSp5kvlIeRH67jU 0S2fWP8x5sYn6Q+r1pIfsr9qtT9fgeL4J2lZ05GpBgQuPzIgTczn/kCRINMoNTXjL01F KPRw== X-Gm-Message-State: AJIora9ikGAl6dRgQzlu15Kspj0FgCqWsasEAXKlcEM7n+nFKuDazezL yZtWFT82xmcxVexP1xz7yu9MWH1lGXdEBwTQCShrN6Ecuf+6uZDcK96NDo/ZZiIoKcF4mvVdUHY WuV5bZ7dXOzXc9YDkNSs2IQUEnsjp5NSD7GauOB3g7bQu66FY6+eS2Nep0ldO20g= X-Google-Smtp-Source: AGRyM1ugp8mTInRzTn89dTmLuO+3dPEEn+uE7zkBAuNm8DMHT06IPtyxIoA4yDNP1Fo9A1AagYYnKk13NH5T+g== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:4462:0:b0:40d:fb07:ec27 with SMTP id t34-20020a634462000000b0040dfb07ec27mr9160634pgk.346.1656627121643; Thu, 30 Jun 2022 15:12:01 -0700 (PDT) Date: Thu, 30 Jun 2022 15:11:44 -0700 In-Reply-To: <20220630221147.45689-1-chooglen@google.com> Message-Id: <20220630221147.45689-4-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v3 3/6] submodule--helper: use correct display path helper From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Replace a chunk of code in update_submodule() with an equivalent do_get_submodule_displaypath() invocation. This is already tested by t/t7406-submodule-update.sh:'submodule update --init --recursive from subdirectory', so no tests are added. The two are equivalent because: - Exactly one of recursive_prefix|prefix is non-NULL at a time; prefix is set at the superproject level, and recursive_prefix is set when recursing into submodules. There is also a BUG() statement in get_submodule_displaypath() that asserts that both cannot be non-NULL. - In get_submodule_displaypath(), get_super_prefix() always returns NULL because "--super-prefix" is never passed. Thus calling it is equivalent to calling do_get_submodule_displaypath() with super_prefix = NULL. Therefore: - When recursive_prefix is non-NULL, prefix is NULL, and thus get_submodule_displaypath() just returns prefixed_path. This is identical to calling do_get_submodule_displaypath() with super_prefix = recursive_prefix because the return value is still the concatenation of recursive_prefix + update_data->sm_path. - When prefix is non-NULL, prefixed_path = update_data->sm_path. Thus calling get_submodule_displaypath() with prefixed_path is equivalent to calling do_get_submodule_displaypath() with update_data->sm_path Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c104b1a023..aad431f898 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2464,19 +2464,11 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * static int update_submodule(struct update_data *update_data) { - char *prefixed_path; - ensure_core_worktree(update_data->sm_path); - if (update_data->recursive_prefix) - prefixed_path = xstrfmt("%s%s", update_data->recursive_prefix, - update_data->sm_path); - else - prefixed_path = xstrdup(update_data->sm_path); - - update_data->displaypath = get_submodule_displaypath(prefixed_path, - update_data->prefix); - free(prefixed_path); + update_data->displaypath = do_get_submodule_displaypath(update_data->sm_path, + update_data->prefix, + update_data->recursive_prefix); determine_submodule_update_strategy(the_repository, update_data->just_cloned, update_data->sm_path, update_data->update_default, From patchwork Thu Jun 30 22:11:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BB07C433EF for ; Thu, 30 Jun 2022 22:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbiF3WMR (ORCPT ); Thu, 30 Jun 2022 18:12:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbiF3WMO (ORCPT ); Thu, 30 Jun 2022 18:12:14 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 549F557229 for ; Thu, 30 Jun 2022 15:12:04 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id e18-20020a656492000000b003fa4033f9a7so260144pgv.17 for ; Thu, 30 Jun 2022 15:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=qsjN5JsYUk4jDp207ShRF9SzkxXAqzbyDp1tK0cnssk=; b=tjFB+5Q0jKDjHKRfKPn3bJ0jp8HiTI0bJcklKhqBJcsY7ecAKuDD9EB901OsYEz1Ss CNZFRX6G7hgLqJCfP7rrdvmEaDs8yf3gCh5Tb+gSWm3bUYmRlqzwxz29nbuLODdCtVui 4P+k3Hlc3w0r24rfv7Wv9lgpkh8pSEfQHsT5iFhu2ZK0ls2s0YKuQ/ObpN0hun1lMX73 jzzDHdc52DHiToTRfCjL9UHONIVrxqkwIyqtLPjLuR3D3cToHh952f6aBfygI0t0vNco ylA+w94BJCA2eM+V2FJU/64xQRNMuLJ4wQvJiwxY2PF8/jlCHzys2fR5VyWwxArZli7L ZQQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=qsjN5JsYUk4jDp207ShRF9SzkxXAqzbyDp1tK0cnssk=; b=E4ldWzNG2pVvkrzfaGOBz/4EAOSNzfNaJxtUTWiS3CyQWBQcgZMij+8pokQDctgl4q su/IscBoptkoML7DMTQG4hYpBYJ2Ajcge7NSs72E3LaorxxngoQZ6GTFE+pjkOs5onee iZGLGLhamabzUeC9Nq01XYGf9W0jIBPRi+tdl/1vHn6UqO3xXki1i14C1GIkF1xLPCFR i1a7q6gYOcxyq6bh5SY2EEJMvT876dkMigZ05GMBAAeELwZHMFswPqzEEc0LCMVYl25H h/On+ZxMo2mdOjVePHlKr1WH6tIRm72KpYhRELUUFMWcEv8/PPHQpNkp1qeDmoAXz6OV 6UGg== X-Gm-Message-State: AJIora/rmMCOqeTqWcWP7ICp9KzhZJyGRYjBkviOGIev+B7Afdx0F2mo D+eq0q6HY8O3q6ZGFiNLhIStyjb7ep/eo6Gi5Sum1T/VE1JxtuGP6Hl8ue8/eoYt+grkwksKP7Z 0Jgqsdy3gM4MwHSv/NrXlyHCD+2UXjVKfM9oExEd/7HuDeljFhhIjOzkBo9hXZVw= X-Google-Smtp-Source: AGRyM1uKS1w8kfVCqShiaSP7QXwDa3ZzJpRdc0DTkhvdUKOfRxxXruQdaCm8tW/liMueaLRIia3LaU7MqAogUw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:bf49:b0:168:d855:883b with SMTP id u9-20020a170902bf4900b00168d855883bmr17630919pls.79.1656627123712; Thu, 30 Jun 2022 15:12:03 -0700 (PDT) Date: Thu, 30 Jun 2022 15:11:45 -0700 In-Reply-To: <20220630221147.45689-1-chooglen@google.com> Message-Id: <20220630221147.45689-5-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v3 4/6] submodule--helper: remove unused SUPPORT_SUPER_PREFIX flags From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Remove the SUPPORT_SUPER_PREFIX flag from "add", "init" and "summary". For the "add" command it hasn't been used since [1], likewise for "init" and "summary" since [2] and [3], respectively. As implemented in 74866d75793 (git: make super-prefix option, 2016-10-07) the SUPPORT_SUPER_PREFIX flag in git.c applies for the entire command, but as implemented in 89c86265576 (submodule helper: support super prefix, 2016-12-08) we assert here in cmd_submodule__helper() that we're not getting the flag unexpectedly. 1. 8c8195e9c3e (submodule--helper: introduce add-clone subcommand, 2021-07-10) 2. 6e7c14e65c8 (submodule update --init: display correct path from submodule, 2017-01-06) 3. 1cf823d8f00 (submodule: remove unnecessary `prefix` based option logic, 2021-06-22) Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index aad431f898..360309195f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3379,15 +3379,15 @@ static struct cmd_struct commands[] = { {"list", module_list, 0}, {"name", module_name, 0}, {"clone", module_clone, 0}, - {"add", module_add, SUPPORT_SUPER_PREFIX}, + {"add", module_add, 0}, {"update", module_update, 0}, {"resolve-relative-url-test", resolve_relative_url_test, 0}, {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, - {"init", module_init, SUPPORT_SUPER_PREFIX}, + {"init", module_init, 0}, {"status", module_status, SUPPORT_SUPER_PREFIX}, {"sync", module_sync, SUPPORT_SUPER_PREFIX}, {"deinit", module_deinit, 0}, - {"summary", module_summary, SUPPORT_SUPER_PREFIX}, + {"summary", module_summary, 0}, {"push-check", push_check, 0}, {"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, {"is-active", is_active, 0}, From patchwork Thu Jun 30 22:11:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29DF0C433EF for ; Thu, 30 Jun 2022 22:12:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbiF3WMS (ORCPT ); Thu, 30 Jun 2022 18:12:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbiF3WMO (ORCPT ); Thu, 30 Jun 2022 18:12:14 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 482B55722C for ; Thu, 30 Jun 2022 15:12:06 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id b11-20020a17090a800b00b001ed433490b5so1983074pjn.8 for ; Thu, 30 Jun 2022 15:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=dmbphWow+fuMVC8dE0ZDP4DI6yK2ZDH6sb5Oh1qWwyk=; b=L6EsI4m3Xr+zPATfW27yIGM5+3cBSNFdIC3CWsxec9KEulVs9HmDkN6a6M+cQpzzve RsG/9tFKurQfafM/k3xmsljW25vIwgjRPFPeieDGJt6BifUztfCryvjpfn0m5qJvKKeu ZCX6QRqMwXtNPvkQ0mWgnS7Thx4/2xRJuGRz33jH3klFoaVWCYrE2niBXqgiDto/IEfk DkHPXYDhn39n04F7vUmACyEVIBkmUHNP943LgN+5iLaoX7CvXdG4fargJStb0Figmqdi AAcDvl3fbJiUAEXQL+o9oGWCx8XZWk2ZWQJBSBwGoMp060zIzM/XARULJZXLb1jMhtL8 uBRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dmbphWow+fuMVC8dE0ZDP4DI6yK2ZDH6sb5Oh1qWwyk=; b=bfQhVpBbpqYy5GtvBsAg7si/PaAGH4JhC+Auj36VfgTaprDAlC1+cuqlpm/uBE+ZY6 QKj+2qlj/uoFKtSne5lGOG6fHIpCbaMnqSOBSJ2o3UbBWegsmXoEJz4h3CgWIrGuWNiH rt4670Pd6tRLchNi6YZQB6cvUUEr4XYpuUOJvw70KCebhF5ohdtK8i0s80ZZhncZ0/pt T0R3JuudlCsGbysxQA9so5w//s44ZEiiZe77tI+hJo7mKvAbSe9IyVM5Ql7JK+NzULYi PKtqjaD4n4C04crh6snlWRXf0kpvZxzmwXVkVdmFi6ppFCgICAPqd9V4forwHcuSasgH yygQ== X-Gm-Message-State: AJIora8uG9LRYuQJRrl+HXnK+GNZYGcwX1PaBwBzZYkXLSLoOqpdGSxP Ju8N29C1QyFuvfaPiyrSKnKBpjg12HHL1c6zGkQblgHQHb0JjAp/an4Zi4WH/ypztl/A8i+NsId QNlq9IjZosEXwD34sC4XLqo6zzaeCVu7Lw5pX9dX3reEgW2k5X0dmdyPcEI528Ls= X-Google-Smtp-Source: AGRyM1t/nP1nekdofcgzfeh5UTYvlbe8CzPalxq84PBi5bKe31hzpI9lVFzP1yQmMxO+hZeeNc+n+RI2B8pJrA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:988a:b0:16a:7f1b:552 with SMTP id s10-20020a170902988a00b0016a7f1b0552mr16665136plp.60.1656627125702; Thu, 30 Jun 2022 15:12:05 -0700 (PDT) Date: Thu, 30 Jun 2022 15:11:46 -0700 In-Reply-To: <20220630221147.45689-1-chooglen@google.com> Message-Id: <20220630221147.45689-6-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v3 5/6] submodule--helper update: use --super-prefix From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Unlike the other subcommands, "git submodule--helper update" uses the "--recursive-prefix" flag instead of "--super-prefix". The two flags are otherwise identical (they only serve to compute the 'display path' of a submodule), except that there is a dedicated helper function to get the value of "--super-prefix". This inconsistency exists because "git submodule update" used to pass "--recursive-prefix" between shell and C (introduced in [1]) before "--super-prefix" was introduced (in [2]), and for simplicity, we kept this name when "git submodule--helper update" was created. Remove "--recursive-prefix" and its associated code from "git submodule--helper update", replacing it with "--super-prefix". To use "--super-prefix", module_update is marked with SUPPORT_SUPER_PREFIX. Note that module_clone must also be marked with SUPPORT_SUPER_PREFIX, otherwise the "git submodule--helper clone" subprocess will fail check because "--super-prefix" is propagated via the environment. [1] 48308681b0 (git submodule update: have a dedicated helper for cloning, 2016-02-29) [2] 74866d7579 (git: make super-prefix option, 2016-10-07) Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 360309195f..41177332dd 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -477,22 +477,18 @@ static int starts_with_dot_dot_slash(const char *const path) struct init_cb { const char *prefix; - const char *superprefix; unsigned int flags; }; #define INIT_CB_INIT { 0 } static void init_submodule(const char *path, const char *prefix, - const char *superprefix, unsigned int flags) + unsigned int flags) { const struct submodule *sub; struct strbuf sb = STRBUF_INIT; char *upd = NULL, *url = NULL, *displaypath; - /* try superprefix from the environment, if it is not passed explicitly */ - if (!superprefix) - superprefix = get_super_prefix(); - displaypath = do_get_submodule_displaypath(path, prefix, superprefix); + displaypath = do_get_submodule_displaypath(path, prefix, get_super_prefix()); sub = submodule_from_path(the_repository, null_oid(), path); @@ -566,7 +562,7 @@ static void init_submodule(const char *path, const char *prefix, static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data) { struct init_cb *info = cb_data; - init_submodule(list_item->name, info->prefix, info->superprefix, info->flags); + init_submodule(list_item->name, info->prefix, info->flags); } static int module_init(int argc, const char **argv, const char *prefix) @@ -1878,7 +1874,6 @@ struct submodule_update_clone { struct update_data { const char *prefix; - const char *recursive_prefix; const char *displaypath; enum submodule_update_type update_default; struct object_id suboid; @@ -1954,7 +1949,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, displaypath = do_get_submodule_displaypath(ce->name, suc->update_data->prefix, - suc->update_data->recursive_prefix); + get_super_prefix()); if (ce_stage(ce)) { strbuf_addf(out, _("Skipping unmerged submodule %s"), displaypath); @@ -2416,11 +2411,11 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * { enum submodule_update_type update_type = update_data->update_default; - strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); - strvec_pushf(args, "--jobs=%d", update_data->max_jobs); if (update_data->displaypath) - strvec_pushf(args, "--recursive-prefix=%s/", + strvec_pushf(args, "--super-prefix=%s/", update_data->displaypath); + strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); + strvec_pushf(args, "--jobs=%d", update_data->max_jobs); if (update_data->quiet) strvec_push(args, "--quiet"); if (update_data->force) @@ -2468,7 +2463,7 @@ static int update_submodule(struct update_data *update_data) update_data->displaypath = do_get_submodule_displaypath(update_data->sm_path, update_data->prefix, - update_data->recursive_prefix); + get_super_prefix()); determine_submodule_update_strategy(the_repository, update_data->just_cloned, update_data->sm_path, update_data->update_default, @@ -2592,10 +2587,6 @@ static int module_update(int argc, const char **argv, const char *prefix) OPT_STRING(0, "prefix", &opt.prefix, N_("path"), N_("path into the working tree")), - OPT_STRING(0, "recursive-prefix", &opt.recursive_prefix, - N_("path"), - N_("path into the working tree, across nested " - "submodule boundaries")), OPT_SET_INT(0, "checkout", &opt.update_default, N_("use the 'checkout' update strategy (default)"), SM_UPDATE_CHECKOUT), @@ -2681,7 +2672,6 @@ static int module_update(int argc, const char **argv, const char *prefix) module_list_active(&list); info.prefix = opt.prefix; - info.superprefix = opt.recursive_prefix; if (opt.quiet) info.flags |= OPT_QUIET; @@ -3378,9 +3368,9 @@ struct cmd_struct { static struct cmd_struct commands[] = { {"list", module_list, 0}, {"name", module_name, 0}, - {"clone", module_clone, 0}, + {"clone", module_clone, SUPPORT_SUPER_PREFIX}, {"add", module_add, 0}, - {"update", module_update, 0}, + {"update", module_update, SUPPORT_SUPER_PREFIX}, {"resolve-relative-url-test", resolve_relative_url_test, 0}, {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, {"init", module_init, 0}, From patchwork Thu Jun 30 22:11:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EE3BC43334 for ; Thu, 30 Jun 2022 22:12:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229813AbiF3WMV (ORCPT ); Thu, 30 Jun 2022 18:12:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230074AbiF3WMP (ORCPT ); Thu, 30 Jun 2022 18:12:15 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFC1A57237 for ; Thu, 30 Jun 2022 15:12:08 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3177608c4a5so5157967b3.14 for ; Thu, 30 Jun 2022 15:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=eBLyHJ7Vj4gMfX0LabfZAIoVNiAmswRt04r+Z0L2ESQ=; b=avjOCQ2RGH14gqVwM6pyzqUzTfUSrTmg2/04cEn+nMCTrMtyWAKzImx/RLMUE/Etij AwHvC78ctCAl//EK/g00RasLZ5Bn7xjE9D3z4UX8r5CxmjdYM+WXgqxSTUCkpD+gw0Tc u/kElIaOBzhU5jVjY8sTUK0KMWB4RVw4dQpMAyb/acpm0A/p4/sJ8YkaHPH3/BrWlh1Q 53QY0h1v8YIdupXC0iNR7jHeLGhRE/HzHwmiLkOnali5aX0QQOalXt2nYSSWgT0Uo8qE 0YJiBYAG6BG6VWOXl+GXKntu298dAgIekIyM7UyGN6FU9FG5wTvNDf15TeV5U9gPdA1h /0ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=eBLyHJ7Vj4gMfX0LabfZAIoVNiAmswRt04r+Z0L2ESQ=; b=YvXs/TgzxFxw+c2gZCGtA9cn4Y88O856L49fWhml7se6OyUqfEgdwiZagfWtQaWITW 63D7Na8jC9oFd4d0u6y3xkPfOiUNKK6TuZFdwreVIA6mc0RtS+QLe+dhUfUCtLgpUDwk 1HJKoGObWfx8yIB9DjZIVJpgyuWHtv3PL0umv3PrKtrPB/QBGIvjdbNDp4bw+GcMfGL7 J06K/c2Sst+Xgp4NfrtvWUiPO5WdtDspL9N5RoGoNhgfd+AMzIbcIHBt6+f6crtyfXCG m0kuwrEeiowNLWFOqmvd4wVTpvxY165wIvu3UOwa19Yy7OiGAkR1BjU9MyZjNmOMxZKK 5WOA== X-Gm-Message-State: AJIora8isqiADgPHZDF5IS3T7b8WTVxyoef/I2lR9iM0AkUQ9Znwqnr4 L3em7+dG4AHeduPOenj9j3ZfDGPMDtxfIMJRFdeJjlReTTD4uQWb5IofgcM+7ZxG9MjI38+O1ht qUljj73DPAfflpvBEARJUtpbb4TnAMG5F+ZkSTj5eFVKkTd4hlnXFAr0TqGwK2wE= X-Google-Smtp-Source: AGRyM1tsGT7uIzZ09nOcxi4X2gNON5GKmxy5SfOL9JDZc4rfGyO/8CmNx7j0bp6br0jCZPGQvZfspBeiLXp66g== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a81:8ce:0:b0:31c:49d1:1731 with SMTP id 197-20020a8108ce000000b0031c49d11731mr4855845ywi.376.1656627127564; Thu, 30 Jun 2022 15:12:07 -0700 (PDT) Date: Thu, 30 Jun 2022 15:11:47 -0700 In-Reply-To: <20220630221147.45689-1-chooglen@google.com> Message-Id: <20220630221147.45689-7-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v3 6/6] submodule--helper: remove display path helper From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org All invocations of do_get_submodule_displaypath() pass get_super_prefix() as the super_prefix arg, which is exactly the same as get_submodule_displaypath(). Replace all calls to do_get_submodule_displaypath() with get_submodule_displaypath(), and since it has no more callers, remove it. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 41177332dd..3e0ceb5258 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -118,10 +118,11 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr return 0; } -static char *do_get_submodule_displaypath(const char *path, - const char *prefix, - const char *super_prefix) +/* the result should be freed by the caller. */ +static char *get_submodule_displaypath(const char *path, const char *prefix) { + const char *super_prefix = get_super_prefix(); + if (prefix && super_prefix) { BUG("cannot have prefix '%s' and superprefix '%s'", prefix, super_prefix); @@ -137,13 +138,6 @@ static char *do_get_submodule_displaypath(const char *path, } } -/* the result should be freed by the caller. */ -static char *get_submodule_displaypath(const char *path, const char *prefix) -{ - const char *super_prefix = get_super_prefix(); - return do_get_submodule_displaypath(path, prefix, super_prefix); -} - static char *compute_rev_name(const char *sub_path, const char* object_id) { struct strbuf sb = STRBUF_INIT; @@ -488,7 +482,7 @@ static void init_submodule(const char *path, const char *prefix, struct strbuf sb = STRBUF_INIT; char *upd = NULL, *url = NULL, *displaypath; - displaypath = do_get_submodule_displaypath(path, prefix, get_super_prefix()); + displaypath = get_submodule_displaypath(path, prefix); sub = submodule_from_path(the_repository, null_oid(), path); @@ -1947,9 +1941,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, int needs_cloning = 0; int need_free_url = 0; - displaypath = do_get_submodule_displaypath(ce->name, - suc->update_data->prefix, - get_super_prefix()); + displaypath = + get_submodule_displaypath(ce->name, suc->update_data->prefix); if (ce_stage(ce)) { strbuf_addf(out, _("Skipping unmerged submodule %s"), displaypath); @@ -2461,9 +2454,8 @@ static int update_submodule(struct update_data *update_data) { ensure_core_worktree(update_data->sm_path); - update_data->displaypath = do_get_submodule_displaypath(update_data->sm_path, - update_data->prefix, - get_super_prefix()); + update_data->displaypath = get_submodule_displaypath( + update_data->sm_path, update_data->prefix); determine_submodule_update_strategy(the_repository, update_data->just_cloned, update_data->sm_path, update_data->update_default,