{"thread":{"id":"32557","subject":"[PATCH] fetch,upload-pack: make --depth=0 or --depth=inf for infinite depth","startedAt":"2013-01-08T12:19:12Z","lastAt":"2013-01-08T12:19:12Z","messageCount":1,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"206291","messageId":"1357647552-15815-1-git-send-email-pclouds@gmail.com","threadId":"32557","inReplyTo":null,"subject":"[PATCH] fetch,upload-pack: make --depth=0 or --depth=inf for infinite depth","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2013-01-08T12:19:12Z","receivedAt":"2013-01-08T12:19:12Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"The user can do fetch --depth=2147483647 for infinite depth now. But\nit's hard to remember. Any other large numbers would also do if it's\nlonger than the longest commit chain in repository (some guessing may\nbe involved). Make --depth=0 or --depth=inf an alias for\n--depth=2147483647. JGit and older C Git store depth as \"int\" so both\nare OK with this number. Dulwich does not support shallow clone.\n\nfetch-pack is not changed because it's a plumbing and the plumber is\nexpected to write this number explicitly.\n\nMake upload-pack recognize this special number as infinite depth. The\neffect is essentially the same as before, except that upload-pack is\nmore efficient in this case as it does not have to traverse the commit\nDAG to the bottom any more. The chance of a user actually wanting\nexactly 2147483647 commits depth, not infinite, is probably too small\nto consider.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n This is a patch from the graveyard, the third patch of a series [1].\n The series, nd/clone-depth-zero, has been merged. Although I don't know\n only the first patch in the original series got in.\n\n http://thread.gmane.org/gmane.comp.version-control.git/154267/focus=154268\n\n Documentation/fetch-options.txt     |  2 ++\n Documentation/technical/shallow.txt |  3 +++\n commit.h                            |  3 +++\n t/t5500-fetch-pack.sh               |  8 ++++++++\n transport.c                         |  5 +++++\n upload-pack.c                       | 13 ++++++++++---\n 6 files changed, 31 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt\nindex 6e98bdf..140d0cd 100644\n--- a/Documentation/fetch-options.txt\n+++ b/Documentation/fetch-options.txt\n@@ -12,6 +12,8 @@\n \t`git clone` with `--depth=<depth>` option (see linkgit:git-clone[1])\n \tto the specified number of commits from the tip of each remote\n \tbranch history. Tags for the deepened commits are not fetched.\n+\tDepth 0 or \"inf\" is infinite, which may turn repository to a\n+\tnon-shallow one again.\n \n ifndef::git-pull[]\n --dry-run::\ndiff --git a/Documentation/technical/shallow.txt b/Documentation/technical/shallow.txt\nindex 0502a54..ea2f69f 100644\n--- a/Documentation/technical/shallow.txt\n+++ b/Documentation/technical/shallow.txt\n@@ -53,3 +53,6 @@ It also writes an appropriate $GIT_DIR/shallow.\n You can deepen a shallow repository with \"git-fetch --depth 20\n repo branch\", which will fetch branch from repo, but stop at depth\n 20, updating $GIT_DIR/shallow.\n+\n+The special depth 2147483647 (or 0x7fffffff, the largest positive\n+number a signed 32-bit integer can contain) means infinite depth.\ndiff --git a/commit.h b/commit.h\nindex 0f469e5..fbde106 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -162,6 +162,9 @@ extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *r\n extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);\n extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);\n \n+/* largest postive number a signed 32-bit integer can contain */\n+#define INFINITE_DEPTH 0x7fffffff\n+\n extern int register_shallow(const unsigned char *sha1);\n extern int unregister_shallow(const unsigned char *sha1);\n extern int for_each_commit_graft(each_commit_graft_fn, void *);\ndiff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh\nindex 6322e8a..2d40073 100755\n--- a/t/t5500-fetch-pack.sh\n+++ b/t/t5500-fetch-pack.sh\n@@ -264,6 +264,14 @@ test_expect_success 'clone shallow object count' '\n \tgrep \"^count: 52\" count.shallow\n '\n \n+test_expect_success 'infinite deepening (full repo)' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit fetch --depth=inf &&\n+\t\t! test -f .git/shallow\n+\t)\n+'\n+\n test_expect_success 'clone shallow without --no-single-branch' '\n \tgit clone --depth 1 \"file://$(pwd)/.\" shallow2\n '\ndiff --git a/transport.c b/transport.c\nindex 2673d27..a938ba0 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -12,6 +12,7 @@\n #include \"url.h\"\n #include \"submodule.h\"\n #include \"string-list.h\"\n+#include \"commit.h\"\n \n /* rsync support */\n \n@@ -475,11 +476,15 @@ static int set_git_option(struct git_transport_options *opts,\n \t} else if (!strcmp(name, TRANS_OPT_DEPTH)) {\n \t\tif (!value)\n \t\t\topts->depth = 0;\n+\t\telse if (!strcmp(value, \"inf\"))\n+\t\t\topts->depth = INFINITE_DEPTH;\n \t\telse {\n \t\t\tchar *end;\n \t\t\topts->depth = strtol(value, &end, 0);\n \t\t\tif (*end)\n \t\t\t\tdie(\"transport: invalid depth option '%s'\", value);\n+\t\t\tif (opts->depth == 0)\n+\t\t\t\topts->depth = INFINITE_DEPTH;\n \t\t}\n \t\treturn 0;\n \t}\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 6142421..88f0029 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -670,10 +670,17 @@ static void receive_needs(void)\n \tif (depth == 0 && shallows.nr == 0)\n \t\treturn;\n \tif (depth > 0) {\n-\t\tstruct commit_list *result, *backup;\n+\t\tstruct commit_list *result = NULL, *backup = NULL;\n \t\tint i;\n-\t\tbackup = result = get_shallow_commits(&want_obj, depth,\n-\t\t\tSHALLOW, NOT_SHALLOW);\n+\t\tif (depth == INFINITE_DEPTH)\n+\t\t\tfor (i = 0; i < shallows.nr; i++) {\n+\t\t\t\tstruct object *object = shallows.objects[i].item;\n+\t\t\t\tobject->flags |= NOT_SHALLOW;\n+\t\t\t}\n+\t\telse\n+\t\t\tbackup = result =\n+\t\t\t\tget_shallow_commits(&want_obj, depth,\n+\t\t\t\t\t\t    SHALLOW, NOT_SHALLOW);\n \t\twhile (result) {\n \t\t\tstruct object *object = &result->item->object;\n \t\t\tif (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {\n-- \n1.8.0.rc2.23.g1fb49df\n"}]}