clone: define shallow clone boundary with --shallow-exclude
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jun 12, 2016 at 17:54 UTC
859e5df916cc3f3cba920c527f485ffaf6d7efa9
2 files changed
+14
-1
Documentation/git-clone.txt
+5
@@ -196,6 +196,11 @@ objects from the source repository into a pack in the cloned repository.
196
--shallow-since=<date>::
197
Create a shallow clone with a history after the specified time.
198
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
+
204
--[no-]single-branch::
205
Clone only the history leading to the tip of a single branch,
206
either specified by the `--branch` option or the primary
builtin/clone.c
+9
-1
@@ -44,6 +44,7 @@ static int deepen;
44
static char *option_template, *option_depth, *option_since;
45
static char *option_origin = NULL;
46
static char *option_branch = NULL;
47
+static struct string_list option_not = STRING_LIST_INIT_NODUP;
48
static const char *real_git_dir;
49
static char *option_upload_pack = "git-upload-pack";
50
static int option_verbosity;
@@ -89,6 +90,8 @@ static struct option builtin_clone_options[] = {
90
N_("create a shallow clone of that depth")),
91
OPT_STRING(0, "shallow-since", &option_since, N_("time"),
92
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")),
95
OPT_BOOL(0, "single-branch", &option_single_branch,
96
N_("clone only one branch, HEAD or --branch")),
97
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)
855
usage_msg_opt(_("You must specify a repository to clone."),
856
builtin_clone_usage, builtin_clone_options);
857
855
- if (option_depth || option_since)
858
+ if (option_depth || option_since || option_not.nr)
859
deepen = 1;
860
if (option_single_branch == -1)
861
option_single_branch = deepen ? 1 : 0;
@@ -983,6 +986,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
986
warning(_("--depth is ignored in local clones; use file:// instead."));
987
if (option_since)
988
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."));
991
if (!access(mkpath("%s/shallow", path), F_OK)) {
992
if (option_local > 0)
993
warning(_("source repository is shallow, ignoring --local"));
@@ -1004,6 +1009,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1009
if (option_since)
1010
transport_set_option(transport, TRANS_OPT_DEEPEN_SINCE,
1011
option_since);
1012
+ if (option_not.nr)
1013
+ transport_set_option(transport, TRANS_OPT_DEEPEN_NOT,
1014
+ (const char *)&option_not);
1015
if (option_single_branch)
1016
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
1017