Skip to content

Commit 859e5df

Browse files
pcloudsgitster
authored andcommitted
clone: define shallow clone boundary with --shallow-exclude
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a45a260 commit 859e5df

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Documentation/git-clone.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ objects from the source repository into a pack in the cloned repository.
196196
--shallow-since=<date>::
197197
Create a shallow clone with a history after the specified time.
198198

199+
--shallow-exclude=<revision>::
200+
Create a shallow clone with a history, excluding commits
201+
reachable from a specified remote branch or tag. This option
202+
can be specified multiple times.
203+
199204
--[no-]single-branch::
200205
Clone only the history leading to the tip of a single branch,
201206
either specified by the `--branch` option or the primary

builtin/clone.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static int deepen;
4444
static char *option_template, *option_depth, *option_since;
4545
static char *option_origin = NULL;
4646
static char *option_branch = NULL;
47+
static struct string_list option_not = STRING_LIST_INIT_NODUP;
4748
static const char *real_git_dir;
4849
static char *option_upload_pack = "git-upload-pack";
4950
static int option_verbosity;
@@ -89,6 +90,8 @@ static struct option builtin_clone_options[] = {
8990
N_("create a shallow clone of that depth")),
9091
OPT_STRING(0, "shallow-since", &option_since, N_("time"),
9192
N_("create a shallow clone since a specific time")),
93+
OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("revision"),
94+
N_("deepen history of shallow clone by excluding rev")),
9295
OPT_BOOL(0, "single-branch", &option_single_branch,
9396
N_("clone only one branch, HEAD or --branch")),
9497
OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
@@ -852,7 +855,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
852855
usage_msg_opt(_("You must specify a repository to clone."),
853856
builtin_clone_usage, builtin_clone_options);
854857

855-
if (option_depth || option_since)
858+
if (option_depth || option_since || option_not.nr)
856859
deepen = 1;
857860
if (option_single_branch == -1)
858861
option_single_branch = deepen ? 1 : 0;
@@ -983,6 +986,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
983986
warning(_("--depth is ignored in local clones; use file:// instead."));
984987
if (option_since)
985988
warning(_("--shallow-since is ignored in local clones; use file:// instead."));
989+
if (option_not.nr)
990+
warning(_("--shallow-exclude is ignored in local clones; use file:// instead."));
986991
if (!access(mkpath("%s/shallow", path), F_OK)) {
987992
if (option_local > 0)
988993
warning(_("source repository is shallow, ignoring --local"));
@@ -1004,6 +1009,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10041009
if (option_since)
10051010
transport_set_option(transport, TRANS_OPT_DEEPEN_SINCE,
10061011
option_since);
1012+
if (option_not.nr)
1013+
transport_set_option(transport, TRANS_OPT_DEEPEN_NOT,
1014+
(const char *)&option_not);
10071015
if (option_single_branch)
10081016
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
10091017

0 commit comments

Comments
 (0)