From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 1D55520323 for ; Thu, 16 Mar 2017 22:36:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754051AbdCPWgy (ORCPT ); Thu, 16 Mar 2017 18:36:54 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36084 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751801AbdCPWgw (ORCPT ); Thu, 16 Mar 2017 18:36:52 -0400 Received: by mail-pf0-f170.google.com with SMTP id o126so30676529pfb.3 for ; Thu, 16 Mar 2017 15:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U9gFfLETkSBc1uN8M4mjM4XhOQM9UZLctSvyNAVrdMM=; b=fJULJvywEBU1iHL5AuJWvDW9qbJ+dKt9Xw+/gUEos0TUO1Z3YykibA+lIBn2j0VFQl LyFy9pfsQBK2NUcPJUsKu2GG9M+c5ZQ4r4/5fe7FWCQPSfcxlt1F7boJN28CmV6U74k3 /k2jUxK/DpB7hxKU054zvnir7dUI3IR2knmFjvefluTUs4gIPQRP00Cnu5rIiWoVa2QF a9sZ20ewPKxnj5nDzBPJGvE3+JolXDgk7iRRa9TtGF7yoIZF6FfblV88CLtZNwLOUdaY GlDnCcqRWAE44OJu3bEmoyoPxlgZ43+Nf4qbv7A3XlWOuNUHBrVGpsp8f/fNPmIuGEAy LR2Q== 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; bh=U9gFfLETkSBc1uN8M4mjM4XhOQM9UZLctSvyNAVrdMM=; b=GHC3Ikp/BEA5YIosrhayEc/uOFbq+6iqb+Bcg60IkJaCeTP6PR7k+2gA4+K2COxtFy YlSvyvRhKpcQNUCQx3siAqxtsVc+a3Vux58/1mQtnR+3Awcu+b/XT7Bckb4vIRuAXfb0 vvgR6VXtRHSMWFZBpfQdOZo91GTvuTfBMHiUth6l+6bqFXSq6yLxjqRzGzQLLKI1oqAz vq7DNmR31t0S41u4xzz6Lu0MkmXHXA/F8CgUMyxairJvm+7+a/fO8B0a9Dfd3N6AXj7R 5NrH177JrRzxHK5UA6TaoarybTzlXYr7ZGaAqEsyAsER7Ql5D1LQ5dXib5qZkHGCBub1 5kYA== X-Gm-Message-State: AFeK/H2tedxkzVfB+XmVxFXeq59Pcb3x1Hq3khejYfdfVj8wB0WqLtTE9Zb6P2E9/8Gc8nGU X-Received: by 10.84.233.134 with SMTP id l6mr15393497plk.49.1489703407633; Thu, 16 Mar 2017 15:30:07 -0700 (PDT) Received: from roshar.mtv.corp.google.com ([100.96.238.26]) by smtp.gmail.com with ESMTPSA id t5sm12520946pgb.36.2017.03.16.15.30.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Mar 2017 15:30:06 -0700 (PDT) From: Brandon Williams To: git@vger.kernel.org Cc: Brandon Williams , sbeller@google.com, gitster@pobox.com Subject: [PATCH v4 06/10] submodule: decouple url and submodule interest Date: Thu, 16 Mar 2017 15:29:48 -0700 Message-Id: <20170316222952.53801-7-bmwill@google.com> X-Mailer: git-send-email 2.12.0.367.g23dc2f6d3c-goog In-Reply-To: <20170316222952.53801-1-bmwill@google.com> References: <20170313214341.172676-1-bmwill@google.com> <20170316222952.53801-1-bmwill@google.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Currently the submodule..url config option is used to determine if a given submodule is of interest to the user. This ends up being cumbersome in a world where we want to have different submodules checked out in different worktrees or a more generalized mechanism to select which submodules are of interest. In a future with worktree support for submodules, there will be multiple working trees, each of which may only need a subset of the submodules checked out. The URL (which is where the submodule repository can be obtained) should not differ between different working trees. It may also be convenient for users to more easily specify groups of submodules they are interested in as apposed to running "git submodule init " on each submodule they want checked out in their working tree. To this end two config options are introduced, submodule.active and submodule..active. The submodule.active config holds a pathspec that specifies which submodules should exist in the working tree. The submodule..active config is a boolean flag used to indicate if that particular submodule should exist in the working tree. Its important to note that submodule.active functions differently than the other configuration options since it takes a pathspec. This allows users to adopt at least two new workflows: 1. Submodules can be grouped with a leading directory, such that a pathspec e.g. 'lib/' would cover all library-ish modules to allow those who are interested in library-ish modules to set "submodule.active = lib/" just once to say any and all modules in 'lib/' are interesting. 2. Once the pathspec-attribute feature is invented, users can label submodules with attributes to group them, so that a broad pathspec with attribute requirements, e.g. ':(attr:lib)', can be used to say any and all modules with the 'lib' attribute are interesting. Since the .gitattributes file, just like the .gitmodules file, is tracked by the superproject, when a submodule moves in the superproject tree, the project can adjust which path gets the attribute in .gitattributes, just like it can adjust which path has the submodule in .gitmodules. Neither of these two additional configuration options solve the problem of wanting different submodules checked out in different worktrees because multiple worktrees share .git/config. Only once per-worktree configurations become a reality can this be solved, but this is a necessary preparatory step for that future. Given these multiple ways to check if a submodule is of interest, the more fine-grained submodule..active option has the highest order of precedence followed by the pathspec check against submodule.active. To ensure backwards compatibility, if neither of these options are set, git falls back to checking the submodule..url option to determine if a submodule is interesting. Signed-off-by: Brandon Williams --- Documentation/config.txt | 15 ++++++++++-- submodule.c | 50 ++++++++++++++++++++++++++++++++------ t/t7413-submodule-is-active.sh | 55 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 10 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 5e5c2ae5f..d2d79b9d4 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -2920,8 +2920,9 @@ submodule..url:: The URL for a submodule. This variable is copied from the .gitmodules file to the git config via 'git submodule init'. The user can change the configured URL before obtaining the submodule via 'git submodule - update'. After obtaining the submodule, the presence of this variable - is used as a sign whether the submodule is of interest to git commands. + update'. If neither submodule..active or submodule.active are + set, the presence of this variable is used as a fallback to indicate + whether the submodule is of interest to git commands. See linkgit:git-submodule[1] and linkgit:gitmodules[5] for details. submodule..update:: @@ -2959,6 +2960,16 @@ submodule..ignore:: "--ignore-submodules" option. The 'git submodule' commands are not affected by this setting. +submodule..active:: + Boolean value indicating if the submodule is of interest to git + commands. This config option takes precedence over the + submodule.active config option. + +submodule.active:: + A repeated field which contains a pathspec used to match against a + submodule's path to determine if the submodule is of interest to git + commands. + submodule.fetchJobs:: Specifies how many submodules are fetched/cloned at the same time. A positive integer allows up to that number of submodules fetched diff --git a/submodule.c b/submodule.c index 0a2831d84..ad2779ee7 100644 --- a/submodule.c +++ b/submodule.c @@ -212,25 +212,59 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1) } /* + * NEEDSWORK: With the addition of different configuration options to determine + * if a submodule is of interests, the validity of this function's name comes + * into question. Once the dust has settled and more concrete terminology is + * decided upon, come up with a more proper name for this function. One + * potential candidate could be 'is_submodule_active()'. + * * Determine if a submodule has been initialized at a given 'path' */ int is_submodule_initialized(const char *path) { int ret = 0; - const struct submodule *module = NULL; + char *key = NULL; + char *value = NULL; + const struct string_list *sl; + const struct submodule *module = submodule_from_path(null_sha1, path); - module = submodule_from_path(null_sha1, path); + /* early return if there isn't a path->module mapping */ + if (!module) + return 0; - if (module) { - char *key = xstrfmt("submodule.%s.url", module->name); - char *value = NULL; + /* submodule..active is set */ + key = xstrfmt("submodule.%s.active", module->name); + if (!git_config_get_bool(key, &ret)) { + free(key); + return ret; + } + free(key); - ret = !git_config_get_string(key, &value); + /* submodule.active is set */ + sl = git_config_get_value_multi("submodule.active"); + if (sl) { + struct pathspec ps; + struct argv_array args = ARGV_ARRAY_INIT; + const struct string_list_item *item; - free(value); - free(key); + for_each_string_list_item(item, sl) { + argv_array_push(&args, item->string); + } + + parse_pathspec(&ps, 0, 0, NULL, args.argv); + ret = match_pathspec(&ps, path, strlen(path), 0, NULL, 1); + + argv_array_clear(&args); + clear_pathspec(&ps); + return ret; } + /* fallback to checking if the URL is set */ + key = xstrfmt("submodule.%s.url", module->name); + ret = !git_config_get_string(key, &value); + + free(value); + free(key); return ret; } diff --git a/t/t7413-submodule-is-active.sh b/t/t7413-submodule-is-active.sh index f18e0c925..ea1644b58 100755 --- a/t/t7413-submodule-is-active.sh +++ b/t/t7413-submodule-is-active.sh @@ -28,4 +28,59 @@ test_expect_success 'is-active works with urls' ' git -C super submodule--helper is-active sub1 ' +test_expect_success 'is-active works with submodule..active config' ' + test_when_finished "git -C super config --unset submodule.sub1.active" && + test_when_finished "git -C super config submodule.sub1.URL ../sub" && + + git -C super config --bool submodule.sub1.active "false" && + test_must_fail git -C super submodule--helper is-active sub1 && + + git -C super config --bool submodule.sub1.active "true" && + git -C super config --unset submodule.sub1.URL && + git -C super submodule--helper is-active sub1 +' + +test_expect_success 'is-active works with basic submodule.active config' ' + test_when_finished "git -C super config submodule.sub1.URL ../sub" && + test_when_finished "git -C super config --unset-all submodule.active" && + + git -C super config --add submodule.active "." && + git -C super config --unset submodule.sub1.URL && + + git -C super submodule--helper is-active sub1 && + git -C super submodule--helper is-active sub2 +' + +test_expect_success 'is-active correctly works with paths that are not submodules' ' + test_when_finished "git -C super config --unset-all submodule.active" && + + test_must_fail git -C super submodule--helper is-active not-a-submodule && + + git -C super config --add submodule.active "." && + test_must_fail git -C super submodule--helper is-active not-a-submodule +' + +test_expect_success 'is-active works with exclusions in submodule.active config' ' + test_when_finished "git -C super config --unset-all submodule.active" && + + git -C super config --add submodule.active "." && + git -C super config --add submodule.active ":(exclude)sub1" && + + test_must_fail git -C super submodule--helper is-active sub1 && + git -C super submodule--helper is-active sub2 +' + +test_expect_success 'is-active with submodule.active and submodule..active' ' + test_when_finished "git -C super config --unset-all submodule.active" && + test_when_finished "git -C super config --unset submodule.sub1.active" && + test_when_finished "git -C super config --unset submodule.sub2.active" && + + git -C super config --add submodule.active "sub1" && + git -C super config --bool submodule.sub1.active "false" && + git -C super config --bool submodule.sub2.active "true" && + + test_must_fail git -C super submodule--helper is-active sub1 && + git -C super submodule--helper is-active sub2 +' + test_done -- 2.12.0.367.g23dc2f6d3c-goog