clone: define shallow clone boundary based on time with --shallow-since

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 994c2aaf31e1f8e8e69f86324e585620fee68c82
2 files changed +16 -3
Documentation/git-clone.txt
+3
@@ -193,6 +193,9 @@ objects from the source repository into a pack in the cloned repository.
193 `--no-single-branch` is given to fetch the histories near the
194 tips of all branches.
195
196 +--shallow-since=<date>::
197 + Create a shallow clone with a history after the specified time.
198 +
199 --[no-]single-branch::
200 Clone only the history leading to the tip of a single branch,
201 either specified by the `--branch` option or the primary
builtin/clone.c
+13 -3
@@ -40,7 +40,8 @@ static const char * const builtin_clone_usage[] = {
40
41 static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;
42 static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;
43 -static char *option_template, *option_depth;
43 +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 const char *real_git_dir;
@@ -86,6 +87,8 @@ static struct option builtin_clone_options[] = {
87 N_("path to git-upload-pack on the remote")),
88 OPT_STRING(0, "depth", &option_depth, N_("depth"),
89 N_("create a shallow clone of that depth")),
90 + OPT_STRING(0, "shallow-since", &option_since, N_("time"),
91 + N_("create a shallow clone since a specific time")),
92 OPT_BOOL(0, "single-branch", &option_single_branch,
93 N_("clone only one branch, HEAD or --branch")),
94 OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
@@ -849,8 +852,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
852 usage_msg_opt(_("You must specify a repository to clone."),
853 builtin_clone_usage, builtin_clone_options);
854
855 + if (option_depth || option_since)
856 + deepen = 1;
857 if (option_single_branch == -1)
853 - option_single_branch = option_depth ? 1 : 0;
858 + option_single_branch = deepen ? 1 : 0;
859
860 if (option_mirror)
861 option_bare = 1;
@@ -976,6 +981,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
981 if (is_local) {
982 if (option_depth)
983 warning(_("--depth is ignored in local clones; use file:// instead."));
984 + if (option_since)
985 + warning(_("--shallow-since is ignored in local clones; use file:// instead."));
986 if (!access(mkpath("%s/shallow", path), F_OK)) {
987 if (option_local > 0)
988 warning(_("source repository is shallow, ignoring --local"));
@@ -994,6 +1001,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1001 if (option_depth)
1002 transport_set_option(transport, TRANS_OPT_DEPTH,
1003 option_depth);
1004 + if (option_since)
1005 + transport_set_option(transport, TRANS_OPT_DEEPEN_SINCE,
1006 + option_since);
1007 if (option_single_branch)
1008 transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
1009
@@ -1001,7 +1011,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1011 transport_set_option(transport, TRANS_OPT_UPLOADPACK,
1012 option_upload_pack);
1013
1004 - if (transport->smart_options && !option_depth)
1014 + if (transport->smart_options && !deepen)
1015 transport->smart_options->check_self_contained_and_connected = 1;
1016
1017 refs = transport_get_remote_refs(transport);