git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* fully deepening a shallow clone
@ 2010-08-17  0:49 Joey Hess
  2010-08-18  9:36 ` Nguyen Thai Ngoc Duy
  0 siblings, 1 reply; 19+ messages in thread
From: Joey Hess @ 2010-08-17  0:49 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 480 bytes --]

git-pull(1):
       --depth=<depth>
           Deepen the history of a shallow repository created by git clone
           with --depth=<depth> option (see git-clone(1)) by the specified
           number of commits.

Well, what if I want to deepen an existing shallow clone to include
the full history? In practice, something like --depth=100000000 is going
to work, but in theory, that will eventually fail some day when there are
enough commits. :)

-- 
see shy jo

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: fully deepening a shallow clone
  2010-08-17  0:49 fully deepening a shallow clone Joey Hess
@ 2010-08-18  9:36 ` Nguyen Thai Ngoc Duy
  2010-08-18 12:54   ` Daniel Johnson
  2010-08-18 15:48   ` fully deepening a shallow clone Joey Hess
  0 siblings, 2 replies; 19+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-08-18  9:36 UTC (permalink / raw)
  To: Joey Hess; +Cc: git

On Tue, Aug 17, 2010 at 10:49 AM, Joey Hess <joey@kitenet.net> wrote:
> git-pull(1):
>       --depth=<depth>
>           Deepen the history of a shallow repository created by git clone
>           with --depth=<depth> option (see git-clone(1)) by the specified
>           number of commits.
>
> Well, what if I want to deepen an existing shallow clone to include
> the full history? In practice, something like --depth=100000000 is going
> to work, but in theory, that will eventually fail some day when there are
> enough commits. :)

I have always thought --depth=0 will make full repo again. Have you tried that?
-- 
Duy

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: fully deepening a shallow clone
  2010-08-18  9:36 ` Nguyen Thai Ngoc Duy
@ 2010-08-18 12:54   ` Daniel Johnson
  2010-08-19 10:40     ` [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
                       ` (2 more replies)
  2010-08-18 15:48   ` fully deepening a shallow clone Joey Hess
  1 sibling, 3 replies; 19+ messages in thread
From: Daniel Johnson @ 2010-08-18 12:54 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: Joey Hess, git

[-- Attachment #1: Type: Text/Plain, Size: 1018 bytes --]

On Wednesday 18 August 2010 05:36:08 Nguyen Thai Ngoc Duy wrote:
> On Tue, Aug 17, 2010 at 10:49 AM, Joey Hess <joey@kitenet.net> wrote:
> > git-pull(1):
> >       --depth=<depth>
> >           Deepen the history of a shallow repository created by git clone
> >           with --depth=<depth> option (see git-clone(1)) by the specified
> >           number of commits.
> > 
> > Well, what if I want to deepen an existing shallow clone to include
> > the full history? In practice, something like --depth=100000000 is going
> > to work, but in theory, that will eventually fail some day when there are
> > enough commits. :)
> 
> I have always thought --depth=0 will make full repo again. Have you tried
> that?
I tried it myself. --depth=0 is the same as leaving the depth argument off 
entirely. If you are already working in a shallow clone fetch or pull without 
arguments won't deepen it at all, only pull in new commits.

I haven't been able to figure out a good way to solve this yet though.

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: fully deepening a shallow clone
  2010-08-18  9:36 ` Nguyen Thai Ngoc Duy
  2010-08-18 12:54   ` Daniel Johnson
@ 2010-08-18 15:48   ` Joey Hess
  1 sibling, 0 replies; 19+ messages in thread
From: Joey Hess @ 2010-08-18 15:48 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 761 bytes --]

Nguyen Thai Ngoc Duy wrote:
> On Tue, Aug 17, 2010 at 10:49 AM, Joey Hess <joey@kitenet.net> wrote:
> > git-pull(1):
> >       --depth=<depth>
> >           Deepen the history of a shallow repository created by git clone
> >           with --depth=<depth> option (see git-clone(1)) by the specified
> >           number of commits.
> >
> > Well, what if I want to deepen an existing shallow clone to include
> > the full history? In practice, something like --depth=100000000 is going
> > to work, but in theory, that will eventually fail some day when there are
> > enough commits. :)
> 
> I have always thought --depth=0 will make full repo again. Have you tried that?

I'd be happy if it did, but it pulls 0 revs actually.

-- 
see shy jo

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/3] clone: do not accept --depth on local clones
  2010-08-18 12:54   ` Daniel Johnson
@ 2010-08-19 10:40     ` Nguyễn Thái Ngọc Duy
  2010-08-19 14:31       ` Daniel Johnson
  2010-08-19 20:49       ` Mikael Magnusson
  2010-08-19 10:40     ` [PATCH 2/3] fetch-pack: use args.shallow to detect shallow clone instead of args.depth Nguyễn Thái Ngọc Duy
  2010-08-19 10:40     ` [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again Nguyễn Thái Ngọc Duy
  2 siblings, 2 replies; 19+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-08-19 10:40 UTC (permalink / raw)
  To: git, computerdruid, joey; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/clone.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index efb1e6f..215c432 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -361,7 +361,7 @@ static void write_remote_refs(const struct ref *local_refs)
 
 int cmd_clone(int argc, const char **argv, const char *prefix)
 {
-	int is_bundle = 0;
+	int is_bundle = 0, is_local;
 	struct stat buf;
 	const char *repo_name, *repo, *work_tree, *git_dir;
 	char *path, *dir;
@@ -414,6 +414,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		repo = xstrdup(make_absolute_path(repo_name));
 	else
 		repo = repo_name;
+	is_local = path && !is_bundle;
+	if (is_local && option_depth)
+		die("local clone with --depth does not make sense");
 
 	if (argc == 2)
 		dir = xstrdup(argv[1]);
@@ -514,7 +517,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	strbuf_reset(&value);
 
-	if (path && !is_bundle) {
+	if (is_local) {
 		refs = clone_local(path, git_dir);
 		mapped_refs = wanted_peer_refs(refs, refspec);
 	} else {
-- 
1.7.1.rc1.69.g24c2f7

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/3] fetch-pack: use args.shallow to detect shallow clone instead of args.depth
  2010-08-18 12:54   ` Daniel Johnson
  2010-08-19 10:40     ` [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
@ 2010-08-19 10:40     ` Nguyễn Thái Ngọc Duy
  2010-08-19 10:40     ` [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again Nguyễn Thái Ngọc Duy
  2 siblings, 0 replies; 19+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-08-19 10:40 UTC (permalink / raw)
  To: git, computerdruid, joey; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/fetch-pack.c |   17 ++++++++++-------
 fetch-pack.h         |    3 ++-
 transport.c          |    9 +++++++--
 transport.h          |    1 +
 4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index dbd8b7b..45d1824 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -167,7 +167,7 @@ enum ack_type {
 
 static void consume_shallow_list(int fd)
 {
-	if (args.stateless_rpc && args.depth > 0) {
+	if (args.stateless_rpc && args.shallow) {
 		/* If we sent a depth we will get back "duplicate"
 		 * shallow and unshallow commands every time there
 		 * is a block of have lines exchanged.
@@ -283,12 +283,12 @@ static int find_common(int fd[2], unsigned char *result_sha1,
 
 	if (is_repository_shallow())
 		write_shallow_commits(&req_buf, 1);
-	if (args.depth > 0)
+	if (args.shallow)
 		packet_buf_write(&req_buf, "deepen %d", args.depth);
 	packet_buf_flush(&req_buf);
 	state_len = req_buf.len;
 
-	if (args.depth > 0) {
+	if (args.shallow) {
 		char line[1024];
 		unsigned char sha1[20];
 
@@ -476,7 +476,7 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)
 		    check_ref_format(ref->name + 5))
 			; /* trash */
 		else if (args.fetch_all &&
-			 (!args.depth || prefixcmp(ref->name, "refs/tags/") )) {
+			 (!args.shallow || prefixcmp(ref->name, "refs/tags/") )) {
 			*newtail = ref;
 			ref->next = NULL;
 			newtail = &ref->next;
@@ -534,7 +534,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
 		}
 	}
 
-	if (!args.depth) {
+	if (!args.shallow) {
 		for_each_ref(mark_complete, NULL);
 		if (cutoff)
 			mark_recent_complete_commits(cutoff);
@@ -845,6 +845,9 @@ 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)
+					die("Invalid depth %d", args.depth);
+				args.shallow = 1;
 				continue;
 			}
 			if (!strcmp("--no-progress", arg)) {
@@ -928,7 +931,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
 	fetch_pack_setup();
 	if (&args != my_args)
 		memcpy(&args, my_args, sizeof(args));
-	if (args.depth > 0) {
+	if (args.shallow) {
 		if (stat(git_path("shallow"), &st))
 			st.st_mtime = 0;
 	}
@@ -941,7 +944,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
 	}
 	ref_cpy = do_fetch_pack(fd, ref, nr_heads, heads, pack_lockfile);
 
-	if (args.depth > 0) {
+	if (args.shallow) {
 		struct cache_time mtime;
 		struct strbuf sb = STRBUF_INIT;
 		char *shallow = git_path("shallow");
diff --git a/fetch-pack.h b/fetch-pack.h
index fbe85ac..abc1ab7 100644
--- a/fetch-pack.h
+++ b/fetch-pack.h
@@ -14,7 +14,8 @@ struct fetch_pack_args
 		verbose:1,
 		no_progress:1,
 		include_tag:1,
-		stateless_rpc:1;
+		stateless_rpc:1,
+		shallow:1;
 };
 
 struct ref *fetch_pack(struct fetch_pack_args *args,
diff --git a/transport.c b/transport.c
index 4dba6f8..cf7030b 100644
--- a/transport.c
+++ b/transport.c
@@ -470,10 +470,14 @@ static int set_git_option(struct git_transport_options *opts,
 		opts->keep = !!value;
 		return 0;
 	} else if (!strcmp(name, TRANS_OPT_DEPTH)) {
-		if (!value)
+		if (!value) {
 			opts->depth = 0;
-		else
+			opts->shallow = 0;
+		}
+		else {
 			opts->depth = atoi(value);
+			opts->shallow = 1;
+		}
 		return 0;
 	}
 	return 1;
@@ -529,6 +533,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 	args.quiet = (transport->verbose < 0);
 	args.no_progress = !transport->progress;
 	args.depth = data->options.depth;
+	args.shallow = data->options.shallow;
 
 	for (i = 0; i < nr_heads; i++)
 		origh[i] = heads[i] = xstrdup(to_fetch[i]->name);
diff --git a/transport.h b/transport.h
index c59d973..e6ac4b1 100644
--- a/transport.h
+++ b/transport.h
@@ -8,6 +8,7 @@ struct git_transport_options {
 	unsigned thin : 1;
 	unsigned keep : 1;
 	unsigned followtags : 1;
+	unsigned shallow : 1;
 	int depth;
 	const char *uploadpack;
 	const char *receivepack;
-- 
1.7.1.rc1.69.g24c2f7

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again
  2010-08-18 12:54   ` Daniel Johnson
  2010-08-19 10:40     ` [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
  2010-08-19 10:40     ` [PATCH 2/3] fetch-pack: use args.shallow to detect shallow clone instead of args.depth Nguyễn Thái Ngọc Duy
@ 2010-08-19 10:40     ` Nguyễn Thái Ngọc Duy
  2010-08-19 21:22       ` Jakub Narebski
  2 siblings, 1 reply; 19+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-08-19 10:40 UTC (permalink / raw)
  To: git, computerdruid, joey; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 The funny thing is, even with --depth=0, I still have two commit grafts
 in $GIT_DIR/shallow, which are grafts of tags. I think there is a bug somewhere..

 builtin/fetch-pack.c |    2 +-
 shallow.c            |    2 +-
 upload-pack.c        |    8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

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/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

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/3] clone: do not accept --depth on local clones
  2010-08-19 10:40     ` [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
@ 2010-08-19 14:31       ` Daniel Johnson
  2010-08-19 22:15         ` Nguyen Thai Ngoc Duy
  2010-08-19 20:49       ` Mikael Magnusson
  1 sibling, 1 reply; 19+ messages in thread
From: Daniel Johnson @ 2010-08-19 14:31 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, joey

[-- Attachment #1: Type: Text/Plain, Size: 436 bytes --]

On Thursday 19 August 2010 06:40:35 you wrote:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/clone.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
Can you make it a little clearer what the rationale is for this change? Why 
wouldn't you be able to do a limited-depth local clone? Seems like this would 
break some tests, and even if not, would prevent the writing of them.

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/3] clone: do not accept --depth on local clones
  2010-08-19 10:40     ` [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
  2010-08-19 14:31       ` Daniel Johnson
@ 2010-08-19 20:49       ` Mikael Magnusson
  1 sibling, 0 replies; 19+ messages in thread
From: Mikael Magnusson @ 2010-08-19 20:49 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, computerdruid, joey

2010/8/19 Nguyễn Thái Ngọc Duy <pclouds@gmail.com>:
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/clone.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/clone.c b/builtin/clone.c
> index efb1e6f..215c432 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -414,6 +414,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>                repo = xstrdup(make_absolute_path(repo_name));
>        else
>                repo = repo_name;
> +       is_local = path && !is_bundle;
> +       if (is_local && option_depth)
> +               die("local clone with --depth does not make sense");
>
>        if (argc == 2)
>                dir = xstrdup(argv[1]);

Wouldn't it be more helpful to also say "Use the file:///blabla syntax
instead" or just automatically fall back to that protocol when --depth
is used?

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again
  2010-08-19 10:40     ` [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again Nguyễn Thái Ngọc Duy
@ 2010-08-19 21:22       ` Jakub Narebski
  2010-08-19 22:11         ` Nguyen Thai Ngoc Duy
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Narebski @ 2010-08-19 21:22 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, computerdruid, joey

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  The funny thing is, even with --depth=0, I still have two commit grafts
>  in $GIT_DIR/shallow, which are grafts of tags. I think there is a bug somewhere..
> 
>  builtin/fetch-pack.c |    2 +-
>  shallow.c            |    2 +-
>  upload-pack.c        |    8 ++++----
>  3 files changed, 6 insertions(+), 6 deletions(-)
> 

Fist, it lacks documentation update that --depth=0 means infinite
depth (making repository not-shallow).

Second, it would be nice (though probably not easy with parseopt, as
it would require hacks/extensions) to be able to use --depth=inf
(like wget supports '-l inf') to mean infinite depth...

-- 
Jakub Narebski
Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again
  2010-08-19 21:22       ` Jakub Narebski
@ 2010-08-19 22:11         ` Nguyen Thai Ngoc Duy
  2010-08-20  9:22           ` Jakub Narebski
  0 siblings, 1 reply; 19+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-08-19 22:11 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git, computerdruid, joey

On Fri, Aug 20, 2010 at 7:22 AM, Jakub Narebski <jnareb@gmail.com> wrote:
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>>  The funny thing is, even with --depth=0, I still have two commit grafts
>>  in $GIT_DIR/shallow, which are grafts of tags. I think there is a bug
>> somewhere..
>>
>>  builtin/fetch-pack.c |    2 +-
>>  shallow.c            |    2 +-
>>  upload-pack.c        |    8 ++++----
>>  3 files changed, 6 insertions(+), 6 deletions(-)
>>
>
> Fist, it lacks documentation update that --depth=0 means infinite
> depth (making repository not-shallow).

Yeah. I would do documentation and tests later once I figured out why
--depth=0 did not give me full repo. It turns out I need --tags to
(refetch?) tags and have full repo.

> Second, it would be nice (though probably not easy with parseopt, as
> it would require hacks/extensions) to be able to use --depth=inf
> (like wget supports '-l inf') to mean infinite depth...

Hmm.. make --depth a string parameter and fetch-pack should parse the
parameter itself, like git-clone. Good idea.
-- 
Duy

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/3] clone: do not accept --depth on local clones
  2010-08-19 14:31       ` Daniel Johnson
@ 2010-08-19 22:15         ` Nguyen Thai Ngoc Duy
  0 siblings, 0 replies; 19+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-08-19 22:15 UTC (permalink / raw)
  To: Daniel Johnson, mikachu; +Cc: git, joey

On Fri, Aug 20, 2010 at 12:31 AM, Daniel Johnson
<computerdruid@gmail.com> wrote:
> On Thursday 19 August 2010 06:40:35 you wrote:
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>>  builtin/clone.c |    7 +++++--
>>  1 files changed, 5 insertions(+), 2 deletions(-)
> Can you make it a little clearer what the rationale is for this change? Why
> wouldn't you be able to do a limited-depth local clone? Seems like this
> would
> break some tests, and even if not, would prevent the writing of them.

It's been like this ever since and it puzzled me, "why 'git clone
--depth=2 ~/foo' did not work? What did I do?" Will do as Mikael
suggested.
-- 
Duy

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/3] clone: do not accept --depth on local clones
@ 2010-08-20  1:51 Nguyễn Thái Ngọc Duy
  2010-08-21  0:27 ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-08-20  1:51 UTC (permalink / raw)
  To: Jakub Narebski, mikachu, computerdruid, Junio C Hamano, git
  Cc: Nguyễn Thái Ngọc Duy

clone_local() function disregards --depth. Make it more apparent.
Also hint users that file:// works with --depth.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/clone.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index efb1e6f..e787cf2 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -361,7 +361,7 @@ static void write_remote_refs(const struct ref *local_refs)
 
 int cmd_clone(int argc, const char **argv, const char *prefix)
 {
-	int is_bundle = 0;
+	int is_bundle = 0, is_local;
 	struct stat buf;
 	const char *repo_name, *repo, *work_tree, *git_dir;
 	char *path, *dir;
@@ -414,6 +414,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		repo = xstrdup(make_absolute_path(repo_name));
 	else
 		repo = repo_name;
+	is_local = path && !is_bundle;
+	if (is_local && option_depth)
+		die("local clone with --depth does not make sense\n"
+		    "hint: use file:// instead");
 
 	if (argc == 2)
 		dir = xstrdup(argv[1]);
@@ -514,7 +518,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	strbuf_reset(&value);
 
-	if (path && !is_bundle) {
+	if (is_local) {
 		refs = clone_local(path, git_dir);
 		mapped_refs = wanted_peer_refs(refs, refspec);
 	} else {
-- 
1.7.1.rc1.69.g24c2f7

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again
  2010-08-19 22:11         ` Nguyen Thai Ngoc Duy
@ 2010-08-20  9:22           ` Jakub Narebski
  2010-08-20  9:28             ` Ramkumar Ramachandra
  2010-08-20 11:55             ` [PATCH] grep -A/-B/-Cinfinity to get full context Jonathan Nieder
  0 siblings, 2 replies; 19+ messages in thread
From: Jakub Narebski @ 2010-08-20  9:22 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy
  Cc: git, computerdruid, joey, Jonathan Nieder, Ramkumar Ramachandra

On Fri, Aug 20, 2010, Nguyen Thai Ngoc Duy wrote:
> On Fri, Aug 20, 2010 at 7:22 AM, Jakub Narebski <jnareb@gmail.com> wrote:
>> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>>
>>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>>> ---
>>>  The funny thing is, even with --depth=0, I still have two commit grafts
>>>  in $GIT_DIR/shallow, which are grafts of tags. I think there is a bug
>>> somewhere..
>>>
>>>  builtin/fetch-pack.c |    2 +-
>>>  shallow.c            |    2 +-
>>>  upload-pack.c        |    8 ++++----
>>>  3 files changed, 6 insertions(+), 6 deletions(-)
>>>
>>
>> Fist, it lacks documentation update that --depth=0 means infinite
>> depth (making repository not-shallow).
> 
> Yeah. I would do documentation and tests later once I figured out why
> --depth=0 did not give me full repo. It turns out I need --tags to
> (refetch?) tags and have full repo.

Perhaps --depth=0 should also work as if --tags were specified on
command line?  BTW. shouldn't git fetch tags that point to commits
that got doenloaded because of deepening the clone?

> 
>> Second, it would be nice (though probably not easy with parseopt, as
>> it would require hacks/extensions) to be able to use --depth=inf
>> (like wget supports '-l inf') to mean infinite depth...
> 
> Hmm.. make --depth a string parameter and fetch-pack should parse the
> parameter itself, like git-clone. Good idea.

If there were more options that use <n> == 0 to actually mean unlimited
(infinity), perhaps it would be better to extend parseopt to provide for
such situation, e.g. OPT_INT_INF or something.  This way we would avoid
code duplication.

... oh, wait, the newly introduced[1] git-merge `--log-limit' option
uses --log-limit=0 to mean unlimited.

[1] http://permalink.gmane.org/gmane.comp.version-control.git/153984
    Message-ID: <20100820081641.GA32127@burratino>
    Subject: Re: wishlist bugreport: make limit configurable for do_fmt_merge_msg (merge.log)

-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again
  2010-08-20  9:22           ` Jakub Narebski
@ 2010-08-20  9:28             ` Ramkumar Ramachandra
  2010-08-20 11:55             ` [PATCH] grep -A/-B/-Cinfinity to get full context Jonathan Nieder
  1 sibling, 0 replies; 19+ messages in thread
From: Ramkumar Ramachandra @ 2010-08-20  9:28 UTC (permalink / raw)
  To: Jakub Narebski
  Cc: Nguyen Thai Ngoc Duy, git, computerdruid, joey, Jonathan Nieder,
	Johannes Sixt

Hi Jakub,

Jakub Narebski writes:
> >> Second, it would be nice (though probably not easy with parseopt, as
> >> it would require hacks/extensions) to be able to use --depth=inf
> >> (like wget supports '-l inf') to mean infinite depth...
> > 
> > Hmm.. make --depth a string parameter and fetch-pack should parse the
> > parameter itself, like git-clone. Good idea.
> 
> If there were more options that use <n> == 0 to actually mean unlimited
> (infinity), perhaps it would be better to extend parseopt to provide for
> such situation, e.g. OPT_INT_INF or something.  This way we would avoid
> code duplication.
> 
> ... oh, wait, the newly introduced[1] git-merge `--log-limit' option
> uses --log-limit=0 to mean unlimited.
> 
> [1] http://permalink.gmane.org/gmane.comp.version-control.git/153984
>     Message-ID: <20100820081641.GA32127@burratino>
>     Subject: Re: wishlist bugreport: make limit configurable for do_fmt_merge_msg (merge.log)

Just outdated by a few seconds. Johannes suggested that we reuse
merge.log, making it a bool_or_int option. I What about using -1 to
mean infinity and reserving 0 for false instead?

-- Ram

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] grep -A/-B/-Cinfinity to get full context
  2010-08-20  9:22           ` Jakub Narebski
  2010-08-20  9:28             ` Ramkumar Ramachandra
@ 2010-08-20 11:55             ` Jonathan Nieder
  2010-08-20 13:32               ` Ramkumar Ramachandra
  1 sibling, 1 reply; 19+ messages in thread
From: Jonathan Nieder @ 2010-08-20 11:55 UTC (permalink / raw)
  To: Jakub Narebski
  Cc: Nguyen Thai Ngoc Duy, git, computerdruid, joey,
	Ramkumar Ramachandra, René Scharfe

Just a proof of concept.

Cc: René Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Jakub Narebski wrote:

> If there were more options that use <n> == 0 to actually mean unlimited
> (infinity), perhaps it would be better to extend parseopt to provide for
> such situation, e.g. OPT_INT_INF or something.

Something like this, maybe.

 Documentation/technical/api-parse-options.txt |    6 ++++++
 builtin/grep.c                                |    8 ++++++--
 grep.c                                        |    8 +++++---
 grep.h                                        |    4 ++--
 parse-options.c                               |   21 +++++++++++++++++++++
 parse-options.h                               |    4 ++++
 6 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
index 312e3b2..f152a3f 100644
--- a/Documentation/technical/api-parse-options.txt
+++ b/Documentation/technical/api-parse-options.txt
@@ -160,6 +160,12 @@ There are some macros to easily define options:
 	Introduce an option with integer argument.
 	The integer is put into `int_var`.
 
+`OPT_INT_INF(short, long, &int_var, inf_val, description)`::
+	Introduce an option with integer argument.
+	The integer is put into `int_var`.  If the special value
+	"inf" (or "infinity") is used as an argument, then `inf_val`
+	is put into `int_var`.
+
 `OPT_DATE(short, long, &int_var, description)`::
 	Introduce an option with date argument, see `approxidate()`.
 	The timestamp is put into `int_var`.
diff --git a/builtin/grep.c b/builtin/grep.c
index 597f76b..9fbc985 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -750,6 +750,10 @@ static int context_callback(const struct option *opt, const char *arg,
 		grep_opt->pre_context = grep_opt->post_context = 0;
 		return 0;
 	}
+	if (!strcasecmp(arg, "inf") || !strcasecmp(arg, "infinity")) {
+		grep_opt->pre_context = grep_opt->post_context = -1;
+		return 0;
+	}
 	value = strtol(arg, (char **)&endp, 10);
 	if (*endp) {
 		return error("switch `%c' expects a numerical value",
@@ -890,9 +894,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		OPT_CALLBACK('C', NULL, &opt, "n",
 			"show <n> context lines before and after matches",
 			context_callback),
-		OPT_INTEGER('B', NULL, &opt.pre_context,
+		OPT_INT_INF('B', NULL, &opt.pre_context, -1,
 			"show <n> context lines before matches"),
-		OPT_INTEGER('A', NULL, &opt.post_context,
+		OPT_INT_INF('A', NULL, &opt.post_context, -1,
 			"show <n> context lines after matches"),
 		OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM",
 			context_callback),
diff --git a/grep.c b/grep.c
index 82fb349..793d41f 100644
--- a/grep.c
+++ b/grep.c
@@ -687,7 +687,7 @@ static void show_pre_context(struct grep_opt *opt, const char *name, char *buf,
 	unsigned cur = lno, from = 1, funcname_lno = 0;
 	int funcname_needed = opt->funcname;
 
-	if (opt->pre_context < lno)
+	if (opt->pre_context >= 0 && opt->pre_context < lno)
 		from = lno - opt->pre_context;
 	if (from <= opt->last_shown)
 		from = opt->last_shown + 1;
@@ -861,7 +861,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
 		 */
 		if (try_lookahead
 		    && !(last_hit
-			 && lno <= last_hit + opt->post_context)
+			 && (opt->post_context < 0
+			     || lno <= last_hit + opt->post_context))
 		    && look_ahead(opt, &left, &lno, &bol))
 			break;
 		eol = end_of_line(bol, &left);
@@ -916,7 +917,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
 			last_hit = lno;
 		}
 		else if (last_hit &&
-			 lno <= last_hit + opt->post_context) {
+			 (opt->post_context < 0 ||
+			  lno <= last_hit + opt->post_context)) {
 			/* If the last hit is within the post context,
 			 * we need to show this line.
 			 */
diff --git a/grep.h b/grep.h
index efa8cff..13aae94 100644
--- a/grep.h
+++ b/grep.h
@@ -95,8 +95,8 @@ struct grep_opt {
 	char color_selected[COLOR_MAXLEN];
 	char color_sep[COLOR_MAXLEN];
 	int regflags;
-	unsigned pre_context;
-	unsigned post_context;
+	int pre_context;
+	int post_context;
 	unsigned last_shown;
 	int show_hunk_mark;
 	void *priv;
diff --git a/parse-options.c b/parse-options.c
index 0fa79bc..b299125 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -612,6 +612,27 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
 	return 0;
 }
 
+int parse_opt_infinity_cb(const struct option *opt, const char *arg,
+			  int unset)
+{
+	const char *endp;
+
+	if (unset) {
+		*(int *)opt->value = 0;
+		return 0;
+	}
+	if (!arg)
+		return opterror(opt, "expects a numerical value", 0);
+	if (!strcasecmp(arg, "inf") || !strcasecmp(arg, "infinity")) {
+		*(int *)opt->value = opt->defval;
+		return 0;
+	}
+	*(int *)opt->value = strtol(arg, (char **)&endp, 10);
+	if (*endp)
+		return opterror(opt, "expects a numerical value", 0);
+	return 0;
+}
+
 int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
 			    int unset)
 {
diff --git a/parse-options.h b/parse-options.h
index 7435cdb..6ae041a 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -126,6 +126,9 @@ struct option {
 #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }
 #define OPT_UYN(s, l, v, h)         { OPTION_CALLBACK, (s), (l), (v), NULL, \
 				      (h), PARSE_OPT_NOARG, &parse_opt_tertiary }
+#define OPT_INT_INF(s, l, v, i, h) \
+	{ OPTION_CALLBACK, (s), (l), (v), "n", (h), 0, \
+	  parse_opt_infinity_cb, (intptr_t)(i) }
 #define OPT_DATE(s, l, v, h) \
 	{ OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \
 	  parse_opt_approxidate_cb }
@@ -193,6 +196,7 @@ extern int parse_options_concat(struct option *dst, size_t, struct option *src);
 /*----- some often used options -----*/
 extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
 extern int parse_opt_approxidate_cb(const struct option *, const char *, int);
+extern int parse_opt_infinity_cb(const struct option *, const char *, int);
 extern int parse_opt_color_flag_cb(const struct option *, const char *, int);
 extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
 extern int parse_opt_with_commit(const struct option *, const char *, int);
-- 
1.7.2.2.536.g42dab.dirty

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] grep -A/-B/-Cinfinity to get full context
  2010-08-20 11:55             ` [PATCH] grep -A/-B/-Cinfinity to get full context Jonathan Nieder
@ 2010-08-20 13:32               ` Ramkumar Ramachandra
  0 siblings, 0 replies; 19+ messages in thread
From: Ramkumar Ramachandra @ 2010-08-20 13:32 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Jakub Narebski, Nguyen Thai Ngoc Duy, git, computerdruid, joey,
	René Scharfe

Hi Jonathan,

Jonathan Nieder writes:
> Just a proof of concept.
> 
> Cc: René Scharfe <rene.scharfe@lsrfire.ath.cx>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

Elegant. OPT_INTEGER for integers without the ability to represent
infinity, and OPT_INT_INF for integers with definite representation
for infinity.

> diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
> index 312e3b2..f152a3f 100644
> --- a/Documentation/technical/api-parse-options.txt
> +++ b/Documentation/technical/api-parse-options.txt
> @@ -160,6 +160,12 @@ There are some macros to easily define options:
>  	Introduce an option with integer argument.
>  	The integer is put into `int_var`.
>  
> +`OPT_INT_INF(short, long, &int_var, inf_val, description)`::
> +	Introduce an option with integer argument.
> +	The integer is put into `int_var`.  If the special value
> +	"inf" (or "infinity") is used as an argument, then `inf_val`
> +	is put into `int_var`.

Nice. You're making the caller pass the `inf_val` argument - this way,
each caller can figure out some integer that's outside its sane range
and use that to represent infinity.

> -		OPT_INTEGER('B', NULL, &opt.pre_context,
> +		OPT_INT_INF('B', NULL, &opt.pre_context, -1,
>  			"show <n> context lines before matches"),
> -		OPT_INTEGER('A', NULL, &opt.post_context,
> +		OPT_INT_INF('A', NULL, &opt.post_context, -1,
>  			"show <n> context lines after matches"),
>  		OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM",
>  			context_callback),

For many cases, -1 is probably a good value to choose.

> diff --git a/parse-options.h b/parse-options.h
> index 7435cdb..6ae041a 100644
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -126,6 +126,9 @@ struct option {
>  #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }
>  #define OPT_UYN(s, l, v, h)         { OPTION_CALLBACK, (s), (l), (v), NULL, \
>  				      (h), PARSE_OPT_NOARG, &parse_opt_tertiary }
> +#define OPT_INT_INF(s, l, v, i, h) \
> +	{ OPTION_CALLBACK, (s), (l), (v), "n", (h), 0, \
> +	  parse_opt_infinity_cb, (intptr_t)(i) }

Okay, you've used the same character "n" for OPT_INTEGER and OPT_INT_INF.

Thanks for the pleasant reading.

-- Ram

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/3] clone: do not accept --depth on local clones
  2010-08-20  1:51 [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
@ 2010-08-21  0:27 ` Junio C Hamano
  2010-08-22 22:43   ` Nguyen Thai Ngoc Duy
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2010-08-21  0:27 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: Jakub Narebski, mikachu, computerdruid, git

Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:

> clone_local() function disregards --depth. Make it more apparent.
> Also hint users that file:// works with --depth.

Hmm---why?

The "--depth" option is an ugly hack that tries to conserve network
bandwidth and disk usage, which is not necessary if you are doing a local
hardlinking clone.  Without this patch we allowed people to clone with the
option without a downside (allowing it didn't result in broken repository,
for example), but with it, what has long been allowed suddenly stops
working.  Is the breakage justifiable?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/3] clone: do not accept --depth on local clones
  2010-08-21  0:27 ` Junio C Hamano
@ 2010-08-22 22:43   ` Nguyen Thai Ngoc Duy
  0 siblings, 0 replies; 19+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-08-22 22:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jakub Narebski, mikachu, computerdruid, git

On Sat, Aug 21, 2010 at 10:27 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
>
>> clone_local() function disregards --depth. Make it more apparent.
>> Also hint users that file:// works with --depth.
>
> Hmm---why?
>
> The "--depth" option is an ugly hack that tries to conserve network
> bandwidth and disk usage, which is not necessary if you are doing a local
> hardlinking clone.  Without this patch we allowed people to clone with the
> option without a downside (allowing it didn't result in broken repository,
> for example), but with it, what has long been allowed suddenly stops
> working.  Is the breakage justifiable?

I also expect it to cut down history too. Maybe it's just me, when I
say --depth=3, 'git log' should give me more or less 3 commits
regardless what kind of transport I use to clone. Or we could make it
a warning, "--depth is ignored in local clone"?
-- 
Duy

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-08-22 22:43 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-17  0:49 fully deepening a shallow clone Joey Hess
2010-08-18  9:36 ` Nguyen Thai Ngoc Duy
2010-08-18 12:54   ` Daniel Johnson
2010-08-19 10:40     ` [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
2010-08-19 14:31       ` Daniel Johnson
2010-08-19 22:15         ` Nguyen Thai Ngoc Duy
2010-08-19 20:49       ` Mikael Magnusson
2010-08-19 10:40     ` [PATCH 2/3] fetch-pack: use args.shallow to detect shallow clone instead of args.depth Nguyễn Thái Ngọc Duy
2010-08-19 10:40     ` [PATCH 3/3] {fetch,upload}-pack: allow --depth=0 to deepen into full repo again Nguyễn Thái Ngọc Duy
2010-08-19 21:22       ` Jakub Narebski
2010-08-19 22:11         ` Nguyen Thai Ngoc Duy
2010-08-20  9:22           ` Jakub Narebski
2010-08-20  9:28             ` Ramkumar Ramachandra
2010-08-20 11:55             ` [PATCH] grep -A/-B/-Cinfinity to get full context Jonathan Nieder
2010-08-20 13:32               ` Ramkumar Ramachandra
2010-08-18 15:48   ` fully deepening a shallow clone Joey Hess
  -- strict thread matches above, loose matches on Subject: below --
2010-08-20  1:51 [PATCH 1/3] clone: do not accept --depth on local clones Nguyễn Thái Ngọc Duy
2010-08-21  0:27 ` Junio C Hamano
2010-08-22 22:43   ` Nguyen Thai Ngoc Duy

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).