Re: [PATCH] builtin-clone: fix for new unpack_trees() semantics

Previous thread: [PATCH 09/11] Provide API access to init_db() by Daniel Barkalow on Saturday, March 8, 2008 - 4:04 pm. (4 messages)

Next thread: [PATCH 08/11] Allow for having for_each_ref() list some refs that aren't local by Daniel Barkalow on Saturday, March 8, 2008 - 4:04 pm. (5 messages)
From: Daniel Barkalow
Date: Saturday, March 8, 2008 - 4:04 pm

This version is still a mess, but it passes all of the tests. I'm
somewhat unconvinced by the test coverage for clone, however; the
last failure I found was actually for which heads get created in a
bare repository, and it was only failing when there was an extra one
in a non-bare clone in a test for something entirely different.

Thanks to Johannes Schindelin for various comments and improvements.
---
 Makefile                                      |    2 +-
 builtin-clone.c                               |  542 +++++++++++++++++++++++++
 builtin.h                                     |    1 +
 git-clone.sh => contrib/examples/git-clone.sh |    0 
 git.c                                         |    1 +
 t/t5701-clone-local.sh                        |    6 +-
 6 files changed, 548 insertions(+), 4 deletions(-)
 create mode 100644 builtin-clone.c
 rename git-clone.sh => contrib/examples/git-clone.sh (100%)

diff --git a/Makefile b/Makefile
index 7917509..aec2ac3 100644
--- a/Makefile
+++ b/Makefile
@@ -231,7 +231,6 @@ BASIC_LDFLAGS =
 
 SCRIPT_SH = \
 	git-bisect.sh \
-	git-clone.sh \
 	git-merge-one-file.sh git-mergetool.sh git-parse-remote.sh \
 	git-pull.sh git-rebase.sh git-rebase--interactive.sh \
 	git-repack.sh git-request-pull.sh \
@@ -348,6 +347,7 @@ BUILTIN_OBJS = \
 	builtin-checkout-index.o \
 	builtin-check-ref-format.o \
 	builtin-clean.o \
+	builtin-clone.o \
 	builtin-commit.o \
 	builtin-commit-tree.o \
 	builtin-count-objects.o \
diff --git a/builtin-clone.c b/builtin-clone.c
new file mode 100644
index 0000000..1b83062
--- /dev/null
+++ b/builtin-clone.c
@@ -0,0 +1,542 @@
+/*
+ * Builtin "git clone"
+ *
+ * Copyright (c) 2007 Kristian H
From: Johannes Schindelin
Date: Sunday, March 9, 2008 - 2:30 pm

In git.git's "next" branch, unpack_trees() must specify source and target 
index.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	To be squashed into 10/11

 builtin-clone.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/builtin-clone.c b/builtin-clone.c
index e4047ed..3890e12 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -534,6 +534,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		opts.verbose_update = !option_quiet;
 		opts.merge = 1;
 		opts.fn = twoway_merge;
+		opts.src_index = &the_index;
+		opts.dst_index = &the_index;
 
 		tree = parse_tree_indirect(remote_head->old_sha1);
 		parse_tree(tree);
-- 
1.5.4.3.653.gbc310

--

From: Daniel Barkalow
Date: Sunday, March 9, 2008 - 3:35 pm

Actually, I think the sensible thing is to just not do a merge here, since 
we know there's no index beforehand and the two trees are the same.

I think the odd twoway merge of two copies of HEAD is just an artifact of 
clone originally just doing "git checkout HEAD", and that got translated 
various times failing to notice the special cases.

	-Daniel
*This .sig left intentionally blank*
--

From: Johannes Schindelin
Date: Sunday, March 9, 2008 - 3:55 pm

Hi,


Okay, but would oneway_merge not want to write the index, too (rightfully 
so)?

Ciao,
Dscho

--

From: Daniel Barkalow
Date: Sunday, March 9, 2008 - 4:02 pm

I'm thinking:

  memset(&opts, 0, sizeof opts);
  opts.update = 1;
  opts.verbose_update = !option_quiet;
  opts.dst_index = &the_index;

  init_tree_desc(&t[0], tree->buffer, tree->size);
  unpack_trees(1, t, &opts);

That is, write it, but not read it, and only have one tree.

	-Daniel
*This .sig left intentionally blank*
--

From: Johannes Schindelin
Date: Sunday, March 9, 2008 - 4:05 pm

Hi,


Yes.  And this sets dst_index (what I tried to hint at with my patch).

Ciao,
Dscho

--

From: Daniel Barkalow
Date: Sunday, March 9, 2008 - 4:14 pm

Oh, yes. Your patch is what prompted me to fix that part (and to find that 
Linus's unpack_trees was in next now). But seeing src_index in your patch 
made me wonder what it wanted a source index for anyway, since this is the 
first index we've had in this repo.

	-Daniel
*This .sig left intentionally blank*
--

From: Johannes Schindelin
Date: Monday, March 10, 2008 - 3:58 am

Hi,


Well, stupid copy-'n-paste.  Well, not all that stupid: because of the 
twoway_merge (and because the segmentation fault was in a line accessing 
src_index), I assumed that the src_index is needed.

But your explanation that oneway_merge is all we want makes tons of sense.

Ciao,
Dscho

--

Previous thread: [PATCH 09/11] Provide API access to init_db() by Daniel Barkalow on Saturday, March 8, 2008 - 4:04 pm. (4 messages)

Next thread: [PATCH 08/11] Allow for having for_each_ref() list some refs that aren't local by Daniel Barkalow on Saturday, March 8, 2008 - 4:04 pm. (5 messages)