From: Andrew Oakley <andrew@adoakley.name>
To: git@vger.kernel.org, Luke Diamand <luke@diamand.org>,
Jonathan Tan <jonathantanmy@google.com>
Cc: Andrew Oakley <andrew@adoakley.name>
Subject: [PATCH 7/7] submodule: use partial clone filter
Date: Tue, 29 Sep 2020 16:53:50 +0100 [thread overview]
Message-ID: <20200929155350.49066-8-andrew@adoakley.name> (raw)
In-Reply-To: <20200929155350.49066-1-andrew@adoakley.name>
Pass the --filter option down when fetching submodules.
Signed-off-by: Andrew Oakley <andrew@adoakley.name>
---
builtin/clone.c | 5 +++++
builtin/submodule--helper.c | 21 ++++++++++++++++-----
git-submodule.sh | 20 +++++++++++++++++++-
3 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index fbfd6568cd..354dadc544 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -844,6 +844,11 @@ static int checkout(int submodule_progress)
"--single-branch" :
"--no-single-branch");
+ if (filter_options.choice)
+ strvec_pushf(&args, "--filter=%s",
+ expand_list_objects_filter_spec(
+ &filter_options));
+
err = run_command_v_opt(args.v, RUN_GIT_CMD);
strvec_clear(&args);
}
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index de5ad73bb8..1ca03ec08b 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1658,7 +1658,8 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
}
static int clone_submodule(const char *path, const char *gitdir, const char *url,
- const char *depth, struct string_list *reference, int dissociate,
+ const char *depth, const char *filter,
+ struct string_list *reference, int dissociate,
int quiet, int progress, int single_branch)
{
struct child_process cp = CHILD_PROCESS_INIT;
@@ -1671,6 +1672,8 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
strvec_push(&cp.args, "--progress");
if (depth && *depth)
strvec_pushl(&cp.args, "--depth", depth, NULL);
+ if (filter && *filter)
+ strvec_pushl(&cp.args, "--filter", filter, NULL);
if (reference->nr) {
struct string_list_item *item;
for_each_string_list_item(item, reference)
@@ -1803,7 +1806,7 @@ static void prepare_possible_alternates(const char *sm_name,
static int module_clone(int argc, const char **argv, const char *prefix)
{
- const char *name = NULL, *url = NULL, *depth = NULL;
+ const char *name = NULL, *url = NULL, *depth = NULL, *filter = NULL;
int quiet = 0;
int progress = 0;
char *p, *path = NULL, *sm_gitdir;
@@ -1834,6 +1837,9 @@ static int module_clone(int argc, const char **argv, const char *prefix)
OPT_STRING(0, "depth", &depth,
N_("string"),
N_("depth for shallow clones")),
+ OPT_STRING(0, "filter", &filter,
+ N_("string"),
+ N_("object filtering")),
OPT__QUIET(&quiet, "Suppress output for cloning a submodule"),
OPT_BOOL(0, "progress", &progress,
N_("force cloning progress")),
@@ -1847,7 +1853,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
const char *const git_submodule_helper_usage[] = {
N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
"[--reference <repository>] [--name <name>] [--depth <depth>] "
- "[--single-branch] "
+ "[--filter <filter>] [--single-branch] "
"--url <url> --path <path>"),
NULL
};
@@ -1879,8 +1885,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
prepare_possible_alternates(name, &reference);
- if (clone_submodule(path, sm_gitdir, url, depth, &reference, dissociate,
- quiet, progress, single_branch))
+ if (clone_submodule(path, sm_gitdir, url, depth, filter, &reference,
+ dissociate, quiet, progress, single_branch))
die(_("clone of '%s' into submodule path '%s' failed"),
url, path);
} else {
@@ -2002,6 +2008,7 @@ struct submodule_update_clone {
int dissociate;
unsigned require_init;
const char *depth;
+ const char *filter;
const char *recursive_prefix;
const char *prefix;
int single_branch;
@@ -2165,6 +2172,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
strvec_push(&child->args, "--dissociate");
if (suc->depth)
strvec_push(&child->args, suc->depth);
+ if (suc->filter)
+ strvec_push(&child->args, suc->filter);
if (suc->single_branch >= 0)
strvec_push(&child->args, suc->single_branch ?
"--single-branch" :
@@ -2339,6 +2348,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
OPT_STRING(0, "depth", &suc.depth, "<depth>",
N_("Create a shallow clone truncated to the "
"specified number of revisions")),
+ OPT_STRING(0, "filter", &suc.filter, "<filter>",
+ N_("object filtering")),
OPT_INTEGER('j', "jobs", &suc.max_jobs,
N_("parallel jobs")),
OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
diff --git a/git-submodule.sh b/git-submodule.sh
index 6fb12585cb..029f7e7f44 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -45,6 +45,7 @@ update=
prefix=
custom_name=
depth=
+filter=
progress=
dissociate=
single_branch=
@@ -132,6 +133,14 @@ cmd_add()
--depth=*)
depth=$1
;;
+ --filter)
+ case "$2" in '') usage ;; esac
+ filter="--filter=$2"
+ shift
+ ;;
+ --filter=*)
+ filter=$1
+ ;;
--)
shift
break
@@ -268,7 +277,7 @@ or you are unsure what this means choose another name with the '--name' option."
eval_gettextln "Reactivating local git directory for submodule '\$sm_name'."
fi
fi
- git submodule--helper clone ${GIT_QUIET:+--quiet} ${progress:+"--progress"} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${dissociate:+"--dissociate"} ${depth:+"$depth"} || exit
+ git submodule--helper clone ${GIT_QUIET:+--quiet} ${progress:+"--progress"} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${dissociate:+"--dissociate"} ${depth:+"$depth"} ${filter:+"$filter"} || exit
(
sanitize_submodule_env
cd "$sm_path" &&
@@ -498,6 +507,14 @@ cmd_update()
--depth=*)
depth=$1
;;
+ --filter)
+ case "$2" in '') usage ;; esac
+ filter="--depth=$2"
+ shift
+ ;;
+ --filter=*)
+ filter=$1
+ ;;
-j|--jobs)
case "$2" in '') usage ;; esac
jobs="--jobs=$2"
@@ -540,6 +557,7 @@ cmd_update()
${reference:+"$reference"} \
${dissociate:+"--dissociate"} \
${depth:+--depth "$depth"} \
+ ${filter:+--filter "$filter"} \
${require_init:+--require-init} \
$single_branch \
$recommend_shallow \
--
2.26.2
next prev parent reply other threads:[~2020-09-29 16:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-29 15:53 [PATCH 0/7] Submodules and partial clones Andrew Oakley
2020-09-29 15:53 ` [PATCH 1/7] refs: store owning repository for object lookup Andrew Oakley
2020-09-29 15:53 ` [PATCH 2/7] submodule: use separate submodule repositories Andrew Oakley
2020-09-29 15:53 ` [PATCH 3/7] Add failing test for partial clones with submodules Andrew Oakley
2020-09-29 15:53 ` [PATCH 4/7] refs: use correct repo in refs_peel_ref Andrew Oakley
2020-09-29 15:53 ` [PATCH 5/7] merge-recursive: use separate submodule repository Andrew Oakley
2020-09-29 15:53 ` [PATCH 6/7] submodule: remove add_submodule_odb Andrew Oakley
2020-09-29 15:53 ` Andrew Oakley [this message]
2020-09-29 18:05 ` [PATCH 0/7] Submodules and partial clones Jonathan Tan
2020-09-30 13:28 ` Andrew Oakley
2020-09-30 20:41 ` Jonathan Tan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200929155350.49066-8-andrew@adoakley.name \
--to=andrew@adoakley.name \
--cc=git@vger.kernel.org \
--cc=jonathantanmy@google.com \
--cc=luke@diamand.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).