2022-11-19 13:07:38 +00:00
|
|
|
#define USE_THE_INDEX_VARIABLE
|
2015-09-02 21:42:24 +00:00
|
|
|
#include "builtin.h"
|
2023-02-24 00:09:24 +00:00
|
|
|
#include "alloc.h"
|
2023-02-24 00:09:27 +00:00
|
|
|
#include "hex.h"
|
2017-06-22 18:43:46 +00:00
|
|
|
#include "repository.h"
|
2015-09-02 21:42:24 +00:00
|
|
|
#include "cache.h"
|
2017-06-14 18:07:36 +00:00
|
|
|
#include "config.h"
|
2015-09-02 21:42:24 +00:00
|
|
|
#include "parse-options.h"
|
|
|
|
#include "quote.h"
|
|
|
|
#include "pathspec.h"
|
|
|
|
#include "dir.h"
|
2015-09-02 21:42:25 +00:00
|
|
|
#include "submodule.h"
|
|
|
|
#include "submodule-config.h"
|
|
|
|
#include "string-list.h"
|
2015-09-08 18:57:45 +00:00
|
|
|
#include "run-command.h"
|
2016-04-16 00:50:12 +00:00
|
|
|
#include "remote.h"
|
|
|
|
#include "refs.h"
|
2018-05-16 22:57:48 +00:00
|
|
|
#include "refspec.h"
|
2016-04-16 00:50:12 +00:00
|
|
|
#include "connect.h"
|
2017-10-06 13:24:15 +00:00
|
|
|
#include "revision.h"
|
|
|
|
#include "diffcore.h"
|
|
|
|
#include "diff.h"
|
2018-03-23 17:20:56 +00:00
|
|
|
#include "object-store.h"
|
2019-12-02 19:57:52 +00:00
|
|
|
#include "advice.h"
|
branch: add --recurse-submodules option for branch creation
To improve the submodules UX, we would like to teach Git to handle
branches in submodules. Start this process by teaching "git branch" the
--recurse-submodules option so that "git branch --recurse-submodules
topic" will create the `topic` branch in the superproject and its
submodules.
Although this commit does not introduce breaking changes, it does not
work well with existing --recurse-submodules commands because "git
branch --recurse-submodules" writes to the submodule ref store, but most
commands only consider the superproject gitlink and ignore the submodule
ref store. For example, "git checkout --recurse-submodules" will check
out the commits in the superproject gitlinks (and put the submodules in
detached HEAD) instead of checking out the submodule branches.
Because of this, this commit introduces a new configuration value,
`submodule.propagateBranches`. The plan is for Git commands to
prioritize submodule ref store information over superproject gitlinks if
this value is true. Because "git branch --recurse-submodules" writes to
submodule ref stores, for the sake of clarity, it will not function
unless this configuration value is set.
This commit also includes changes that support working with submodules
from a superproject commit because "branch --recurse-submodules" (and
future commands) need to read .gitmodules and gitlinks from the
superproject commit, but submodules are typically read from the
filesystem's .gitmodules and the index's gitlinks. These changes are:
* add a submodules_of_tree() helper that gives the relevant
information of an in-tree submodule (e.g. path and oid) and
initializes the repository
* add is_tree_submodule_active() by adding a treeish_name parameter to
is_submodule_active()
* add the "submoduleNotUpdated" advice to advise users to update the
submodules in their trees
Incidentally, fix an incorrect usage string that combined the 'list'
usage of git branch (-l) with the 'create' usage; this string has been
incorrect since its inception, a8dfd5eac4 (Make builtin-branch.c use
parse_options., 2007-10-07).
Helped-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-29 00:04:45 +00:00
|
|
|
#include "branch.h"
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
#include "list-objects-filter-options.h"
|
2016-04-16 00:50:12 +00:00
|
|
|
|
2017-10-06 13:24:14 +00:00
|
|
|
#define OPT_QUIET (1 << 0)
|
2017-10-06 13:24:15 +00:00
|
|
|
#define OPT_CACHED (1 << 1)
|
|
|
|
#define OPT_RECURSIVE (1 << 2)
|
2018-01-14 21:15:29 +00:00
|
|
|
#define OPT_FORCE (1 << 3)
|
2017-10-06 13:24:14 +00:00
|
|
|
|
|
|
|
typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
|
|
|
|
void *cb_data);
|
2016-04-16 00:50:12 +00:00
|
|
|
|
2022-08-31 23:18:13 +00:00
|
|
|
static int repo_get_default_remote(struct repository *repo, char **default_remote)
|
2016-04-16 00:50:12 +00:00
|
|
|
{
|
2022-08-31 23:18:13 +00:00
|
|
|
char *dest = NULL;
|
2016-04-16 00:50:12 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2022-03-05 00:13:53 +00:00
|
|
|
struct ref_store *store = get_main_ref_store(repo);
|
|
|
|
const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL,
|
|
|
|
NULL);
|
2016-04-16 00:50:12 +00:00
|
|
|
|
|
|
|
if (!refname)
|
2022-08-31 23:18:13 +00:00
|
|
|
return die_message(_("No such ref: %s"), "HEAD");
|
2016-04-16 00:50:12 +00:00
|
|
|
|
|
|
|
/* detached HEAD */
|
2022-08-31 23:18:13 +00:00
|
|
|
if (!strcmp(refname, "HEAD")) {
|
|
|
|
*default_remote = xstrdup("origin");
|
|
|
|
return 0;
|
|
|
|
}
|
2016-04-16 00:50:12 +00:00
|
|
|
|
|
|
|
if (!skip_prefix(refname, "refs/heads/", &refname))
|
2022-08-31 23:18:13 +00:00
|
|
|
return die_message(_("Expecting a full ref name, got %s"),
|
|
|
|
refname);
|
2016-04-16 00:50:12 +00:00
|
|
|
|
|
|
|
strbuf_addf(&sb, "branch.%s.remote", refname);
|
2022-03-05 00:13:53 +00:00
|
|
|
if (repo_config_get_string(repo, sb.buf, &dest))
|
2022-08-31 23:18:13 +00:00
|
|
|
*default_remote = xstrdup("origin");
|
2016-04-16 00:50:12 +00:00
|
|
|
else
|
2022-08-31 23:18:13 +00:00
|
|
|
*default_remote = dest;
|
2016-04-16 00:50:12 +00:00
|
|
|
|
|
|
|
strbuf_release(&sb);
|
2022-08-31 23:18:13 +00:00
|
|
|
return 0;
|
2016-04-16 00:50:12 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 23:18:13 +00:00
|
|
|
static int get_default_remote_submodule(const char *module_path, char **default_remote)
|
2018-01-14 21:15:28 +00:00
|
|
|
{
|
2022-03-05 00:13:53 +00:00
|
|
|
struct repository subrepo;
|
2022-08-31 23:14:17 +00:00
|
|
|
int ret;
|
2018-01-14 21:15:28 +00:00
|
|
|
|
2022-08-31 23:18:12 +00:00
|
|
|
if (repo_submodule_init(&subrepo, the_repository, module_path,
|
|
|
|
null_oid()) < 0)
|
2022-08-31 23:18:13 +00:00
|
|
|
return die_message(_("could not get a repository handle for submodule '%s'"),
|
|
|
|
module_path);
|
2022-08-31 23:14:17 +00:00
|
|
|
ret = repo_get_default_remote(&subrepo, default_remote);
|
|
|
|
repo_clear(&subrepo);
|
|
|
|
|
|
|
|
return ret;
|
2022-03-05 00:13:53 +00:00
|
|
|
}
|
2018-01-14 21:15:28 +00:00
|
|
|
|
2022-03-05 00:13:53 +00:00
|
|
|
static char *get_default_remote(void)
|
|
|
|
{
|
2022-08-31 23:18:13 +00:00
|
|
|
char *default_remote;
|
|
|
|
int code = repo_get_default_remote(the_repository, &default_remote);
|
|
|
|
|
|
|
|
if (code)
|
|
|
|
exit(code);
|
|
|
|
|
|
|
|
return default_remote;
|
2018-01-14 21:15:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:46:41 +00:00
|
|
|
static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)
|
2016-04-16 00:50:12 +00:00
|
|
|
{
|
2021-08-10 11:46:34 +00:00
|
|
|
char *remoteurl, *resolved_url;
|
2016-04-16 00:50:12 +00:00
|
|
|
char *remote = get_default_remote();
|
2021-08-10 11:46:34 +00:00
|
|
|
struct strbuf remotesb = STRBUF_INIT;
|
2016-04-16 00:50:12 +00:00
|
|
|
|
2021-08-10 11:46:34 +00:00
|
|
|
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);
|
2016-04-16 00:50:12 +00:00
|
|
|
remoteurl = xgetcwd();
|
2021-08-10 11:46:34 +00:00
|
|
|
}
|
|
|
|
resolved_url = relative_url(remoteurl, rel_url, up_path);
|
2016-04-16 00:50:12 +00:00
|
|
|
|
2021-08-10 11:46:34 +00:00
|
|
|
free(remote);
|
2016-04-16 00:50:12 +00:00
|
|
|
free(remoteurl);
|
2021-08-10 11:46:34 +00:00
|
|
|
strbuf_release(&remotesb);
|
|
|
|
|
|
|
|
return resolved_url;
|
2016-04-16 00:50:12 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 02:11:57 +00:00
|
|
|
/* the result should be freed by the caller. */
|
2022-12-20 12:39:50 +00:00
|
|
|
static char *get_submodule_displaypath(const char *path, const char *prefix,
|
|
|
|
const char *super_prefix)
|
2017-09-29 09:44:51 +00:00
|
|
|
{
|
|
|
|
if (prefix && super_prefix) {
|
|
|
|
BUG("cannot have prefix '%s' and superprefix '%s'",
|
|
|
|
prefix, super_prefix);
|
|
|
|
} else if (prefix) {
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
char *displaypath = xstrdup(relative_path(path, prefix, &sb));
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return displaypath;
|
|
|
|
} else if (super_prefix) {
|
|
|
|
return xstrfmt("%s%s", super_prefix, path);
|
|
|
|
} else {
|
|
|
|
return xstrdup(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 13:24:15 +00:00
|
|
|
static char *compute_rev_name(const char *sub_path, const char* object_id)
|
|
|
|
{
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
const char ***d;
|
|
|
|
|
|
|
|
static const char *describe_bare[] = { NULL };
|
|
|
|
|
|
|
|
static const char *describe_tags[] = { "--tags", NULL };
|
|
|
|
|
|
|
|
static const char *describe_contains[] = { "--contains", NULL };
|
|
|
|
|
|
|
|
static const char *describe_all_always[] = { "--all", "--always", NULL };
|
|
|
|
|
|
|
|
static const char **describe_argv[] = { describe_bare, describe_tags,
|
|
|
|
describe_contains,
|
|
|
|
describe_all_always, NULL };
|
|
|
|
|
|
|
|
for (d = describe_argv; *d; d++) {
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp.env);
|
2017-10-06 13:24:15 +00:00
|
|
|
cp.dir = sub_path;
|
|
|
|
cp.git_cmd = 1;
|
|
|
|
cp.no_stderr = 1;
|
|
|
|
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&cp.args, "describe");
|
|
|
|
strvec_pushv(&cp.args, *d);
|
|
|
|
strvec_push(&cp.args, object_id);
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
if (!capture_command(&cp, &sb, 0)) {
|
|
|
|
strbuf_strip_suffix(&sb, "\n");
|
|
|
|
return strbuf_detach(&sb, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-02 21:42:24 +00:00
|
|
|
struct module_list {
|
|
|
|
const struct cache_entry **entries;
|
|
|
|
int alloc, nr;
|
|
|
|
};
|
2021-09-27 12:54:25 +00:00
|
|
|
#define MODULE_LIST_INIT { 0 }
|
2015-09-02 21:42:24 +00:00
|
|
|
|
2022-08-31 23:14:13 +00:00
|
|
|
static void module_list_release(struct module_list *ml)
|
|
|
|
{
|
|
|
|
free(ml->entries);
|
|
|
|
}
|
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
static int module_list_compute(const char **argv,
|
2015-09-02 21:42:24 +00:00
|
|
|
const char *prefix,
|
|
|
|
struct pathspec *pathspec,
|
|
|
|
struct module_list *list)
|
|
|
|
{
|
|
|
|
int i, result = 0;
|
2016-02-24 21:15:02 +00:00
|
|
|
char *ps_matched = NULL;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2015-09-02 21:42:24 +00:00
|
|
|
parse_pathspec(pathspec, 0,
|
2017-05-11 22:04:26 +00:00
|
|
|
PATHSPEC_PREFER_FULL,
|
2015-09-02 21:42:24 +00:00
|
|
|
prefix, argv);
|
|
|
|
|
|
|
|
if (pathspec->nr)
|
|
|
|
ps_matched = xcalloc(pathspec->nr, 1);
|
|
|
|
|
2022-11-19 13:07:38 +00:00
|
|
|
if (repo_read_index(the_repository) < 0)
|
2015-09-02 21:42:24 +00:00
|
|
|
die(_("index file corrupt"));
|
|
|
|
|
2022-11-19 13:07:34 +00:00
|
|
|
for (i = 0; i < the_index.cache_nr; i++) {
|
|
|
|
const struct cache_entry *ce = the_index.cache[i];
|
2015-09-02 21:42:24 +00:00
|
|
|
|
2018-08-13 16:14:22 +00:00
|
|
|
if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),
|
submodule: fix regression for deinit without submodules
Per Cederqvist wrote:
> It used to be possible to run
>
> git submodule deinit -f .
>
> to remove any submodules, no matter how many submodules you had. That
> is no longer possible in projects that don't have any submodules at
> all. The command will fail with:
>
> error: pathspec '.' did not match any file(s) known to git.
This regression was introduced in 74703a1e4dfc (submodule: rewrite
`module_list` shell function in C, 2015-09-02), as we changed the
order of checking in new module listing to first check whether it is
a gitlin before feeding it to match_pathspec(). It used to be that
a pathspec that does not match any path were diagnosed as an error,
but the new code complains for a pathspec that does not match any
submodule path.
Arguably the new behaviour may give us a better diagnosis, but that
is inconsistent with the suggestion "deinit" gives, and also this
was an unintended accident. The new behaviour hopefully can be
redesigned and implemented better in future releases, but for now,
switch these two checks to restore the same behavior as before. In
an empty repository, giving the pathspec '.' will still get the same
"did not match" error, but that is the same bug we had before 1.7.0.
Reported-by: Per Cederqvist <cederp@opera.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-03-22 23:42:14 +00:00
|
|
|
0, ps_matched, 1) ||
|
|
|
|
!S_ISGITLINK(ce->ce_mode))
|
2015-09-02 21:42:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
|
|
|
|
list->entries[list->nr++] = ce;
|
2022-11-19 13:07:34 +00:00
|
|
|
while (i + 1 < the_index.cache_nr &&
|
|
|
|
!strcmp(ce->name, the_index.cache[i + 1]->name))
|
2015-09-02 21:42:24 +00:00
|
|
|
/*
|
|
|
|
* Skip entries with the same name in different stages
|
|
|
|
* to make sure an entry is returned only once.
|
|
|
|
*/
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2019-03-20 08:15:48 +00:00
|
|
|
if (ps_matched && report_path_error(ps_matched, pathspec))
|
2015-09-02 21:42:24 +00:00
|
|
|
result = -1;
|
|
|
|
|
|
|
|
free(ps_matched);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-03-17 22:38:02 +00:00
|
|
|
static void module_list_active(struct module_list *list)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct module_list active_modules = MODULE_LIST_INIT;
|
|
|
|
|
|
|
|
for (i = 0; i < list->nr; i++) {
|
|
|
|
const struct cache_entry *ce = list->entries[i];
|
|
|
|
|
2017-06-22 18:43:46 +00:00
|
|
|
if (!is_submodule_active(the_repository, ce->name))
|
2017-03-17 22:38:02 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ALLOC_GROW(active_modules.entries,
|
|
|
|
active_modules.nr + 1,
|
|
|
|
active_modules.alloc);
|
|
|
|
active_modules.entries[active_modules.nr++] = ce;
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(list);
|
2017-03-17 22:38:02 +00:00
|
|
|
*list = active_modules;
|
|
|
|
}
|
|
|
|
|
2018-01-14 21:15:28 +00:00
|
|
|
static char *get_up_path(const char *path)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
|
|
|
for (i = count_slashes(path); i; i--)
|
|
|
|
strbuf_addstr(&sb, "../");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if 'path' ends with slash or not
|
|
|
|
* for having the same output for dir/sub_dir
|
|
|
|
* and dir/sub_dir/
|
|
|
|
*/
|
|
|
|
if (!is_dir_sep(path[strlen(path) - 1]))
|
|
|
|
strbuf_addstr(&sb, "../");
|
|
|
|
|
|
|
|
return strbuf_detach(&sb, NULL);
|
|
|
|
}
|
|
|
|
|
2017-10-06 13:24:14 +00:00
|
|
|
static void for_each_listed_submodule(const struct module_list *list,
|
|
|
|
each_submodule_fn fn, void *cb_data)
|
|
|
|
{
|
|
|
|
int i;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2017-10-06 13:24:14 +00:00
|
|
|
for (i = 0; i < list->nr; i++)
|
|
|
|
fn(list->entries[i], cb_data);
|
|
|
|
}
|
|
|
|
|
2020-03-18 14:20:24 +00:00
|
|
|
struct foreach_cb {
|
2018-05-10 21:25:01 +00:00
|
|
|
int argc;
|
|
|
|
const char **argv;
|
|
|
|
const char *prefix;
|
2022-12-20 12:39:52 +00:00
|
|
|
const char *super_prefix;
|
2018-05-10 21:25:01 +00:00
|
|
|
int quiet;
|
|
|
|
int recursive;
|
|
|
|
};
|
2020-03-18 14:20:24 +00:00
|
|
|
#define FOREACH_CB_INIT { 0 }
|
2018-05-10 21:25:01 +00:00
|
|
|
|
|
|
|
static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
|
|
|
|
void *cb_data)
|
|
|
|
{
|
2020-03-18 14:20:24 +00:00
|
|
|
struct foreach_cb *info = cb_data;
|
2018-05-10 21:25:01 +00:00
|
|
|
const char *path = list_item->name;
|
|
|
|
const struct object_id *ce_oid = &list_item->oid;
|
|
|
|
const struct submodule *sub;
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
char *displaypath;
|
|
|
|
|
2022-12-20 12:39:50 +00:00
|
|
|
displaypath = get_submodule_displaypath(path, info->prefix,
|
2022-12-20 12:39:52 +00:00
|
|
|
info->super_prefix);
|
2018-05-10 21:25:01 +00:00
|
|
|
|
2021-04-26 01:02:56 +00:00
|
|
|
sub = submodule_from_path(the_repository, null_oid(), path);
|
2018-05-10 21:25:01 +00:00
|
|
|
|
|
|
|
if (!sub)
|
|
|
|
die(_("No url found for submodule path '%s' in .gitmodules"),
|
|
|
|
displaypath);
|
|
|
|
|
|
|
|
if (!is_submodule_populated_gently(path, NULL))
|
|
|
|
goto cleanup;
|
|
|
|
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp.env);
|
2018-05-10 21:25:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For the purpose of executing <command> in the submodule,
|
|
|
|
* separate shell is used for the purpose of running the
|
|
|
|
* child process.
|
|
|
|
*/
|
|
|
|
cp.use_shell = 1;
|
|
|
|
cp.dir = path;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NEEDSWORK: the command currently has access to the variables $name,
|
|
|
|
* $sm_path, $displaypath, $sha1 and $toplevel only when the command
|
|
|
|
* contains a single argument. This is done for maintaining a faithful
|
|
|
|
* translation from shell script.
|
|
|
|
*/
|
|
|
|
if (info->argc == 1) {
|
|
|
|
char *toplevel = xgetcwd();
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
2022-06-02 09:09:50 +00:00
|
|
|
strvec_pushf(&cp.env, "name=%s", sub->name);
|
|
|
|
strvec_pushf(&cp.env, "sm_path=%s", path);
|
|
|
|
strvec_pushf(&cp.env, "displaypath=%s", displaypath);
|
|
|
|
strvec_pushf(&cp.env, "sha1=%s",
|
strvec: fix indentation in renamed calls
Code which split an argv_array call across multiple lines, like:
argv_array_pushl(&args, "one argument",
"another argument", "and more",
NULL);
was recently mechanically renamed to use strvec, which results in
mis-matched indentation like:
strvec_pushl(&args, "one argument",
"another argument", "and more",
NULL);
Let's fix these up to align the arguments with the opening paren. I did
this manually by sifting through the results of:
git jump grep 'strvec_.*,$'
and liberally applying my editor's auto-format. Most of the changes are
of the form shown above, though I also normalized a few that had
originally used a single-tab indentation (rather than our usual style of
aligning with the open paren). I also rewrapped a couple of obvious
cases (e.g., where previously too-long lines became short enough to fit
on one), but I wasn't aggressive about it. In cases broken to three or
more lines, the grouping of arguments is sometimes meaningful, and it
wasn't worth my time or reviewer time to ponder each case individually.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-28 20:26:31 +00:00
|
|
|
oid_to_hex(ce_oid));
|
2022-06-02 09:09:50 +00:00
|
|
|
strvec_pushf(&cp.env, "toplevel=%s", toplevel);
|
2018-05-10 21:25:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since the path variable was accessible from the script
|
|
|
|
* before porting, it is also made available after porting.
|
|
|
|
* The environment variable "PATH" has a very special purpose
|
|
|
|
* on windows. And since environment variables are
|
|
|
|
* case-insensitive in windows, it interferes with the
|
|
|
|
* existing PATH variable. Hence, to avoid that, we expose
|
2022-06-02 09:09:51 +00:00
|
|
|
* path via the args strvec and not via env.
|
2018-05-10 21:25:01 +00:00
|
|
|
*/
|
|
|
|
sq_quote_buf(&sb, path);
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushf(&cp.args, "path=%s; %s",
|
strvec: fix indentation in renamed calls
Code which split an argv_array call across multiple lines, like:
argv_array_pushl(&args, "one argument",
"another argument", "and more",
NULL);
was recently mechanically renamed to use strvec, which results in
mis-matched indentation like:
strvec_pushl(&args, "one argument",
"another argument", "and more",
NULL);
Let's fix these up to align the arguments with the opening paren. I did
this manually by sifting through the results of:
git jump grep 'strvec_.*,$'
and liberally applying my editor's auto-format. Most of the changes are
of the form shown above, though I also normalized a few that had
originally used a single-tab indentation (rather than our usual style of
aligning with the open paren). I also rewrapped a couple of obvious
cases (e.g., where previously too-long lines became short enough to fit
on one), but I wasn't aggressive about it. In cases broken to three or
more lines, the grouping of arguments is sometimes meaningful, and it
wasn't worth my time or reviewer time to ponder each case individually.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-28 20:26:31 +00:00
|
|
|
sb.buf, info->argv[0]);
|
2018-05-10 21:25:01 +00:00
|
|
|
strbuf_release(&sb);
|
|
|
|
free(toplevel);
|
|
|
|
} else {
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushv(&cp.args, info->argv);
|
2018-05-10 21:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!info->quiet)
|
|
|
|
printf(_("Entering '%s'\n"), displaypath);
|
|
|
|
|
|
|
|
if (info->argv[0] && run_command(&cp))
|
|
|
|
die(_("run_command returned non-zero status for %s\n."),
|
|
|
|
displaypath);
|
|
|
|
|
|
|
|
if (info->recursive) {
|
|
|
|
struct child_process cpr = CHILD_PROCESS_INIT;
|
|
|
|
|
|
|
|
cpr.git_cmd = 1;
|
|
|
|
cpr.dir = path;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cpr.env);
|
2018-05-10 21:25:01 +00:00
|
|
|
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive",
|
strvec: fix indentation in renamed calls
Code which split an argv_array call across multiple lines, like:
argv_array_pushl(&args, "one argument",
"another argument", "and more",
NULL);
was recently mechanically renamed to use strvec, which results in
mis-matched indentation like:
strvec_pushl(&args, "one argument",
"another argument", "and more",
NULL);
Let's fix these up to align the arguments with the opening paren. I did
this manually by sifting through the results of:
git jump grep 'strvec_.*,$'
and liberally applying my editor's auto-format. Most of the changes are
of the form shown above, though I also normalized a few that had
originally used a single-tab indentation (rather than our usual style of
aligning with the open paren). I also rewrapped a couple of obvious
cases (e.g., where previously too-long lines became short enough to fit
on one), but I wasn't aggressive about it. In cases broken to three or
more lines, the grouping of arguments is sometimes meaningful, and it
wasn't worth my time or reviewer time to ponder each case individually.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-28 20:26:31 +00:00
|
|
|
NULL);
|
2022-12-20 12:39:52 +00:00
|
|
|
strvec_pushl(&cpr.args, "--super-prefix", NULL);
|
|
|
|
strvec_pushf(&cpr.args, "%s/", displaypath);
|
2018-05-10 21:25:01 +00:00
|
|
|
|
|
|
|
if (info->quiet)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&cpr.args, "--quiet");
|
2018-05-10 21:25:01 +00:00
|
|
|
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&cpr.args, "--");
|
|
|
|
strvec_pushv(&cpr.args, info->argv);
|
2018-05-10 21:25:01 +00:00
|
|
|
|
|
|
|
if (run_command(&cpr))
|
2018-08-23 21:00:56 +00:00
|
|
|
die(_("run_command returned non-zero status while "
|
2018-05-10 21:25:01 +00:00
|
|
|
"recursing in the nested submodules of %s\n."),
|
|
|
|
displaypath);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free(displaypath);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int module_foreach(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2020-03-18 14:20:24 +00:00
|
|
|
struct foreach_cb info = FOREACH_CB_INIT;
|
2022-08-31 23:14:10 +00:00
|
|
|
struct pathspec pathspec = { 0 };
|
2018-05-10 21:25:01 +00:00
|
|
|
struct module_list list = MODULE_LIST_INIT;
|
|
|
|
struct option module_foreach_options[] = {
|
2022-12-20 12:39:52 +00:00
|
|
|
OPT__SUPER_PREFIX(&info.super_prefix),
|
2021-01-06 14:44:03 +00:00
|
|
|
OPT__QUIET(&info.quiet, N_("suppress output of entering each submodule command")),
|
2018-05-10 21:25:01 +00:00
|
|
|
OPT_BOOL(0, "recursive", &info.recursive,
|
2021-01-06 14:44:03 +00:00
|
|
|
N_("recurse into nested submodules")),
|
2018-05-10 21:25:01 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
submodule--helper: report "submodule" as our name in some "-h" output
Change the user-facing "git submodule--helper" commands so that
they'll report their name as being "git submodule". To a user these
commands are internal implementation details, and it doesn't make
sense to emit usage about an internal helper when "git submodule" is
invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
[...]
And:
$ git submodule set-url -- --
usage: git submodule--helper set-url [--quiet] <path> <newurl>
[...]
Now we'll start with "usage: git submodule [...]" in both of those
cases. This change does not alter the "list", "name", "clone",
"config" and "create-branch" commands, those are internal-only (as an
aside; their usage info should probably invoke BUG(...)). This only
changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this
change, because their usage information already used "submodule"
rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage
information in practice, as git-submodule.sh will catch unknown
options, and e.g. it doesn't seem to be possible to get "add" to emit
its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and
will allow us to eventually dispatch further into "git
submodule--helper" from git-submodule.sh, while emitting the correct
usage output.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-28 10:05:30 +00:00
|
|
|
N_("git submodule foreach [--quiet] [--recursive] [--] <command>"),
|
2018-05-10 21:25:01 +00:00
|
|
|
NULL
|
|
|
|
};
|
2022-08-31 23:14:10 +00:00
|
|
|
int ret = 1;
|
2018-05-10 21:25:01 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, module_foreach_options,
|
2019-04-12 10:08:19 +00:00
|
|
|
git_submodule_helper_usage, 0);
|
2018-05-10 21:25:01 +00:00
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
if (module_list_compute(NULL, prefix, &pathspec, &list) < 0)
|
2022-08-31 23:14:10 +00:00
|
|
|
goto cleanup;
|
2018-05-10 21:25:01 +00:00
|
|
|
|
|
|
|
info.argc = argc;
|
|
|
|
info.argv = argv;
|
|
|
|
info.prefix = prefix;
|
|
|
|
|
|
|
|
for_each_listed_submodule(&list, runcommand_in_submodule_cb, &info);
|
|
|
|
|
2022-08-31 23:14:10 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&list);
|
2022-08-31 23:14:10 +00:00
|
|
|
clear_pathspec(&pathspec);
|
|
|
|
return ret;
|
2018-05-10 21:25:01 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 20:11:03 +00:00
|
|
|
static int starts_with_dot_slash(const char *const path)
|
|
|
|
{
|
|
|
|
return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_SLASH |
|
|
|
|
PATH_MATCH_XPLATFORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int starts_with_dot_dot_slash(const char *const path)
|
|
|
|
{
|
|
|
|
return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH |
|
|
|
|
PATH_MATCH_XPLATFORM);
|
|
|
|
}
|
|
|
|
|
2017-10-06 13:24:14 +00:00
|
|
|
struct init_cb {
|
|
|
|
const char *prefix;
|
2022-12-20 12:39:55 +00:00
|
|
|
const char *super_prefix;
|
2017-10-06 13:24:14 +00:00
|
|
|
unsigned int flags;
|
|
|
|
};
|
2021-09-27 12:54:25 +00:00
|
|
|
#define INIT_CB_INIT { 0 }
|
2017-10-06 13:24:14 +00:00
|
|
|
|
|
|
|
static void init_submodule(const char *path, const char *prefix,
|
2022-12-20 12:39:55 +00:00
|
|
|
const char *super_prefix,
|
2022-07-01 02:11:56 +00:00
|
|
|
unsigned int flags)
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
{
|
|
|
|
const struct submodule *sub;
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2022-08-31 23:18:05 +00:00
|
|
|
const char *upd;
|
|
|
|
char *url = NULL, *displaypath;
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
|
2022-12-20 12:39:55 +00:00
|
|
|
displaypath = get_submodule_displaypath(path, prefix, super_prefix);
|
2016-04-28 20:02:45 +00:00
|
|
|
|
2021-04-26 01:02:56 +00:00
|
|
|
sub = submodule_from_path(the_repository, null_oid(), path);
|
2016-04-28 20:02:45 +00:00
|
|
|
|
|
|
|
if (!sub)
|
|
|
|
die(_("No url found for submodule path '%s' in .gitmodules"),
|
|
|
|
displaypath);
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
|
2017-03-17 22:38:04 +00:00
|
|
|
/*
|
|
|
|
* NEEDSWORK: In a multi-working-tree world, this needs to be
|
|
|
|
* set in the per-worktree config.
|
|
|
|
*
|
|
|
|
* Set active flag for the submodule being initialized
|
|
|
|
*/
|
2017-06-22 18:43:46 +00:00
|
|
|
if (!is_submodule_active(the_repository, path)) {
|
2017-03-17 22:38:04 +00:00
|
|
|
strbuf_addf(&sb, "submodule.%s.active", sub->name);
|
|
|
|
git_config_set_gently(sb.buf, "true");
|
2017-09-29 09:44:51 +00:00
|
|
|
strbuf_reset(&sb);
|
2017-03-17 22:38:04 +00:00
|
|
|
}
|
|
|
|
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
/*
|
|
|
|
* Copy url setting when it is not set yet.
|
|
|
|
* To look up the url in .git/config, we must not fall back to
|
|
|
|
* .gitmodules, so look it up directly.
|
|
|
|
*/
|
|
|
|
strbuf_addf(&sb, "submodule.%s.url", sub->name);
|
|
|
|
if (git_config_get_string(sb.buf, &url)) {
|
2017-04-25 00:57:47 +00:00
|
|
|
if (!sub->url)
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
die(_("No url found for submodule path '%s' in .gitmodules"),
|
|
|
|
displaypath);
|
|
|
|
|
2017-04-25 00:57:47 +00:00
|
|
|
url = xstrdup(sub->url);
|
|
|
|
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
/* Possibly a url relative to parent */
|
|
|
|
if (starts_with_dot_dot_slash(url) ||
|
|
|
|
starts_with_dot_slash(url)) {
|
2018-10-16 17:27:03 +00:00
|
|
|
char *oldurl = url;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2021-08-10 11:46:41 +00:00
|
|
|
url = resolve_relative_url(oldurl, NULL, 0);
|
2018-10-16 17:27:03 +00:00
|
|
|
free(oldurl);
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (git_config_set_gently(sb.buf, url))
|
|
|
|
die(_("Failed to register url for submodule path '%s'"),
|
|
|
|
displaypath);
|
2017-10-06 13:24:14 +00:00
|
|
|
if (!(flags & OPT_QUIET))
|
2016-05-02 22:24:04 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
_("Submodule '%s' (%s) registered for path '%s'\n"),
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
sub->name, url, displaypath);
|
|
|
|
}
|
2017-09-29 09:44:51 +00:00
|
|
|
strbuf_reset(&sb);
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
|
|
|
|
/* Copy "update" setting when it is not set yet */
|
|
|
|
strbuf_addf(&sb, "submodule.%s.update", sub->name);
|
2022-08-31 23:18:05 +00:00
|
|
|
if (git_config_get_string_tmp(sb.buf, &upd) &&
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
|
|
|
|
if (sub->update_strategy.type == SM_UPDATE_COMMAND) {
|
|
|
|
fprintf(stderr, _("warning: command update mode suggested for submodule '%s'\n"),
|
|
|
|
sub->name);
|
2022-08-31 23:18:05 +00:00
|
|
|
upd = "none";
|
2022-08-31 23:18:03 +00:00
|
|
|
} else {
|
2022-08-31 23:18:05 +00:00
|
|
|
upd = submodule_update_type_to_string(sub->update_strategy.type);
|
2022-08-31 23:18:03 +00:00
|
|
|
}
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
|
|
|
|
if (git_config_set_gently(sb.buf, upd))
|
|
|
|
die(_("Failed to register update mode for submodule path '%s'"), displaypath);
|
|
|
|
}
|
|
|
|
strbuf_release(&sb);
|
|
|
|
free(displaypath);
|
|
|
|
free(url);
|
|
|
|
}
|
|
|
|
|
2017-10-06 13:24:14 +00:00
|
|
|
static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data)
|
|
|
|
{
|
|
|
|
struct init_cb *info = cb_data;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2022-12-20 12:39:55 +00:00
|
|
|
init_submodule(list_item->name, info->prefix, info->super_prefix,
|
|
|
|
info->flags);
|
2017-10-06 13:24:14 +00:00
|
|
|
}
|
|
|
|
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
static int module_init(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2017-10-06 13:24:14 +00:00
|
|
|
struct init_cb info = INIT_CB_INIT;
|
2022-08-31 23:14:10 +00:00
|
|
|
struct pathspec pathspec = { 0 };
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
struct module_list list = MODULE_LIST_INIT;
|
|
|
|
int quiet = 0;
|
|
|
|
struct option module_init_options[] = {
|
2021-01-06 14:44:03 +00:00
|
|
|
OPT__QUIET(&quiet, N_("suppress output for initializing a submodule")),
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
submodule--helper: report "submodule" as our name in some "-h" output
Change the user-facing "git submodule--helper" commands so that
they'll report their name as being "git submodule". To a user these
commands are internal implementation details, and it doesn't make
sense to emit usage about an internal helper when "git submodule" is
invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
[...]
And:
$ git submodule set-url -- --
usage: git submodule--helper set-url [--quiet] <path> <newurl>
[...]
Now we'll start with "usage: git submodule [...]" in both of those
cases. This change does not alter the "list", "name", "clone",
"config" and "create-branch" commands, those are internal-only (as an
aside; their usage info should probably invoke BUG(...)). This only
changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this
change, because their usage information already used "submodule"
rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage
information in practice, as git-submodule.sh will catch unknown
options, and e.g. it doesn't seem to be possible to get "add" to emit
its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and
will allow us to eventually dispatch further into "git
submodule--helper" from git-submodule.sh, while emitting the correct
usage output.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-28 10:05:30 +00:00
|
|
|
N_("git submodule init [<options>] [<path>]"),
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
NULL
|
|
|
|
};
|
2022-08-31 23:14:10 +00:00
|
|
|
int ret = 1;
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, module_init_options,
|
|
|
|
git_submodule_helper_usage, 0);
|
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
|
2022-08-31 23:14:10 +00:00
|
|
|
goto cleanup;
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
|
2017-03-17 22:38:02 +00:00
|
|
|
/*
|
|
|
|
* If there are no path args and submodule.active is set then,
|
|
|
|
* by default, only initialize 'active' modules.
|
|
|
|
*/
|
|
|
|
if (!argc && git_config_get_value_multi("submodule.active"))
|
|
|
|
module_list_active(&list);
|
|
|
|
|
2017-10-06 13:24:14 +00:00
|
|
|
info.prefix = prefix;
|
|
|
|
if (quiet)
|
|
|
|
info.flags |= OPT_QUIET;
|
|
|
|
|
|
|
|
for_each_listed_submodule(&list, init_submodule_cb, &info);
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
|
2022-08-31 23:14:10 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&list);
|
2022-08-31 23:14:10 +00:00
|
|
|
clear_pathspec(&pathspec);
|
|
|
|
return ret;
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 13:24:15 +00:00
|
|
|
struct status_cb {
|
|
|
|
const char *prefix;
|
2022-12-20 12:39:54 +00:00
|
|
|
const char *super_prefix;
|
2017-10-06 13:24:15 +00:00
|
|
|
unsigned int flags;
|
|
|
|
};
|
2021-09-27 12:54:25 +00:00
|
|
|
#define STATUS_CB_INIT { 0 }
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
static void print_status(unsigned int flags, char state, const char *path,
|
|
|
|
const struct object_id *oid, const char *displaypath)
|
|
|
|
{
|
|
|
|
if (flags & OPT_QUIET)
|
|
|
|
return;
|
|
|
|
|
|
|
|
printf("%c%s %s", state, oid_to_hex(oid), displaypath);
|
|
|
|
|
2018-04-18 14:53:37 +00:00
|
|
|
if (state == ' ' || state == '+') {
|
2022-08-31 23:14:21 +00:00
|
|
|
char *name = compute_rev_name(path, oid_to_hex(oid));
|
2018-04-18 14:53:37 +00:00
|
|
|
|
|
|
|
if (name)
|
|
|
|
printf(" (%s)", name);
|
2022-08-31 23:14:21 +00:00
|
|
|
free(name);
|
2018-04-18 14:53:37 +00:00
|
|
|
}
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2022-08-25 17:09:48 +00:00
|
|
|
static int handle_submodule_head_ref(const char *refname UNUSED,
|
2022-08-19 10:08:32 +00:00
|
|
|
const struct object_id *oid,
|
2022-08-25 17:09:48 +00:00
|
|
|
int flags UNUSED,
|
2017-10-06 13:24:15 +00:00
|
|
|
void *cb_data)
|
|
|
|
{
|
|
|
|
struct object_id *output = cb_data;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2017-10-06 13:24:15 +00:00
|
|
|
if (oid)
|
|
|
|
oidcpy(output, oid);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void status_submodule(const char *path, const struct object_id *ce_oid,
|
|
|
|
unsigned int ce_flags, const char *prefix,
|
2022-12-20 12:39:54 +00:00
|
|
|
const char *super_prefix, unsigned int flags)
|
2017-10-06 13:24:15 +00:00
|
|
|
{
|
|
|
|
char *displaypath;
|
2020-07-28 20:24:27 +00:00
|
|
|
struct strvec diff_files_args = STRVEC_INIT;
|
2022-04-13 20:01:38 +00:00
|
|
|
struct rev_info rev = REV_INFO_INIT;
|
2017-10-06 13:24:15 +00:00
|
|
|
int diff_files_result;
|
2020-01-24 10:34:04 +00:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
const char *git_dir;
|
2022-11-08 14:10:34 +00:00
|
|
|
struct setup_revision_opt opt = {
|
|
|
|
.free_removed_argv_elements = 1,
|
|
|
|
};
|
2017-10-06 13:24:15 +00:00
|
|
|
|
2021-04-26 01:02:56 +00:00
|
|
|
if (!submodule_from_path(the_repository, null_oid(), path))
|
2017-10-06 13:24:15 +00:00
|
|
|
die(_("no submodule mapping found in .gitmodules for path '%s'"),
|
|
|
|
path);
|
|
|
|
|
2022-12-20 12:39:54 +00:00
|
|
|
displaypath = get_submodule_displaypath(path, prefix, super_prefix);
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) {
|
2021-04-26 01:02:56 +00:00
|
|
|
print_status(flags, 'U', path, null_oid(), displaypath);
|
2017-10-06 13:24:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2020-01-24 10:34:04 +00:00
|
|
|
strbuf_addf(&buf, "%s/.git", path);
|
|
|
|
git_dir = read_gitfile(buf.buf);
|
|
|
|
if (!git_dir)
|
|
|
|
git_dir = buf.buf;
|
|
|
|
|
|
|
|
if (!is_submodule_active(the_repository, path) ||
|
|
|
|
!is_git_directory(git_dir)) {
|
2017-10-06 13:24:15 +00:00
|
|
|
print_status(flags, '-', path, ce_oid, displaypath);
|
2020-01-24 10:34:04 +00:00
|
|
|
strbuf_release(&buf);
|
2017-10-06 13:24:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2020-01-24 10:34:04 +00:00
|
|
|
strbuf_release(&buf);
|
2017-10-06 13:24:15 +00:00
|
|
|
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushl(&diff_files_args, "diff-files",
|
strvec: fix indentation in renamed calls
Code which split an argv_array call across multiple lines, like:
argv_array_pushl(&args, "one argument",
"another argument", "and more",
NULL);
was recently mechanically renamed to use strvec, which results in
mis-matched indentation like:
strvec_pushl(&args, "one argument",
"another argument", "and more",
NULL);
Let's fix these up to align the arguments with the opening paren. I did
this manually by sifting through the results of:
git jump grep 'strvec_.*,$'
and liberally applying my editor's auto-format. Most of the changes are
of the form shown above, though I also normalized a few that had
originally used a single-tab indentation (rather than our usual style of
aligning with the open paren). I also rewrapped a couple of obvious
cases (e.g., where previously too-long lines became short enough to fit
on one), but I wasn't aggressive about it. In cases broken to three or
more lines, the grouping of arguments is sometimes meaningful, and it
wasn't worth my time or reviewer time to ponder each case individually.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-28 20:26:31 +00:00
|
|
|
"--ignore-submodules=dirty", "--quiet", "--",
|
|
|
|
path, NULL);
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
git_config(git_diff_basic_config, NULL);
|
2019-11-25 04:15:44 +00:00
|
|
|
|
|
|
|
repo_init_revisions(the_repository, &rev, NULL);
|
2017-10-06 13:24:15 +00:00
|
|
|
rev.abbrev = 0;
|
2022-11-08 14:10:34 +00:00
|
|
|
setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
|
2017-10-06 13:24:15 +00:00
|
|
|
diff_files_result = run_diff_files(&rev, 0);
|
|
|
|
|
|
|
|
if (!diff_result_code(&rev.diffopt, diff_files_result)) {
|
|
|
|
print_status(flags, ' ', path, ce_oid,
|
|
|
|
displaypath);
|
|
|
|
} else if (!(flags & OPT_CACHED)) {
|
|
|
|
struct object_id oid;
|
2018-03-28 21:14:08 +00:00
|
|
|
struct ref_store *refs = get_submodule_ref_store(path);
|
2017-10-06 13:24:15 +00:00
|
|
|
|
2018-03-28 21:14:08 +00:00
|
|
|
if (!refs) {
|
|
|
|
print_status(flags, '-', path, ce_oid, displaypath);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (refs_head_ref(refs, handle_submodule_head_ref, &oid))
|
2017-11-25 19:55:24 +00:00
|
|
|
die(_("could not resolve HEAD ref inside the "
|
2017-10-06 13:24:15 +00:00
|
|
|
"submodule '%s'"), path);
|
|
|
|
|
|
|
|
print_status(flags, '+', path, &oid, displaypath);
|
|
|
|
} else {
|
|
|
|
print_status(flags, '+', path, ce_oid, displaypath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & OPT_RECURSIVE) {
|
|
|
|
struct child_process cpr = CHILD_PROCESS_INIT;
|
|
|
|
|
|
|
|
cpr.git_cmd = 1;
|
|
|
|
cpr.dir = path;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cpr.env);
|
2017-10-06 13:24:15 +00:00
|
|
|
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushl(&cpr.args, "submodule--helper", "status",
|
strvec: fix indentation in renamed calls
Code which split an argv_array call across multiple lines, like:
argv_array_pushl(&args, "one argument",
"another argument", "and more",
NULL);
was recently mechanically renamed to use strvec, which results in
mis-matched indentation like:
strvec_pushl(&args, "one argument",
"another argument", "and more",
NULL);
Let's fix these up to align the arguments with the opening paren. I did
this manually by sifting through the results of:
git jump grep 'strvec_.*,$'
and liberally applying my editor's auto-format. Most of the changes are
of the form shown above, though I also normalized a few that had
originally used a single-tab indentation (rather than our usual style of
aligning with the open paren). I also rewrapped a couple of obvious
cases (e.g., where previously too-long lines became short enough to fit
on one), but I wasn't aggressive about it. In cases broken to three or
more lines, the grouping of arguments is sometimes meaningful, and it
wasn't worth my time or reviewer time to ponder each case individually.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-28 20:26:31 +00:00
|
|
|
"--recursive", NULL);
|
2022-12-20 12:39:54 +00:00
|
|
|
strvec_push(&cpr.args, "--super-prefix");
|
|
|
|
strvec_pushf(&cpr.args, "%s/", displaypath);
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
if (flags & OPT_CACHED)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&cpr.args, "--cached");
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
if (flags & OPT_QUIET)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&cpr.args, "--quiet");
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
if (run_command(&cpr))
|
|
|
|
die(_("failed to recurse into submodule '%s'"), path);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_clear(&diff_files_args);
|
2017-10-06 13:24:15 +00:00
|
|
|
free(displaypath);
|
2022-04-13 20:01:38 +00:00
|
|
|
release_revisions(&rev);
|
2017-10-06 13:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void status_submodule_cb(const struct cache_entry *list_item,
|
|
|
|
void *cb_data)
|
|
|
|
{
|
|
|
|
struct status_cb *info = cb_data;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2017-10-06 13:24:15 +00:00
|
|
|
status_submodule(list_item->name, &list_item->oid, list_item->ce_flags,
|
2022-12-20 12:39:54 +00:00
|
|
|
info->prefix, info->super_prefix, info->flags);
|
2017-10-06 13:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int module_status(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct status_cb info = STATUS_CB_INIT;
|
2022-08-31 23:14:10 +00:00
|
|
|
struct pathspec pathspec = { 0 };
|
2017-10-06 13:24:15 +00:00
|
|
|
struct module_list list = MODULE_LIST_INIT;
|
|
|
|
int quiet = 0;
|
|
|
|
struct option module_status_options[] = {
|
2022-12-20 12:39:54 +00:00
|
|
|
OPT__SUPER_PREFIX(&info.super_prefix),
|
2021-01-06 14:44:03 +00:00
|
|
|
OPT__QUIET(&quiet, N_("suppress submodule status output")),
|
|
|
|
OPT_BIT(0, "cached", &info.flags, N_("use commit stored in the index instead of the one stored in the submodule HEAD"), OPT_CACHED),
|
2017-10-06 13:24:15 +00:00
|
|
|
OPT_BIT(0, "recursive", &info.flags, N_("recurse into nested submodules"), OPT_RECURSIVE),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
|
|
|
N_("git submodule status [--quiet] [--cached] [--recursive] [<path>...]"),
|
|
|
|
NULL
|
|
|
|
};
|
2022-08-31 23:14:10 +00:00
|
|
|
int ret = 1;
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, module_status_options,
|
|
|
|
git_submodule_helper_usage, 0);
|
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
|
2022-08-31 23:14:10 +00:00
|
|
|
goto cleanup;
|
2017-10-06 13:24:15 +00:00
|
|
|
|
|
|
|
info.prefix = prefix;
|
|
|
|
if (quiet)
|
|
|
|
info.flags |= OPT_QUIET;
|
|
|
|
|
|
|
|
for_each_listed_submodule(&list, status_submodule_cb, &info);
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
|
2022-08-31 23:14:10 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&list);
|
2022-08-31 23:14:10 +00:00
|
|
|
clear_pathspec(&pathspec);
|
|
|
|
return ret;
|
submodule: port init from shell to C
By having the `submodule init` functionality in C, we can reference it
easier from other parts in the code in later patches. The code is split
up to have one function to initialize one submodule and a calling function
that takes care of the rest, such as argument handling and translating the
arguments to the paths of the submodules.
This is the first submodule subcommand that is fully converted to C
except for the usage string, so this is actually removing a call to
the `submodule--helper list` function, which is supposed to be used in
this transition. Instead we'll make a direct call to `module_list_compute`.
An explanation why we need to edit the prefixes in cmd_update in
git-submodule.sh in this patch:
By having no processing in the shell part, we need to convey the notion
of wt_prefix and prefix to the C parts, which former patches punted on
and did the processing of displaying path in the shell.
`wt_prefix` used to hold the path from the repository root to the current
directory, e.g. wt_prefix would be t/ if the user invoked the
`git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
`prefix` used to hold the relative path from the repository root to the
operation, e.g. if you have recursive submodules, the shell script would
modify the `prefix` in each recursive step by adding the submodule path.
We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
will setup git in the directory the user actually called git-submodule.sh
from. The `prefix` will be passed in via the `--prefix` option.
Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
calling superproject is unfortunate with this patch as the C code doesn't
know about a possible recursion from a superproject via `submodule update
--init --recursive`.
To fix this, we change the meaning of `wt_prefix` to point to the current
project instead of the superproject and `prefix` to include any relative
paths issues in the superproject. That way `prefix` will become the leading
part for displaying paths and `wt_prefix` will be empty in recursive
calls for now.
The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
the calling directory in the superproject by just traveling reverse of
`prefix`.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-16 00:50:13 +00:00
|
|
|
}
|
|
|
|
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
struct module_cb {
|
|
|
|
unsigned int mod_src;
|
|
|
|
unsigned int mod_dst;
|
|
|
|
struct object_id oid_src;
|
|
|
|
struct object_id oid_dst;
|
|
|
|
char status;
|
2022-08-31 23:14:15 +00:00
|
|
|
char *sm_path;
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
};
|
2021-09-27 12:54:25 +00:00
|
|
|
#define MODULE_CB_INIT { 0 }
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
|
2022-08-31 23:14:15 +00:00
|
|
|
static void module_cb_release(struct module_cb *mcb)
|
|
|
|
{
|
|
|
|
free(mcb->sm_path);
|
|
|
|
}
|
|
|
|
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
struct module_cb_list {
|
|
|
|
struct module_cb **entries;
|
|
|
|
int alloc, nr;
|
|
|
|
};
|
2021-09-27 12:54:25 +00:00
|
|
|
#define MODULE_CB_LIST_INIT { 0 }
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
|
2022-08-31 23:14:15 +00:00
|
|
|
static void module_cb_list_release(struct module_cb_list *mcbl)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < mcbl->nr; i++) {
|
|
|
|
struct module_cb *mcb = mcbl->entries[i];
|
|
|
|
|
|
|
|
module_cb_release(mcb);
|
|
|
|
free(mcb);
|
|
|
|
}
|
|
|
|
free(mcbl->entries);
|
|
|
|
}
|
|
|
|
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
struct summary_cb {
|
|
|
|
int argc;
|
|
|
|
const char **argv;
|
|
|
|
const char *prefix;
|
2022-12-20 12:39:55 +00:00
|
|
|
const char *super_prefix;
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
unsigned int cached: 1;
|
|
|
|
unsigned int for_status: 1;
|
|
|
|
unsigned int files: 1;
|
|
|
|
int summary_limit;
|
|
|
|
};
|
2021-09-27 12:54:25 +00:00
|
|
|
#define SUMMARY_CB_INIT { 0 }
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
|
|
|
|
enum diff_cmd {
|
|
|
|
DIFF_INDEX,
|
|
|
|
DIFF_FILES
|
|
|
|
};
|
|
|
|
|
2020-08-25 11:30:19 +00:00
|
|
|
static char *verify_submodule_committish(const char *sm_path,
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
const char *committish)
|
|
|
|
{
|
|
|
|
struct child_process cp_rev_parse = CHILD_PROCESS_INIT;
|
|
|
|
struct strbuf result = STRBUF_INIT;
|
|
|
|
|
|
|
|
cp_rev_parse.git_cmd = 1;
|
|
|
|
cp_rev_parse.dir = sm_path;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp_rev_parse.env);
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
strvec_pushl(&cp_rev_parse.args, "rev-parse", "-q", "--short", NULL);
|
|
|
|
strvec_pushf(&cp_rev_parse.args, "%s^0", committish);
|
|
|
|
strvec_push(&cp_rev_parse.args, "--");
|
|
|
|
|
|
|
|
if (capture_command(&cp_rev_parse, &result, 0))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
strbuf_trim_trailing_newline(&result);
|
|
|
|
return strbuf_detach(&result, NULL);
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:17:59 +00:00
|
|
|
static void print_submodule_summary(struct summary_cb *info, const char *errmsg,
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
int total_commits, const char *displaypath,
|
|
|
|
const char *src_abbrev, const char *dst_abbrev,
|
|
|
|
struct module_cb *p)
|
|
|
|
{
|
|
|
|
if (p->status == 'T') {
|
|
|
|
if (S_ISGITLINK(p->mod_dst))
|
|
|
|
printf(_("* %s %s(blob)->%s(submodule)"),
|
|
|
|
displaypath, src_abbrev, dst_abbrev);
|
|
|
|
else
|
|
|
|
printf(_("* %s %s(submodule)->%s(blob)"),
|
|
|
|
displaypath, src_abbrev, dst_abbrev);
|
|
|
|
} else {
|
|
|
|
printf("* %s %s...%s",
|
|
|
|
displaypath, src_abbrev, dst_abbrev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total_commits < 0)
|
|
|
|
printf(":\n");
|
|
|
|
else
|
|
|
|
printf(" (%d):\n", total_commits);
|
|
|
|
|
|
|
|
if (errmsg) {
|
|
|
|
printf(_("%s"), errmsg);
|
|
|
|
} else if (total_commits > 0) {
|
|
|
|
struct child_process cp_log = CHILD_PROCESS_INIT;
|
|
|
|
|
|
|
|
cp_log.git_cmd = 1;
|
|
|
|
cp_log.dir = p->sm_path;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp_log.env);
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
strvec_pushl(&cp_log.args, "log", NULL);
|
|
|
|
|
|
|
|
if (S_ISGITLINK(p->mod_src) && S_ISGITLINK(p->mod_dst)) {
|
|
|
|
if (info->summary_limit > 0)
|
|
|
|
strvec_pushf(&cp_log.args, "-%d",
|
|
|
|
info->summary_limit);
|
|
|
|
|
|
|
|
strvec_pushl(&cp_log.args, "--pretty= %m %s",
|
|
|
|
"--first-parent", NULL);
|
|
|
|
strvec_pushf(&cp_log.args, "%s...%s",
|
|
|
|
src_abbrev, dst_abbrev);
|
|
|
|
} else if (S_ISGITLINK(p->mod_dst)) {
|
|
|
|
strvec_pushl(&cp_log.args, "--pretty= > %s",
|
|
|
|
"-1", dst_abbrev, NULL);
|
|
|
|
} else {
|
|
|
|
strvec_pushl(&cp_log.args, "--pretty= < %s",
|
|
|
|
"-1", src_abbrev, NULL);
|
|
|
|
}
|
|
|
|
run_command(&cp_log);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void generate_submodule_summary(struct summary_cb *info,
|
|
|
|
struct module_cb *p)
|
|
|
|
{
|
2020-08-27 17:45:01 +00:00
|
|
|
char *displaypath, *src_abbrev = NULL, *dst_abbrev;
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
int missing_src = 0, missing_dst = 0;
|
2022-08-31 23:17:59 +00:00
|
|
|
struct strbuf errmsg = STRBUF_INIT;
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
int total_commits = -1;
|
|
|
|
|
2021-04-26 01:02:56 +00:00
|
|
|
if (!info->cached && oideq(&p->oid_dst, null_oid())) {
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
if (S_ISGITLINK(p->mod_dst)) {
|
|
|
|
struct ref_store *refs = get_submodule_ref_store(p->sm_path);
|
2022-08-31 23:17:52 +00:00
|
|
|
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
if (refs)
|
|
|
|
refs_head_ref(refs, handle_submodule_head_ref, &p->oid_dst);
|
|
|
|
} else if (S_ISLNK(p->mod_dst) || S_ISREG(p->mod_dst)) {
|
|
|
|
struct stat st;
|
|
|
|
int fd = open(p->sm_path, O_RDONLY);
|
|
|
|
|
|
|
|
if (fd < 0 || fstat(fd, &st) < 0 ||
|
|
|
|
index_fd(&the_index, &p->oid_dst, fd, &st, OBJ_BLOB,
|
|
|
|
p->sm_path, 0))
|
|
|
|
error(_("couldn't hash object from '%s'"), p->sm_path);
|
|
|
|
} else {
|
|
|
|
/* for a submodule removal (mode:0000000), don't warn */
|
|
|
|
if (p->mod_dst)
|
2020-08-25 11:30:19 +00:00
|
|
|
warning(_("unexpected mode %o\n"), p->mod_dst);
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISGITLINK(p->mod_src)) {
|
2020-08-27 17:45:01 +00:00
|
|
|
if (p->status != 'D')
|
|
|
|
src_abbrev = verify_submodule_committish(p->sm_path,
|
|
|
|
oid_to_hex(&p->oid_src));
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
if (!src_abbrev) {
|
|
|
|
missing_src = 1;
|
|
|
|
/*
|
|
|
|
* As `rev-parse` failed, we fallback to getting
|
|
|
|
* the abbreviated hash using oid_src. We do
|
|
|
|
* this as we might still need the abbreviated
|
|
|
|
* hash in cases like a submodule type change, etc.
|
|
|
|
*/
|
|
|
|
src_abbrev = xstrndup(oid_to_hex(&p->oid_src), 7);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The source does not point to a submodule.
|
|
|
|
* So, we fallback to getting the abbreviation using
|
|
|
|
* oid_src as we might still need the abbreviated
|
|
|
|
* hash in cases like submodule add, etc.
|
|
|
|
*/
|
|
|
|
src_abbrev = xstrndup(oid_to_hex(&p->oid_src), 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISGITLINK(p->mod_dst)) {
|
|
|
|
dst_abbrev = verify_submodule_committish(p->sm_path,
|
|
|
|
oid_to_hex(&p->oid_dst));
|
|
|
|
if (!dst_abbrev) {
|
|
|
|
missing_dst = 1;
|
|
|
|
/*
|
|
|
|
* As `rev-parse` failed, we fallback to getting
|
|
|
|
* the abbreviated hash using oid_dst. We do
|
|
|
|
* this as we might still need the abbreviated
|
|
|
|
* hash in cases like a submodule type change, etc.
|
|
|
|
*/
|
|
|
|
dst_abbrev = xstrndup(oid_to_hex(&p->oid_dst), 7);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The destination does not point to a submodule.
|
|
|
|
* So, we fallback to getting the abbreviation using
|
|
|
|
* oid_dst as we might still need the abbreviated
|
|
|
|
* hash in cases like a submodule removal, etc.
|
|
|
|
*/
|
|
|
|
dst_abbrev = xstrndup(oid_to_hex(&p->oid_dst), 7);
|
|
|
|
}
|
|
|
|
|
2022-12-20 12:39:50 +00:00
|
|
|
displaypath = get_submodule_displaypath(p->sm_path, info->prefix,
|
2022-12-20 12:39:55 +00:00
|
|
|
info->super_prefix);
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
|
|
|
|
if (!missing_src && !missing_dst) {
|
|
|
|
struct child_process cp_rev_list = CHILD_PROCESS_INIT;
|
|
|
|
struct strbuf sb_rev_list = STRBUF_INIT;
|
|
|
|
|
|
|
|
strvec_pushl(&cp_rev_list.args, "rev-list",
|
|
|
|
"--first-parent", "--count", NULL);
|
|
|
|
if (S_ISGITLINK(p->mod_src) && S_ISGITLINK(p->mod_dst))
|
|
|
|
strvec_pushf(&cp_rev_list.args, "%s...%s",
|
|
|
|
src_abbrev, dst_abbrev);
|
|
|
|
else
|
|
|
|
strvec_push(&cp_rev_list.args, S_ISGITLINK(p->mod_src) ?
|
|
|
|
src_abbrev : dst_abbrev);
|
|
|
|
strvec_push(&cp_rev_list.args, "--");
|
|
|
|
|
|
|
|
cp_rev_list.git_cmd = 1;
|
|
|
|
cp_rev_list.dir = p->sm_path;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp_rev_list.env);
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
|
|
|
|
if (!capture_command(&cp_rev_list, &sb_rev_list, 0))
|
|
|
|
total_commits = atoi(sb_rev_list.buf);
|
|
|
|
|
|
|
|
strbuf_release(&sb_rev_list);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Don't give error msg for modification whose dst is not
|
|
|
|
* submodule, i.e., deleted or changed to blob
|
|
|
|
*/
|
|
|
|
if (S_ISGITLINK(p->mod_dst)) {
|
|
|
|
if (missing_src && missing_dst) {
|
2022-08-31 23:17:59 +00:00
|
|
|
strbuf_addf(&errmsg, " Warn: %s doesn't contain commits %s and %s\n",
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
displaypath, oid_to_hex(&p->oid_src),
|
|
|
|
oid_to_hex(&p->oid_dst));
|
|
|
|
} else {
|
2022-08-31 23:17:59 +00:00
|
|
|
strbuf_addf(&errmsg, " Warn: %s doesn't contain commit %s\n",
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
displaypath, missing_src ?
|
|
|
|
oid_to_hex(&p->oid_src) :
|
|
|
|
oid_to_hex(&p->oid_dst));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:17:59 +00:00
|
|
|
print_submodule_summary(info, errmsg.len ? errmsg.buf : NULL,
|
|
|
|
total_commits, displaypath, src_abbrev,
|
2020-08-25 11:30:18 +00:00
|
|
|
dst_abbrev, p);
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
|
|
|
|
free(displaypath);
|
|
|
|
free(src_abbrev);
|
|
|
|
free(dst_abbrev);
|
2022-08-31 23:14:14 +00:00
|
|
|
strbuf_release(&errmsg);
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void prepare_submodule_summary(struct summary_cb *info,
|
|
|
|
struct module_cb_list *list)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < list->nr; i++) {
|
|
|
|
const struct submodule *sub;
|
|
|
|
struct module_cb *p = list->entries[i];
|
|
|
|
struct strbuf sm_gitdir = STRBUF_INIT;
|
|
|
|
|
|
|
|
if (p->status == 'D' || p->status == 'T') {
|
|
|
|
generate_submodule_summary(info, p);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->for_status && p->status != 'A' &&
|
|
|
|
(sub = submodule_from_path(the_repository,
|
2021-04-26 01:02:56 +00:00
|
|
|
null_oid(), p->sm_path))) {
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
char *config_key = NULL;
|
|
|
|
const char *value;
|
|
|
|
int ignore_all = 0;
|
|
|
|
|
|
|
|
config_key = xstrfmt("submodule.%s.ignore",
|
|
|
|
sub->name);
|
2020-09-09 20:53:05 +00:00
|
|
|
if (!git_config_get_string_tmp(config_key, &value))
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
ignore_all = !strcmp(value, "all");
|
|
|
|
else if (sub->ignore)
|
|
|
|
ignore_all = !strcmp(sub->ignore, "all");
|
|
|
|
|
|
|
|
free(config_key);
|
|
|
|
if (ignore_all)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Also show added or modified modules which are checked out */
|
|
|
|
strbuf_addstr(&sm_gitdir, p->sm_path);
|
|
|
|
if (is_nonbare_repository_dir(&sm_gitdir))
|
|
|
|
generate_submodule_summary(info, p);
|
|
|
|
strbuf_release(&sm_gitdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void submodule_summary_callback(struct diff_queue_struct *q,
|
2022-12-13 11:13:48 +00:00
|
|
|
struct diff_options *options UNUSED,
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct module_cb_list *list = data;
|
|
|
|
for (i = 0; i < q->nr; i++) {
|
|
|
|
struct diff_filepair *p = q->queue[i];
|
|
|
|
struct module_cb *temp;
|
|
|
|
|
|
|
|
if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
|
|
|
|
continue;
|
|
|
|
temp = (struct module_cb*)malloc(sizeof(struct module_cb));
|
|
|
|
temp->mod_src = p->one->mode;
|
|
|
|
temp->mod_dst = p->two->mode;
|
|
|
|
temp->oid_src = p->one->oid;
|
|
|
|
temp->oid_dst = p->two->oid;
|
|
|
|
temp->status = p->status;
|
|
|
|
temp->sm_path = xstrdup(p->one->path);
|
|
|
|
|
|
|
|
ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
|
|
|
|
list->entries[list->nr++] = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *get_diff_cmd(enum diff_cmd diff_cmd)
|
|
|
|
{
|
|
|
|
switch (diff_cmd) {
|
|
|
|
case DIFF_INDEX: return "diff-index";
|
|
|
|
case DIFF_FILES: return "diff-files";
|
|
|
|
default: BUG("bad diff_cmd value %d", diff_cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compute_summary_module_list(struct object_id *head_oid,
|
|
|
|
struct summary_cb *info,
|
|
|
|
enum diff_cmd diff_cmd)
|
|
|
|
{
|
|
|
|
struct strvec diff_args = STRVEC_INIT;
|
|
|
|
struct rev_info rev;
|
2022-08-02 15:33:16 +00:00
|
|
|
struct setup_revision_opt opt = {
|
|
|
|
.free_removed_argv_elements = 1,
|
|
|
|
};
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
struct module_cb_list list = MODULE_CB_LIST_INIT;
|
2022-04-13 20:01:40 +00:00
|
|
|
int ret = 0;
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
|
|
|
|
strvec_push(&diff_args, get_diff_cmd(diff_cmd));
|
|
|
|
if (info->cached)
|
|
|
|
strvec_push(&diff_args, "--cached");
|
|
|
|
strvec_pushl(&diff_args, "--ignore-submodules=dirty", "--raw", NULL);
|
|
|
|
if (head_oid)
|
|
|
|
strvec_push(&diff_args, oid_to_hex(head_oid));
|
|
|
|
strvec_push(&diff_args, "--");
|
|
|
|
if (info->argc)
|
|
|
|
strvec_pushv(&diff_args, info->argv);
|
|
|
|
|
|
|
|
git_config(git_diff_basic_config, NULL);
|
|
|
|
init_revisions(&rev, info->prefix);
|
|
|
|
rev.abbrev = 0;
|
MacOS: precompose_argv_prefix()
The following sequence leads to a "BUG" assertion running under MacOS:
DIR=git-test-restore-p
Adiarnfd=$(printf 'A\314\210')
DIRNAME=xx${Adiarnfd}yy
mkdir $DIR &&
cd $DIR &&
git init &&
mkdir $DIRNAME &&
cd $DIRNAME &&
echo "Initial" >file &&
git add file &&
echo "One more line" >>file &&
echo y | git restore -p .
Initialized empty Git repository in /tmp/git-test-restore-p/.git/
BUG: pathspec.c:495: error initializing pathspec_item
Cannot close git diff-index --cached --numstat
[snip]
The command `git restore` is run from a directory inside a Git repo.
Git needs to split the $CWD into 2 parts:
The path to the repo and "the rest", if any.
"The rest" becomes a "prefix" later used inside the pathspec code.
As an example, "/path/to/repo/dir-inside-repå" would determine
"/path/to/repo" as the root of the repo, the place where the
configuration file .git/config is found.
The rest becomes the prefix ("dir-inside-repå"), from where the
pathspec machinery expands the ".", more about this later.
If there is a decomposed form, (making the decomposing visible like this),
"dir-inside-rep°a" doesn't match "dir-inside-repå".
Git commands need to:
(a) read the configuration variable "core.precomposeunicode"
(b) precocompose argv[]
(c) precompose the prefix, if there was any
The first commit,
76759c7dff53 "git on Mac OS and precomposed unicode"
addressed (a) and (b).
The call to precompose_argv() was added into parse-options.c,
because that seemed to be a good place when the patch was written.
Commands that don't use parse-options need to do (a) and (b) themselfs.
The commands `diff-files`, `diff-index`, `diff-tree` and `diff`
learned (a) and (b) in
commit 90a78b83e0b8 "diff: run arguments through precompose_argv"
Branch names (or refs in general) using decomposed code points
resulting in decomposed file names had been fixed in
commit 8e712ef6fc97 "Honor core.precomposeUnicode in more places"
The bug report from above shows 2 things:
- more commands need to handle precomposed unicode
- (c) should be implemented for all commands using pathspecs
Solution:
precompose_argv() now handles the prefix (if needed), and is renamed into
precompose_argv_prefix().
Inside this function the config variable core.precomposeunicode is read
into the global variable precomposed_unicode, as before.
This reading is skipped if precomposed_unicode had been read before.
The original patch for preocomposed unicode, 76759c7dff53, placed
precompose_argv() into parse-options.c
Now add it into git.c::run_builtin() as well. Existing precompose
calls in diff-files.c and others may become redundant, and if we
audit the callflows that reach these places to make sure that they
can never be reached without going through the new call added to
run_builtin(), we might be able to remove these existing ones.
But in this commit, we do not bother to do so and leave these
precompose callsites as they are. Because precompose() is
idempotent and can be called on an already precomposed string
safely, this is safer than removing existing calls without fully
vetting the callflows.
There is certainly room for cleanups - this change intends to be a bug fix.
Cleanups needs more tests in e.g. t/t3910-mac-os-precompose.sh, and should
be done in future commits.
[1] git-bugreport-2021-01-06-1209.txt (git can't deal with special characters)
[2] https://lore.kernel.org/git/A102844A-9501-4A86-854D-E3B387D378AA@icloud.com/
Reported-by: Daniel Troger <random_n0body@icloud.com>
Helped-By: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-02-03 16:28:23 +00:00
|
|
|
precompose_argv_prefix(diff_args.nr, diff_args.v, NULL);
|
2022-08-02 15:33:16 +00:00
|
|
|
setup_revisions(diff_args.nr, diff_args.v, &rev, &opt);
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
rev.diffopt.output_format = DIFF_FORMAT_NO_OUTPUT | DIFF_FORMAT_CALLBACK;
|
|
|
|
rev.diffopt.format_callback = submodule_summary_callback;
|
|
|
|
rev.diffopt.format_callback_data = &list;
|
|
|
|
|
|
|
|
if (!info->cached) {
|
|
|
|
if (diff_cmd == DIFF_INDEX)
|
|
|
|
setup_work_tree();
|
2022-11-19 13:07:38 +00:00
|
|
|
if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
|
|
|
|
perror("repo_read_index_preload");
|
2022-04-13 20:01:40 +00:00
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
}
|
2022-11-19 13:07:38 +00:00
|
|
|
} else if (repo_read_index(the_repository) < 0) {
|
|
|
|
perror("repo_read_cache");
|
2022-04-13 20:01:40 +00:00
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (diff_cmd == DIFF_INDEX)
|
|
|
|
run_diff_index(&rev, info->cached);
|
|
|
|
else
|
|
|
|
run_diff_files(&rev, 0);
|
|
|
|
prepare_submodule_summary(info, &list);
|
2022-04-13 20:01:40 +00:00
|
|
|
cleanup:
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
strvec_clear(&diff_args);
|
2022-04-13 20:01:36 +00:00
|
|
|
release_revisions(&rev);
|
2022-08-31 23:14:15 +00:00
|
|
|
module_cb_list_release(&list);
|
2022-04-13 20:01:40 +00:00
|
|
|
return ret;
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int module_summary(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct summary_cb info = SUMMARY_CB_INIT;
|
|
|
|
int cached = 0;
|
|
|
|
int for_status = 0;
|
|
|
|
int files = 0;
|
|
|
|
int summary_limit = -1;
|
|
|
|
enum diff_cmd diff_cmd = DIFF_INDEX;
|
|
|
|
struct object_id head_oid;
|
|
|
|
int ret;
|
|
|
|
struct option module_summary_options[] = {
|
|
|
|
OPT_BOOL(0, "cached", &cached,
|
|
|
|
N_("use the commit stored in the index instead of the submodule HEAD")),
|
|
|
|
OPT_BOOL(0, "files", &files,
|
2021-05-16 21:59:57 +00:00
|
|
|
N_("compare the commit in the index with that in the submodule HEAD")),
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
OPT_BOOL(0, "for-status", &for_status,
|
|
|
|
N_("skip submodules with 'ignore_config' value set to 'all'")),
|
|
|
|
OPT_INTEGER('n', "summary-limit", &summary_limit,
|
|
|
|
N_("limit the summary size")),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
submodule--helper: report "submodule" as our name in some "-h" output
Change the user-facing "git submodule--helper" commands so that
they'll report their name as being "git submodule". To a user these
commands are internal implementation details, and it doesn't make
sense to emit usage about an internal helper when "git submodule" is
invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
[...]
And:
$ git submodule set-url -- --
usage: git submodule--helper set-url [--quiet] <path> <newurl>
[...]
Now we'll start with "usage: git submodule [...]" in both of those
cases. This change does not alter the "list", "name", "clone",
"config" and "create-branch" commands, those are internal-only (as an
aside; their usage info should probably invoke BUG(...)). This only
changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this
change, because their usage information already used "submodule"
rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage
information in practice, as git-submodule.sh will catch unknown
options, and e.g. it doesn't seem to be possible to get "add" to emit
its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and
will allow us to eventually dispatch further into "git
submodule--helper" from git-submodule.sh, while emitting the correct
usage output.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-28 10:05:30 +00:00
|
|
|
N_("git submodule summary [<options>] [<commit>] [--] [<path>]"),
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, module_summary_options,
|
|
|
|
git_submodule_helper_usage, 0);
|
|
|
|
|
|
|
|
if (!summary_limit)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!get_oid(argc ? argv[0] : "HEAD", &head_oid)) {
|
|
|
|
if (argc) {
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
} else if (!argc || !strcmp(argv[0], "HEAD")) {
|
|
|
|
/* before the first commit: compare with an empty tree */
|
|
|
|
oidcpy(&head_oid, the_hash_algo->empty_tree);
|
|
|
|
if (argc) {
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (get_oid("HEAD", &head_oid))
|
|
|
|
die(_("could not fetch a revision for HEAD"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (files) {
|
|
|
|
if (cached)
|
2022-01-05 20:02:14 +00:00
|
|
|
die(_("options '%s' and '%s' cannot be used together"), "--cached", "--files");
|
submodule: port submodule subcommand 'summary' from shell to C
Convert submodule subcommand 'summary' to a builtin and call it via
'git-submodule.sh'.
The shell version had to call $diff_cmd twice, once to find the modified
modules cared by the user and then again, with that list of modules
to do various operations for computing the summary of those modules.
On the other hand, the C version does not need a second call to
$diff_cmd since it reuses the module list from the first call to do the
aforementioned tasks.
In the C version, we use the combination of setting a child process'
working directory to the submodule path and then calling
'prepare_submodule_repo_env()' which also sets the 'GIT_DIR' to '.git',
so that we can be certain that those spawned processes will not access
the superproject's ODB by mistake.
A behavioural difference between the C and the shell version is that the
shell version outputs two line feeds after the 'git log' output when run
outside of the tests while the C version outputs one line feed in any
case. The reason for this is that the shell version calls log with
'--pretty=format:<fmt>' whose output is followed by two echo
calls; 'format' does not have "terminator" semantics like its 'tformat'
counterpart. So, the log output is terminated by a newline only when
invoked by the user and not when invoked from the scripts. This results
in the one & two line feed differences in the shell version.
On the other hand, the C version calls log with '--pretty=<fmt>'
which is equivalent to '--pretty:tformat:<fmt>' which is then
followed by a 'printf("\n")'. Due to its "terminator" semantics the
log output is always terminated by newline and hence one line feed in
any case.
Also, when we try to pass an option-like argument after a non-option
argument, for instance:
git submodule summary HEAD --foo-bar
(or)
git submodule summary HEAD --cached
That argument would be treated like a path to the submodule for which
the user is requesting a summary. So, the option ends up having no
effect. Though, passing '--quiet' is an exception to this:
git submodule summary HEAD --quiet
While 'summary' doesn't support '--quiet', we don't get an output for
the above command as '--quiet' is treated as a path which means we get
an output only if a submodule whose path is '--quiet' exists.
The error message in case of computing a summary for non-existent
submodules in the C version is different from that of the shell version.
Since the new error message is not marked for translation, change the
'test_i18ngrep' in t7421.4 to 'grep'.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Stefan Beller <stefanbeller@gmail.com>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-12 19:44:04 +00:00
|
|
|
diff_cmd = DIFF_FILES;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.argc = argc;
|
|
|
|
info.argv = argv;
|
|
|
|
info.prefix = prefix;
|
|
|
|
info.cached = !!cached;
|
|
|
|
info.files = !!files;
|
|
|
|
info.for_status = !!for_status;
|
|
|
|
info.summary_limit = summary_limit;
|
|
|
|
|
|
|
|
ret = compute_summary_module_list((diff_cmd == DIFF_INDEX) ? &head_oid : NULL,
|
|
|
|
&info, diff_cmd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-14 21:15:28 +00:00
|
|
|
struct sync_cb {
|
|
|
|
const char *prefix;
|
2022-12-20 12:39:53 +00:00
|
|
|
const char *super_prefix;
|
2018-01-14 21:15:28 +00:00
|
|
|
unsigned int flags;
|
|
|
|
};
|
2021-09-27 12:54:25 +00:00
|
|
|
#define SYNC_CB_INIT { 0 }
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
static void sync_submodule(const char *path, const char *prefix,
|
2022-12-20 12:39:53 +00:00
|
|
|
const char *super_prefix, unsigned int flags)
|
2018-01-14 21:15:28 +00:00
|
|
|
{
|
|
|
|
const struct submodule *sub;
|
|
|
|
char *remote_key = NULL;
|
2022-03-05 00:13:53 +00:00
|
|
|
char *sub_origin_url, *super_config_url, *displaypath, *default_remote;
|
2018-01-14 21:15:28 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
char *sub_config_path = NULL;
|
2022-08-31 23:18:13 +00:00
|
|
|
int code;
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
if (!is_submodule_active(the_repository, path))
|
|
|
|
return;
|
|
|
|
|
2021-04-26 01:02:56 +00:00
|
|
|
sub = submodule_from_path(the_repository, null_oid(), path);
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
if (sub && sub->url) {
|
|
|
|
if (starts_with_dot_dot_slash(sub->url) ||
|
|
|
|
starts_with_dot_slash(sub->url)) {
|
2021-08-10 11:46:35 +00:00
|
|
|
char *up_path = get_up_path(path);
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2021-08-10 11:46:41 +00:00
|
|
|
sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
|
|
|
|
super_config_url = resolve_relative_url(sub->url, NULL, 1);
|
2018-01-14 21:15:28 +00:00
|
|
|
free(up_path);
|
|
|
|
} else {
|
|
|
|
sub_origin_url = xstrdup(sub->url);
|
|
|
|
super_config_url = xstrdup(sub->url);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sub_origin_url = xstrdup("");
|
|
|
|
super_config_url = xstrdup("");
|
|
|
|
}
|
|
|
|
|
2022-12-20 12:39:53 +00:00
|
|
|
displaypath = get_submodule_displaypath(path, prefix, super_prefix);
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
if (!(flags & OPT_QUIET))
|
|
|
|
printf(_("Synchronizing submodule url for '%s'\n"),
|
|
|
|
displaypath);
|
|
|
|
|
|
|
|
strbuf_reset(&sb);
|
|
|
|
strbuf_addf(&sb, "submodule.%s.url", sub->name);
|
|
|
|
if (git_config_set_gently(sb.buf, super_config_url))
|
|
|
|
die(_("failed to register url for submodule path '%s'"),
|
|
|
|
displaypath);
|
|
|
|
|
|
|
|
if (!is_submodule_populated_gently(path, NULL))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
strbuf_reset(&sb);
|
2022-08-31 23:18:13 +00:00
|
|
|
code = get_default_remote_submodule(path, &default_remote);
|
|
|
|
if (code)
|
|
|
|
exit(code);
|
2018-01-14 21:15:28 +00:00
|
|
|
|
2022-03-05 00:13:53 +00:00
|
|
|
remote_key = xstrfmt("remote.%s.url", default_remote);
|
|
|
|
free(default_remote);
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
submodule_to_gitdir(&sb, path);
|
|
|
|
strbuf_addstr(&sb, "/config");
|
|
|
|
|
|
|
|
if (git_config_set_in_file_gently(sb.buf, remote_key, sub_origin_url))
|
|
|
|
die(_("failed to update remote for submodule '%s'"),
|
|
|
|
path);
|
|
|
|
|
|
|
|
if (flags & OPT_RECURSIVE) {
|
|
|
|
struct child_process cpr = CHILD_PROCESS_INIT;
|
|
|
|
|
|
|
|
cpr.git_cmd = 1;
|
|
|
|
cpr.dir = path;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cpr.env);
|
2018-01-14 21:15:28 +00:00
|
|
|
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushl(&cpr.args, "submodule--helper", "sync",
|
strvec: fix indentation in renamed calls
Code which split an argv_array call across multiple lines, like:
argv_array_pushl(&args, "one argument",
"another argument", "and more",
NULL);
was recently mechanically renamed to use strvec, which results in
mis-matched indentation like:
strvec_pushl(&args, "one argument",
"another argument", "and more",
NULL);
Let's fix these up to align the arguments with the opening paren. I did
this manually by sifting through the results of:
git jump grep 'strvec_.*,$'
and liberally applying my editor's auto-format. Most of the changes are
of the form shown above, though I also normalized a few that had
originally used a single-tab indentation (rather than our usual style of
aligning with the open paren). I also rewrapped a couple of obvious
cases (e.g., where previously too-long lines became short enough to fit
on one), but I wasn't aggressive about it. In cases broken to three or
more lines, the grouping of arguments is sometimes meaningful, and it
wasn't worth my time or reviewer time to ponder each case individually.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-28 20:26:31 +00:00
|
|
|
"--recursive", NULL);
|
2022-12-20 12:39:53 +00:00
|
|
|
strvec_push(&cpr.args, "--super-prefix");
|
|
|
|
strvec_pushf(&cpr.args, "%s/", displaypath);
|
|
|
|
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
if (flags & OPT_QUIET)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&cpr.args, "--quiet");
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
if (run_command(&cpr))
|
|
|
|
die(_("failed to recurse into submodule '%s'"),
|
|
|
|
path);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free(super_config_url);
|
|
|
|
free(sub_origin_url);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
free(remote_key);
|
|
|
|
free(displaypath);
|
|
|
|
free(sub_config_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data)
|
|
|
|
{
|
|
|
|
struct sync_cb *info = cb_data;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2022-12-20 12:39:53 +00:00
|
|
|
sync_submodule(list_item->name, info->prefix, info->super_prefix,
|
|
|
|
info->flags);
|
2018-01-14 21:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int module_sync(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct sync_cb info = SYNC_CB_INIT;
|
2022-08-31 23:14:10 +00:00
|
|
|
struct pathspec pathspec = { 0 };
|
2018-01-14 21:15:28 +00:00
|
|
|
struct module_list list = MODULE_LIST_INIT;
|
|
|
|
int quiet = 0;
|
|
|
|
int recursive = 0;
|
|
|
|
struct option module_sync_options[] = {
|
2022-12-20 12:39:53 +00:00
|
|
|
OPT__SUPER_PREFIX(&info.super_prefix),
|
2021-01-06 14:44:03 +00:00
|
|
|
OPT__QUIET(&quiet, N_("suppress output of synchronizing submodule url")),
|
2018-01-14 21:15:28 +00:00
|
|
|
OPT_BOOL(0, "recursive", &recursive,
|
2021-01-06 14:44:03 +00:00
|
|
|
N_("recurse into nested submodules")),
|
2018-01-14 21:15:28 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
submodule--helper: report "submodule" as our name in some "-h" output
Change the user-facing "git submodule--helper" commands so that
they'll report their name as being "git submodule". To a user these
commands are internal implementation details, and it doesn't make
sense to emit usage about an internal helper when "git submodule" is
invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
[...]
And:
$ git submodule set-url -- --
usage: git submodule--helper set-url [--quiet] <path> <newurl>
[...]
Now we'll start with "usage: git submodule [...]" in both of those
cases. This change does not alter the "list", "name", "clone",
"config" and "create-branch" commands, those are internal-only (as an
aside; their usage info should probably invoke BUG(...)). This only
changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this
change, because their usage information already used "submodule"
rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage
information in practice, as git-submodule.sh will catch unknown
options, and e.g. it doesn't seem to be possible to get "add" to emit
its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and
will allow us to eventually dispatch further into "git
submodule--helper" from git-submodule.sh, while emitting the correct
usage output.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-28 10:05:30 +00:00
|
|
|
N_("git submodule sync [--quiet] [--recursive] [<path>]"),
|
2018-01-14 21:15:28 +00:00
|
|
|
NULL
|
|
|
|
};
|
2022-08-31 23:14:10 +00:00
|
|
|
int ret = 1;
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, module_sync_options,
|
|
|
|
git_submodule_helper_usage, 0);
|
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
|
2022-08-31 23:14:10 +00:00
|
|
|
goto cleanup;
|
2018-01-14 21:15:28 +00:00
|
|
|
|
|
|
|
info.prefix = prefix;
|
|
|
|
if (quiet)
|
|
|
|
info.flags |= OPT_QUIET;
|
|
|
|
if (recursive)
|
|
|
|
info.flags |= OPT_RECURSIVE;
|
|
|
|
|
|
|
|
for_each_listed_submodule(&list, sync_submodule_cb, &info);
|
|
|
|
|
2022-08-31 23:14:10 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&list);
|
2022-08-31 23:14:10 +00:00
|
|
|
clear_pathspec(&pathspec);
|
|
|
|
return ret;
|
2018-01-14 21:15:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 21:15:29 +00:00
|
|
|
struct deinit_cb {
|
|
|
|
const char *prefix;
|
|
|
|
unsigned int flags;
|
|
|
|
};
|
2021-09-27 12:54:25 +00:00
|
|
|
#define DEINIT_CB_INIT { 0 }
|
2018-01-14 21:15:29 +00:00
|
|
|
|
|
|
|
static void deinit_submodule(const char *path, const char *prefix,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
const struct submodule *sub;
|
|
|
|
char *displaypath = NULL;
|
|
|
|
struct child_process cp_config = CHILD_PROCESS_INIT;
|
|
|
|
struct strbuf sb_config = STRBUF_INIT;
|
|
|
|
char *sub_git_dir = xstrfmt("%s/.git", path);
|
|
|
|
|
2021-04-26 01:02:56 +00:00
|
|
|
sub = submodule_from_path(the_repository, null_oid(), path);
|
2018-01-14 21:15:29 +00:00
|
|
|
|
|
|
|
if (!sub || !sub->name)
|
|
|
|
goto cleanup;
|
|
|
|
|
2022-12-20 12:39:50 +00:00
|
|
|
displaypath = get_submodule_displaypath(path, prefix, NULL);
|
2018-01-14 21:15:29 +00:00
|
|
|
|
|
|
|
/* remove the submodule work tree (unless the user already did it) */
|
|
|
|
if (is_directory(path)) {
|
|
|
|
struct strbuf sb_rm = STRBUF_INIT;
|
|
|
|
const char *format;
|
|
|
|
|
2021-11-19 10:56:27 +00:00
|
|
|
if (is_directory(sub_git_dir)) {
|
|
|
|
if (!(flags & OPT_QUIET))
|
|
|
|
warning(_("Submodule work tree '%s' contains a .git "
|
|
|
|
"directory. This will be replaced with a "
|
|
|
|
".git file by using absorbgitdirs."),
|
|
|
|
displaypath);
|
|
|
|
|
2022-12-20 12:39:50 +00:00
|
|
|
absorb_git_dir_into_superproject(path, NULL);
|
2021-11-19 10:56:27 +00:00
|
|
|
|
|
|
|
}
|
2018-01-14 21:15:29 +00:00
|
|
|
|
|
|
|
if (!(flags & OPT_FORCE)) {
|
|
|
|
struct child_process cp_rm = CHILD_PROCESS_INIT;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2018-01-14 21:15:29 +00:00
|
|
|
cp_rm.git_cmd = 1;
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushl(&cp_rm.args, "rm", "-qn",
|
strvec: fix indentation in renamed calls
Code which split an argv_array call across multiple lines, like:
argv_array_pushl(&args, "one argument",
"another argument", "and more",
NULL);
was recently mechanically renamed to use strvec, which results in
mis-matched indentation like:
strvec_pushl(&args, "one argument",
"another argument", "and more",
NULL);
Let's fix these up to align the arguments with the opening paren. I did
this manually by sifting through the results of:
git jump grep 'strvec_.*,$'
and liberally applying my editor's auto-format. Most of the changes are
of the form shown above, though I also normalized a few that had
originally used a single-tab indentation (rather than our usual style of
aligning with the open paren). I also rewrapped a couple of obvious
cases (e.g., where previously too-long lines became short enough to fit
on one), but I wasn't aggressive about it. In cases broken to three or
more lines, the grouping of arguments is sometimes meaningful, and it
wasn't worth my time or reviewer time to ponder each case individually.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-28 20:26:31 +00:00
|
|
|
path, NULL);
|
2018-01-14 21:15:29 +00:00
|
|
|
|
|
|
|
if (run_command(&cp_rm))
|
|
|
|
die(_("Submodule work tree '%s' contains local "
|
|
|
|
"modifications; use '-f' to discard them"),
|
|
|
|
displaypath);
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_addstr(&sb_rm, path);
|
|
|
|
|
|
|
|
if (!remove_dir_recursively(&sb_rm, 0))
|
|
|
|
format = _("Cleared directory '%s'\n");
|
|
|
|
else
|
|
|
|
format = _("Could not remove submodule work tree '%s'\n");
|
|
|
|
|
|
|
|
if (!(flags & OPT_QUIET))
|
|
|
|
printf(format, displaypath);
|
|
|
|
|
submodule deinit: unset core.worktree
When a submodule is deinit'd, the working tree is gone, so the setting of
core.worktree is bogus. Unset it. As we covered the only other case in
which a submodule loses its working tree in the earlier step
(i.e. switching branches of top-level project to move to a commit that did
not have the submodule), this makes the code always maintain
core.worktree correctly unset when there is no working tree
for a submodule.
This re-introduces 984cd77ddb (submodule deinit: unset core.worktree,
2018-06-18), which was reverted as part of f178c13fda (Revert "Merge
branch 'sb/submodule-core-worktree'", 2018-09-07)
The whole series was reverted as the offending commit e98317508c
(submodule: ensure core.worktree is set after update, 2018-06-18)
was relied on by other commits such as 984cd77ddb.
Keep the offending commit reverted, but its functionality came back via
4d6d6ef1fc (Merge branch 'sb/submodule-update-in-c', 2018-09-17), such
that we can reintroduce 984cd77ddb now.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-12-14 23:59:45 +00:00
|
|
|
submodule_unset_core_worktree(sub);
|
|
|
|
|
2018-01-14 21:15:29 +00:00
|
|
|
strbuf_release(&sb_rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mkdir(path, 0777))
|
|
|
|
printf(_("could not create empty submodule directory %s"),
|
|
|
|
displaypath);
|
|
|
|
|
|
|
|
cp_config.git_cmd = 1;
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushl(&cp_config.args, "config", "--get-regexp", NULL);
|
|
|
|
strvec_pushf(&cp_config.args, "submodule.%s\\.", sub->name);
|
2018-01-14 21:15:29 +00:00
|
|
|
|
|
|
|
/* remove the .git/config entries (unless the user already did it) */
|
|
|
|
if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) {
|
|
|
|
char *sub_key = xstrfmt("submodule.%s", sub->name);
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2018-01-14 21:15:29 +00:00
|
|
|
/*
|
|
|
|
* remove the whole section so we have a clean state when
|
|
|
|
* the user later decides to init this submodule again
|
|
|
|
*/
|
|
|
|
git_config_rename_section_in_file(NULL, sub_key, NULL);
|
|
|
|
if (!(flags & OPT_QUIET))
|
|
|
|
printf(_("Submodule '%s' (%s) unregistered for path '%s'\n"),
|
|
|
|
sub->name, sub->url, displaypath);
|
|
|
|
free(sub_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free(displaypath);
|
|
|
|
free(sub_git_dir);
|
|
|
|
strbuf_release(&sb_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deinit_submodule_cb(const struct cache_entry *list_item,
|
|
|
|
void *cb_data)
|
|
|
|
{
|
|
|
|
struct deinit_cb *info = cb_data;
|
|
|
|
deinit_submodule(list_item->name, info->prefix, info->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int module_deinit(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct deinit_cb info = DEINIT_CB_INIT;
|
2022-08-31 23:14:10 +00:00
|
|
|
struct pathspec pathspec = { 0 };
|
2018-01-14 21:15:29 +00:00
|
|
|
struct module_list list = MODULE_LIST_INIT;
|
|
|
|
int quiet = 0;
|
|
|
|
int force = 0;
|
|
|
|
int all = 0;
|
|
|
|
struct option module_deinit_options[] = {
|
2021-01-06 14:44:03 +00:00
|
|
|
OPT__QUIET(&quiet, N_("suppress submodule status output")),
|
|
|
|
OPT__FORCE(&force, N_("remove submodule working trees even if they contain local changes"), 0),
|
|
|
|
OPT_BOOL(0, "all", &all, N_("unregister all submodules")),
|
2018-01-14 21:15:29 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
|
|
|
N_("git submodule deinit [--quiet] [-f | --force] [--all | [--] [<path>...]]"),
|
|
|
|
NULL
|
|
|
|
};
|
2022-08-31 23:14:10 +00:00
|
|
|
int ret = 1;
|
2018-01-14 21:15:29 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, module_deinit_options,
|
|
|
|
git_submodule_helper_usage, 0);
|
|
|
|
|
|
|
|
if (all && argc) {
|
|
|
|
error("pathspec and --all are incompatible");
|
|
|
|
usage_with_options(git_submodule_helper_usage,
|
|
|
|
module_deinit_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!argc && !all)
|
|
|
|
die(_("Use '--all' if you really want to deinitialize all submodules"));
|
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
|
2022-08-31 23:14:10 +00:00
|
|
|
goto cleanup;
|
2018-01-14 21:15:29 +00:00
|
|
|
|
|
|
|
info.prefix = prefix;
|
|
|
|
if (quiet)
|
|
|
|
info.flags |= OPT_QUIET;
|
|
|
|
if (force)
|
|
|
|
info.flags |= OPT_FORCE;
|
|
|
|
|
|
|
|
for_each_listed_submodule(&list, deinit_submodule_cb, &info);
|
|
|
|
|
2022-08-31 23:14:10 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&list);
|
2022-08-31 23:14:10 +00:00
|
|
|
clear_pathspec(&pathspec);
|
|
|
|
return ret;
|
2018-01-14 21:15:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 07:48:00 +00:00
|
|
|
struct module_clone_data {
|
|
|
|
const char *prefix;
|
|
|
|
const char *path;
|
|
|
|
const char *name;
|
|
|
|
const char *url;
|
|
|
|
const char *depth;
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
struct list_objects_filter_options *filter_options;
|
2021-07-10 07:48:00 +00:00
|
|
|
unsigned int quiet: 1;
|
|
|
|
unsigned int progress: 1;
|
|
|
|
unsigned int dissociate: 1;
|
|
|
|
unsigned int require_init: 1;
|
|
|
|
int single_branch;
|
|
|
|
};
|
2022-03-15 21:09:22 +00:00
|
|
|
#define MODULE_CLONE_DATA_INIT { \
|
|
|
|
.single_branch = -1, \
|
|
|
|
}
|
2015-09-08 18:57:45 +00:00
|
|
|
|
2016-08-17 22:45:35 +00:00
|
|
|
struct submodule_alternate_setup {
|
|
|
|
const char *submodule_name;
|
|
|
|
enum SUBMODULE_ALTERNATE_ERROR_MODE {
|
|
|
|
SUBMODULE_ALTERNATE_ERROR_DIE,
|
|
|
|
SUBMODULE_ALTERNATE_ERROR_INFO,
|
|
|
|
SUBMODULE_ALTERNATE_ERROR_IGNORE
|
|
|
|
} error_mode;
|
|
|
|
struct string_list *reference;
|
|
|
|
};
|
2021-09-27 12:54:27 +00:00
|
|
|
#define SUBMODULE_ALTERNATE_SETUP_INIT { \
|
|
|
|
.error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE, \
|
|
|
|
}
|
2016-08-17 22:45:35 +00:00
|
|
|
|
2019-12-02 19:57:52 +00:00
|
|
|
static const char alternate_error_advice[] = N_(
|
|
|
|
"An alternate computed from a superproject's alternate is invalid.\n"
|
|
|
|
"To allow Git to clone without an alternate in such a case, set\n"
|
|
|
|
"submodule.alternateErrorStrategy to 'info' or, equivalently, clone with\n"
|
|
|
|
"'--reference-if-able' instead of '--reference'."
|
|
|
|
);
|
|
|
|
|
2016-08-17 22:45:35 +00:00
|
|
|
static int add_possible_reference_from_superproject(
|
2018-11-12 14:48:47 +00:00
|
|
|
struct object_directory *odb, void *sas_cb)
|
2016-08-17 22:45:35 +00:00
|
|
|
{
|
|
|
|
struct submodule_alternate_setup *sas = sas_cb;
|
2018-11-12 14:47:04 +00:00
|
|
|
size_t len;
|
2016-08-17 22:45:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the alternate object store is another repository, try the
|
2016-12-08 01:38:14 +00:00
|
|
|
* standard layout with .git/(modules/<name>)+/objects
|
2016-08-17 22:45:35 +00:00
|
|
|
*/
|
2018-11-12 14:48:47 +00:00
|
|
|
if (strip_suffix(odb->path, "/objects", &len)) {
|
2021-09-15 18:59:19 +00:00
|
|
|
struct repository alternate;
|
2016-08-17 22:45:35 +00:00
|
|
|
char *sm_alternate;
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
struct strbuf err = STRBUF_INIT;
|
2018-11-12 14:48:47 +00:00
|
|
|
strbuf_add(&sb, odb->path, len);
|
2016-10-03 20:35:51 +00:00
|
|
|
|
2022-08-31 23:18:12 +00:00
|
|
|
if (repo_init(&alternate, sb.buf, NULL) < 0)
|
|
|
|
die(_("could not get a repository handle for gitdir '%s'"),
|
|
|
|
sb.buf);
|
2021-09-15 18:59:19 +00:00
|
|
|
|
2016-08-17 22:45:35 +00:00
|
|
|
/*
|
|
|
|
* We need to end the new path with '/' to mark it as a dir,
|
|
|
|
* otherwise a submodule name containing '/' will be broken
|
|
|
|
* as the last part of a missing submodule reference would
|
|
|
|
* be taken as a file name.
|
|
|
|
*/
|
2021-09-15 18:59:19 +00:00
|
|
|
strbuf_reset(&sb);
|
|
|
|
submodule_name_to_gitdir(&sb, &alternate, sas->submodule_name);
|
|
|
|
strbuf_addch(&sb, '/');
|
|
|
|
repo_clear(&alternate);
|
2016-08-17 22:45:35 +00:00
|
|
|
|
|
|
|
sm_alternate = compute_alternate_path(sb.buf, &err);
|
|
|
|
if (sm_alternate) {
|
submodule--helper: fix "reference" leak
Fix leaks in the "reference" variable declared in add_submodule() and
module_clone().
In preceding commits this variable was refactored out of the "struct
module_clone_data", but the leak has been with us since
31224cbdc72 (clone: recursive and reference option triggers submodule
alternates, 2016-08-17) and 8c8195e9c3e (submodule--helper: introduce
add-clone subcommand, 2021-07-10).
Those commits added an xstrdup()'d member of the
STRING_LIST_INIT_NODUP'd "struct string_list". We need to free()
those, but not the ones we get from argv, let's make use of the "util"
member, if it has a pointer it's the pointer we'll need to free,
otherwise it'll be NULL (i.e. from argv).
Note that the free() of the "util" member is needed in both
module_clone() and add_submodule(). The module_clone() function itself
doesn't populate the "util" pointer as add_submodule() does, but
module_clone() is upstream of the
add_possible_reference_from_superproject() caller we're modifying
here, which does do that.
This does preclude the use of the "util" pointer for any other reasons
for now, but that's OK. If we ever need to use it for something else
we could turn it into a small "struct" with an optional "to_free"
member, and switch to using string_list_clear_func().
Alternatively we could have another "struct string_list to_free" which
would keep a copy of the strings we've dup'd to free(). But for now
this is perfectly adequate.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:14:18 +00:00
|
|
|
char *p = strbuf_detach(&sb, NULL);
|
|
|
|
|
|
|
|
string_list_append(sas->reference, p)->util = p;
|
2016-08-17 22:45:35 +00:00
|
|
|
free(sm_alternate);
|
|
|
|
} else {
|
|
|
|
switch (sas->error_mode) {
|
|
|
|
case SUBMODULE_ALTERNATE_ERROR_DIE:
|
2021-08-23 10:44:00 +00:00
|
|
|
if (advice_enabled(ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE))
|
2019-12-02 19:57:52 +00:00
|
|
|
advise(_(alternate_error_advice));
|
2016-08-17 22:45:35 +00:00
|
|
|
die(_("submodule '%s' cannot add alternate: %s"),
|
|
|
|
sas->submodule_name, err.buf);
|
|
|
|
case SUBMODULE_ALTERNATE_ERROR_INFO:
|
2019-05-07 09:50:37 +00:00
|
|
|
fprintf_ln(stderr, _("submodule '%s' cannot add alternate: %s"),
|
2016-08-17 22:45:35 +00:00
|
|
|
sas->submodule_name, err.buf);
|
|
|
|
case SUBMODULE_ALTERNATE_ERROR_IGNORE:
|
|
|
|
; /* nothing */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prepare_possible_alternates(const char *sm_name,
|
|
|
|
struct string_list *reference)
|
|
|
|
{
|
|
|
|
char *sm_alternate = NULL, *error_strategy = NULL;
|
|
|
|
struct submodule_alternate_setup sas = SUBMODULE_ALTERNATE_SETUP_INIT;
|
|
|
|
|
|
|
|
git_config_get_string("submodule.alternateLocation", &sm_alternate);
|
|
|
|
if (!sm_alternate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
git_config_get_string("submodule.alternateErrorStrategy", &error_strategy);
|
|
|
|
|
|
|
|
if (!error_strategy)
|
|
|
|
error_strategy = xstrdup("die");
|
|
|
|
|
|
|
|
sas.submodule_name = sm_name;
|
|
|
|
sas.reference = reference;
|
|
|
|
if (!strcmp(error_strategy, "die"))
|
|
|
|
sas.error_mode = SUBMODULE_ALTERNATE_ERROR_DIE;
|
|
|
|
else if (!strcmp(error_strategy, "info"))
|
|
|
|
sas.error_mode = SUBMODULE_ALTERNATE_ERROR_INFO;
|
|
|
|
else if (!strcmp(error_strategy, "ignore"))
|
|
|
|
sas.error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE;
|
|
|
|
else
|
|
|
|
die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
|
|
|
|
|
|
|
|
if (!strcmp(sm_alternate, "superproject"))
|
|
|
|
foreach_alt_odb(add_possible_reference_from_superproject, &sas);
|
|
|
|
else if (!strcmp(sm_alternate, "no"))
|
|
|
|
; /* do nothing */
|
|
|
|
else
|
|
|
|
die(_("Value '%s' for submodule.alternateLocation is not recognized"), sm_alternate);
|
|
|
|
|
|
|
|
free(sm_alternate);
|
|
|
|
free(error_strategy);
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:17:55 +00:00
|
|
|
static char *clone_submodule_sm_gitdir(const char *name)
|
2015-09-08 18:57:45 +00:00
|
|
|
{
|
2021-07-10 07:48:00 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2022-08-31 23:17:55 +00:00
|
|
|
char *sm_gitdir;
|
2021-07-10 07:48:00 +00:00
|
|
|
|
2022-08-31 23:17:55 +00:00
|
|
|
submodule_name_to_gitdir(&sb, the_repository, name);
|
2021-07-10 07:48:00 +00:00
|
|
|
sm_gitdir = absolute_pathdup(sb.buf);
|
2022-08-31 23:17:55 +00:00
|
|
|
strbuf_release(&sb);
|
2021-07-10 07:48:00 +00:00
|
|
|
|
2022-08-31 23:17:55 +00:00
|
|
|
return sm_gitdir;
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:17:56 +00:00
|
|
|
static int clone_submodule(const struct module_clone_data *clone_data,
|
|
|
|
struct string_list *reference)
|
2022-08-31 23:17:55 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name);
|
|
|
|
char *sm_alternate = NULL, *error_strategy = NULL;
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
2022-08-31 23:14:08 +00:00
|
|
|
const char *clone_data_path = clone_data->path;
|
|
|
|
char *to_free = NULL;
|
2021-07-10 07:48:00 +00:00
|
|
|
|
2022-08-31 23:17:54 +00:00
|
|
|
if (!is_absolute_path(clone_data->path))
|
2022-08-31 23:14:08 +00:00
|
|
|
clone_data_path = to_free = xstrfmt("%s/%s", get_git_work_tree(),
|
|
|
|
clone_data->path);
|
2021-07-10 07:48:00 +00:00
|
|
|
|
|
|
|
if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)
|
|
|
|
die(_("refusing to create/use '%s' in another submodule's "
|
|
|
|
"git dir"), sm_gitdir);
|
|
|
|
|
|
|
|
if (!file_exists(sm_gitdir)) {
|
|
|
|
if (safe_create_leading_directories_const(sm_gitdir) < 0)
|
|
|
|
die(_("could not create directory '%s'"), sm_gitdir);
|
|
|
|
|
2022-08-31 23:17:56 +00:00
|
|
|
prepare_possible_alternates(clone_data->name, reference);
|
2021-07-10 07:48:00 +00:00
|
|
|
|
|
|
|
strvec_push(&cp.args, "clone");
|
|
|
|
strvec_push(&cp.args, "--no-checkout");
|
|
|
|
if (clone_data->quiet)
|
|
|
|
strvec_push(&cp.args, "--quiet");
|
|
|
|
if (clone_data->progress)
|
|
|
|
strvec_push(&cp.args, "--progress");
|
|
|
|
if (clone_data->depth && *(clone_data->depth))
|
|
|
|
strvec_pushl(&cp.args, "--depth", clone_data->depth, NULL);
|
2022-08-31 23:17:56 +00:00
|
|
|
if (reference->nr) {
|
2021-07-10 07:48:00 +00:00
|
|
|
struct string_list_item *item;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2022-08-31 23:17:56 +00:00
|
|
|
for_each_string_list_item(item, reference)
|
2021-07-10 07:48:00 +00:00
|
|
|
strvec_pushl(&cp.args, "--reference",
|
|
|
|
item->string, NULL);
|
|
|
|
}
|
|
|
|
if (clone_data->dissociate)
|
|
|
|
strvec_push(&cp.args, "--dissociate");
|
|
|
|
if (sm_gitdir && *sm_gitdir)
|
|
|
|
strvec_pushl(&cp.args, "--separate-git-dir", sm_gitdir, NULL);
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
if (clone_data->filter_options && clone_data->filter_options->choice)
|
|
|
|
strvec_pushf(&cp.args, "--filter=%s",
|
|
|
|
expand_list_objects_filter_spec(
|
|
|
|
clone_data->filter_options));
|
2021-07-10 07:48:00 +00:00
|
|
|
if (clone_data->single_branch >= 0)
|
|
|
|
strvec_push(&cp.args, clone_data->single_branch ?
|
|
|
|
"--single-branch" :
|
|
|
|
"--no-single-branch");
|
|
|
|
|
|
|
|
strvec_push(&cp.args, "--");
|
|
|
|
strvec_push(&cp.args, clone_data->url);
|
2022-08-31 23:17:56 +00:00
|
|
|
strvec_push(&cp.args, clone_data_path);
|
2021-07-10 07:48:00 +00:00
|
|
|
|
|
|
|
cp.git_cmd = 1;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp.env);
|
2021-07-10 07:48:00 +00:00
|
|
|
cp.no_stdin = 1;
|
|
|
|
|
|
|
|
if(run_command(&cp))
|
|
|
|
die(_("clone of '%s' into submodule path '%s' failed"),
|
2022-08-31 23:17:56 +00:00
|
|
|
clone_data->url, clone_data_path);
|
2021-07-10 07:48:00 +00:00
|
|
|
} else {
|
2022-08-31 23:17:54 +00:00
|
|
|
char *path;
|
|
|
|
|
2022-08-31 23:17:56 +00:00
|
|
|
if (clone_data->require_init && !access(clone_data_path, X_OK) &&
|
|
|
|
!is_empty_dir(clone_data_path))
|
|
|
|
die(_("directory not empty: '%s'"), clone_data_path);
|
|
|
|
if (safe_create_leading_directories_const(clone_data_path) < 0)
|
|
|
|
die(_("could not create directory '%s'"), clone_data_path);
|
2022-08-31 23:17:54 +00:00
|
|
|
path = xstrfmt("%s/index", sm_gitdir);
|
|
|
|
unlink_or_warn(path);
|
|
|
|
free(path);
|
2021-07-10 07:48:00 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 23:17:56 +00:00
|
|
|
connect_work_tree_and_git_dir(clone_data_path, sm_gitdir, 0);
|
2021-07-10 07:48:00 +00:00
|
|
|
|
2022-08-31 23:17:56 +00:00
|
|
|
p = git_pathdup_submodule(clone_data_path, "config");
|
2021-07-10 07:48:00 +00:00
|
|
|
if (!p)
|
2022-08-31 23:17:56 +00:00
|
|
|
die(_("could not get submodule directory for '%s'"), clone_data_path);
|
2021-07-10 07:48:00 +00:00
|
|
|
|
|
|
|
/* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */
|
|
|
|
git_config_get_string("submodule.alternateLocation", &sm_alternate);
|
|
|
|
if (sm_alternate)
|
|
|
|
git_config_set_in_file(p, "submodule.alternateLocation",
|
|
|
|
sm_alternate);
|
|
|
|
git_config_get_string("submodule.alternateErrorStrategy", &error_strategy);
|
|
|
|
if (error_strategy)
|
|
|
|
git_config_set_in_file(p, "submodule.alternateErrorStrategy",
|
|
|
|
error_strategy);
|
|
|
|
|
|
|
|
free(sm_alternate);
|
|
|
|
free(error_strategy);
|
|
|
|
|
|
|
|
free(sm_gitdir);
|
|
|
|
free(p);
|
2022-08-31 23:14:08 +00:00
|
|
|
free(to_free);
|
2021-07-10 07:48:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int module_clone(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int dissociate = 0, quiet = 0, progress = 0, require_init = 0;
|
|
|
|
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
|
2022-08-31 23:17:56 +00:00
|
|
|
struct string_list reference = STRING_LIST_INIT_NODUP;
|
list-objects-filter: add and use initializers
In 7e2619d8ff (list_objects_filter_options: plug leak of filter_spec
strings, 2022-09-08), we noted that the filter_spec string_list was
inconsistent in how it handled memory ownership of strings stored in the
list. The fix there was a bit of a band-aid to set the "strdup_strings"
variable right before adding anything.
That works OK, and it lets the users of the API continue to
zero-initialize the struct. But it makes the code a bit hard to follow
and accident-prone, as any other spots appending the filter_spec need to
think about whether to set the strdup_strings value, too (there's one
such spot in partial_clone_get_default_filter_spec(), which is probably
a possible memory leak).
So let's do that full cleanup now. We'll introduce a
LIST_OBJECTS_FILTER_INIT macro and matching function, and use them as
appropriate (though it is for the "_options" struct, this matches the
corresponding list_objects_filter_release() function).
This is harder than it seems! Many other structs, like
git_transport_data, embed the filter struct. So they need to initialize
it themselves even if the rest of the enclosing struct is OK with
zero-initialization. I found all of the relevant spots by grepping
manually for declarations of list_objects_filter_options. And then doing
so recursively for structs which embed it, and ones which embed those,
and so on.
I'm pretty sure I got everything, but there's no change that would alert
the compiler if any topics in flight added new declarations. To catch
this case, we now double-check in the parsing function that things were
initialized as expected and BUG() if appropriate.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-09-11 05:03:07 +00:00
|
|
|
struct list_objects_filter_options filter_options =
|
|
|
|
LIST_OBJECTS_FILTER_INIT;
|
2015-09-08 18:57:45 +00:00
|
|
|
|
|
|
|
struct option module_clone_options[] = {
|
2021-07-10 07:48:00 +00:00
|
|
|
OPT_STRING(0, "prefix", &clone_data.prefix,
|
2015-09-08 18:57:45 +00:00
|
|
|
N_("path"),
|
|
|
|
N_("alternative anchor for relative paths")),
|
2021-07-10 07:48:00 +00:00
|
|
|
OPT_STRING(0, "path", &clone_data.path,
|
2015-09-08 18:57:45 +00:00
|
|
|
N_("path"),
|
|
|
|
N_("where the new submodule will be cloned to")),
|
2021-07-10 07:48:00 +00:00
|
|
|
OPT_STRING(0, "name", &clone_data.name,
|
2015-09-08 18:57:45 +00:00
|
|
|
N_("string"),
|
|
|
|
N_("name of the new submodule")),
|
2021-07-10 07:48:00 +00:00
|
|
|
OPT_STRING(0, "url", &clone_data.url,
|
2015-09-08 18:57:45 +00:00
|
|
|
N_("string"),
|
|
|
|
N_("url where to clone the submodule from")),
|
2022-08-31 23:17:56 +00:00
|
|
|
OPT_STRING_LIST(0, "reference", &reference,
|
2016-08-11 23:14:00 +00:00
|
|
|
N_("repo"),
|
2015-09-08 18:57:45 +00:00
|
|
|
N_("reference repository")),
|
2018-05-03 10:53:46 +00:00
|
|
|
OPT_BOOL(0, "dissociate", &dissociate,
|
|
|
|
N_("use --reference only while cloning")),
|
2021-07-10 07:48:00 +00:00
|
|
|
OPT_STRING(0, "depth", &clone_data.depth,
|
2015-09-08 18:57:45 +00:00
|
|
|
N_("string"),
|
|
|
|
N_("depth for shallow clones")),
|
2022-02-23 14:27:34 +00:00
|
|
|
OPT__QUIET(&quiet, "suppress output for cloning a submodule"),
|
clone: pass --progress decision to recursive submodules
When cloning with "--recursive", we'd generally expect
submodules to show progress reports if the main clone did,
too.
In older versions of git, this mostly worked out of the
box. Since we show progress by default when stderr is a tty,
and since the child clones inherit the parent stderr, then
both processes would come to the same decision by default.
If the parent clone was asked for "--quiet", we passed down
"--quiet" to the child. However, if stderr was not a tty and
the user specified "--progress", we did not propagate this
to the child.
That's a minor bug, but things got much worse when we
switched recently to submodule--helper's update_clone
command. With that change, the stderr of the child clones
are always connected to a pipe, and we never output
progress at all.
This patch teaches git-submodule and git-submodule--helper
how to pass down an explicit "--progress" flag when cloning.
The clone command then decides to propagate that flag based
on the cloning decision made earlier (which takes into
account isatty(2) of the parent process, existing --progress
or --quiet flags, etc). Since the child processes always run
without a tty on stderr, we don't have to worry about
passing an explicit "--no-progress"; it's the default for
them.
This fixes the recent loss of progress during recursive
clones. And as a bonus, it makes:
git clone --recursive --progress ... 2>&1 | cat
work by triggering progress explicitly in the children.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-09-22 05:24:46 +00:00
|
|
|
OPT_BOOL(0, "progress", &progress,
|
|
|
|
N_("force cloning progress")),
|
clone --recurse-submodules: prevent name squatting on Windows
In addition to preventing `.git` from being tracked by Git, on Windows
we also have to prevent `git~1` from being tracked, as the default NTFS
short name (also known as the "8.3 filename") for the file name `.git`
is `git~1`, otherwise it would be possible for malicious repositories to
write directly into the `.git/` directory, e.g. a `post-checkout` hook
that would then be executed _during_ a recursive clone.
When we implemented appropriate protections in 2b4c6efc821 (read-cache:
optionally disallow NTFS .git variants, 2014-12-16), we had analyzed
carefully that the `.git` directory or file would be guaranteed to be
the first directory entry to be written. Otherwise it would be possible
e.g. for a file named `..git` to be assigned the short name `git~1` and
subsequently, the short name generated for `.git` would be `git~2`. Or
`git~3`. Or even `~9999999` (for a detailed explanation of the lengths
we have to go to protect `.gitmodules`, see the commit message of
e7cb0b4455c (is_ntfs_dotgit: match other .git files, 2018-05-11)).
However, by exploiting two issues (that will be addressed in a related
patch series close by), it is currently possible to clone a submodule
into a non-empty directory:
- On Windows, file names cannot end in a space or a period (for
historical reasons: the period separating the base name from the file
extension was not actually written to disk, and the base name/file
extension was space-padded to the full 8/3 characters, respectively).
Helpfully, when creating a directory under the name, say, `sub.`, that
trailing period is trimmed automatically and the actual name on disk
is `sub`.
This means that while Git thinks that the submodule names `sub` and
`sub.` are different, they both access `.git/modules/sub/`.
- While the backslash character is a valid file name character on Linux,
it is not so on Windows. As Git tries to be cross-platform, it
therefore allows backslash characters in the file names stored in tree
objects.
Which means that it is totally possible that a submodule `c` sits next
to a file `c\..git`, and on Windows, during recursive clone a file
called `..git` will be written into `c/`, of course _before_ the
submodule is cloned.
Note that the actual exploit is not quite as simple as having a
submodule `c` next to a file `c\..git`, as we have to make sure that the
directory `.git/modules/b` already exists when the submodule is checked
out, otherwise a different code path is taken in `module_clone()` that
does _not_ allow a non-empty submodule directory to exist already.
Even if we will address both issues nearby (the next commit will
disallow backslash characters in tree entries' file names on Windows,
and another patch will disallow creating directories/files with trailing
spaces or periods), it is a wise idea to defend in depth against this
sort of attack vector: when submodules are cloned recursively, we now
_require_ the directory to be empty, addressing CVE-2019-1349.
Note: the code path we patch is shared with the code path of `git
submodule update --init`, which must not expect, in general, that the
directory is empty. Hence we have to introduce the new option
`--force-init` and hand it all the way down from `git submodule` to the
actual `git submodule--helper` process that performs the initial clone.
Reported-by: Nicolas Joly <Nicolas.Joly@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-09-12 12:20:39 +00:00
|
|
|
OPT_BOOL(0, "require-init", &require_init,
|
|
|
|
N_("disallow cloning into non-empty directory")),
|
2021-07-10 07:48:00 +00:00
|
|
|
OPT_BOOL(0, "single-branch", &clone_data.single_branch,
|
2020-02-21 03:10:27 +00:00
|
|
|
N_("clone only one branch, HEAD or --branch")),
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
|
2015-09-08 18:57:45 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
|
|
|
N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
|
2016-02-29 22:58:33 +00:00
|
|
|
"[--reference <repository>] [--name <name>] [--depth <depth>] "
|
2022-04-06 20:32:57 +00:00
|
|
|
"[--single-branch] [--filter <filter-spec>] "
|
2016-02-29 22:58:33 +00:00
|
|
|
"--url <url> --path <path>"),
|
2015-09-08 18:57:45 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, module_clone_options,
|
|
|
|
git_submodule_helper_usage, 0);
|
|
|
|
|
2021-07-10 07:48:00 +00:00
|
|
|
clone_data.dissociate = !!dissociate;
|
|
|
|
clone_data.quiet = !!quiet;
|
|
|
|
clone_data.progress = !!progress;
|
|
|
|
clone_data.require_init = !!require_init;
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
clone_data.filter_options = &filter_options;
|
2021-07-10 07:48:00 +00:00
|
|
|
|
|
|
|
if (argc || !clone_data.url || !clone_data.path || !*(clone_data.path))
|
2016-02-29 22:58:31 +00:00
|
|
|
usage_with_options(git_submodule_helper_usage,
|
|
|
|
module_clone_options);
|
|
|
|
|
2022-08-31 23:17:56 +00:00
|
|
|
clone_submodule(&clone_data, &reference);
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
list_objects_filter_release(&filter_options);
|
submodule--helper: fix "reference" leak
Fix leaks in the "reference" variable declared in add_submodule() and
module_clone().
In preceding commits this variable was refactored out of the "struct
module_clone_data", but the leak has been with us since
31224cbdc72 (clone: recursive and reference option triggers submodule
alternates, 2016-08-17) and 8c8195e9c3e (submodule--helper: introduce
add-clone subcommand, 2021-07-10).
Those commits added an xstrdup()'d member of the
STRING_LIST_INIT_NODUP'd "struct string_list". We need to free()
those, but not the ones we get from argv, let's make use of the "util"
member, if it has a pointer it's the pointer we'll need to free,
otherwise it'll be NULL (i.e. from argv).
Note that the free() of the "util" member is needed in both
module_clone() and add_submodule(). The module_clone() function itself
doesn't populate the "util" pointer as add_submodule() does, but
module_clone() is upstream of the
add_possible_reference_from_superproject() caller we're modifying
here, which does do that.
This does preclude the use of the "util" pointer for any other reasons
for now, but that's OK. If we ever need to use it for something else
we could turn it into a small "struct" with an optional "to_free"
member, and switch to using string_list_clear_func().
Alternatively we could have another "struct string_list to_free" which
would keep a copy of the strings we've dup'd to free(). But for now
this is perfectly adequate.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:14:18 +00:00
|
|
|
string_list_clear(&reference, 1);
|
2015-09-08 18:57:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-09-02 21:42:24 +00:00
|
|
|
|
2022-08-31 23:18:08 +00:00
|
|
|
static int determine_submodule_update_strategy(struct repository *r,
|
|
|
|
int just_cloned,
|
|
|
|
const char *path,
|
|
|
|
enum submodule_update_type update,
|
|
|
|
struct submodule_update_strategy *out)
|
2018-08-13 22:42:35 +00:00
|
|
|
{
|
2021-04-26 01:02:56 +00:00
|
|
|
const struct submodule *sub = submodule_from_path(r, null_oid(), path);
|
2018-08-13 22:42:35 +00:00
|
|
|
char *key;
|
|
|
|
const char *val;
|
2022-08-31 23:18:08 +00:00
|
|
|
int ret;
|
2018-08-13 22:42:35 +00:00
|
|
|
|
|
|
|
key = xstrfmt("submodule.%s.update", sub->name);
|
|
|
|
|
|
|
|
if (update) {
|
2022-06-28 10:05:32 +00:00
|
|
|
out->type = update;
|
2020-08-14 16:17:36 +00:00
|
|
|
} else if (!repo_config_get_string_tmp(r, key, &val)) {
|
2022-08-31 23:18:08 +00:00
|
|
|
if (parse_submodule_update_strategy(val, out) < 0) {
|
|
|
|
ret = die_message(_("Invalid update mode '%s' configured for submodule path '%s'"),
|
|
|
|
val, path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-08-13 22:42:35 +00:00
|
|
|
} else if (sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
|
2019-12-05 09:28:28 +00:00
|
|
|
if (sub->update_strategy.type == SM_UPDATE_COMMAND)
|
|
|
|
BUG("how did we read update = !command from .gitmodules?");
|
2018-08-13 22:42:35 +00:00
|
|
|
out->type = sub->update_strategy.type;
|
|
|
|
out->command = sub->update_strategy.command;
|
|
|
|
} else
|
|
|
|
out->type = SM_UPDATE_CHECKOUT;
|
|
|
|
|
|
|
|
if (just_cloned &&
|
|
|
|
(out->type == SM_UPDATE_MERGE ||
|
|
|
|
out->type == SM_UPDATE_REBASE ||
|
|
|
|
out->type == SM_UPDATE_NONE))
|
|
|
|
out->type = SM_UPDATE_CHECKOUT;
|
|
|
|
|
2022-08-31 23:18:08 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2018-08-13 22:42:35 +00:00
|
|
|
free(key);
|
2022-08-31 23:18:08 +00:00
|
|
|
return ret;
|
2018-08-13 22:42:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 22:23:19 +00:00
|
|
|
struct update_clone_data {
|
|
|
|
const struct submodule *sub;
|
|
|
|
struct object_id oid;
|
|
|
|
unsigned just_cloned;
|
|
|
|
};
|
|
|
|
|
2016-03-01 02:07:17 +00:00
|
|
|
struct submodule_update_clone {
|
2022-03-15 21:09:22 +00:00
|
|
|
/* index into 'update_data.list', the list of submodules to look into for cloning */
|
2016-03-01 02:07:17 +00:00
|
|
|
int current;
|
|
|
|
|
|
|
|
/* configuration parameters which are passed on to the children */
|
2022-08-31 23:17:57 +00:00
|
|
|
const struct update_data *update_data;
|
2016-03-01 02:07:17 +00:00
|
|
|
|
2022-03-15 21:09:24 +00:00
|
|
|
/* to be consumed by update_submodule() */
|
2018-08-03 22:23:19 +00:00
|
|
|
struct update_clone_data *update_clone;
|
|
|
|
int update_clone_nr; int update_clone_alloc;
|
2016-03-01 02:07:17 +00:00
|
|
|
|
|
|
|
/* If we want to stop as fast as possible and return an error */
|
|
|
|
unsigned quickstop : 1;
|
2016-06-10 00:35:36 +00:00
|
|
|
|
|
|
|
/* failed clones to be retried again */
|
|
|
|
const struct cache_entry **failed_clones;
|
|
|
|
int failed_clones_nr, failed_clones_alloc;
|
2016-03-01 02:07:17 +00:00
|
|
|
};
|
2022-03-15 21:09:22 +00:00
|
|
|
#define SUBMODULE_UPDATE_CLONE_INIT { 0 }
|
2016-03-01 02:07:17 +00:00
|
|
|
|
2022-08-31 23:14:13 +00:00
|
|
|
static void submodule_update_clone_release(struct submodule_update_clone *suc)
|
|
|
|
{
|
|
|
|
free(suc->update_clone);
|
|
|
|
free(suc->failed_clones);
|
|
|
|
}
|
|
|
|
|
2021-08-24 14:06:09 +00:00
|
|
|
struct update_data {
|
2022-03-15 21:09:22 +00:00
|
|
|
const char *prefix;
|
2022-12-20 12:39:55 +00:00
|
|
|
const char *super_prefix;
|
2022-08-31 23:14:22 +00:00
|
|
|
char *displaypath;
|
2022-06-28 10:05:32 +00:00
|
|
|
enum submodule_update_type update_default;
|
2021-08-24 14:06:09 +00:00
|
|
|
struct object_id suboid;
|
2022-03-15 21:09:22 +00:00
|
|
|
struct string_list references;
|
2021-08-24 14:06:09 +00:00
|
|
|
struct submodule_update_strategy update_strategy;
|
2022-03-15 21:09:22 +00:00
|
|
|
struct list_objects_filter_options *filter_options;
|
|
|
|
struct module_list list;
|
2021-08-24 14:06:09 +00:00
|
|
|
int depth;
|
2022-03-15 21:09:22 +00:00
|
|
|
int max_jobs;
|
|
|
|
int single_branch;
|
|
|
|
int recommend_shallow;
|
|
|
|
unsigned int require_init;
|
2022-03-05 00:13:54 +00:00
|
|
|
unsigned int force;
|
|
|
|
unsigned int quiet;
|
|
|
|
unsigned int nofetch;
|
2022-03-05 00:13:55 +00:00
|
|
|
unsigned int remote;
|
2022-03-15 21:09:22 +00:00
|
|
|
unsigned int progress;
|
|
|
|
unsigned int dissociate;
|
|
|
|
unsigned int init;
|
|
|
|
unsigned int warn_if_uninitialized;
|
2022-03-15 21:09:24 +00:00
|
|
|
unsigned int recursive;
|
|
|
|
|
|
|
|
/* copied over from update_clone_data */
|
|
|
|
struct object_id oid;
|
|
|
|
unsigned int just_cloned;
|
|
|
|
const char *sm_path;
|
2021-08-24 14:06:09 +00:00
|
|
|
};
|
2022-03-15 21:09:22 +00:00
|
|
|
#define UPDATE_DATA_INIT { \
|
|
|
|
.update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT, \
|
|
|
|
.list = MODULE_LIST_INIT, \
|
|
|
|
.recommend_shallow = -1, \
|
|
|
|
.references = STRING_LIST_INIT_DUP, \
|
|
|
|
.single_branch = -1, \
|
|
|
|
.max_jobs = 1, \
|
|
|
|
}
|
2016-04-28 20:02:46 +00:00
|
|
|
|
2022-08-31 23:14:13 +00:00
|
|
|
static void update_data_release(struct update_data *ud)
|
|
|
|
{
|
2022-08-31 23:14:22 +00:00
|
|
|
free(ud->displaypath);
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&ud->list);
|
|
|
|
}
|
|
|
|
|
2016-04-28 20:02:46 +00:00
|
|
|
static void next_submodule_warn_missing(struct submodule_update_clone *suc,
|
|
|
|
struct strbuf *out, const char *displaypath)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Only mention uninitialized submodules when their
|
|
|
|
* paths have been specified.
|
|
|
|
*/
|
2022-03-15 21:09:22 +00:00
|
|
|
if (suc->update_data->warn_if_uninitialized) {
|
2016-04-28 20:02:46 +00:00
|
|
|
strbuf_addf(out,
|
|
|
|
_("Submodule path '%s' not initialized"),
|
|
|
|
displaypath);
|
|
|
|
strbuf_addch(out, '\n');
|
|
|
|
strbuf_addstr(out,
|
|
|
|
_("Maybe you want to use 'update --init'?"));
|
|
|
|
strbuf_addch(out, '\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-01 02:07:17 +00:00
|
|
|
/**
|
|
|
|
* Determine whether 'ce' needs to be cloned. If so, prepare the 'child' to
|
|
|
|
* run the clone. Returns 1 if 'ce' needs to be cloned, 0 otherwise.
|
|
|
|
*/
|
|
|
|
static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
|
|
|
|
struct child_process *child,
|
|
|
|
struct submodule_update_clone *suc,
|
|
|
|
struct strbuf *out)
|
|
|
|
{
|
|
|
|
const struct submodule *sub = NULL;
|
2017-08-03 18:19:50 +00:00
|
|
|
const char *url = NULL;
|
|
|
|
const char *update_string;
|
|
|
|
enum submodule_update_type update_type;
|
|
|
|
char *key;
|
2022-08-31 23:17:57 +00:00
|
|
|
const struct update_data *ud = suc->update_data;
|
2022-12-20 12:39:50 +00:00
|
|
|
char *displaypath = get_submodule_displaypath(ce->name, ud->prefix,
|
2022-12-20 12:39:55 +00:00
|
|
|
ud->super_prefix);
|
2016-03-01 02:07:17 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
int needs_cloning = 0;
|
2018-10-16 17:27:03 +00:00
|
|
|
int need_free_url = 0;
|
2016-03-01 02:07:17 +00:00
|
|
|
|
|
|
|
if (ce_stage(ce)) {
|
2022-07-01 02:11:52 +00:00
|
|
|
strbuf_addf(out, _("Skipping unmerged submodule %s"), displaypath);
|
2016-03-01 02:07:17 +00:00
|
|
|
strbuf_addch(out, '\n');
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2021-04-26 01:02:56 +00:00
|
|
|
sub = submodule_from_path(the_repository, null_oid(), ce->name);
|
2016-03-01 02:07:17 +00:00
|
|
|
|
2016-04-28 20:02:46 +00:00
|
|
|
if (!sub) {
|
|
|
|
next_submodule_warn_missing(suc, out, displaypath);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:19:50 +00:00
|
|
|
key = xstrfmt("submodule.%s.update", sub->name);
|
2020-08-14 16:17:36 +00:00
|
|
|
if (!repo_config_get_string_tmp(the_repository, key, &update_string)) {
|
2017-08-03 18:19:50 +00:00
|
|
|
update_type = parse_submodule_update_type(update_string);
|
|
|
|
} else {
|
|
|
|
update_type = sub->update_strategy.type;
|
|
|
|
}
|
|
|
|
free(key);
|
|
|
|
|
2022-03-15 21:09:22 +00:00
|
|
|
if (suc->update_data->update_strategy.type == SM_UPDATE_NONE
|
|
|
|
|| (suc->update_data->update_strategy.type == SM_UPDATE_UNSPECIFIED
|
2017-08-03 18:19:50 +00:00
|
|
|
&& update_type == SM_UPDATE_NONE)) {
|
2016-03-01 02:07:17 +00:00
|
|
|
strbuf_addf(out, _("Skipping submodule '%s'"), displaypath);
|
|
|
|
strbuf_addch(out, '\n');
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-03-16 22:29:47 +00:00
|
|
|
/* Check if the submodule has been initialized. */
|
2017-06-22 18:43:46 +00:00
|
|
|
if (!is_submodule_active(the_repository, ce->name)) {
|
2016-04-28 20:02:46 +00:00
|
|
|
next_submodule_warn_missing(suc, out, displaypath);
|
2016-03-01 02:07:17 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:19:50 +00:00
|
|
|
strbuf_reset(&sb);
|
|
|
|
strbuf_addf(&sb, "submodule.%s.url", sub->name);
|
2020-08-14 16:17:36 +00:00
|
|
|
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
|
2018-10-16 17:27:03 +00:00
|
|
|
if (starts_with_dot_slash(sub->url) ||
|
|
|
|
starts_with_dot_dot_slash(sub->url)) {
|
2021-08-10 11:46:41 +00:00
|
|
|
url = resolve_relative_url(sub->url, NULL, 0);
|
2018-10-16 17:27:03 +00:00
|
|
|
need_free_url = 1;
|
|
|
|
} else
|
|
|
|
url = sub->url;
|
|
|
|
}
|
2017-08-03 18:19:50 +00:00
|
|
|
|
2016-03-01 02:07:17 +00:00
|
|
|
strbuf_reset(&sb);
|
|
|
|
strbuf_addf(&sb, "%s/.git", ce->name);
|
|
|
|
needs_cloning = !file_exists(sb.buf);
|
|
|
|
|
2018-08-03 22:23:19 +00:00
|
|
|
ALLOC_GROW(suc->update_clone, suc->update_clone_nr + 1,
|
|
|
|
suc->update_clone_alloc);
|
|
|
|
oidcpy(&suc->update_clone[suc->update_clone_nr].oid, &ce->oid);
|
|
|
|
suc->update_clone[suc->update_clone_nr].just_cloned = needs_cloning;
|
|
|
|
suc->update_clone[suc->update_clone_nr].sub = sub;
|
|
|
|
suc->update_clone_nr++;
|
2016-03-01 02:07:17 +00:00
|
|
|
|
|
|
|
if (!needs_cloning)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
child->git_cmd = 1;
|
|
|
|
child->no_stdin = 1;
|
|
|
|
child->stdout_to_stderr = 1;
|
|
|
|
child->err = -1;
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&child->args, "submodule--helper");
|
|
|
|
strvec_push(&child->args, "clone");
|
2022-03-15 21:09:22 +00:00
|
|
|
if (suc->update_data->progress)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&child->args, "--progress");
|
2022-03-15 21:09:22 +00:00
|
|
|
if (suc->update_data->quiet)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&child->args, "--quiet");
|
2022-03-15 21:09:22 +00:00
|
|
|
if (suc->update_data->prefix)
|
|
|
|
strvec_pushl(&child->args, "--prefix", suc->update_data->prefix, NULL);
|
|
|
|
if (suc->update_data->recommend_shallow && sub->recommend_shallow == 1)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&child->args, "--depth=1");
|
2022-03-15 21:09:22 +00:00
|
|
|
else if (suc->update_data->depth)
|
|
|
|
strvec_pushf(&child->args, "--depth=%d", suc->update_data->depth);
|
|
|
|
if (suc->update_data->filter_options && suc->update_data->filter_options->choice)
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
strvec_pushf(&child->args, "--filter=%s",
|
2022-03-15 21:09:22 +00:00
|
|
|
expand_list_objects_filter_spec(suc->update_data->filter_options));
|
|
|
|
if (suc->update_data->require_init)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&child->args, "--require-init");
|
|
|
|
strvec_pushl(&child->args, "--path", sub->path, NULL);
|
|
|
|
strvec_pushl(&child->args, "--name", sub->name, NULL);
|
|
|
|
strvec_pushl(&child->args, "--url", url, NULL);
|
2022-03-15 21:09:22 +00:00
|
|
|
if (suc->update_data->references.nr) {
|
2016-08-11 23:14:01 +00:00
|
|
|
struct string_list_item *item;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2022-03-15 21:09:22 +00:00
|
|
|
for_each_string_list_item(item, &suc->update_data->references)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_pushl(&child->args, "--reference", item->string, NULL);
|
2016-08-11 23:14:01 +00:00
|
|
|
}
|
2022-03-15 21:09:22 +00:00
|
|
|
if (suc->update_data->dissociate)
|
2020-07-28 20:24:27 +00:00
|
|
|
strvec_push(&child->args, "--dissociate");
|
2022-03-15 21:09:22 +00:00
|
|
|
if (suc->update_data->single_branch >= 0)
|
|
|
|
strvec_push(&child->args, suc->update_data->single_branch ?
|
2020-02-21 03:10:27 +00:00
|
|
|
"--single-branch" :
|
|
|
|
"--no-single-branch");
|
2016-03-01 02:07:17 +00:00
|
|
|
|
|
|
|
cleanup:
|
2022-07-01 02:11:52 +00:00
|
|
|
free(displaypath);
|
2020-08-14 16:14:14 +00:00
|
|
|
strbuf_release(&sb);
|
2018-10-16 17:27:03 +00:00
|
|
|
if (need_free_url)
|
|
|
|
free((void*)url);
|
2016-03-01 02:07:17 +00:00
|
|
|
|
|
|
|
return needs_cloning;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int update_clone_get_next_task(struct child_process *child,
|
|
|
|
struct strbuf *err,
|
|
|
|
void *suc_cb,
|
2016-06-10 00:35:36 +00:00
|
|
|
void **idx_task_cb)
|
2016-03-01 02:07:17 +00:00
|
|
|
{
|
|
|
|
struct submodule_update_clone *suc = suc_cb;
|
2016-06-10 00:35:36 +00:00
|
|
|
const struct cache_entry *ce;
|
|
|
|
int index;
|
2016-03-01 02:07:17 +00:00
|
|
|
|
2022-03-15 21:09:22 +00:00
|
|
|
for (; suc->current < suc->update_data->list.nr; suc->current++) {
|
|
|
|
ce = suc->update_data->list.entries[suc->current];
|
2016-03-01 02:07:17 +00:00
|
|
|
if (prepare_to_clone_next_submodule(ce, child, suc, err)) {
|
2016-06-10 00:35:36 +00:00
|
|
|
int *p = xmalloc(sizeof(*p));
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2016-06-10 00:35:36 +00:00
|
|
|
*p = suc->current;
|
|
|
|
*idx_task_cb = p;
|
2016-03-01 02:07:17 +00:00
|
|
|
suc->current++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2016-06-10 00:35:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The loop above tried cloning each submodule once, now try the
|
|
|
|
* stragglers again, which we can imagine as an extension of the
|
|
|
|
* entry list.
|
|
|
|
*/
|
2022-03-15 21:09:22 +00:00
|
|
|
index = suc->current - suc->update_data->list.nr;
|
2016-06-10 00:35:36 +00:00
|
|
|
if (index < suc->failed_clones_nr) {
|
|
|
|
int *p;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2016-06-10 00:35:36 +00:00
|
|
|
ce = suc->failed_clones[index];
|
submodule--helper: use parallel processor correctly
When developing another patch series I had a temporary state in
which git-clone would segfault, when the call was prepared in
prepare_to_clone_next_submodule. This lead to the call failing,
i.e. in `update_clone_task_finished` the task was scheduled to be
tried again. The second call to prepare_to_clone_next_submodule
would return 0, as the segfaulted clone did create the .git file
already, such that was not considered to need to be cloned again. I
was seeing the "BUG: ce was a submodule before?\n" message, which
was the correct behavior at the time as my local code was
buggy. When trying to debug this failure, I tried to use printing
messages into the strbuf that is passed around, but these messages
were never printed as the die(..) doesn't flush the `err` strbuf.
When implementing the die() in 665b35ecc (2016-06-09, "submodule--helper:
initial clone learns retry logic"), I considered this condition to be
a severe condition, which should lead to an immediate abort as we do not
trust ourselves any more. However the queued messages in `err` are valuable
so let's not toss them out by immediately dying, but a graceful return.
Another thing to note: The error message itself was misleading. A return
value of 0 doesn't indicate the passed in `ce` is not a submodule any more,
but just that we do not consider cloning it any more.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-08-09 21:29:13 +00:00
|
|
|
if (!prepare_to_clone_next_submodule(ce, child, suc, err)) {
|
|
|
|
suc->current ++;
|
2016-09-15 18:31:00 +00:00
|
|
|
strbuf_addstr(err, "BUG: submodule considered for "
|
|
|
|
"cloning, doesn't need cloning "
|
|
|
|
"any more?\n");
|
submodule--helper: use parallel processor correctly
When developing another patch series I had a temporary state in
which git-clone would segfault, when the call was prepared in
prepare_to_clone_next_submodule. This lead to the call failing,
i.e. in `update_clone_task_finished` the task was scheduled to be
tried again. The second call to prepare_to_clone_next_submodule
would return 0, as the segfaulted clone did create the .git file
already, such that was not considered to need to be cloned again. I
was seeing the "BUG: ce was a submodule before?\n" message, which
was the correct behavior at the time as my local code was
buggy. When trying to debug this failure, I tried to use printing
messages into the strbuf that is passed around, but these messages
were never printed as the die(..) doesn't flush the `err` strbuf.
When implementing the die() in 665b35ecc (2016-06-09, "submodule--helper:
initial clone learns retry logic"), I considered this condition to be
a severe condition, which should lead to an immediate abort as we do not
trust ourselves any more. However the queued messages in `err` are valuable
so let's not toss them out by immediately dying, but a graceful return.
Another thing to note: The error message itself was misleading. A return
value of 0 doesn't indicate the passed in `ce` is not a submodule any more,
but just that we do not consider cloning it any more.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-08-09 21:29:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-06-10 00:35:36 +00:00
|
|
|
p = xmalloc(sizeof(*p));
|
|
|
|
*p = suc->current;
|
|
|
|
*idx_task_cb = p;
|
|
|
|
suc->current ++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-01 02:07:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int update_clone_start_failure(struct strbuf *err,
|
|
|
|
void *suc_cb,
|
2016-06-10 00:35:36 +00:00
|
|
|
void *idx_task_cb)
|
2016-03-01 02:07:17 +00:00
|
|
|
{
|
|
|
|
struct submodule_update_clone *suc = suc_cb;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2016-03-01 02:07:17 +00:00
|
|
|
suc->quickstop = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int update_clone_task_finished(int result,
|
|
|
|
struct strbuf *err,
|
|
|
|
void *suc_cb,
|
2016-06-10 00:35:36 +00:00
|
|
|
void *idx_task_cb)
|
2016-03-01 02:07:17 +00:00
|
|
|
{
|
2016-06-10 00:35:36 +00:00
|
|
|
const struct cache_entry *ce;
|
2016-03-01 02:07:17 +00:00
|
|
|
struct submodule_update_clone *suc = suc_cb;
|
2017-07-19 14:56:19 +00:00
|
|
|
int *idxP = idx_task_cb;
|
2016-06-10 00:35:36 +00:00
|
|
|
int idx = *idxP;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2016-06-10 00:35:36 +00:00
|
|
|
free(idxP);
|
|
|
|
|
2016-03-01 02:07:17 +00:00
|
|
|
if (!result)
|
|
|
|
return 0;
|
|
|
|
|
2022-03-15 21:09:22 +00:00
|
|
|
if (idx < suc->update_data->list.nr) {
|
|
|
|
ce = suc->update_data->list.entries[idx];
|
2016-06-10 00:35:36 +00:00
|
|
|
strbuf_addf(err, _("Failed to clone '%s'. Retry scheduled"),
|
|
|
|
ce->name);
|
|
|
|
strbuf_addch(err, '\n');
|
|
|
|
ALLOC_GROW(suc->failed_clones,
|
|
|
|
suc->failed_clones_nr + 1,
|
|
|
|
suc->failed_clones_alloc);
|
|
|
|
suc->failed_clones[suc->failed_clones_nr++] = ce;
|
|
|
|
return 0;
|
|
|
|
} else {
|
2022-03-15 21:09:22 +00:00
|
|
|
idx -= suc->update_data->list.nr;
|
2016-06-10 00:35:36 +00:00
|
|
|
ce = suc->failed_clones[idx];
|
|
|
|
strbuf_addf(err, _("Failed to clone '%s' a second time, aborting"),
|
|
|
|
ce->name);
|
|
|
|
strbuf_addch(err, '\n');
|
|
|
|
suc->quickstop = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-03-01 02:07:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 10:47:07 +00:00
|
|
|
static int git_update_clone_config(const char *var, const char *value,
|
|
|
|
void *cb)
|
2017-08-02 19:49:18 +00:00
|
|
|
{
|
|
|
|
int *max_jobs = cb;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2017-08-02 19:49:18 +00:00
|
|
|
if (!strcmp(var, "submodule.fetchjobs"))
|
|
|
|
*max_jobs = parse_submodule_fetchjobs(var, value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:17:58 +00:00
|
|
|
static int is_tip_reachable(const char *path, const struct object_id *oid)
|
2021-08-24 14:06:09 +00:00
|
|
|
{
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
struct strbuf rev = STRBUF_INIT;
|
|
|
|
char *hex = oid_to_hex(oid);
|
|
|
|
|
|
|
|
cp.git_cmd = 1;
|
2022-08-31 23:14:12 +00:00
|
|
|
cp.dir = path;
|
2021-08-24 14:06:09 +00:00
|
|
|
cp.no_stderr = 1;
|
|
|
|
strvec_pushl(&cp.args, "rev-list", "-n", "1", hex, "--not", "--all", NULL);
|
|
|
|
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp.env);
|
2021-08-24 14:06:09 +00:00
|
|
|
|
|
|
|
if (capture_command(&cp, &rev, GIT_MAX_HEXSZ + 1) || rev.len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:17:58 +00:00
|
|
|
static int fetch_in_submodule(const char *module_path, int depth, int quiet,
|
|
|
|
const struct object_id *oid)
|
2021-08-24 14:06:09 +00:00
|
|
|
{
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp.env);
|
2021-08-24 14:06:09 +00:00
|
|
|
cp.git_cmd = 1;
|
2022-08-31 23:14:12 +00:00
|
|
|
cp.dir = module_path;
|
2021-08-24 14:06:09 +00:00
|
|
|
|
|
|
|
strvec_push(&cp.args, "fetch");
|
|
|
|
if (quiet)
|
|
|
|
strvec_push(&cp.args, "--quiet");
|
|
|
|
if (depth)
|
|
|
|
strvec_pushf(&cp.args, "--depth=%d", depth);
|
|
|
|
if (oid) {
|
|
|
|
char *hex = oid_to_hex(oid);
|
|
|
|
char *remote = get_default_remote();
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2021-08-24 14:06:09 +00:00
|
|
|
strvec_pushl(&cp.args, remote, hex, NULL);
|
2022-06-15 23:35:41 +00:00
|
|
|
free(remote);
|
2021-08-24 14:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return run_command(&cp);
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:18:09 +00:00
|
|
|
static int run_update_command(const struct update_data *ud, int subforce)
|
2021-08-24 14:06:09 +00:00
|
|
|
{
|
2022-03-15 21:09:19 +00:00
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
2021-08-24 14:06:09 +00:00
|
|
|
char *oid = oid_to_hex(&ud->oid);
|
submodule--helper update: don't override 'checkout' exit code
When "git submodule update" runs it might call "checkout", "merge",
"rebase", or a custom command. Ever since run_update_command() was
added in c51f8f94e5b (submodule--helper: run update procedures from C,
2021-08-24) we'd either exit immediately if the
"submodule.<name>.update" method failed, or in the case of "checkout"
continue trying to update other submodules.
This code used to use the magical "2" return code, but in
55b3f12cb54 (submodule update: use die_message(), 2022-03-15) it was
made to exit(128), which in preceding commits has been changed to
return that 128 code to the top-level.
Let's "libify" this code even more by not having it arbitrarily
override the return code. In practice this doesn't change anything as
the code "git checkout" would return on any normal failure is "1", but
we'll now in principle properly abort the operation if "git checkout"
were to exit with 128.
It would make sense to follow-up this change with a change to allow
the "submodule.<name>.update = !..." (SM_UPDATE_COMMAND) method the
same liberties as "checkout", and perhaps to do the same with a failed
"merge" or "rebase". But let's leave that for now.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:18:10 +00:00
|
|
|
int ret;
|
2021-08-24 14:06:09 +00:00
|
|
|
|
|
|
|
switch (ud->update_strategy.type) {
|
|
|
|
case SM_UPDATE_CHECKOUT:
|
2022-03-15 21:09:19 +00:00
|
|
|
cp.git_cmd = 1;
|
|
|
|
strvec_pushl(&cp.args, "checkout", "-q", NULL);
|
2021-08-24 14:06:09 +00:00
|
|
|
if (subforce)
|
2022-03-15 21:09:19 +00:00
|
|
|
strvec_push(&cp.args, "-f");
|
2021-08-24 14:06:09 +00:00
|
|
|
break;
|
|
|
|
case SM_UPDATE_REBASE:
|
2022-03-15 21:09:19 +00:00
|
|
|
cp.git_cmd = 1;
|
|
|
|
strvec_push(&cp.args, "rebase");
|
2021-08-24 14:06:09 +00:00
|
|
|
if (ud->quiet)
|
2022-03-15 21:09:19 +00:00
|
|
|
strvec_push(&cp.args, "--quiet");
|
2021-08-24 14:06:09 +00:00
|
|
|
break;
|
|
|
|
case SM_UPDATE_MERGE:
|
2022-03-15 21:09:19 +00:00
|
|
|
cp.git_cmd = 1;
|
|
|
|
strvec_push(&cp.args, "merge");
|
2021-08-24 14:06:09 +00:00
|
|
|
if (ud->quiet)
|
2022-03-15 21:09:19 +00:00
|
|
|
strvec_push(&cp.args, "--quiet");
|
2021-08-24 14:06:09 +00:00
|
|
|
break;
|
|
|
|
case SM_UPDATE_COMMAND:
|
2022-03-15 21:09:19 +00:00
|
|
|
cp.use_shell = 1;
|
|
|
|
strvec_push(&cp.args, ud->update_strategy.command);
|
2021-08-24 14:06:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2022-08-31 23:18:04 +00:00
|
|
|
BUG("unexpected update strategy type: %d",
|
|
|
|
ud->update_strategy.type);
|
2021-08-24 14:06:09 +00:00
|
|
|
}
|
2022-03-15 21:09:19 +00:00
|
|
|
strvec_push(&cp.args, oid);
|
2021-08-24 14:06:09 +00:00
|
|
|
|
2022-08-31 23:14:12 +00:00
|
|
|
cp.dir = ud->sm_path;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp.env);
|
submodule--helper update: don't override 'checkout' exit code
When "git submodule update" runs it might call "checkout", "merge",
"rebase", or a custom command. Ever since run_update_command() was
added in c51f8f94e5b (submodule--helper: run update procedures from C,
2021-08-24) we'd either exit immediately if the
"submodule.<name>.update" method failed, or in the case of "checkout"
continue trying to update other submodules.
This code used to use the magical "2" return code, but in
55b3f12cb54 (submodule update: use die_message(), 2022-03-15) it was
made to exit(128), which in preceding commits has been changed to
return that 128 code to the top-level.
Let's "libify" this code even more by not having it arbitrarily
override the return code. In practice this doesn't change anything as
the code "git checkout" would return on any normal failure is "1", but
we'll now in principle properly abort the operation if "git checkout"
were to exit with 128.
It would make sense to follow-up this change with a change to allow
the "submodule.<name>.update = !..." (SM_UPDATE_COMMAND) method the
same liberties as "checkout", and perhaps to do the same with a failed
"merge" or "rebase". But let's leave that for now.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:18:10 +00:00
|
|
|
if ((ret = run_command(&cp))) {
|
2021-08-24 14:06:09 +00:00
|
|
|
switch (ud->update_strategy.type) {
|
|
|
|
case SM_UPDATE_CHECKOUT:
|
2022-03-15 21:09:20 +00:00
|
|
|
die_message(_("Unable to checkout '%s' in submodule path '%s'"),
|
|
|
|
oid, ud->displaypath);
|
submodule--helper update: don't override 'checkout' exit code
When "git submodule update" runs it might call "checkout", "merge",
"rebase", or a custom command. Ever since run_update_command() was
added in c51f8f94e5b (submodule--helper: run update procedures from C,
2021-08-24) we'd either exit immediately if the
"submodule.<name>.update" method failed, or in the case of "checkout"
continue trying to update other submodules.
This code used to use the magical "2" return code, but in
55b3f12cb54 (submodule update: use die_message(), 2022-03-15) it was
made to exit(128), which in preceding commits has been changed to
return that 128 code to the top-level.
Let's "libify" this code even more by not having it arbitrarily
override the return code. In practice this doesn't change anything as
the code "git checkout" would return on any normal failure is "1", but
we'll now in principle properly abort the operation if "git checkout"
were to exit with 128.
It would make sense to follow-up this change with a change to allow
the "submodule.<name>.update = !..." (SM_UPDATE_COMMAND) method the
same liberties as "checkout", and perhaps to do the same with a failed
"merge" or "rebase". But let's leave that for now.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:18:10 +00:00
|
|
|
/* No "ret" assignment, use "git checkout"'s */
|
2021-08-24 14:06:09 +00:00
|
|
|
break;
|
|
|
|
case SM_UPDATE_REBASE:
|
2022-08-31 23:18:06 +00:00
|
|
|
ret = die_message(_("Unable to rebase '%s' in submodule path '%s'"),
|
|
|
|
oid, ud->displaypath);
|
2021-08-24 14:06:09 +00:00
|
|
|
break;
|
|
|
|
case SM_UPDATE_MERGE:
|
2022-08-31 23:18:06 +00:00
|
|
|
ret = die_message(_("Unable to merge '%s' in submodule path '%s'"),
|
|
|
|
oid, ud->displaypath);
|
2021-08-24 14:06:09 +00:00
|
|
|
break;
|
|
|
|
case SM_UPDATE_COMMAND:
|
2022-08-31 23:18:06 +00:00
|
|
|
ret = die_message(_("Execution of '%s %s' failed in submodule path '%s'"),
|
|
|
|
ud->update_strategy.command, oid, ud->displaypath);
|
2021-08-24 14:06:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2022-08-31 23:18:04 +00:00
|
|
|
BUG("unexpected update strategy type: %d",
|
|
|
|
ud->update_strategy.type);
|
2021-08-24 14:06:09 +00:00
|
|
|
}
|
2022-03-15 21:09:20 +00:00
|
|
|
|
2022-08-31 23:18:06 +00:00
|
|
|
return ret;
|
2021-08-24 14:06:09 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 21:09:20 +00:00
|
|
|
if (ud->quiet)
|
|
|
|
return 0;
|
|
|
|
|
2021-08-24 14:06:09 +00:00
|
|
|
switch (ud->update_strategy.type) {
|
|
|
|
case SM_UPDATE_CHECKOUT:
|
|
|
|
printf(_("Submodule path '%s': checked out '%s'\n"),
|
|
|
|
ud->displaypath, oid);
|
|
|
|
break;
|
|
|
|
case SM_UPDATE_REBASE:
|
|
|
|
printf(_("Submodule path '%s': rebased into '%s'\n"),
|
|
|
|
ud->displaypath, oid);
|
|
|
|
break;
|
|
|
|
case SM_UPDATE_MERGE:
|
|
|
|
printf(_("Submodule path '%s': merged in '%s'\n"),
|
|
|
|
ud->displaypath, oid);
|
|
|
|
break;
|
|
|
|
case SM_UPDATE_COMMAND:
|
|
|
|
printf(_("Submodule path '%s': '%s %s'\n"),
|
|
|
|
ud->displaypath, ud->update_strategy.command, oid);
|
|
|
|
break;
|
|
|
|
default:
|
2022-08-31 23:18:04 +00:00
|
|
|
BUG("unexpected update strategy type: %d",
|
|
|
|
ud->update_strategy.type);
|
2021-08-24 14:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:18:09 +00:00
|
|
|
static int run_update_procedure(const struct update_data *ud)
|
2021-08-24 14:06:09 +00:00
|
|
|
{
|
|
|
|
int subforce = is_null_oid(&ud->suboid) || ud->force;
|
|
|
|
|
|
|
|
if (!ud->nofetch) {
|
|
|
|
/*
|
|
|
|
* Run fetch only if `oid` isn't present or it
|
|
|
|
* is not reachable from a ref.
|
|
|
|
*/
|
|
|
|
if (!is_tip_reachable(ud->sm_path, &ud->oid) &&
|
|
|
|
fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, NULL) &&
|
|
|
|
!ud->quiet)
|
|
|
|
fprintf_ln(stderr,
|
|
|
|
_("Unable to fetch in submodule path '%s'; "
|
|
|
|
"trying to directly fetch %s:"),
|
|
|
|
ud->displaypath, oid_to_hex(&ud->oid));
|
|
|
|
/*
|
|
|
|
* Now we tried the usual fetch, but `oid` may
|
|
|
|
* not be reachable from any of the refs.
|
|
|
|
*/
|
|
|
|
if (!is_tip_reachable(ud->sm_path, &ud->oid) &&
|
|
|
|
fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, &ud->oid))
|
2022-08-31 23:18:11 +00:00
|
|
|
return die_message(_("Fetched in submodule path '%s', but it did not "
|
|
|
|
"contain %s. Direct fetching of that commit failed."),
|
|
|
|
ud->displaypath, oid_to_hex(&ud->oid));
|
2021-08-24 14:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return run_update_command(ud, subforce);
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:18:14 +00:00
|
|
|
static int remote_submodule_branch(const char *path, const char **branch)
|
2022-03-15 21:09:25 +00:00
|
|
|
{
|
|
|
|
const struct submodule *sub;
|
|
|
|
char *key;
|
2022-08-31 23:18:14 +00:00
|
|
|
*branch = NULL;
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
sub = submodule_from_path(the_repository, null_oid(), path);
|
|
|
|
if (!sub)
|
2022-08-31 23:18:14 +00:00
|
|
|
return die_message(_("could not initialize submodule at path '%s'"),
|
|
|
|
path);
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
key = xstrfmt("submodule.%s.branch", sub->name);
|
2022-08-31 23:18:14 +00:00
|
|
|
if (repo_config_get_string_tmp(the_repository, key, branch))
|
|
|
|
*branch = sub->branch;
|
2022-03-15 21:09:25 +00:00
|
|
|
free(key);
|
|
|
|
|
2022-08-31 23:18:14 +00:00
|
|
|
if (!*branch) {
|
|
|
|
*branch = "HEAD";
|
|
|
|
return 0;
|
|
|
|
}
|
2022-03-15 21:09:25 +00:00
|
|
|
|
2022-08-31 23:18:14 +00:00
|
|
|
if (!strcmp(*branch, ".")) {
|
2022-03-15 21:09:25 +00:00
|
|
|
const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
|
|
|
|
|
|
|
|
if (!refname)
|
2022-08-31 23:18:14 +00:00
|
|
|
return die_message(_("No such ref: %s"), "HEAD");
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
/* detached HEAD */
|
|
|
|
if (!strcmp(refname, "HEAD"))
|
2022-08-31 23:18:14 +00:00
|
|
|
return die_message(_("Submodule (%s) branch configured to inherit "
|
|
|
|
"branch from superproject, but the superproject "
|
|
|
|
"is not on any branch"), sub->name);
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
if (!skip_prefix(refname, "refs/heads/", &refname))
|
2022-08-31 23:18:14 +00:00
|
|
|
return die_message(_("Expecting a full ref name, got %s"),
|
|
|
|
refname);
|
|
|
|
|
|
|
|
*branch = refname;
|
|
|
|
return 0;
|
2022-03-15 21:09:25 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 23:18:14 +00:00
|
|
|
/* Our "branch" is coming from repo_config_get_string_tmp() */
|
|
|
|
return 0;
|
2022-03-15 21:09:25 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 23:18:11 +00:00
|
|
|
static int ensure_core_worktree(const char *path)
|
2022-03-15 21:09:25 +00:00
|
|
|
{
|
|
|
|
const char *cw;
|
|
|
|
struct repository subrepo;
|
|
|
|
|
|
|
|
if (repo_submodule_init(&subrepo, the_repository, path, null_oid()))
|
2022-08-31 23:18:11 +00:00
|
|
|
return die_message(_("could not get a repository handle for submodule '%s'"),
|
|
|
|
path);
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) {
|
|
|
|
char *cfg_file, *abs_path;
|
|
|
|
const char *rel_path;
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
|
|
|
|
cfg_file = repo_git_path(&subrepo, "config");
|
|
|
|
|
|
|
|
abs_path = absolute_pathdup(path);
|
|
|
|
rel_path = relative_path(abs_path, subrepo.gitdir, &sb);
|
|
|
|
|
|
|
|
git_config_set_in_file(cfg_file, "core.worktree", rel_path);
|
|
|
|
|
|
|
|
free(cfg_file);
|
|
|
|
free(abs_path);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
2022-08-31 23:18:11 +00:00
|
|
|
|
2022-08-31 23:14:16 +00:00
|
|
|
repo_clear(&subrepo);
|
2022-08-31 23:18:11 +00:00
|
|
|
return 0;
|
2022-03-15 21:09:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 10:05:31 +00:00
|
|
|
static const char *submodule_update_type_to_label(enum submodule_update_type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case SM_UPDATE_CHECKOUT:
|
|
|
|
return "checkout";
|
|
|
|
case SM_UPDATE_MERGE:
|
|
|
|
return "merge";
|
|
|
|
case SM_UPDATE_REBASE:
|
|
|
|
return "rebase";
|
|
|
|
case SM_UPDATE_UNSPECIFIED:
|
|
|
|
case SM_UPDATE_NONE:
|
|
|
|
case SM_UPDATE_COMMAND:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BUG("unreachable with type %d", type);
|
|
|
|
}
|
|
|
|
|
2022-08-31 23:17:58 +00:00
|
|
|
static void update_data_to_args(const struct update_data *update_data,
|
|
|
|
struct strvec *args)
|
2022-03-15 21:09:25 +00:00
|
|
|
{
|
2022-06-28 10:05:32 +00:00
|
|
|
enum submodule_update_type update_type = update_data->update_default;
|
|
|
|
|
2022-12-20 12:39:55 +00:00
|
|
|
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
|
2022-07-01 02:11:53 +00:00
|
|
|
if (update_data->displaypath) {
|
2022-07-01 02:11:56 +00:00
|
|
|
strvec_push(args, "--super-prefix");
|
2022-07-01 02:11:53 +00:00
|
|
|
strvec_pushf(args, "%s/", update_data->displaypath);
|
|
|
|
}
|
2022-07-01 02:11:56 +00:00
|
|
|
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
|
2022-03-15 21:09:25 +00:00
|
|
|
if (update_data->quiet)
|
|
|
|
strvec_push(args, "--quiet");
|
|
|
|
if (update_data->force)
|
|
|
|
strvec_push(args, "--force");
|
|
|
|
if (update_data->init)
|
|
|
|
strvec_push(args, "--init");
|
|
|
|
if (update_data->remote)
|
|
|
|
strvec_push(args, "--remote");
|
|
|
|
if (update_data->nofetch)
|
|
|
|
strvec_push(args, "--no-fetch");
|
|
|
|
if (update_data->dissociate)
|
|
|
|
strvec_push(args, "--dissociate");
|
|
|
|
if (update_data->progress)
|
|
|
|
strvec_push(args, "--progress");
|
|
|
|
if (update_data->require_init)
|
|
|
|
strvec_push(args, "--require-init");
|
|
|
|
if (update_data->depth)
|
|
|
|
strvec_pushf(args, "--depth=%d", update_data->depth);
|
2022-06-28 10:05:32 +00:00
|
|
|
if (update_type != SM_UPDATE_UNSPECIFIED)
|
|
|
|
strvec_pushf(args, "--%s",
|
|
|
|
submodule_update_type_to_label(update_type));
|
|
|
|
|
2022-03-15 21:09:25 +00:00
|
|
|
if (update_data->references.nr) {
|
|
|
|
struct string_list_item *item;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2022-03-15 21:09:25 +00:00
|
|
|
for_each_string_list_item(item, &update_data->references)
|
|
|
|
strvec_pushl(args, "--reference", item->string, NULL);
|
|
|
|
}
|
|
|
|
if (update_data->filter_options && update_data->filter_options->choice)
|
|
|
|
strvec_pushf(args, "--filter=%s",
|
|
|
|
expand_list_objects_filter_spec(
|
|
|
|
update_data->filter_options));
|
|
|
|
if (update_data->recommend_shallow == 0)
|
|
|
|
strvec_push(args, "--no-recommend-shallow");
|
|
|
|
else if (update_data->recommend_shallow == 1)
|
|
|
|
strvec_push(args, "--recommend-shallow");
|
|
|
|
if (update_data->single_branch >= 0)
|
|
|
|
strvec_push(args, update_data->single_branch ?
|
|
|
|
"--single-branch" :
|
|
|
|
"--no-single-branch");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int update_submodule(struct update_data *update_data)
|
|
|
|
{
|
2022-08-31 23:18:08 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = determine_submodule_update_strategy(the_repository,
|
|
|
|
update_data->just_cloned,
|
|
|
|
update_data->sm_path,
|
|
|
|
update_data->update_default,
|
|
|
|
&update_data->update_strategy);
|
2022-08-31 23:18:09 +00:00
|
|
|
if (ret)
|
2022-08-31 23:18:08 +00:00
|
|
|
return ret;
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
if (update_data->just_cloned)
|
|
|
|
oidcpy(&update_data->suboid, null_oid());
|
|
|
|
else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid))
|
2022-08-31 23:18:11 +00:00
|
|
|
return die_message(_("Unable to find current revision in submodule path '%s'"),
|
|
|
|
update_data->displaypath);
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
if (update_data->remote) {
|
2022-08-31 23:18:13 +00:00
|
|
|
char *remote_name;
|
|
|
|
const char *branch;
|
|
|
|
char *remote_ref;
|
|
|
|
int code;
|
|
|
|
|
|
|
|
code = get_default_remote_submodule(update_data->sm_path, &remote_name);
|
|
|
|
if (code)
|
|
|
|
return code;
|
2022-08-31 23:18:14 +00:00
|
|
|
code = remote_submodule_branch(update_data->sm_path, &branch);
|
|
|
|
if (code)
|
|
|
|
return code;
|
2022-08-31 23:18:13 +00:00
|
|
|
remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch);
|
2022-03-15 21:09:25 +00:00
|
|
|
|
2022-08-31 23:14:09 +00:00
|
|
|
free(remote_name);
|
|
|
|
|
2022-03-15 21:09:25 +00:00
|
|
|
if (!update_data->nofetch) {
|
|
|
|
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
|
|
|
|
0, NULL))
|
2022-08-31 23:18:11 +00:00
|
|
|
return die_message(_("Unable to fetch in submodule path '%s'"),
|
|
|
|
update_data->sm_path);
|
2022-03-15 21:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid))
|
2022-08-31 23:18:11 +00:00
|
|
|
return die_message(_("Unable to find %s revision in submodule path '%s'"),
|
|
|
|
remote_ref, update_data->sm_path);
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
free(remote_ref);
|
|
|
|
}
|
|
|
|
|
submodule--helper: don't exit() on failure, return
Change code downstream of module_update() to short-circuit and return
to the top-level on failure, rather than calling exit().
To do so we need to diligently check whether we "must_die_on_failure",
which is a pattern started in c51f8f94e5b (submodule--helper: run
update procedures from C, 2021-08-24), but which hadn't been completed
to the point where we could avoid calling exit() here.
This introduces no functional changes, but makes it easier to both
call these routines as a library in the future, and to eventually
avoid leaking memory.
This and similar control flow in submodule--helper.c could be made
simpler by properly "libifying" it, i.e. to have it consistently
return -1 on failures, and to early return on any non-success.
But let's leave that larger project for now, and (mostly) emulate what
were doing with the "exit(128)" before this change.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:18:07 +00:00
|
|
|
if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) {
|
2022-08-31 23:18:09 +00:00
|
|
|
ret = run_update_procedure(update_data);
|
submodule--helper: don't exit() on failure, return
Change code downstream of module_update() to short-circuit and return
to the top-level on failure, rather than calling exit().
To do so we need to diligently check whether we "must_die_on_failure",
which is a pattern started in c51f8f94e5b (submodule--helper: run
update procedures from C, 2021-08-24), but which hadn't been completed
to the point where we could avoid calling exit() here.
This introduces no functional changes, but makes it easier to both
call these routines as a library in the future, and to eventually
avoid leaking memory.
This and similar control flow in submodule--helper.c could be made
simpler by properly "libifying" it, i.e. to have it consistently
return -1 on failures, and to early return on any non-success.
But let's leave that larger project for now, and (mostly) emulate what
were doing with the "exit(128)" before this change.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:18:07 +00:00
|
|
|
if (ret)
|
2022-08-31 23:18:09 +00:00
|
|
|
return ret;
|
submodule--helper: don't exit() on failure, return
Change code downstream of module_update() to short-circuit and return
to the top-level on failure, rather than calling exit().
To do so we need to diligently check whether we "must_die_on_failure",
which is a pattern started in c51f8f94e5b (submodule--helper: run
update procedures from C, 2021-08-24), but which hadn't been completed
to the point where we could avoid calling exit() here.
This introduces no functional changes, but makes it easier to both
call these routines as a library in the future, and to eventually
avoid leaking memory.
This and similar control flow in submodule--helper.c could be made
simpler by properly "libifying" it, i.e. to have it consistently
return -1 on failures, and to early return on any non-success.
But let's leave that larger project for now, and (mostly) emulate what
were doing with the "exit(128)" before this change.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:18:07 +00:00
|
|
|
}
|
2022-03-15 21:09:25 +00:00
|
|
|
|
|
|
|
if (update_data->recursive) {
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
|
|
|
struct update_data next = *update_data;
|
|
|
|
|
|
|
|
next.prefix = NULL;
|
|
|
|
oidcpy(&next.oid, null_oid());
|
|
|
|
oidcpy(&next.suboid, null_oid());
|
|
|
|
|
|
|
|
cp.dir = update_data->sm_path;
|
|
|
|
cp.git_cmd = 1;
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp.env);
|
2022-03-15 21:09:25 +00:00
|
|
|
update_data_to_args(&next, &cp.args);
|
|
|
|
|
2022-08-31 23:18:01 +00:00
|
|
|
ret = run_command(&cp);
|
2022-08-31 23:18:09 +00:00
|
|
|
if (ret)
|
|
|
|
die_message(_("Failed to recurse into submodule path '%s'"),
|
|
|
|
update_data->displaypath);
|
2022-08-31 23:18:02 +00:00
|
|
|
return ret;
|
2022-03-15 21:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-15 21:09:22 +00:00
|
|
|
static int update_submodules(struct update_data *update_data)
|
2018-08-03 22:23:18 +00:00
|
|
|
{
|
2022-08-31 23:18:01 +00:00
|
|
|
int i, ret = 0;
|
2022-03-15 21:09:22 +00:00
|
|
|
struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
|
2022-10-12 21:02:27 +00:00
|
|
|
const struct run_process_parallel_opts opts = {
|
|
|
|
.tr2_category = "submodule",
|
|
|
|
.tr2_label = "parallel/update",
|
|
|
|
|
|
|
|
.processes = update_data->max_jobs,
|
|
|
|
|
|
|
|
.get_next_task = update_clone_get_next_task,
|
|
|
|
.start_failure = update_clone_start_failure,
|
|
|
|
.task_finished = update_clone_task_finished,
|
|
|
|
.data = &suc,
|
|
|
|
};
|
2018-08-03 22:23:18 +00:00
|
|
|
|
2022-03-15 21:09:22 +00:00
|
|
|
suc.update_data = update_data;
|
2022-10-12 21:02:27 +00:00
|
|
|
run_processes_parallel(&opts);
|
2018-08-03 22:23:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We saved the output and put it out all at once now.
|
|
|
|
* That means:
|
|
|
|
* - the listener does not have to interleave their (checkout)
|
|
|
|
* work with our fetching. The writes involved in a
|
|
|
|
* checkout involve more straightforward sequential I/O.
|
|
|
|
* - the listener can avoid doing any work if fetching failed.
|
|
|
|
*/
|
2022-03-15 21:09:24 +00:00
|
|
|
if (suc.quickstop) {
|
2022-08-31 23:18:01 +00:00
|
|
|
ret = 1;
|
2022-03-15 21:09:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-08-03 22:23:18 +00:00
|
|
|
|
2022-03-15 21:09:24 +00:00
|
|
|
for (i = 0; i < suc.update_clone_nr; i++) {
|
|
|
|
struct update_clone_data ucd = suc.update_clone[i];
|
submodule--helper: don't exit() on failure, return
Change code downstream of module_update() to short-circuit and return
to the top-level on failure, rather than calling exit().
To do so we need to diligently check whether we "must_die_on_failure",
which is a pattern started in c51f8f94e5b (submodule--helper: run
update procedures from C, 2021-08-24), but which hadn't been completed
to the point where we could avoid calling exit() here.
This introduces no functional changes, but makes it easier to both
call these routines as a library in the future, and to eventually
avoid leaking memory.
This and similar control flow in submodule--helper.c could be made
simpler by properly "libifying" it, i.e. to have it consistently
return -1 on failures, and to early return on any non-success.
But let's leave that larger project for now, and (mostly) emulate what
were doing with the "exit(128)" before this change.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:18:07 +00:00
|
|
|
int code;
|
2018-08-03 22:23:18 +00:00
|
|
|
|
2022-03-15 21:09:24 +00:00
|
|
|
oidcpy(&update_data->oid, &ucd.oid);
|
|
|
|
update_data->just_cloned = ucd.just_cloned;
|
|
|
|
update_data->sm_path = ucd.sub->path;
|
|
|
|
|
submodule--helper: free rest of "displaypath" in "struct update_data"
Fix a leak in code added in c51f8f94e5b (submodule--helper: run update
procedures from C, 2021-08-24), we clobber the "displaypath" member of
the passed-in "struct update_data" both so that die() messages in this
update_submodule() function itself can use it, and for the
run_update_procedure() called within this function.
Fix a leak in code added in 51f8f94e5b (submodule--helper: run update
procedures from C, 2021-08-24). We'd always clobber the old
"displaypath" member of the previously passed-in "struct update_data".
A better fix for this would be to remove the "displaypath" member from
the "struct update_data" entirely. Along with "oid", "suboid",
"just_cloned" and "sm_path" it's managing members that mainly need to
be passed between 1-3 stack frames of functions adjacent to this
code. But doing so would be a much larger change (I have it locally,
and fully untangling that in an incremental way is a 10 patch
journey).
So let's go for this much more isolated fix suggested by Glen. We
FREE_AND_NULL() the "update_data->displaypath", the "AND_NULL()" part
of that is needed due to the later "free(ud->displaypath)" in
"update_data_release()" introduced in the preceding commit
Moving ensure_core_worktree() out of update_submodule() may not be
strictly required, but in doing so we are left with the exact same
ordering as before, making this a smaller functional change.
Helped-by: Glen Choo <chooglen@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:14:23 +00:00
|
|
|
code = ensure_core_worktree(update_data->sm_path);
|
|
|
|
if (code)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
update_data->displaypath = get_submodule_displaypath(
|
2022-12-20 12:39:50 +00:00
|
|
|
update_data->sm_path, update_data->prefix,
|
2022-12-20 12:39:55 +00:00
|
|
|
update_data->super_prefix);
|
2022-08-31 23:18:09 +00:00
|
|
|
code = update_submodule(update_data);
|
submodule--helper: free rest of "displaypath" in "struct update_data"
Fix a leak in code added in c51f8f94e5b (submodule--helper: run update
procedures from C, 2021-08-24), we clobber the "displaypath" member of
the passed-in "struct update_data" both so that die() messages in this
update_submodule() function itself can use it, and for the
run_update_procedure() called within this function.
Fix a leak in code added in 51f8f94e5b (submodule--helper: run update
procedures from C, 2021-08-24). We'd always clobber the old
"displaypath" member of the previously passed-in "struct update_data".
A better fix for this would be to remove the "displaypath" member from
the "struct update_data" entirely. Along with "oid", "suboid",
"just_cloned" and "sm_path" it's managing members that mainly need to
be passed between 1-3 stack frames of functions adjacent to this
code. But doing so would be a much larger change (I have it locally,
and fully untangling that in an incremental way is a 10 patch
journey).
So let's go for this much more isolated fix suggested by Glen. We
FREE_AND_NULL() the "update_data->displaypath", the "AND_NULL()" part
of that is needed due to the later "free(ud->displaypath)" in
"update_data_release()" introduced in the preceding commit
Moving ensure_core_worktree() out of update_submodule() may not be
strictly required, but in doing so we are left with the exact same
ordering as before, making this a smaller functional change.
Helped-by: Glen Choo <chooglen@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:14:23 +00:00
|
|
|
FREE_AND_NULL(update_data->displaypath);
|
|
|
|
fail:
|
2022-08-31 23:18:09 +00:00
|
|
|
if (!code)
|
|
|
|
continue;
|
|
|
|
ret = code;
|
|
|
|
if (ret == 128)
|
submodule--helper: don't exit() on failure, return
Change code downstream of module_update() to short-circuit and return
to the top-level on failure, rather than calling exit().
To do so we need to diligently check whether we "must_die_on_failure",
which is a pattern started in c51f8f94e5b (submodule--helper: run
update procedures from C, 2021-08-24), but which hadn't been completed
to the point where we could avoid calling exit() here.
This introduces no functional changes, but makes it easier to both
call these routines as a library in the future, and to eventually
avoid leaking memory.
This and similar control flow in submodule--helper.c could be made
simpler by properly "libifying" it, i.e. to have it consistently
return -1 on failures, and to early return on any non-success.
But let's leave that larger project for now, and (mostly) emulate what
were doing with the "exit(128)" before this change.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:18:07 +00:00
|
|
|
goto cleanup;
|
2022-03-15 21:09:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2022-08-31 23:14:13 +00:00
|
|
|
submodule_update_clone_release(&suc);
|
2022-03-15 21:09:24 +00:00
|
|
|
string_list_clear(&update_data->references, 0);
|
2022-08-31 23:18:01 +00:00
|
|
|
return ret;
|
2018-08-03 22:23:18 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 21:09:24 +00:00
|
|
|
static int module_update(int argc, const char **argv, const char *prefix)
|
2016-03-01 02:07:17 +00:00
|
|
|
{
|
2022-08-31 23:14:10 +00:00
|
|
|
struct pathspec pathspec = { 0 };
|
2022-08-31 23:14:11 +00:00
|
|
|
struct pathspec pathspec2 = { 0 };
|
2022-03-15 21:09:22 +00:00
|
|
|
struct update_data opt = UPDATE_DATA_INIT;
|
list-objects-filter: add and use initializers
In 7e2619d8ff (list_objects_filter_options: plug leak of filter_spec
strings, 2022-09-08), we noted that the filter_spec string_list was
inconsistent in how it handled memory ownership of strings stored in the
list. The fix there was a bit of a band-aid to set the "strdup_strings"
variable right before adding anything.
That works OK, and it lets the users of the API continue to
zero-initialize the struct. But it makes the code a bit hard to follow
and accident-prone, as any other spots appending the filter_spec need to
think about whether to set the strdup_strings value, too (there's one
such spot in partial_clone_get_default_filter_spec(), which is probably
a possible memory leak).
So let's do that full cleanup now. We'll introduce a
LIST_OBJECTS_FILTER_INIT macro and matching function, and use them as
appropriate (though it is for the "_options" struct, this matches the
corresponding list_objects_filter_release() function).
This is harder than it seems! Many other structs, like
git_transport_data, embed the filter struct. So they need to initialize
it themselves even if the rest of the enclosing struct is OK with
zero-initialization. I found all of the relevant spots by grepping
manually for declarations of list_objects_filter_options. And then doing
so recursively for structs which embed it, and ones which embed those,
and so on.
I'm pretty sure I got everything, but there's no change that would alert
the compiler if any topics in flight added new declarations. To catch
this case, we now double-check in the parsing function that things were
initialized as expected and BUG() if appropriate.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-09-11 05:03:07 +00:00
|
|
|
struct list_objects_filter_options filter_options =
|
|
|
|
LIST_OBJECTS_FILTER_INIT;
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
int ret;
|
2022-03-15 21:09:24 +00:00
|
|
|
struct option module_update_options[] = {
|
2022-12-20 12:39:55 +00:00
|
|
|
OPT__SUPER_PREFIX(&opt.super_prefix),
|
2022-03-15 21:09:24 +00:00
|
|
|
OPT__FORCE(&opt.force, N_("force checkout updates"), 0),
|
2022-03-15 21:09:21 +00:00
|
|
|
OPT_BOOL(0, "init", &opt.init,
|
2022-03-05 00:13:58 +00:00
|
|
|
N_("initialize uninitialized submodules before update")),
|
2022-03-15 21:09:24 +00:00
|
|
|
OPT_BOOL(0, "remote", &opt.remote,
|
|
|
|
N_("use SHA-1 of submodule's remote tracking branch")),
|
|
|
|
OPT_BOOL(0, "recursive", &opt.recursive,
|
|
|
|
N_("traverse submodules recursively")),
|
|
|
|
OPT_BOOL('N', "no-fetch", &opt.nofetch,
|
|
|
|
N_("don't fetch new objects from the remote site")),
|
2022-06-28 10:05:32 +00:00
|
|
|
OPT_SET_INT(0, "checkout", &opt.update_default,
|
2022-06-28 10:05:31 +00:00
|
|
|
N_("use the 'checkout' update strategy (default)"),
|
|
|
|
SM_UPDATE_CHECKOUT),
|
2022-06-28 10:05:32 +00:00
|
|
|
OPT_SET_INT('m', "merge", &opt.update_default,
|
2022-06-28 10:05:31 +00:00
|
|
|
N_("use the 'merge' update strategy"),
|
|
|
|
SM_UPDATE_MERGE),
|
2022-06-28 10:05:32 +00:00
|
|
|
OPT_SET_INT('r', "rebase", &opt.update_default,
|
2022-06-28 10:05:31 +00:00
|
|
|
N_("use the 'rebase' update strategy"),
|
|
|
|
SM_UPDATE_REBASE),
|
2022-03-15 21:09:21 +00:00
|
|
|
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
|
2016-03-01 02:07:17 +00:00
|
|
|
N_("reference repository")),
|
2022-03-15 21:09:21 +00:00
|
|
|
OPT_BOOL(0, "dissociate", &opt.dissociate,
|
2018-05-03 10:53:46 +00:00
|
|
|
N_("use --reference only while cloning")),
|
2022-03-15 21:09:22 +00:00
|
|
|
OPT_INTEGER(0, "depth", &opt.depth,
|
2021-01-06 14:44:03 +00:00
|
|
|
N_("create a shallow clone truncated to the "
|
2016-03-01 02:07:17 +00:00
|
|
|
"specified number of revisions")),
|
2022-03-15 21:09:21 +00:00
|
|
|
OPT_INTEGER('j', "jobs", &opt.max_jobs,
|
2016-03-01 02:07:19 +00:00
|
|
|
N_("parallel jobs")),
|
2022-03-15 21:09:21 +00:00
|
|
|
OPT_BOOL(0, "recommend-shallow", &opt.recommend_shallow,
|
2016-05-26 21:59:43 +00:00
|
|
|
N_("whether the initial clone should follow the shallow recommendation")),
|
2022-03-15 21:09:21 +00:00
|
|
|
OPT__QUIET(&opt.quiet, N_("don't print cloning progress")),
|
|
|
|
OPT_BOOL(0, "progress", &opt.progress,
|
clone: pass --progress decision to recursive submodules
When cloning with "--recursive", we'd generally expect
submodules to show progress reports if the main clone did,
too.
In older versions of git, this mostly worked out of the
box. Since we show progress by default when stderr is a tty,
and since the child clones inherit the parent stderr, then
both processes would come to the same decision by default.
If the parent clone was asked for "--quiet", we passed down
"--quiet" to the child. However, if stderr was not a tty and
the user specified "--progress", we did not propagate this
to the child.
That's a minor bug, but things got much worse when we
switched recently to submodule--helper's update_clone
command. With that change, the stderr of the child clones
are always connected to a pipe, and we never output
progress at all.
This patch teaches git-submodule and git-submodule--helper
how to pass down an explicit "--progress" flag when cloning.
The clone command then decides to propagate that flag based
on the cloning decision made earlier (which takes into
account isatty(2) of the parent process, existing --progress
or --quiet flags, etc). Since the child processes always run
without a tty on stderr, we don't have to worry about
passing an explicit "--no-progress"; it's the default for
them.
This fixes the recent loss of progress during recursive
clones. And as a bonus, it makes:
git clone --recursive --progress ... 2>&1 | cat
work by triggering progress explicitly in the children.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-09-22 05:24:46 +00:00
|
|
|
N_("force cloning progress")),
|
2022-03-15 21:09:21 +00:00
|
|
|
OPT_BOOL(0, "require-init", &opt.require_init,
|
2022-06-28 10:05:27 +00:00
|
|
|
N_("disallow cloning into non-empty directory, implies --init")),
|
2022-03-15 21:09:21 +00:00
|
|
|
OPT_BOOL(0, "single-branch", &opt.single_branch,
|
2020-02-21 03:10:27 +00:00
|
|
|
N_("clone only one branch, HEAD or --branch")),
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
|
2016-03-01 02:07:17 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
2022-03-05 00:14:01 +00:00
|
|
|
N_("git submodule [--quiet] update"
|
|
|
|
" [--init [--filter=<filter-spec>]] [--remote]"
|
|
|
|
" [-N|--no-fetch] [-f|--force]"
|
|
|
|
" [--checkout|--merge|--rebase]"
|
|
|
|
" [--[no-]recommend-shallow] [--reference <repository>]"
|
|
|
|
" [--recursive] [--[no-]single-branch] [--] [<path>...]"),
|
2016-03-01 02:07:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2022-03-15 21:09:21 +00:00
|
|
|
update_clone_config_from_gitmodules(&opt.max_jobs);
|
|
|
|
git_config(git_update_clone_config, &opt.max_jobs);
|
2017-08-02 19:49:18 +00:00
|
|
|
|
2022-03-15 21:09:24 +00:00
|
|
|
argc = parse_options(argc, argv, prefix, module_update_options,
|
2016-03-01 02:07:17 +00:00
|
|
|
git_submodule_helper_usage, 0);
|
2022-03-05 00:14:01 +00:00
|
|
|
|
2022-06-28 10:05:27 +00:00
|
|
|
if (opt.require_init)
|
|
|
|
opt.init = 1;
|
|
|
|
|
2022-03-15 21:09:21 +00:00
|
|
|
if (filter_options.choice && !opt.init) {
|
2022-03-15 21:09:24 +00:00
|
|
|
usage_with_options(git_submodule_helper_usage,
|
|
|
|
module_update_options);
|
2022-03-05 00:14:01 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 21:09:21 +00:00
|
|
|
opt.filter_options = &filter_options;
|
2022-11-08 14:10:39 +00:00
|
|
|
opt.prefix = prefix;
|
2016-03-01 02:07:17 +00:00
|
|
|
|
2022-03-15 21:09:22 +00:00
|
|
|
if (opt.update_default)
|
2022-06-28 10:05:32 +00:00
|
|
|
opt.update_strategy.type = opt.update_default;
|
2016-03-01 02:07:17 +00:00
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
if (module_list_compute(argv, prefix, &pathspec, &opt.list) < 0) {
|
2022-08-31 23:14:10 +00:00
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
}
|
2016-03-01 02:07:17 +00:00
|
|
|
|
|
|
|
if (pathspec.nr)
|
2022-03-15 21:09:21 +00:00
|
|
|
opt.warn_if_uninitialized = 1;
|
2016-03-01 02:07:17 +00:00
|
|
|
|
2022-03-15 21:09:21 +00:00
|
|
|
if (opt.init) {
|
2022-03-05 00:13:58 +00:00
|
|
|
struct module_list list = MODULE_LIST_INIT;
|
|
|
|
struct init_cb info = INIT_CB_INIT;
|
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
if (module_list_compute(argv, opt.prefix,
|
2022-08-31 23:14:11 +00:00
|
|
|
&pathspec2, &list) < 0) {
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&list);
|
2022-08-31 23:14:10 +00:00
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2022-03-05 00:13:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are no path args and submodule.active is set then,
|
|
|
|
* by default, only initialize 'active' modules.
|
|
|
|
*/
|
|
|
|
if (!argc && git_config_get_value_multi("submodule.active"))
|
|
|
|
module_list_active(&list);
|
|
|
|
|
2022-03-15 21:09:21 +00:00
|
|
|
info.prefix = opt.prefix;
|
2022-12-20 12:39:55 +00:00
|
|
|
info.super_prefix = opt.super_prefix;
|
2022-03-15 21:09:21 +00:00
|
|
|
if (opt.quiet)
|
2022-03-05 00:13:58 +00:00
|
|
|
info.flags |= OPT_QUIET;
|
|
|
|
|
|
|
|
for_each_listed_submodule(&list, init_submodule_cb, &info);
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&list);
|
2022-03-05 00:13:58 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 21:09:21 +00:00
|
|
|
ret = update_submodules(&opt);
|
2022-08-31 23:14:10 +00:00
|
|
|
cleanup:
|
2022-08-31 23:14:13 +00:00
|
|
|
update_data_release(&opt);
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
list_objects_filter_release(&filter_options);
|
2022-08-31 23:14:10 +00:00
|
|
|
clear_pathspec(&pathspec);
|
2022-08-31 23:14:11 +00:00
|
|
|
clear_pathspec(&pathspec2);
|
clone, submodule: pass partial clone filters to submodules
When cloning a repo with a --filter and with --recurse-submodules
enabled, the partial clone filter only applies to the top-level repo.
This can lead to unexpected bandwidth and disk usage for projects which
include large submodules. For example, a user might wish to make a
partial clone of Gerrit and would run:
`git clone --recurse-submodules --filter=blob:5k https://gerrit.googlesource.com/gerrit`.
However, only the superproject would be a partial clone; all the
submodules would have all blobs downloaded regardless of their size.
With this change, the same filter can also be applied to submodules,
meaning the expected bandwidth and disk savings apply consistently.
To avoid changing default behavior, add a new clone flag,
`--also-filter-submodules`. When this is set along with `--filter` and
`--recurse-submodules`, the filter spec is passed along to git-submodule
and git-submodule--helper, such that submodule clones also have the
filter applied.
This applies the same filter to the superproject and all submodules.
Users who need to customize the filter per-submodule would need to clone
with `--no-recurse-submodules` and then manually initialize each
submodule with the proper filter.
Applying filters to submodules should be safe thanks to Jonathan Tan's
recent work [1, 2, 3] eliminating the use of alternates as a method of
accessing submodule objects, so any submodule object access now triggers
a lazy fetch from the submodule's promisor remote if the accessed object
is missing. This patch is a reworked version of [4], which was created
prior to Jonathan Tan's work.
[1]: 8721e2e (Merge branch 'jt/partial-clone-submodule-1', 2021-07-16)
[2]: 11e5d0a (Merge branch 'jt/grep-wo-submodule-odb-as-alternate',
2021-09-20)
[3]: 162a13b (Merge branch 'jt/no-abuse-alternate-odb-for-submodules',
2021-10-25)
[4]: https://lore.kernel.org/git/52bf9d45b8e2b72ff32aa773f2415bf7b2b86da2.1563322192.git.steadmon@google.com/
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-05 05:00:49 +00:00
|
|
|
return ret;
|
2016-03-01 02:07:17 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 17:47:18 +00:00
|
|
|
static int push_check(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct remote *remote;
|
2017-07-20 17:40:37 +00:00
|
|
|
const char *superproject_head;
|
|
|
|
char *head;
|
|
|
|
int detached_head = 0;
|
|
|
|
struct object_id head_oid;
|
2017-04-05 17:47:18 +00:00
|
|
|
|
2017-07-20 17:40:37 +00:00
|
|
|
if (argc < 3)
|
|
|
|
die("submodule--helper push-check requires at least 2 arguments");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* superproject's resolved head ref.
|
|
|
|
* if HEAD then the superproject is in a detached head state, otherwise
|
|
|
|
* it will be the resolved head ref.
|
|
|
|
*/
|
|
|
|
superproject_head = argv[1];
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
/* Get the submodule's head ref and determine if it is detached */
|
refs: convert resolve_refdup and refs_resolve_refdup to struct object_id
All of the callers already pass the hash member of struct object_id, so
update them to pass a pointer to the struct directly,
This transformation was done with an update to declaration and
definition and the following semantic patch:
@@
expression E1, E2, E3, E4;
@@
- resolve_refdup(E1, E2, E3.hash, E4)
+ resolve_refdup(E1, E2, &E3, E4)
@@
expression E1, E2, E3, E4;
@@
- resolve_refdup(E1, E2, E3->hash, E4)
+ resolve_refdup(E1, E2, E3, E4)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-15 22:06:55 +00:00
|
|
|
head = resolve_refdup("HEAD", 0, &head_oid, NULL);
|
2017-07-20 17:40:37 +00:00
|
|
|
if (!head)
|
|
|
|
die(_("Failed to resolve HEAD as a valid ref."));
|
|
|
|
if (!strcmp(head, "HEAD"))
|
|
|
|
detached_head = 1;
|
2017-04-05 17:47:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The remote must be configured.
|
|
|
|
* This is to avoid pushing to the exact same URL as the parent.
|
|
|
|
*/
|
|
|
|
remote = pushremote_get(argv[1]);
|
|
|
|
if (!remote || remote->origin == REMOTE_UNCONFIGURED)
|
|
|
|
die("remote '%s' not configured", argv[1]);
|
|
|
|
|
|
|
|
/* Check the refspec */
|
|
|
|
if (argc > 2) {
|
2018-05-16 22:57:53 +00:00
|
|
|
int i;
|
2017-04-05 17:47:18 +00:00
|
|
|
struct ref *local_refs = get_local_heads();
|
2018-05-16 22:57:53 +00:00
|
|
|
struct refspec refspec = REFSPEC_INIT_PUSH;
|
2017-04-05 17:47:18 +00:00
|
|
|
|
2018-05-16 22:57:53 +00:00
|
|
|
refspec_appendn(&refspec, argv + 2, argc - 2);
|
|
|
|
|
|
|
|
for (i = 0; i < refspec.nr; i++) {
|
|
|
|
const struct refspec_item *rs = &refspec.items[i];
|
2017-04-05 17:47:18 +00:00
|
|
|
|
|
|
|
if (rs->pattern || rs->matching)
|
|
|
|
continue;
|
|
|
|
|
2017-07-20 17:40:37 +00:00
|
|
|
/* LHS must match a single ref */
|
|
|
|
switch (count_refspec_match(rs->src, local_refs, NULL)) {
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
/*
|
|
|
|
* If LHS matches 'HEAD' then we need to ensure
|
|
|
|
* that it matches the same named branch
|
|
|
|
* checked out in the superproject.
|
|
|
|
*/
|
|
|
|
if (!strcmp(rs->src, "HEAD")) {
|
|
|
|
if (!detached_head &&
|
|
|
|
!strcmp(head, superproject_head))
|
|
|
|
break;
|
|
|
|
die("HEAD does not match the named branch in the superproject");
|
|
|
|
}
|
consistently use "fallthrough" comments in switches
Gcc 7 adds -Wimplicit-fallthrough, which can warn when a
switch case falls through to the next case. The general idea
is that the compiler can't tell if this was intentional or
not, so you should annotate any intentional fall-throughs as
such, leaving it to complain about any unannotated ones.
There's a GNU __attribute__ which can be used for
annotation, but of course we'd have to #ifdef it away on
non-gcc compilers. Gcc will also recognize
specially-formatted comments, which matches our current
practice. Let's extend that practice to all of the
unannotated sites (which I did look over and verify that
they were behaving as intended).
Ideally in each case we'd actually give some reasons in the
comment about why we're falling through, or what we're
falling through to. And gcc does support that with
-Wimplicit-fallthrough=2, which relaxes the comment pattern
matching to anything that contains "fallthrough" (or a
variety of spelling variants). However, this isn't the
default for -Wimplicit-fallthrough, nor for -Wextra. In the
name of simplicity, it's probably better for us to support
the default level, which requires "fallthrough" to be the
only thing in the comment (modulo some window dressing like
"else" and some punctuation; see the gcc manual for the
complete set of patterns).
This patch suppresses all warnings due to
-Wimplicit-fallthrough. We might eventually want to add that
to the DEVELOPER Makefile knob, but we should probably wait
until gcc 7 is more widely adopted (since earlier versions
will complain about the unknown warning type).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-09-21 06:25:41 +00:00
|
|
|
/* fallthrough */
|
2017-07-20 17:40:37 +00:00
|
|
|
default:
|
2017-04-05 17:47:18 +00:00
|
|
|
die("src refspec '%s' must name a ref",
|
|
|
|
rs->src);
|
2017-07-20 17:40:37 +00:00
|
|
|
}
|
2017-04-05 17:47:18 +00:00
|
|
|
}
|
2018-05-16 22:57:53 +00:00
|
|
|
refspec_clear(&refspec);
|
2017-04-05 17:47:18 +00:00
|
|
|
}
|
2017-07-20 17:40:37 +00:00
|
|
|
free(head);
|
2017-04-05 17:47:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-12 19:04:35 +00:00
|
|
|
static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int i;
|
2022-08-31 23:14:10 +00:00
|
|
|
struct pathspec pathspec = { 0 };
|
2016-12-12 19:04:35 +00:00
|
|
|
struct module_list list = MODULE_LIST_INIT;
|
submodule--helper: don't use global --super-prefix in "absorbgitdirs"
The "--super-prefix" facility was introduced in [1] has always been a
transitory hack, which is why we've made it an error to supply it as
an option to "git" to commands that don't know about it.
That's been a good goal, as it has a global effect we haven't wanted
calls to get_super_prefix() from built-ins we didn't expect.
But it has meant that when we've had chains of different built-ins
using it all of the processes in that "chain" have needed to support
it, and worse processes that don't need it have needed to ask for
"SUPPORT_SUPER_PREFIX" because their parent process needs it.
That's how "fsmonitor--daemon" ended up with it, per [2] it's called
from (among other things) "submodule--helper absorbgitdirs", but as we
declared "submodule--helper" as "SUPPORT_SUPER_PREFIX" we needed to
declare "fsmonitor--daemon" as accepting it too, even though it
doesn't care about it.
But in the case of "absorbgitdirs" it only needed "--super-prefix" to
invoke itself recursively, and we'd never have another "in-between"
process in the chain. So we didn't need the bigger hammer of "git
--super-prefix", and the "setenv(GIT_SUPER_PREFIX_ENVIRONMENT, ...)"
that it entails.
Let's instead accept a hidden "--super-prefix" option to
"submodule--helper absorbgitdirs" itself.
Eventually (as with all other "--super-prefix" users) we'll want to
clean this code up so that this all happens in-process. I.e. needing
any variant of "--super-prefix" is itself a hack around our various
global state, and implicit reliance on "the_repository". This stepping
stone makes such an eventual change easier, as we'll need to deal with
less global state at that point.
The "fsmonitor--daemon" test adjusted here was added in [3]. To assert
that it didn't run into the "--super-prefix" message it was asserting
the output it didn't have. Let's instead assert the full output that
we *do* have, using the same pattern as a preceding change to
"t/t7412-submodule-absorbgitdirs.sh" used.
We could also remove the test entirely (as [4] did), but even though
the initial reason for having it is gone we're still getting some
marginal benefit from testing the "fsmonitor" and "submodule
absorbgitdirs" interaction, so let's keep it.
The change here to have either a NULL or non-"" string as a
"super_prefix" instead of the previous arrangement of "" or non-"" is
somewhat arbitrary. We could also decide to never have to check for
NULL.
As we'll be changing the rest of the "git --super-prefix" users to the
same pattern, leaving them all consistent makes sense. Why not pick ""
over NULL? Because that's how the "prefix" works[5], and having
"prefix" and "super_prefix" work the same way will be less
confusing. That "prefix" picked NULL instead of "" is itself
arbitrary, but as it's easy to make this small bit of our overall API
consistent, let's go with that.
1. 74866d75793 (git: make super-prefix option, 2016-10-07)
2. 53fcfbc84f6 (fsmonitor--daemon: allow --super-prefix argument,
2022-05-26)
3. 53fcfbc84f6 (fsmonitor--daemon: allow --super-prefix argument,
2022-05-26)
4. https://lore.kernel.org/git/20221109004708.97668-5-chooglen@google.com/
5. 9725c8dda20 (built-ins: trust the "prefix" from run_builtin(),
2022-02-16)
Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-12-20 12:39:51 +00:00
|
|
|
const char *super_prefix = NULL;
|
2016-12-12 19:04:35 +00:00
|
|
|
struct option embed_gitdir_options[] = {
|
submodule--helper: don't use global --super-prefix in "absorbgitdirs"
The "--super-prefix" facility was introduced in [1] has always been a
transitory hack, which is why we've made it an error to supply it as
an option to "git" to commands that don't know about it.
That's been a good goal, as it has a global effect we haven't wanted
calls to get_super_prefix() from built-ins we didn't expect.
But it has meant that when we've had chains of different built-ins
using it all of the processes in that "chain" have needed to support
it, and worse processes that don't need it have needed to ask for
"SUPPORT_SUPER_PREFIX" because their parent process needs it.
That's how "fsmonitor--daemon" ended up with it, per [2] it's called
from (among other things) "submodule--helper absorbgitdirs", but as we
declared "submodule--helper" as "SUPPORT_SUPER_PREFIX" we needed to
declare "fsmonitor--daemon" as accepting it too, even though it
doesn't care about it.
But in the case of "absorbgitdirs" it only needed "--super-prefix" to
invoke itself recursively, and we'd never have another "in-between"
process in the chain. So we didn't need the bigger hammer of "git
--super-prefix", and the "setenv(GIT_SUPER_PREFIX_ENVIRONMENT, ...)"
that it entails.
Let's instead accept a hidden "--super-prefix" option to
"submodule--helper absorbgitdirs" itself.
Eventually (as with all other "--super-prefix" users) we'll want to
clean this code up so that this all happens in-process. I.e. needing
any variant of "--super-prefix" is itself a hack around our various
global state, and implicit reliance on "the_repository". This stepping
stone makes such an eventual change easier, as we'll need to deal with
less global state at that point.
The "fsmonitor--daemon" test adjusted here was added in [3]. To assert
that it didn't run into the "--super-prefix" message it was asserting
the output it didn't have. Let's instead assert the full output that
we *do* have, using the same pattern as a preceding change to
"t/t7412-submodule-absorbgitdirs.sh" used.
We could also remove the test entirely (as [4] did), but even though
the initial reason for having it is gone we're still getting some
marginal benefit from testing the "fsmonitor" and "submodule
absorbgitdirs" interaction, so let's keep it.
The change here to have either a NULL or non-"" string as a
"super_prefix" instead of the previous arrangement of "" or non-"" is
somewhat arbitrary. We could also decide to never have to check for
NULL.
As we'll be changing the rest of the "git --super-prefix" users to the
same pattern, leaving them all consistent makes sense. Why not pick ""
over NULL? Because that's how the "prefix" works[5], and having
"prefix" and "super_prefix" work the same way will be less
confusing. That "prefix" picked NULL instead of "" is itself
arbitrary, but as it's easy to make this small bit of our overall API
consistent, let's go with that.
1. 74866d75793 (git: make super-prefix option, 2016-10-07)
2. 53fcfbc84f6 (fsmonitor--daemon: allow --super-prefix argument,
2022-05-26)
3. 53fcfbc84f6 (fsmonitor--daemon: allow --super-prefix argument,
2022-05-26)
4. https://lore.kernel.org/git/20221109004708.97668-5-chooglen@google.com/
5. 9725c8dda20 (built-ins: trust the "prefix" from run_builtin(),
2022-02-16)
Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-12-20 12:39:51 +00:00
|
|
|
OPT__SUPER_PREFIX(&super_prefix),
|
2016-12-12 19:04:35 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const git_submodule_helper_usage[] = {
|
submodule--helper: report "submodule" as our name in some "-h" output
Change the user-facing "git submodule--helper" commands so that
they'll report their name as being "git submodule". To a user these
commands are internal implementation details, and it doesn't make
sense to emit usage about an internal helper when "git submodule" is
invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
[...]
And:
$ git submodule set-url -- --
usage: git submodule--helper set-url [--quiet] <path> <newurl>
[...]
Now we'll start with "usage: git submodule [...]" in both of those
cases. This change does not alter the "list", "name", "clone",
"config" and "create-branch" commands, those are internal-only (as an
aside; their usage info should probably invoke BUG(...)). This only
changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this
change, because their usage information already used "submodule"
rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage
information in practice, as git-submodule.sh will catch unknown
options, and e.g. it doesn't seem to be possible to get "add" to emit
its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and
will allow us to eventually dispatch further into "git
submodule--helper" from git-submodule.sh, while emitting the correct
usage output.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-28 10:05:30 +00:00
|
|
|
N_("git submodule absorbgitdirs [<options>] [<path>...]"),
|
2016-12-12 19:04:35 +00:00
|
|
|
NULL
|
|
|
|
};
|
2022-08-31 23:14:10 +00:00
|
|
|
int ret = 1;
|
2016-12-12 19:04:35 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, embed_gitdir_options,
|
|
|
|
git_submodule_helper_usage, 0);
|
|
|
|
|
2022-10-18 01:02:02 +00:00
|
|
|
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
|
2022-08-31 23:14:10 +00:00
|
|
|
goto cleanup;
|
2016-12-12 19:04:35 +00:00
|
|
|
|
|
|
|
for (i = 0; i < list.nr; i++)
|
2022-12-20 12:39:50 +00:00
|
|
|
absorb_git_dir_into_superproject(list.entries[i]->name,
|
|
|
|
super_prefix);
|
2016-12-12 19:04:35 +00:00
|
|
|
|
2022-08-31 23:14:10 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
clear_pathspec(&pathspec);
|
2022-08-31 23:14:13 +00:00
|
|
|
module_list_release(&list);
|
2022-08-31 23:14:10 +00:00
|
|
|
return ret;
|
2016-12-12 19:04:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 06:21:36 +00:00
|
|
|
static int module_set_url(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int quiet = 0;
|
|
|
|
const char *newurl;
|
|
|
|
const char *path;
|
|
|
|
char *config_name;
|
|
|
|
struct option options[] = {
|
2021-01-06 14:44:03 +00:00
|
|
|
OPT__QUIET(&quiet, N_("suppress output for setting url of a submodule")),
|
2020-05-08 06:21:36 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const usage[] = {
|
submodule--helper: report "submodule" as our name in some "-h" output
Change the user-facing "git submodule--helper" commands so that
they'll report their name as being "git submodule". To a user these
commands are internal implementation details, and it doesn't make
sense to emit usage about an internal helper when "git submodule" is
invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
[...]
And:
$ git submodule set-url -- --
usage: git submodule--helper set-url [--quiet] <path> <newurl>
[...]
Now we'll start with "usage: git submodule [...]" in both of those
cases. This change does not alter the "list", "name", "clone",
"config" and "create-branch" commands, those are internal-only (as an
aside; their usage info should probably invoke BUG(...)). This only
changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this
change, because their usage information already used "submodule"
rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage
information in practice, as git-submodule.sh will catch unknown
options, and e.g. it doesn't seem to be possible to get "add" to emit
its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and
will allow us to eventually dispatch further into "git
submodule--helper" from git-submodule.sh, while emitting the correct
usage output.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-28 10:05:30 +00:00
|
|
|
N_("git submodule set-url [--quiet] <path> <newurl>"),
|
2020-05-08 06:21:36 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
|
|
|
|
|
|
|
if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1]))
|
|
|
|
usage_with_options(usage, options);
|
|
|
|
|
|
|
|
config_name = xstrfmt("submodule.%s.url", path);
|
|
|
|
|
|
|
|
config_set_in_gitmodules_file_gently(config_name, newurl);
|
2022-12-20 12:39:53 +00:00
|
|
|
sync_submodule(path, prefix, NULL, quiet ? OPT_QUIET : 0);
|
2020-05-08 06:21:36 +00:00
|
|
|
|
|
|
|
free(config_name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-02 16:35:23 +00:00
|
|
|
static int module_set_branch(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int opt_default = 0, ret;
|
|
|
|
const char *opt_branch = NULL;
|
|
|
|
const char *path;
|
|
|
|
char *config_name;
|
|
|
|
struct option options[] = {
|
2022-08-31 23:17:51 +00:00
|
|
|
/*
|
|
|
|
* We accept the `quiet` option for uniformity across subcommands,
|
|
|
|
* though there is nothing to make less verbose in this subcommand.
|
|
|
|
*/
|
2020-06-02 16:35:23 +00:00
|
|
|
OPT_NOOP_NOARG('q', "quiet"),
|
2022-08-31 23:17:51 +00:00
|
|
|
|
2020-06-02 16:35:23 +00:00
|
|
|
OPT_BOOL('d', "default", &opt_default,
|
|
|
|
N_("set the default tracking branch to master")),
|
|
|
|
OPT_STRING('b', "branch", &opt_branch, N_("branch"),
|
|
|
|
N_("set the default tracking branch")),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const usage[] = {
|
submodule--helper: report "submodule" as our name in some "-h" output
Change the user-facing "git submodule--helper" commands so that
they'll report their name as being "git submodule". To a user these
commands are internal implementation details, and it doesn't make
sense to emit usage about an internal helper when "git submodule" is
invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
[...]
And:
$ git submodule set-url -- --
usage: git submodule--helper set-url [--quiet] <path> <newurl>
[...]
Now we'll start with "usage: git submodule [...]" in both of those
cases. This change does not alter the "list", "name", "clone",
"config" and "create-branch" commands, those are internal-only (as an
aside; their usage info should probably invoke BUG(...)). This only
changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this
change, because their usage information already used "submodule"
rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage
information in practice, as git-submodule.sh will catch unknown
options, and e.g. it doesn't seem to be possible to get "add" to emit
its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and
will allow us to eventually dispatch further into "git
submodule--helper" from git-submodule.sh, while emitting the correct
usage output.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-28 10:05:30 +00:00
|
|
|
N_("git submodule set-branch [-q|--quiet] (-d|--default) <path>"),
|
|
|
|
N_("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
|
2020-06-02 16:35:23 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
|
|
|
|
|
|
|
if (!opt_branch && !opt_default)
|
|
|
|
die(_("--branch or --default required"));
|
|
|
|
|
|
|
|
if (opt_branch && opt_default)
|
2022-01-05 20:02:14 +00:00
|
|
|
die(_("options '%s' and '%s' cannot be used together"), "--branch", "--default");
|
2020-06-02 16:35:23 +00:00
|
|
|
|
|
|
|
if (argc != 1 || !(path = argv[0]))
|
|
|
|
usage_with_options(usage, options);
|
|
|
|
|
|
|
|
config_name = xstrfmt("submodule.%s.branch", path);
|
|
|
|
ret = config_set_in_gitmodules_file_gently(config_name, opt_branch);
|
|
|
|
|
|
|
|
free(config_name);
|
|
|
|
return !!ret;
|
|
|
|
}
|
|
|
|
|
branch: add --recurse-submodules option for branch creation
To improve the submodules UX, we would like to teach Git to handle
branches in submodules. Start this process by teaching "git branch" the
--recurse-submodules option so that "git branch --recurse-submodules
topic" will create the `topic` branch in the superproject and its
submodules.
Although this commit does not introduce breaking changes, it does not
work well with existing --recurse-submodules commands because "git
branch --recurse-submodules" writes to the submodule ref store, but most
commands only consider the superproject gitlink and ignore the submodule
ref store. For example, "git checkout --recurse-submodules" will check
out the commits in the superproject gitlinks (and put the submodules in
detached HEAD) instead of checking out the submodule branches.
Because of this, this commit introduces a new configuration value,
`submodule.propagateBranches`. The plan is for Git commands to
prioritize submodule ref store information over superproject gitlinks if
this value is true. Because "git branch --recurse-submodules" writes to
submodule ref stores, for the sake of clarity, it will not function
unless this configuration value is set.
This commit also includes changes that support working with submodules
from a superproject commit because "branch --recurse-submodules" (and
future commands) need to read .gitmodules and gitlinks from the
superproject commit, but submodules are typically read from the
filesystem's .gitmodules and the index's gitlinks. These changes are:
* add a submodules_of_tree() helper that gives the relevant
information of an in-tree submodule (e.g. path and oid) and
initializes the repository
* add is_tree_submodule_active() by adding a treeish_name parameter to
is_submodule_active()
* add the "submoduleNotUpdated" advice to advise users to update the
submodules in their trees
Incidentally, fix an incorrect usage string that combined the 'list'
usage of git branch (-l) with the 'create' usage; this string has been
incorrect since its inception, a8dfd5eac4 (Make builtin-branch.c use
parse_options., 2007-10-07).
Helped-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-29 00:04:45 +00:00
|
|
|
static int module_create_branch(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
enum branch_track track;
|
|
|
|
int quiet = 0, force = 0, reflog = 0, dry_run = 0;
|
|
|
|
struct option options[] = {
|
|
|
|
OPT__QUIET(&quiet, N_("print only error messages")),
|
|
|
|
OPT__FORCE(&force, N_("force creation"), 0),
|
|
|
|
OPT_BOOL(0, "create-reflog", &reflog,
|
|
|
|
N_("create the branch's reflog")),
|
2022-03-29 20:01:16 +00:00
|
|
|
OPT_CALLBACK_F('t', "track", &track, "(direct|inherit)",
|
|
|
|
N_("set branch tracking configuration"),
|
|
|
|
PARSE_OPT_OPTARG,
|
|
|
|
parse_opt_tracking_mode),
|
branch: add --recurse-submodules option for branch creation
To improve the submodules UX, we would like to teach Git to handle
branches in submodules. Start this process by teaching "git branch" the
--recurse-submodules option so that "git branch --recurse-submodules
topic" will create the `topic` branch in the superproject and its
submodules.
Although this commit does not introduce breaking changes, it does not
work well with existing --recurse-submodules commands because "git
branch --recurse-submodules" writes to the submodule ref store, but most
commands only consider the superproject gitlink and ignore the submodule
ref store. For example, "git checkout --recurse-submodules" will check
out the commits in the superproject gitlinks (and put the submodules in
detached HEAD) instead of checking out the submodule branches.
Because of this, this commit introduces a new configuration value,
`submodule.propagateBranches`. The plan is for Git commands to
prioritize submodule ref store information over superproject gitlinks if
this value is true. Because "git branch --recurse-submodules" writes to
submodule ref stores, for the sake of clarity, it will not function
unless this configuration value is set.
This commit also includes changes that support working with submodules
from a superproject commit because "branch --recurse-submodules" (and
future commands) need to read .gitmodules and gitlinks from the
superproject commit, but submodules are typically read from the
filesystem's .gitmodules and the index's gitlinks. These changes are:
* add a submodules_of_tree() helper that gives the relevant
information of an in-tree submodule (e.g. path and oid) and
initializes the repository
* add is_tree_submodule_active() by adding a treeish_name parameter to
is_submodule_active()
* add the "submoduleNotUpdated" advice to advise users to update the
submodules in their trees
Incidentally, fix an incorrect usage string that combined the 'list'
usage of git branch (-l) with the 'create' usage; this string has been
incorrect since its inception, a8dfd5eac4 (Make builtin-branch.c use
parse_options., 2007-10-07).
Helped-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-29 00:04:45 +00:00
|
|
|
OPT__DRY_RUN(&dry_run,
|
|
|
|
N_("show whether the branch would be created")),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const usage[] = {
|
2022-04-11 19:23:30 +00:00
|
|
|
N_("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>"),
|
branch: add --recurse-submodules option for branch creation
To improve the submodules UX, we would like to teach Git to handle
branches in submodules. Start this process by teaching "git branch" the
--recurse-submodules option so that "git branch --recurse-submodules
topic" will create the `topic` branch in the superproject and its
submodules.
Although this commit does not introduce breaking changes, it does not
work well with existing --recurse-submodules commands because "git
branch --recurse-submodules" writes to the submodule ref store, but most
commands only consider the superproject gitlink and ignore the submodule
ref store. For example, "git checkout --recurse-submodules" will check
out the commits in the superproject gitlinks (and put the submodules in
detached HEAD) instead of checking out the submodule branches.
Because of this, this commit introduces a new configuration value,
`submodule.propagateBranches`. The plan is for Git commands to
prioritize submodule ref store information over superproject gitlinks if
this value is true. Because "git branch --recurse-submodules" writes to
submodule ref stores, for the sake of clarity, it will not function
unless this configuration value is set.
This commit also includes changes that support working with submodules
from a superproject commit because "branch --recurse-submodules" (and
future commands) need to read .gitmodules and gitlinks from the
superproject commit, but submodules are typically read from the
filesystem's .gitmodules and the index's gitlinks. These changes are:
* add a submodules_of_tree() helper that gives the relevant
information of an in-tree submodule (e.g. path and oid) and
initializes the repository
* add is_tree_submodule_active() by adding a treeish_name parameter to
is_submodule_active()
* add the "submoduleNotUpdated" advice to advise users to update the
submodules in their trees
Incidentally, fix an incorrect usage string that combined the 'list'
usage of git branch (-l) with the 'create' usage; this string has been
incorrect since its inception, a8dfd5eac4 (Make builtin-branch.c use
parse_options., 2007-10-07).
Helped-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-29 00:04:45 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
git_config(git_default_config, NULL);
|
|
|
|
track = git_branch_track;
|
|
|
|
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
usage_with_options(usage, options);
|
|
|
|
|
|
|
|
if (!quiet && !dry_run)
|
|
|
|
printf_ln(_("creating branch '%s'"), argv[0]);
|
|
|
|
|
|
|
|
create_branches_recursively(the_repository, argv[0], argv[1], argv[2],
|
|
|
|
force, reflog, quiet, track, dry_run);
|
|
|
|
return 0;
|
|
|
|
}
|
2022-03-05 00:13:51 +00:00
|
|
|
|
2021-07-10 07:48:01 +00:00
|
|
|
struct add_data {
|
|
|
|
const char *prefix;
|
|
|
|
const char *branch;
|
|
|
|
const char *reference_path;
|
2021-08-10 11:46:37 +00:00
|
|
|
char *sm_path;
|
2021-07-10 07:48:01 +00:00
|
|
|
const char *sm_name;
|
|
|
|
const char *repo;
|
|
|
|
const char *realrepo;
|
|
|
|
int depth;
|
|
|
|
unsigned int force: 1;
|
|
|
|
unsigned int quiet: 1;
|
|
|
|
unsigned int progress: 1;
|
|
|
|
unsigned int dissociate: 1;
|
|
|
|
};
|
|
|
|
#define ADD_DATA_INIT { .depth = -1 }
|
|
|
|
|
2021-10-26 05:25:10 +00:00
|
|
|
static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
|
2021-07-10 07:48:01 +00:00
|
|
|
{
|
|
|
|
struct child_process cp_remote = CHILD_PROCESS_INIT;
|
|
|
|
struct strbuf sb_remote_out = STRBUF_INIT;
|
|
|
|
|
|
|
|
cp_remote.git_cmd = 1;
|
2022-06-02 09:09:50 +00:00
|
|
|
strvec_pushf(&cp_remote.env,
|
2021-07-10 07:48:01 +00:00
|
|
|
"GIT_DIR=%s", git_dir_path);
|
2022-06-02 09:09:50 +00:00
|
|
|
strvec_push(&cp_remote.env, "GIT_WORK_TREE=.");
|
2021-07-10 07:48:01 +00:00
|
|
|
strvec_pushl(&cp_remote.args, "remote", "-v", NULL);
|
|
|
|
if (!capture_command(&cp_remote, &sb_remote_out, 0)) {
|
|
|
|
char *next_line;
|
|
|
|
char *line = sb_remote_out.buf;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2021-07-10 07:48:01 +00:00
|
|
|
while ((next_line = strchr(line, '\n')) != NULL) {
|
|
|
|
size_t len = next_line - line;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2021-07-10 07:48:01 +00:00
|
|
|
if (strip_suffix_mem(line, &len, " (fetch)"))
|
2021-10-23 12:57:22 +00:00
|
|
|
strbuf_addf(msg, " %.*s\n", (int)len, line);
|
2021-07-10 07:48:01 +00:00
|
|
|
line = next_line + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_release(&sb_remote_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_submodule(const struct add_data *add_data)
|
|
|
|
{
|
|
|
|
char *submod_gitdir_path;
|
|
|
|
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
|
2022-08-31 23:17:56 +00:00
|
|
|
struct string_list reference = STRING_LIST_INIT_NODUP;
|
submodule--helper: fix "reference" leak
Fix leaks in the "reference" variable declared in add_submodule() and
module_clone().
In preceding commits this variable was refactored out of the "struct
module_clone_data", but the leak has been with us since
31224cbdc72 (clone: recursive and reference option triggers submodule
alternates, 2016-08-17) and 8c8195e9c3e (submodule--helper: introduce
add-clone subcommand, 2021-07-10).
Those commits added an xstrdup()'d member of the
STRING_LIST_INIT_NODUP'd "struct string_list". We need to free()
those, but not the ones we get from argv, let's make use of the "util"
member, if it has a pointer it's the pointer we'll need to free,
otherwise it'll be NULL (i.e. from argv).
Note that the free() of the "util" member is needed in both
module_clone() and add_submodule(). The module_clone() function itself
doesn't populate the "util" pointer as add_submodule() does, but
module_clone() is upstream of the
add_possible_reference_from_superproject() caller we're modifying
here, which does do that.
This does preclude the use of the "util" pointer for any other reasons
for now, but that's OK. If we ever need to use it for something else
we could turn it into a small "struct" with an optional "to_free"
member, and switch to using string_list_clear_func().
Alternatively we could have another "struct string_list to_free" which
would keep a copy of the strings we've dup'd to free(). But for now
this is perfectly adequate.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:14:18 +00:00
|
|
|
int ret = -1;
|
2021-07-10 07:48:01 +00:00
|
|
|
|
|
|
|
/* perhaps the path already exists and is already a git repo, else clone it */
|
|
|
|
if (is_directory(add_data->sm_path)) {
|
|
|
|
struct strbuf sm_path = STRBUF_INIT;
|
|
|
|
strbuf_addstr(&sm_path, add_data->sm_path);
|
|
|
|
submod_gitdir_path = xstrfmt("%s/.git", add_data->sm_path);
|
|
|
|
if (is_nonbare_repository_dir(&sm_path))
|
|
|
|
printf(_("Adding existing repo at '%s' to the index\n"),
|
|
|
|
add_data->sm_path);
|
|
|
|
else
|
|
|
|
die(_("'%s' already exists and is not a valid git repo"),
|
|
|
|
add_data->sm_path);
|
|
|
|
strbuf_release(&sm_path);
|
|
|
|
free(submod_gitdir_path);
|
|
|
|
} else {
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
2022-08-31 23:17:56 +00:00
|
|
|
|
2021-07-10 07:48:01 +00:00
|
|
|
submod_gitdir_path = xstrfmt(".git/modules/%s", add_data->sm_name);
|
|
|
|
|
|
|
|
if (is_directory(submod_gitdir_path)) {
|
|
|
|
if (!add_data->force) {
|
2021-10-23 12:57:22 +00:00
|
|
|
struct strbuf msg = STRBUF_INIT;
|
|
|
|
char *die_msg;
|
|
|
|
|
|
|
|
strbuf_addf(&msg, _("A git directory for '%s' is found "
|
|
|
|
"locally with remote(s):\n"),
|
|
|
|
add_data->sm_name);
|
|
|
|
|
2021-10-26 05:25:10 +00:00
|
|
|
append_fetch_remotes(&msg, submod_gitdir_path);
|
2021-07-10 07:48:01 +00:00
|
|
|
free(submod_gitdir_path);
|
2021-10-23 12:57:22 +00:00
|
|
|
|
|
|
|
strbuf_addf(&msg, _("If you want to reuse this local git "
|
|
|
|
"directory instead of cloning again from\n"
|
|
|
|
" %s\n"
|
|
|
|
"use the '--force' option. If the local git "
|
|
|
|
"directory is not the correct repo\n"
|
|
|
|
"or you are unsure what this means choose "
|
|
|
|
"another name with the '--name' option."),
|
|
|
|
add_data->realrepo);
|
|
|
|
|
|
|
|
die_msg = strbuf_detach(&msg, NULL);
|
|
|
|
die("%s", die_msg);
|
2021-07-10 07:48:01 +00:00
|
|
|
} else {
|
|
|
|
printf(_("Reactivating local git directory for "
|
|
|
|
"submodule '%s'\n"), add_data->sm_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(submod_gitdir_path);
|
|
|
|
|
|
|
|
clone_data.prefix = add_data->prefix;
|
|
|
|
clone_data.path = add_data->sm_path;
|
|
|
|
clone_data.name = add_data->sm_name;
|
|
|
|
clone_data.url = add_data->realrepo;
|
|
|
|
clone_data.quiet = add_data->quiet;
|
|
|
|
clone_data.progress = add_data->progress;
|
submodule--helper: fix "reference" leak
Fix leaks in the "reference" variable declared in add_submodule() and
module_clone().
In preceding commits this variable was refactored out of the "struct
module_clone_data", but the leak has been with us since
31224cbdc72 (clone: recursive and reference option triggers submodule
alternates, 2016-08-17) and 8c8195e9c3e (submodule--helper: introduce
add-clone subcommand, 2021-07-10).
Those commits added an xstrdup()'d member of the
STRING_LIST_INIT_NODUP'd "struct string_list". We need to free()
those, but not the ones we get from argv, let's make use of the "util"
member, if it has a pointer it's the pointer we'll need to free,
otherwise it'll be NULL (i.e. from argv).
Note that the free() of the "util" member is needed in both
module_clone() and add_submodule(). The module_clone() function itself
doesn't populate the "util" pointer as add_submodule() does, but
module_clone() is upstream of the
add_possible_reference_from_superproject() caller we're modifying
here, which does do that.
This does preclude the use of the "util" pointer for any other reasons
for now, but that's OK. If we ever need to use it for something else
we could turn it into a small "struct" with an optional "to_free"
member, and switch to using string_list_clear_func().
Alternatively we could have another "struct string_list to_free" which
would keep a copy of the strings we've dup'd to free(). But for now
this is perfectly adequate.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:14:18 +00:00
|
|
|
if (add_data->reference_path) {
|
|
|
|
char *p = xstrdup(add_data->reference_path);
|
|
|
|
|
|
|
|
string_list_append(&reference, p)->util = p;
|
|
|
|
}
|
2021-07-10 07:48:01 +00:00
|
|
|
clone_data.dissociate = add_data->dissociate;
|
|
|
|
if (add_data->depth >= 0)
|
|
|
|
clone_data.depth = xstrfmt("%d", add_data->depth);
|
|
|
|
|
2022-08-31 23:17:56 +00:00
|
|
|
if (clone_submodule(&clone_data, &reference))
|
submodule--helper: fix "reference" leak
Fix leaks in the "reference" variable declared in add_submodule() and
module_clone().
In preceding commits this variable was refactored out of the "struct
module_clone_data", but the leak has been with us since
31224cbdc72 (clone: recursive and reference option triggers submodule
alternates, 2016-08-17) and 8c8195e9c3e (submodule--helper: introduce
add-clone subcommand, 2021-07-10).
Those commits added an xstrdup()'d member of the
STRING_LIST_INIT_NODUP'd "struct string_list". We need to free()
those, but not the ones we get from argv, let's make use of the "util"
member, if it has a pointer it's the pointer we'll need to free,
otherwise it'll be NULL (i.e. from argv).
Note that the free() of the "util" member is needed in both
module_clone() and add_submodule(). The module_clone() function itself
doesn't populate the "util" pointer as add_submodule() does, but
module_clone() is upstream of the
add_possible_reference_from_superproject() caller we're modifying
here, which does do that.
This does preclude the use of the "util" pointer for any other reasons
for now, but that's OK. If we ever need to use it for something else
we could turn it into a small "struct" with an optional "to_free"
member, and switch to using string_list_clear_func().
Alternatively we could have another "struct string_list to_free" which
would keep a copy of the strings we've dup'd to free(). But for now
this is perfectly adequate.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:14:18 +00:00
|
|
|
goto cleanup;
|
2021-07-10 07:48:01 +00:00
|
|
|
|
2022-06-02 09:09:50 +00:00
|
|
|
prepare_submodule_repo_env(&cp.env);
|
2021-07-10 07:48:01 +00:00
|
|
|
cp.git_cmd = 1;
|
|
|
|
cp.dir = add_data->sm_path;
|
Comment important codepaths regarding nuking untracked files/dirs
In the last few commits we focused on code in unpack-trees.c that
mistakenly removed untracked files or directories. There may be more of
those, but in this commit we change our focus: callers of toplevel
commands that are expected to remove untracked files or directories.
As noted previously, we have toplevel commands that are expected to
delete untracked files such as 'read-tree --reset', 'reset --hard', and
'checkout --force'. However, that does not mean that other highlevel
commands that happen to call these other commands thought about or
conveyed to users the possibility that untracked files could be removed.
Audit the code for such callsites, and add comments near existing
callsites to mention whether these are safe or not.
My auditing is somewhat incomplete, though; it skipped several cases:
* git-rebase--preserve-merges.sh: is in the process of being
deprecated/removed, so I won't leave a note that there are
likely more bugs in that script.
* contrib/git-new-workdir: why is the -f flag being used in a new
empty directory?? It shouldn't hurt, but it seems useless.
* git-p4.py: Don't see why -f is needed for a new dir (maybe it's
not and is just superfluous), but I'm not at all familiar with
the p4 stuff
* git-archimport.perl: Don't care; arch is long since dead
* git-cvs*.perl: Don't care; cvs is long since dead
Also, the reset --hard in builtin/worktree.c looks safe, due to only
running in an empty directory.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-27 16:33:47 +00:00
|
|
|
/*
|
|
|
|
* NOTE: we only get here if add_data->force is true, so
|
|
|
|
* passing --force to checkout is reasonable.
|
|
|
|
*/
|
2021-07-10 07:48:01 +00:00
|
|
|
strvec_pushl(&cp.args, "checkout", "-f", "-q", NULL);
|
|
|
|
|
|
|
|
if (add_data->branch) {
|
|
|
|
strvec_pushl(&cp.args, "-B", add_data->branch, NULL);
|
|
|
|
strvec_pushf(&cp.args, "origin/%s", add_data->branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (run_command(&cp))
|
|
|
|
die(_("unable to checkout submodule '%s'"), add_data->sm_path);
|
|
|
|
}
|
submodule--helper: fix "reference" leak
Fix leaks in the "reference" variable declared in add_submodule() and
module_clone().
In preceding commits this variable was refactored out of the "struct
module_clone_data", but the leak has been with us since
31224cbdc72 (clone: recursive and reference option triggers submodule
alternates, 2016-08-17) and 8c8195e9c3e (submodule--helper: introduce
add-clone subcommand, 2021-07-10).
Those commits added an xstrdup()'d member of the
STRING_LIST_INIT_NODUP'd "struct string_list". We need to free()
those, but not the ones we get from argv, let's make use of the "util"
member, if it has a pointer it's the pointer we'll need to free,
otherwise it'll be NULL (i.e. from argv).
Note that the free() of the "util" member is needed in both
module_clone() and add_submodule(). The module_clone() function itself
doesn't populate the "util" pointer as add_submodule() does, but
module_clone() is upstream of the
add_possible_reference_from_superproject() caller we're modifying
here, which does do that.
This does preclude the use of the "util" pointer for any other reasons
for now, but that's OK. If we ever need to use it for something else
we could turn it into a small "struct" with an optional "to_free"
member, and switch to using string_list_clear_func().
Alternatively we could have another "struct string_list to_free" which
would keep a copy of the strings we've dup'd to free(). But for now
this is perfectly adequate.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-31 23:14:18 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
string_list_clear(&reference, 1);
|
|
|
|
return ret;
|
2021-07-10 07:48:01 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 14:04:31 +00:00
|
|
|
static int config_submodule_in_gitmodules(const char *name, const char *var, const char *value)
|
|
|
|
{
|
|
|
|
char *key;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!is_writing_gitmodules_ok())
|
|
|
|
die(_("please make sure that the .gitmodules file is in the working tree"));
|
|
|
|
|
|
|
|
key = xstrfmt("submodule.%s.%s", name, var);
|
|
|
|
ret = config_set_in_gitmodules_file_gently(key, value);
|
|
|
|
free(key);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void configure_added_submodule(struct add_data *add_data)
|
|
|
|
{
|
|
|
|
char *key;
|
2022-08-31 23:14:24 +00:00
|
|
|
const char *val;
|
2021-08-06 14:04:31 +00:00
|
|
|
struct child_process add_submod = CHILD_PROCESS_INIT;
|
|
|
|
struct child_process add_gitmodules = CHILD_PROCESS_INIT;
|
|
|
|
|
|
|
|
key = xstrfmt("submodule.%s.url", add_data->sm_name);
|
|
|
|
git_config_set_gently(key, add_data->realrepo);
|
|
|
|
free(key);
|
|
|
|
|
|
|
|
add_submod.git_cmd = 1;
|
|
|
|
strvec_pushl(&add_submod.args, "add",
|
|
|
|
"--no-warn-embedded-repo", NULL);
|
|
|
|
if (add_data->force)
|
|
|
|
strvec_push(&add_submod.args, "--force");
|
|
|
|
strvec_pushl(&add_submod.args, "--", add_data->sm_path, NULL);
|
|
|
|
|
|
|
|
if (run_command(&add_submod))
|
|
|
|
die(_("Failed to add submodule '%s'"), add_data->sm_path);
|
|
|
|
|
|
|
|
if (config_submodule_in_gitmodules(add_data->sm_name, "path", add_data->sm_path) ||
|
|
|
|
config_submodule_in_gitmodules(add_data->sm_name, "url", add_data->repo))
|
|
|
|
die(_("Failed to register submodule '%s'"), add_data->sm_path);
|
|
|
|
|
|
|
|
if (add_data->branch) {
|
|
|
|
if (config_submodule_in_gitmodules(add_data->sm_name,
|
|
|
|
"branch", add_data->branch))
|
|
|
|
die(_("Failed to register submodule '%s'"), add_data->sm_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_gitmodules.git_cmd = 1;
|
|
|
|
strvec_pushl(&add_gitmodules.args,
|
|
|
|
"add", "--force", "--", ".gitmodules", NULL);
|
|
|
|
|
|
|
|
if (run_command(&add_gitmodules))
|
|
|
|
die(_("Failed to register submodule '%s'"), add_data->sm_path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NEEDSWORK: In a multi-working-tree world this needs to be
|
|
|
|
* set in the per-worktree config.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* NEEDSWORK: In the longer run, we need to get rid of this
|
|
|
|
* pattern of querying "submodule.active" before calling
|
|
|
|
* is_submodule_active(), since that function needs to find
|
|
|
|
* out the value of "submodule.active" again anyway.
|
|
|
|
*/
|
2022-08-31 23:14:24 +00:00
|
|
|
if (!git_config_get_string_tmp("submodule.active", &val)) {
|
2021-08-06 14:04:31 +00:00
|
|
|
/*
|
|
|
|
* If the submodule being added isn't already covered by the
|
|
|
|
* current configured pathspec, set the submodule's active flag
|
|
|
|
*/
|
|
|
|
if (!is_submodule_active(the_repository, add_data->sm_path)) {
|
|
|
|
key = xstrfmt("submodule.%s.active", add_data->sm_name);
|
|
|
|
git_config_set_gently(key, "true");
|
|
|
|
free(key);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
key = xstrfmt("submodule.%s.active", add_data->sm_name);
|
|
|
|
git_config_set_gently(key, "true");
|
|
|
|
free(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 11:46:37 +00:00
|
|
|
static void die_on_index_match(const char *path, int force)
|
2021-08-06 14:04:31 +00:00
|
|
|
{
|
2021-08-10 11:46:37 +00:00
|
|
|
struct pathspec ps;
|
|
|
|
const char *args[] = { path, NULL };
|
|
|
|
parse_pathspec(&ps, 0, PATHSPEC_PREFER_CWD, NULL, args);
|
|
|
|
|
2022-11-19 13:07:38 +00:00
|
|
|
if (repo_read_index_preload(the_repository, NULL, 0) < 0)
|
2021-08-10 11:46:37 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
2023-01-07 13:56:55 +00:00
|
|
|
* Since there is only one pathspec, we just need to
|
|
|
|
* check ps_matched[0] to know if a cache entry matched.
|
2021-08-10 11:46:37 +00:00
|
|
|
*/
|
2022-11-19 13:07:34 +00:00
|
|
|
for (i = 0; i < the_index.cache_nr; i++) {
|
|
|
|
ce_path_match(&the_index, the_index.cache[i], &ps,
|
2021-08-10 11:46:37 +00:00
|
|
|
ps_matched);
|
|
|
|
|
|
|
|
if (ps_matched[0]) {
|
|
|
|
if (!force)
|
|
|
|
die(_("'%s' already exists in the index"),
|
|
|
|
path);
|
2022-11-19 13:07:34 +00:00
|
|
|
if (!S_ISGITLINK(the_index.cache[i]->ce_mode))
|
2021-08-10 11:46:37 +00:00
|
|
|
die(_("'%s' already exists in the index "
|
|
|
|
"and is not a submodule"), path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(ps_matched);
|
|
|
|
}
|
2021-10-22 08:55:43 +00:00
|
|
|
clear_pathspec(&ps);
|
2021-08-10 11:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2021-10-22 08:55:43 +00:00
|
|
|
strbuf_release(&sb);
|
2021-08-10 11:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int module_add(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int force = 0, quiet = 0, progress = 0, dissociate = 0;
|
2021-08-06 14:04:31 +00:00
|
|
|
struct add_data add_data = ADD_DATA_INIT;
|
2022-03-04 18:32:11 +00:00
|
|
|
char *to_free = NULL;
|
2021-08-06 14:04:31 +00:00
|
|
|
struct option options[] = {
|
2021-08-10 11:46:37 +00:00
|
|
|
OPT_STRING('b', "branch", &add_data.branch, N_("branch"),
|
|
|
|
N_("branch of repository to add as submodule")),
|
2021-08-06 14:04:31 +00:00
|
|
|
OPT__FORCE(&force, N_("allow adding an otherwise ignored submodule path"),
|
|
|
|
PARSE_OPT_NOCOMPLETE),
|
2021-08-10 11:46:37 +00:00
|
|
|
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"),
|
i18n CI: stop allowing non-ASCII source messages in po/git.pot
In the preceding commit we moved away from using xgettext(1) to both
generate the po/git.pot, and to merge the incrementally generated
po/git.pot+ file as we sourced translations from C, shell and Perl.
Doing it this way, which dates back to my initial
implementation[1][2][3] was conflating two things: With xgettext(1)
the --from-code both controls what encoding is specified in the
po/git.pot's header, and what encoding we allow in source messages.
We don't ever want to allow non-ASCII in *source messages*, and doing
so has hid e.g. a buggy message introduced in
a6226fd772b (submodule--helper: convert the bulk of cmd_add() to C,
2021-08-10) from us, we'd warn about it before, but only when running
"make pot", but the operation would still succeed. Now we'll error out
on it when running "make pot".
Since the preceding Makefile changes made this easy: let's add a "make
check-pot" target with the same prerequisites as the "po/git.pot"
target, but without changing the file "po/git.pot". Running it as part
of the "static-analysis" CI target will ensure that we catch any such
issues in the future. E.g.:
$ make check-pot
XGETTEXT .build/pot/po/builtin/submodule--helper.c.po
xgettext: Non-ASCII string at builtin/submodule--helper.c:3381.
Please specify the source encoding through --from-code.
make: *** [.build/pot/po/builtin/submodule--helper.c.po] Error 1
1. cd5513a7168 (i18n: Makefile: "pot" target to extract messages
marked for translation, 2011-02-22)
2. adc3b2b2767 (Makefile: add xgettext target for *.sh files,
2011-05-14)
3. 5e9637c6297 (i18n: add infrastructure for translating Git with
gettext, 2011-11-18)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-05-26 14:50:29 +00:00
|
|
|
N_("sets the submodule's name to the given string "
|
2021-08-10 11:46:37 +00:00
|
|
|
"instead of defaulting to its path")),
|
|
|
|
OPT_INTEGER(0, "depth", &add_data.depth, N_("depth for shallow clones")),
|
2021-08-06 14:04:31 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char *const usage[] = {
|
submodule--helper: report "submodule" as our name in some "-h" output
Change the user-facing "git submodule--helper" commands so that
they'll report their name as being "git submodule". To a user these
commands are internal implementation details, and it doesn't make
sense to emit usage about an internal helper when "git submodule" is
invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
[...]
And:
$ git submodule set-url -- --
usage: git submodule--helper set-url [--quiet] <path> <newurl>
[...]
Now we'll start with "usage: git submodule [...]" in both of those
cases. This change does not alter the "list", "name", "clone",
"config" and "create-branch" commands, those are internal-only (as an
aside; their usage info should probably invoke BUG(...)). This only
changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this
change, because their usage information already used "submodule"
rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage
information in practice, as git-submodule.sh will catch unknown
options, and e.g. it doesn't seem to be possible to get "add" to emit
its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and
will allow us to eventually dispatch further into "git
submodule--helper" from git-submodule.sh, while emitting the correct
usage output.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-28 10:05:30 +00:00
|
|
|
N_("git submodule add [<options>] [--] <repository> [<path>]"),
|
2021-08-06 14:04:31 +00:00
|
|
|
NULL
|
|
|
|
};
|
2022-08-31 23:14:19 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
int ret = 1;
|
2021-08-06 14:04:31 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
|
|
|
|
2021-08-10 11:46:37 +00:00
|
|
|
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)
|
2021-08-06 14:04:31 +00:00
|
|
|
usage_with_options(usage, options);
|
|
|
|
|
2021-08-10 11:46:37 +00:00
|
|
|
add_data.repo = argv[0];
|
|
|
|
if (argc == 1)
|
|
|
|
add_data.sm_path = git_url_basename(add_data.repo, 0, 0);
|
|
|
|
else
|
|
|
|
add_data.sm_path = xstrdup(argv[1]);
|
|
|
|
|
2022-08-31 23:14:20 +00:00
|
|
|
if (prefix && *prefix && !is_absolute_path(add_data.sm_path)) {
|
|
|
|
char *sm_path = add_data.sm_path;
|
|
|
|
|
|
|
|
add_data.sm_path = xstrfmt("%s%s", prefix, sm_path);
|
|
|
|
free(sm_path);
|
|
|
|
}
|
2021-08-10 11:46:37 +00:00
|
|
|
|
|
|
|
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 */
|
2022-03-04 18:32:11 +00:00
|
|
|
to_free = resolve_relative_url(add_data.repo, NULL, 1);
|
|
|
|
add_data.realrepo = to_free;
|
2021-08-10 11:46:37 +00:00
|
|
|
} 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) {
|
|
|
|
struct child_process cp = CHILD_PROCESS_INIT;
|
2022-08-31 23:17:52 +00:00
|
|
|
|
2021-08-10 11:46:37 +00:00
|
|
|
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);
|
2022-08-31 23:14:19 +00:00
|
|
|
if ((ret = pipe_command(&cp, NULL, 0, NULL, 0, &sb, 0))) {
|
2021-08-10 11:46:37 +00:00
|
|
|
strbuf_complete_line(&sb);
|
|
|
|
fputs(sb.buf, stderr);
|
2022-08-31 23:14:19 +00:00
|
|
|
goto cleanup;
|
2021-08-10 11:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-08-06 14:04:31 +00:00
|
|
|
add_data.force = !!force;
|
2021-08-10 11:46:37 +00:00
|
|
|
add_data.quiet = !!quiet;
|
|
|
|
add_data.progress = !!progress;
|
|
|
|
add_data.dissociate = !!dissociate;
|
|
|
|
|
2022-08-31 23:14:19 +00:00
|
|
|
if (add_submodule(&add_data))
|
|
|
|
goto cleanup;
|
2021-08-06 14:04:31 +00:00
|
|
|
configure_added_submodule(&add_data);
|
2022-08-31 23:14:19 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2021-08-10 11:46:37 +00:00
|
|
|
free(add_data.sm_path);
|
2022-03-04 18:32:11 +00:00
|
|
|
free(to_free);
|
2022-08-31 23:14:19 +00:00
|
|
|
strbuf_release(&sb);
|
2021-08-06 14:04:31 +00:00
|
|
|
|
2022-08-31 23:14:19 +00:00
|
|
|
return ret;
|
2021-08-06 14:04:31 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 21:42:24 +00:00
|
|
|
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2022-11-08 14:10:40 +00:00
|
|
|
parse_opt_subcommand_fn *fn = NULL;
|
|
|
|
const char *const usage[] = {
|
|
|
|
N_("git submodule--helper <command>"),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_SUBCOMMAND("clone", &fn, module_clone),
|
|
|
|
OPT_SUBCOMMAND("add", &fn, module_add),
|
|
|
|
OPT_SUBCOMMAND("update", &fn, module_update),
|
|
|
|
OPT_SUBCOMMAND("foreach", &fn, module_foreach),
|
|
|
|
OPT_SUBCOMMAND("init", &fn, module_init),
|
|
|
|
OPT_SUBCOMMAND("status", &fn, module_status),
|
|
|
|
OPT_SUBCOMMAND("sync", &fn, module_sync),
|
|
|
|
OPT_SUBCOMMAND("deinit", &fn, module_deinit),
|
|
|
|
OPT_SUBCOMMAND("summary", &fn, module_summary),
|
|
|
|
OPT_SUBCOMMAND("push-check", &fn, push_check),
|
|
|
|
OPT_SUBCOMMAND("absorbgitdirs", &fn, absorb_git_dirs),
|
|
|
|
OPT_SUBCOMMAND("set-url", &fn, module_set_url),
|
|
|
|
OPT_SUBCOMMAND("set-branch", &fn, module_set_branch),
|
|
|
|
OPT_SUBCOMMAND("create-branch", &fn, module_create_branch),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
2015-09-02 21:42:24 +00:00
|
|
|
|
2022-11-08 14:10:40 +00:00
|
|
|
return fn(argc, argv, prefix);
|
2015-09-02 21:42:24 +00:00
|
|
|
}
|