[PATCH 3/3] {fetch,upload}-pack: allow --depth=0 for infinite depth

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Users can do --depth=2147483648 for infinite depth now. It just looks
ugly. So make "0" special (i.e. infinite depth) at plumbing/protocol
level.

To make it even more user friendly, "git fetch" accepts --depth=inf as
an alternative to --depth=0. "git clone" also can. It just does not
make much sense for doing "git clone --depth=inf"

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 Documentation/fetch-options.txt     |    3 ++-
 Documentation/git-fetch-pack.txt    |    1 +
 Documentation/technical/shallow.txt |    2 ++
 builtin/fetch-pack.c                |    2 +-
 shallow.c                           |    2 +-
 t/t5500-fetch-pack.sh               |    8 ++++++++
 transport.c                         |    2 +-
 upload-pack.c                       |    8 ++++----
 8 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 9333c42..a22d839 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -10,7 +10,8 @@
 --depth=<depth>::
 	Deepen the history of a 'shallow' repository created by
 	`git clone` with `--depth=<depth>` option (see linkgit:git-clone[1])
-	by the specified number of commits.
+	by the specified number of commits. Specify "inf" for
+	infinite depth.
 
 ifndef::git-pull[]
 --dry-run::
diff --git a/Documentation/git-fetch-pack.txt b/Documentation/git-fetch-pack.txt
index 4a8487c..75e4669 100644
--- a/Documentation/git-fetch-pack.txt
+++ b/Documentation/git-fetch-pack.txt
@@ -70,6 +70,7 @@ OPTIONS
 
 --depth=<n>::
 	Limit fetching to ancestor-chains not longer than n.
+	Specify 0 for infinite depth.
 
 --no-progress::
 	Do not show the progress.
diff --git a/Documentation/technical/shallow.txt b/Documentation/technical/shallow.txt
index 559263a..405170f 100644
--- a/Documentation/technical/shallow.txt
+++ b/Documentation/technical/shallow.txt
@@ -47,3 +47,5 @@ It also writes an appropriate $GIT_DIR/shallow.
 You can deepen a shallow repository with "git-fetch --depth 20
 repo branch", which will fetch branch from repo, but stop at depth
 20, updating $GIT_DIR/shallow.
+
+"--depth 0" (or "--depth inf" for git-fetch) means infinite depth.
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 45d1824..7d7af2e 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -845,7 +845,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 			}
 			if (!prefixcmp(arg, "--depth=")) {
 				args.depth = strtol(arg + 8, NULL, 0);
-				if (args.depth <= 0)
+				if (args.depth < 0)
 					die("Invalid depth %d", args.depth);
 				args.shallow = 1;
 				continue;
diff --git a/shallow.c b/shallow.c
index 4d90eda..eab97c6 100644
--- a/shallow.c
+++ b/shallow.c
@@ -85,7 +85,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
 					continue;
 				*pointer = cur_depth;
 			}
-			if (cur_depth < depth) {
+			if (!depth || cur_depth < depth) {
 				if (p->next)
 					add_object_array(&p->item->object,
 							NULL, &stack);
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 18376d6..47fd87c 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -248,4 +248,12 @@ test_expect_success 'clone shallow object count' '
 	grep "^count: 52" count.shallow
 '
 
+test_expect_success 'infinite deepening (full repo)' '
+	(
+		cd shallow &&
+		git fetch --depth=inf &&
+		! test -f .git/shallow
+	)
+'
+
 test_done
diff --git a/transport.c b/transport.c
index cf7030b..9303aef 100644
--- a/transport.c
+++ b/transport.c
@@ -475,7 +475,7 @@ static int set_git_option(struct git_transport_options *opts,
 			opts->shallow = 0;
 		}
 		else {
-			opts->depth = atoi(value);
+			opts->depth = !strcmp(value, "inf") ? 0 : atoi(value);
 			opts->shallow = 1;
 		}
 		return 0;
diff --git a/upload-pack.c b/upload-pack.c
index fc79dde..7b004b9 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -484,7 +484,7 @@ static void receive_needs(void)
 {
 	struct object_array shallows = {0, 0, NULL};
 	static char line[1000];
-	int len, depth = 0;
+	int len, depth = -1;
 
 	shallow_nr = 0;
 	if (debug_fd)
@@ -514,7 +514,7 @@ static void receive_needs(void)
 		if (!prefixcmp(line, "deepen ")) {
 			char *end;
 			depth = strtol(line + 7, &end, 0);
-			if (end == line + 7 || depth <= 0)
+			if (end == line + 7 || depth < 0)
 				die("Invalid deepen: %s", line);
 			continue;
 		}
@@ -562,9 +562,9 @@ static void receive_needs(void)
 	if (!use_sideband && daemon_mode)
 		no_progress = 1;
 
-	if (depth == 0 && shallows.nr == 0)
+	if (depth == -1 && shallows.nr == 0)
 		return;
-	if (depth > 0) {
+	if (depth >= 0) {
 		struct commit_list *result, *backup;
 		int i;
 		backup = result = get_shallow_commits(&want_obj, depth,
-- 
1.7.1.rc1.69.g24c2f7

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]