git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/6] git clone: Marry --recursive and --reference
@ 2016-08-04 19:51 Stefan Beller
  2016-08-04 19:51 ` [PATCH 1/6] t7408: modernize style Stefan Beller
                   ` (7 more replies)
  0 siblings, 8 replies; 25+ messages in thread
From: Stefan Beller @ 2016-08-04 19:51 UTC (permalink / raw)
  To: gitster; +Cc: git, mst, Jens.Lehmann, Stefan Beller

 Currently when cloning a superproject with --recursive and --reference
 only the superproject learns about its alternates. The submodules are
 cloned independently, which may incur lots of network costs.
 
 Assume that the reference repository has the submodules at the same
 paths as the to-be-cloned submodule and try to setup alternates from
 there.
 
 Some submodules in the referenced superproject may not be there, 
 (they are just not initialized/cloned/checked out), which yields
 an error for now. In future work we may want to soften the alternate
 check and not die in the clone when one of the given alternates doesn't
 exist.
 
 patch 1,2 are modernizing style of t7408, 
 patches 3,4 are not strictly necessary, but I think it is a good thing
 to not leave the submodule related C code in a crippled state (i.e.
 allowing only one reference). The shell code would also need this update,
 but it looked ugly to me, so I postpone it until more of the submodule code
 is written in C. 
 
 Thanks,
 Stefan 

Stefan Beller (6):
  t7408: modernize style
  t7408: merge short tests, factor out testing method
  submodule--helper module-clone: allow multiple references
  submodule--helper update-clone: allow multiple references
  submodule update: add super-reference flag
  clone: reference flag is used for submodules as well

 builtin/clone.c                |  22 ++++--
 builtin/submodule--helper.c    |  45 ++++++++----
 git-submodule.sh               |  12 +++-
 t/t7408-submodule-reference.sh | 153 +++++++++++++++++++++++------------------
 4 files changed, 147 insertions(+), 85 deletions(-)

-- 
2.9.2.572.g9d9644e.dirty


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

* [PATCH 1/6] t7408: modernize style
  2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
@ 2016-08-04 19:51 ` Stefan Beller
  2016-08-05 20:30   ` Junio C Hamano
  2016-08-04 19:51 ` [PATCH 2/6] t7408: merge short tests, factor out testing method Stefan Beller
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-04 19:51 UTC (permalink / raw)
  To: gitster; +Cc: git, mst, Jens.Lehmann, Stefan Beller

No functional change intended. This commit only changes formatting
to the style we recently use, e.g. starting the body of a test with a
single quote on the same line as the header, and then having the test
indented in the following lines.

Whenever we change directories, we do that in subshells.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 t/t7408-submodule-reference.sh | 138 +++++++++++++++++++++--------------------
 1 file changed, 71 insertions(+), 67 deletions(-)

diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
index eaea19b..afcc629 100755
--- a/t/t7408-submodule-reference.sh
+++ b/t/t7408-submodule-reference.sh
@@ -10,72 +10,76 @@ base_dir=$(pwd)
 
 U=$base_dir/UPLOAD_LOG
 
-test_expect_success 'preparing first repository' \
-'test_create_repo A && cd A &&
-echo first > file1 &&
-git add file1 &&
-git commit -m A-initial'
-
-cd "$base_dir"
-
-test_expect_success 'preparing second repository' \
-'git clone A B && cd B &&
-echo second > file2 &&
-git add file2 &&
-git commit -m B-addition &&
-git repack -a -d &&
-git prune'
-
-cd "$base_dir"
-
-test_expect_success 'preparing superproject' \
-'test_create_repo super && cd super &&
-echo file > file &&
-git add file &&
-git commit -m B-super-initial'
-
-cd "$base_dir"
-
-test_expect_success 'submodule add --reference' \
-'cd super && git submodule add --reference ../B "file://$base_dir/A" sub &&
-git commit -m B-super-added'
-
-cd "$base_dir"
-
-test_expect_success 'after add: existence of info/alternates' \
-'test_line_count = 1 super/.git/modules/sub/objects/info/alternates'
-
-cd "$base_dir"
-
-test_expect_success 'that reference gets used with add' \
-'cd super/sub &&
-echo "0 objects, 0 kilobytes" > expected &&
-git count-objects > current &&
-diff expected current'
-
-cd "$base_dir"
-
-test_expect_success 'cloning superproject' \
-'git clone super super-clone'
-
-cd "$base_dir"
-
-test_expect_success 'update with reference' \
-'cd super-clone && git submodule update --init --reference ../B'
-
-cd "$base_dir"
-
-test_expect_success 'after update: existence of info/alternates' \
-'test_line_count = 1 super-clone/.git/modules/sub/objects/info/alternates'
-
-cd "$base_dir"
-
-test_expect_success 'that reference gets used with update' \
-'cd super-clone/sub &&
-echo "0 objects, 0 kilobytes" > expected &&
-git count-objects > current &&
-diff expected current'
-
-cd "$base_dir"
+test_expect_success 'preparing first repository' '
+	test_create_repo A &&
+	(
+		cd A &&
+		echo first >file1 &&
+		git add file1 &&
+		git commit -m A-initial
+	)
+'
+
+test_expect_success 'preparing second repository' '
+	git clone A B &&
+	(
+		cd B &&
+		echo second >file2 &&
+		git add file2 &&
+		git commit -m B-addition &&
+		git repack -a -d &&
+		git prune
+	)
+'
+
+test_expect_success 'preparing superproject' '
+	test_create_repo super &&
+	(
+		cd super &&
+		echo file >file &&
+		git add file &&
+		git commit -m B-super-initial
+	)
+'
+
+test_expect_success 'submodule add --reference' '
+	(
+		cd super &&
+		git submodule add --reference ../B "file://$base_dir/A" sub &&
+		git commit -m B-super-added
+	)
+'
+
+test_expect_success 'after add: existence of info/alternates' '
+	test_line_count = 1 super/.git/modules/sub/objects/info/alternates
+'
+
+test_expect_success 'that reference gets used with add' '
+	(
+		cd super/sub &&
+		echo "0 objects, 0 kilobytes" > expected &&
+		git count-objects > current &&
+		diff expected current
+	)
+'
+
+test_expect_success 'cloning superproject' '
+	git clone super super-clone
+'
+
+test_expect_success 'update with reference' '
+	cd super-clone && git submodule update --init --reference ../B
+'
+
+test_expect_success 'after update: existence of info/alternates' '
+	test_line_count = 1 super-clone/.git/modules/sub/objects/info/alternates
+'
+
+test_expect_success 'that reference gets used with update' '
+	cd super-clone/sub &&
+	echo "0 objects, 0 kilobytes" > expected &&
+	git count-objects > current &&
+	diff expected current
+'
 
 test_done
-- 
2.9.2.572.g9d9644e.dirty


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

* [PATCH 2/6] t7408: merge short tests, factor out testing method
  2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
  2016-08-04 19:51 ` [PATCH 1/6] t7408: modernize style Stefan Beller
@ 2016-08-04 19:51 ` Stefan Beller
  2016-08-05 20:45   ` Junio C Hamano
  2016-08-04 19:51 ` [PATCH 3/6] submodule--helper module-clone: allow multiple references Stefan Beller
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-04 19:51 UTC (permalink / raw)
  To: gitster; +Cc: git, mst, Jens.Lehmann, Stefan Beller

Tests consisting of one line each can be consolidated to have fewer tests
to run as well as fewer lines of code.

When having just a few git commands, do not create a new shell but
use the -C flag in Git to execute in the correct directory.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 t/t7408-submodule-reference.sh | 50 +++++++++++++++---------------------------
 1 file changed, 18 insertions(+), 32 deletions(-)

diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
index afcc629..1416cbd 100755
--- a/t/t7408-submodule-reference.sh
+++ b/t/t7408-submodule-reference.sh
@@ -10,6 +10,16 @@ base_dir=$(pwd)
 
 U=$base_dir/UPLOAD_LOG
 
+test_alternate_usage()
+{
+	alternates_file=$1
+	working_dir=$2
+	test_line_count = 1 $alternates_file &&
+	echo "0 objects, 0 kilobytes" >expect &&
+	git -C $working_dir count-objects >current &&
+	diff expect current
+}
+
 test_expect_success 'preparing first repository' '
 	test_create_repo A &&
 	(
@@ -42,44 +52,20 @@ test_expect_success 'preparing superproject' '
 	)
 '
 
-test_expect_success 'submodule add --reference' '
+test_expect_success 'submodule add --reference uses alternates' '
 	(
 		cd super &&
 		git submodule add --reference ../B "file://$base_dir/A" sub &&
 		git commit -m B-super-added
-	)
-'
-
-test_expect_success 'after add: existence of info/alternates' '
-	test_line_count = 1 super/.git/modules/sub/objects/info/alternates
-'
-
-test_expect_success 'that reference gets used with add' '
-	(
-		cd super/sub &&
-		echo "0 objects, 0 kilobytes" > expected &&
-		git count-objects > current &&
-		diff expected current
-	)
-'
-
-test_expect_success 'cloning superproject' '
-	git clone super super-clone
-'
-
-test_expect_success 'update with reference' '
-	cd super-clone && git submodule update --init --reference ../B
-'
-
-test_expect_success 'after update: existence of info/alternates' '
-	test_line_count = 1 super-clone/.git/modules/sub/objects/info/alternates
+	) &&
+	test_alternate_usage super/.git/modules/sub/objects/info/alternates super/sub
 '
 
-test_expect_success 'that reference gets used with update' '
-	cd super-clone/sub &&
-	echo "0 objects, 0 kilobytes" > expected &&
-	git count-objects > current &&
-	diff expected current
+test_expect_success 'updating superproject keeps alternates' '
+	test_when_finished "rm -rf super-clone" &&
+	git clone super super-clone &&
+	git -C super-clone submodule update --init --reference ../B &&
+	test_alternate_usage super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
 '
 
 test_done
-- 
2.9.2.572.g9d9644e.dirty


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

* [PATCH 3/6] submodule--helper module-clone: allow multiple references
  2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
  2016-08-04 19:51 ` [PATCH 1/6] t7408: modernize style Stefan Beller
  2016-08-04 19:51 ` [PATCH 2/6] t7408: merge short tests, factor out testing method Stefan Beller
@ 2016-08-04 19:51 ` Stefan Beller
  2016-08-05 20:54   ` Junio C Hamano
  2016-08-04 19:51 ` [PATCH 4/6] submodule--helper update-clone: " Stefan Beller
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-04 19:51 UTC (permalink / raw)
  To: gitster; +Cc: git, mst, Jens.Lehmann, Stefan Beller

Allow users to pass in multiple references, just as clone accepts multiple
references as well.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index b22352b..896a3ec 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -442,7 +442,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
 }
 
 static int clone_submodule(const char *path, const char *gitdir, const char *url,
-			   const char *depth, const char *reference, int quiet)
+			   const char *depth, struct string_list *reference, int quiet)
 {
 	struct child_process cp;
 	child_process_init(&cp);
@@ -453,8 +453,11 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
 		argv_array_push(&cp.args, "--quiet");
 	if (depth && *depth)
 		argv_array_pushl(&cp.args, "--depth", depth, NULL);
-	if (reference && *reference)
-		argv_array_pushl(&cp.args, "--reference", reference, NULL);
+	if (reference->nr) {
+		struct string_list_item *item;
+		for_each_string_list_item(item, reference)
+			argv_array_pushl(&cp.args, "--reference", item->string, NULL);
+	}
 	if (gitdir && *gitdir)
 		argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL);
 
@@ -470,13 +473,13 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
 
 static int module_clone(int argc, const char **argv, const char *prefix)
 {
-	const char *name = NULL, *url = NULL;
-	const char *reference = NULL, *depth = NULL;
+	const char *name = NULL, *url = NULL, *depth = NULL;
 	int quiet = 0;
 	FILE *submodule_dot_git;
 	char *p, *path = NULL, *sm_gitdir;
 	struct strbuf rel_path = STRBUF_INIT;
 	struct strbuf sb = STRBUF_INIT;
+	struct string_list reference = STRING_LIST_INIT_NODUP;
 
 	struct option module_clone_options[] = {
 		OPT_STRING(0, "prefix", &prefix,
@@ -491,8 +494,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "url", &url,
 			   N_("string"),
 			   N_("url where to clone the submodule from")),
-		OPT_STRING(0, "reference", &reference,
-			   N_("string"),
+		OPT_STRING_LIST(0, "reference", &reference,
+			   N_("repo"),
 			   N_("reference repository")),
 		OPT_STRING(0, "depth", &depth,
 			   N_("string"),
@@ -528,7 +531,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	if (!file_exists(sm_gitdir)) {
 		if (safe_create_leading_directories_const(sm_gitdir) < 0)
 			die(_("could not create directory '%s'"), sm_gitdir);
-		if (clone_submodule(path, sm_gitdir, url, depth, reference, quiet))
+		if (clone_submodule(path, sm_gitdir, url, depth, &reference, quiet))
 			die(_("clone of '%s' into submodule path '%s' failed"),
 			    url, path);
 	} else {
-- 
2.9.2.572.g9d9644e.dirty


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

* [PATCH 4/6] submodule--helper update-clone: allow multiple references
  2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
                   ` (2 preceding siblings ...)
  2016-08-04 19:51 ` [PATCH 3/6] submodule--helper module-clone: allow multiple references Stefan Beller
@ 2016-08-04 19:51 ` Stefan Beller
  2016-08-05 19:08   ` Stefan Beller
  2016-08-04 19:51 ` [PATCH 5/6] submodule update: add super-reference flag Stefan Beller
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-04 19:51 UTC (permalink / raw)
  To: gitster; +Cc: git, mst, Jens.Lehmann, Stefan Beller

Allow the user to pass in multiple references to update_clone.
Currently this is only internal API, but once the shell script is
replaced by a C version, this is needed.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 14 +++++++++-----
 git-submodule.sh            |  2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 896a3ec..b6f297b 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -583,7 +583,7 @@ struct submodule_update_clone {
 	/* configuration parameters which are passed on to the children */
 	int quiet;
 	int recommend_shallow;
-	const char *reference;
+	struct string_list references;
 	const char *depth;
 	const char *recursive_prefix;
 	const char *prefix;
@@ -599,7 +599,8 @@ struct submodule_update_clone {
 	int failed_clones_nr, failed_clones_alloc;
 };
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
-	SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \
+	SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, STRING_LIST_INIT_DUP, \
+	NULL, NULL, NULL, \
 	STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
 
 
@@ -709,8 +710,11 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 	argv_array_pushl(&child->args, "--path", sub->path, NULL);
 	argv_array_pushl(&child->args, "--name", sub->name, NULL);
 	argv_array_pushl(&child->args, "--url", url, NULL);
-	if (suc->reference)
-		argv_array_push(&child->args, suc->reference);
+	if (suc->references.nr) {
+		struct string_list_item *item;
+		for_each_string_list_item(item, &suc->references)
+			argv_array_pushl(&child->args, "--reference", item->string, NULL);
+	}
 	if (suc->depth)
 		argv_array_push(&child->args, suc->depth);
 
@@ -829,7 +833,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "update", &update,
 			   N_("string"),
 			   N_("rebase, merge, checkout or none")),
-		OPT_STRING(0, "reference", &suc.reference, N_("repo"),
+		OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"),
 			   N_("reference repository")),
 		OPT_STRING(0, "depth", &suc.depth, "<depth>",
 			   N_("Create a shallow clone truncated to the "
diff --git a/git-submodule.sh b/git-submodule.sh
index 2b23ce6..526ea5d 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -575,7 +575,7 @@ cmd_update()
 		${wt_prefix:+--prefix "$wt_prefix"} \
 		${prefix:+--recursive-prefix "$prefix"} \
 		${update:+--update "$update"} \
-		${reference:+--reference "$reference"} \
+		${reference:+"$reference"} \
 		${depth:+--depth "$depth"} \
 		${recommend_shallow:+"$recommend_shallow"} \
 		${jobs:+$jobs} \
-- 
2.9.2.572.g9d9644e.dirty


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

* [PATCH 5/6] submodule update: add super-reference flag
  2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
                   ` (3 preceding siblings ...)
  2016-08-04 19:51 ` [PATCH 4/6] submodule--helper update-clone: " Stefan Beller
@ 2016-08-04 19:51 ` Stefan Beller
  2016-08-05 21:16   ` Junio C Hamano
  2016-08-04 19:51 ` [PATCH 6/6] clone: reference flag is used for submodules as well Stefan Beller
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-04 19:51 UTC (permalink / raw)
  To: gitster; +Cc: git, mst, Jens.Lehmann, Stefan Beller

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 14 +++++++++++++-
 git-submodule.sh            | 10 ++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index b6f297b..707f201 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -584,6 +584,7 @@ struct submodule_update_clone {
 	int quiet;
 	int recommend_shallow;
 	struct string_list references;
+	struct string_list superreferences;
 	const char *depth;
 	const char *recursive_prefix;
 	const char *prefix;
@@ -600,7 +601,7 @@ struct submodule_update_clone {
 };
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
 	SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, STRING_LIST_INIT_DUP, \
-	NULL, NULL, NULL, \
+	STRING_LIST_INIT_DUP, NULL, NULL, NULL, \
 	STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
 
 
@@ -715,6 +716,15 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 		for_each_string_list_item(item, &suc->references)
 			argv_array_pushl(&child->args, "--reference", item->string, NULL);
 	}
+	if (suc->superreferences.nr) {
+		struct string_list_item *item;
+		for_each_string_list_item(item, &suc->superreferences) {
+			strbuf_reset(&sb);
+			argv_array_pushf(&child->args, "--reference=%s/%s",
+					 relative_path(item->string, suc->prefix, &sb),
+					 sub->path);
+		}
+	}
 	if (suc->depth)
 		argv_array_push(&child->args, suc->depth);
 
@@ -835,6 +845,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 			   N_("rebase, merge, checkout or none")),
 		OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"),
 			   N_("reference repository")),
+		OPT_STRING_LIST(0, "super-reference", &suc.superreferences, N_("repo"),
+			   N_("superproject of a reference repository")),
 		OPT_STRING(0, "depth", &suc.depth, "<depth>",
 			   N_("Create a shallow clone truncated to the "
 			      "specified number of revisions")),
diff --git a/git-submodule.sh b/git-submodule.sh
index 526ea5d..99d45c8 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -34,6 +34,7 @@ command=
 branch=
 force=
 reference=
+superreference=
 cached=
 recursive=
 init=
@@ -520,6 +521,14 @@ cmd_update()
 		--reference=*)
 			reference="$1"
 			;;
+		--super-reference)
+			case "$2" in '') usage ;; esac
+			superreference="--super-reference=$2"
+			shift
+			;;
+		--super-reference=*)
+			superreference="$1"
+			;;
 		-m|--merge)
 			update="merge"
 			;;
@@ -576,6 +585,7 @@ cmd_update()
 		${prefix:+--recursive-prefix "$prefix"} \
 		${update:+--update "$update"} \
 		${reference:+"$reference"} \
+		${superreference:+"$superreference"} \
 		${depth:+--depth "$depth"} \
 		${recommend_shallow:+"$recommend_shallow"} \
 		${jobs:+$jobs} \
-- 
2.9.2.572.g9d9644e.dirty


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

* [PATCH 6/6] clone: reference flag is used for submodules as well
  2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
                   ` (4 preceding siblings ...)
  2016-08-04 19:51 ` [PATCH 5/6] submodule update: add super-reference flag Stefan Beller
@ 2016-08-04 19:51 ` Stefan Beller
  2016-08-05 21:36   ` Junio C Hamano
  2016-08-05 19:47 ` [PATCH 0/6] git clone: Marry --recursive and --reference Junio C Hamano
  2016-08-05 23:26 ` Rename detection within in files WAS: [PATCH 2/6] t7408: merge short tests, factor out testing method Stefan Beller
  7 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-04 19:51 UTC (permalink / raw)
  To: gitster; +Cc: git, mst, Jens.Lehmann, Stefan Beller

When giving a --reference while also giving --recurse, the alternates
for the submodules are assumed to be in the superproject as well.

In case they are not, we error out when cloning the submodule.
However the update command succeeds as usual (with no alternates).

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/clone.c                | 22 ++++++++++++++++++----
 t/t7408-submodule-reference.sh | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index f044a8c..f586df5 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -51,6 +51,7 @@ static int option_progress = -1;
 static enum transport_family family;
 static struct string_list option_config = STRING_LIST_INIT_NODUP;
 static struct string_list option_reference = STRING_LIST_INIT_NODUP;
+static struct string_list superreferences = STRING_LIST_INIT_DUP;
 static int option_dissociate;
 static int max_jobs = -1;
 
@@ -280,10 +281,11 @@ static void strip_trailing_slashes(char *dir)
 	*end = '\0';
 }
 
-static int add_one_reference(struct string_list_item *item, void *cb_data)
+static int add_one_reference(struct string_list_item *item, void *cb_dir)
 {
 	char *ref_git;
 	const char *repo;
+	const char *dir = cb_dir;
 	struct strbuf alternate = STRBUF_INIT;
 
 	/* Beware: read_gitfile(), real_path() and mkpath() return static buffer */
@@ -316,6 +318,13 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
 	if (!access(mkpath("%s/info/grafts", ref_git), F_OK))
 		die(_("reference repository '%s' is grafted"), item->string);
 
+	if (option_recursive) {
+		struct strbuf sb = STRBUF_INIT;
+		char *rel = xstrdup(relative_path(item->string, dir, &sb));
+		string_list_append(&superreferences, rel);
+		strbuf_reset(&sb);
+	}
+
 	strbuf_addf(&alternate, "%s/objects", ref_git);
 	add_to_alternates_file(alternate.buf);
 	strbuf_release(&alternate);
@@ -323,9 +332,9 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
 	return 0;
 }
 
-static void setup_reference(void)
+static void setup_reference(char *dir)
 {
-	for_each_string_list(&option_reference, add_one_reference, NULL);
+	for_each_string_list(&option_reference, add_one_reference, dir);
 }
 
 static void copy_alternates(struct strbuf *src, struct strbuf *dst,
@@ -736,6 +745,7 @@ static int checkout(void)
 
 	if (!err && option_recursive) {
 		struct argv_array args = ARGV_ARRAY_INIT;
+		static struct string_list_item *item;
 		argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
 
 		if (option_shallow_submodules == 1)
@@ -744,6 +754,10 @@ static int checkout(void)
 		if (max_jobs != -1)
 			argv_array_pushf(&args, "--jobs=%d", max_jobs);
 
+		if (superreferences.nr)
+			for_each_string_list_item(item, &superreferences)
+				argv_array_pushf(&args, "--super-reference=%s", item->string);
+
 		err = run_command_v_opt(args.argv, RUN_GIT_CMD);
 		argv_array_clear(&args);
 	}
@@ -978,7 +992,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	strbuf_reset(&key);
 
 	if (option_reference.nr)
-		setup_reference();
+		setup_reference(dir);
 
 	fetch_pattern = value.buf;
 	refspec = parse_fetch_refspec(1, &fetch_pattern);
diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
index 1416cbd..2652cfe 100755
--- a/t/t7408-submodule-reference.sh
+++ b/t/t7408-submodule-reference.sh
@@ -56,7 +56,8 @@ test_expect_success 'submodule add --reference uses alternates' '
 	(
 		cd super &&
 		git submodule add --reference ../B "file://$base_dir/A" sub &&
-		git commit -m B-super-added
+		git commit -m B-super-added &&
+		git repack -ad
 	) &&
 	test_alternate_usage super/.git/modules/sub/objects/info/alternates super/sub
 '
@@ -68,4 +69,32 @@ test_expect_success 'updating superproject keeps alternates' '
 	test_alternate_usage super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
 '
 
+test_expect_success 'submodules use alternates when cloning a superproject' '
+	test_when_finished "rm -rf super-clone" &&
+	git clone --reference super --recursive super super-clone &&
+	(
+		cd super-clone &&
+		# test superproject has alternates setup correctly
+		test_alternate_usage .git/objects/info/alternates . &&
+		# test submodule has correct setup
+		test_alternate_usage .git/modules/sub/objects/info/alternates sub
+	)
+'
+
+test_expect_success 'cloning superproject, missing submodule alternates' '
+	test_when_finished "rm -rf super-clone" &&
+	git clone super super2 &&
+	test_must_fail git clone --recursive --reference super2 super2 super-clone &&
+	(
+		cd super-clone &&
+		# test superproject has alternates setup correctly
+		test_alternate_usage .git/objects/info/alternates . &&
+		# update of the submodule succeeds
+		git submodule update --init &&
+		# and we have no alternates:
+		test_must_fail test_alternate_usage .git/modules/sub/objects/info/alternates sub &&
+		test_path_is_file sub/file1
+	)
+'
+
 test_done
-- 
2.9.2.572.g9d9644e.dirty


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

* Re: [PATCH 4/6] submodule--helper update-clone: allow multiple references
  2016-08-04 19:51 ` [PATCH 4/6] submodule--helper update-clone: " Stefan Beller
@ 2016-08-05 19:08   ` Stefan Beller
  2016-08-05 21:06     ` Junio C Hamano
  0 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-05 19:08 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, mst, Jens Lehmann, Stefan Beller

> -               ${reference:+--reference "$reference"} \
> +               ${reference:+"$reference"} \

Note how this changed the API of the submodule--helper.
Currently we pass in --reference $reference
and $reference consists of the string "--reference" and the actual
reference. So it looked like '--reference' '--reference=foo'

That is why we can pass the argument unseen to clone in the helper
via

    argv_array_push(&child->args, suc->reference);

This is fixed now.

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

* Re: [PATCH 0/6] git clone: Marry --recursive and --reference
  2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
                   ` (5 preceding siblings ...)
  2016-08-04 19:51 ` [PATCH 6/6] clone: reference flag is used for submodules as well Stefan Beller
@ 2016-08-05 19:47 ` Junio C Hamano
  2016-08-05 21:23   ` Stefan Beller
  2016-08-05 23:26 ` Rename detection within in files WAS: [PATCH 2/6] t7408: merge short tests, factor out testing method Stefan Beller
  7 siblings, 1 reply; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 19:47 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, mst, Jens.Lehmann

Stefan Beller <sbeller@google.com> writes:

>  Currently when cloning a superproject with --recursive and --reference
>  only the superproject learns about its alternates. The submodules are
>  cloned independently, which may incur lots of network costs.
>  
>  Assume that the reference repository has the submodules at the same
>  paths as the to-be-cloned submodule and try to setup alternates from
>  there.

I am a bit fuzzy about what scenario you are trying to help.  Is it
something like this? [*1*]

 * The superproject is at git://frotz.xz/super.git but you locally
   have a mirror at /var/cache/super.git (bare) repository.

 * "git clone --refererence /var/cache/super.git git://frotz.xz/super.git"
   would borrow that existing local mirror to cut down the traffic.

 * The super.git project uses git://nitfol.xz/xyzzy.git as its
   submodule.  You locally have a mirror of it at
   /var/cache/xyzzy.git (bare) repository.

 * The xyzzy submodule is bound at libs/xyzzy in the superproject
   tree.

 * You want the "clone" command above with "--recursive" to do "the
   right thing".  That is, the clone of the superproject borrows
   from /var/cache/super.git local mirror, and the clone of xyzzy
   that would be made at .git/modules/xyzzy in the superproject
   would borrow from /var/cache/xyzzy.git local mirror.

What I am not sure about is how /var/cache/xyzzy.git should be
automatically derived from the information given from the command
line of "clone" and what the clone of the superproject contains.
You'd need to make certain assumptions, like

 - The parent directory of the --reference for superproject,
   i.e. /var/cache/, is the directry that has many other mirrors;

 - The .gitmodules file in superproject says a "xyzzy" project from
   git://nitfol.xz/xyzzy.git must be checked out at "libs/xyzzy",
   and it is a reasonable assumption that we would find a local
   mirror at /var/cache/xyzzy.git (the /var/cache prefix comes from
   the above assumptino).

There may be some other assumptions you are making.  I am wondering
if your specific assumption is applicable generally.


[Footnote]

*1* Another common arrangement could be that you have one full clone
    of the superproject at /var/cache/super.git and its submodule
    xyzzy in /var/cache/super.git/modules/xyzzy and assuming that
    would allow you to guess where to borrow submodules from.  But
    the result of assuming this layout would already be different
    from the scenario I gave the above.  If the organization uses
    the xyzzy project only in the context of the frotz superproject,
    "borrow from submodule repository inside $GIT_DIR/modules/ of
    the superproject" may be sensible, but that makes use of "xyzzy"
    as an independent project quite awkward (also you may have
    another superproject that is unrelated to super.git that uses
    the same "xyzzy" project as its submodule).  The more "xyzzy"
    project is suitable to be used as "submodule", the more it makes
    sense to have its mirror independent from the superprojects that
    use it, by using /var/cache/{super,xyzzy}.git layout.

    IOW, both layouts are equally sensible; what layout (either one
    of the above two, or something entirely different) is your "at
    the same paths" assumption meant to serve well, and what is the
    plan to serve other layouts?




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

* Re: [PATCH 1/6] t7408: modernize style
  2016-08-04 19:51 ` [PATCH 1/6] t7408: modernize style Stefan Beller
@ 2016-08-05 20:30   ` Junio C Hamano
  0 siblings, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 20:30 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, mst, Jens.Lehmann

Stefan Beller <sbeller@google.com> writes:

> No functional change intended. This commit only changes formatting
> to the style we recently use, e.g. starting the body of a test with a
> single quote on the same line as the header, and then having the test
> indented in the following lines.
>
> Whenever we change directories, we do that in subshells.

All look sensible; I think it is OK to also do minor and trivial
tweaks here, but let's see what 2/6 does.

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

* Re: [PATCH 2/6] t7408: merge short tests, factor out testing method
  2016-08-04 19:51 ` [PATCH 2/6] t7408: merge short tests, factor out testing method Stefan Beller
@ 2016-08-05 20:45   ` Junio C Hamano
  2016-08-05 22:45     ` Stefan Beller
  0 siblings, 1 reply; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 20:45 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, mst, Jens.Lehmann

Stefan Beller <sbeller@google.com> writes:

> Tests consisting of one line each can be consolidated to have fewer tests
> to run as well as fewer lines of code.
>
> When having just a few git commands, do not create a new shell but
> use the -C flag in Git to execute in the correct directory.

Good motivations.

> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  t/t7408-submodule-reference.sh | 50 +++++++++++++++---------------------------
>  1 file changed, 18 insertions(+), 32 deletions(-)
>
> diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
> index afcc629..1416cbd 100755
> --- a/t/t7408-submodule-reference.sh
> +++ b/t/t7408-submodule-reference.sh
> @@ -10,6 +10,16 @@ base_dir=$(pwd)
>  
>  U=$base_dir/UPLOAD_LOG

Is this line needed anywhere?

We (perhaps unfortunately) still need $base_dir because we want to
give an absolute file:/// URL to "submodule add", but I do not think
we use $U, so let's get rid of it.

> +test_alternate_usage()
> +{

According to Documentation/CodingGuidelines, this should be:

    test_alternate_usage () {

Somehow the helper name sounds as if it is testing if an alternate
is used correctly (i.e. the machinery may attempt to use alternate
but not in a correct way), not testing if an alternate is correctly
used (i.e. the machinery incorrectly forgets to use an alternate at
all), but maybe it is just me.

> +	alternates_file=$1
> +	working_dir=$2

These are good (they can be on a single line), but you would
want &&-chain just as other lines.

> +	test_line_count = 1 $alternates_file &&

This needs to quote "$alternates_file" especially in a helper
function you have no control over future callers of.

I wonder if we want to check the actual contents of the alternate;
it may force us to worry about the infamous "should we expect
$(pwd)/something or $PWD/something" if we did so, so it is not a
strong suggestion.

> +	echo "0 objects, 0 kilobytes" >expect &&
> +	git -C $working_dir count-objects >current &&
> +	diff expect current

It is more customary to name two "expect" vs "actual", and compare
them using "test_cmp" not "diff".

> +}
> +
>  test_expect_success 'preparing first repository' '
>  	test_create_repo A &&
>  	(
> @@ -42,44 +52,20 @@ test_expect_success 'preparing superproject' '
>  	)
>  '
>  
> -test_expect_success 'submodule add --reference' '
> +test_expect_success 'submodule add --reference uses alternates' '
>  	(
>  		cd super &&
>  		git submodule add --reference ../B "file://$base_dir/A" sub &&
>  		git commit -m B-super-added
> -	)
> -'
> -
> -test_expect_success 'after add: existence of info/alternates' '
> -	test_line_count = 1 super/.git/modules/sub/objects/info/alternates
> -'
> -
> -test_expect_success 'that reference gets used with add' '
> -	(
> -		cd super/sub &&
> -		echo "0 objects, 0 kilobytes" > expected &&
> -		git count-objects > current &&
> -		diff expected current
> -	)
> -'

Completely unrelated tangent, but after seeing the "how would we
make a more intelligent choice of the diff boundary" topic, I
wondered if we can notice that at this point there is a logical
boundary and do something intelligent about it.  All the removed
lines above have become "test_alternate" we see below, while all the
removed lines below upto "test_alternate" correspond to the updated
test at the end.

> -test_expect_success 'cloning superproject' '
> -	git clone super super-clone
> -'
> -
> -test_expect_success 'update with reference' '
> -	cd super-clone && git submodule update --init --reference ../B
> -'
> -
> -test_expect_success 'after update: existence of info/alternates' '
> -	test_line_count = 1 super-clone/.git/modules/sub/objects/info/alternates
> +	) &&
> +	test_alternate_usage super/.git/modules/sub/objects/info/alternates super/sub
>  '
>  
> -test_expect_success 'that reference gets used with update' '
> -	cd super-clone/sub &&
> -	echo "0 objects, 0 kilobytes" > expected &&
> -	git count-objects > current &&
> -	diff expected current
> +test_expect_success 'updating superproject keeps alternates' '
> +	test_when_finished "rm -rf super-clone" &&

This one is new; we do not remove A, B or super.  Does it matter if
we leave super-clone behind?  Is super-clone so special?

> +	git clone super super-clone &&
> +	git -C super-clone submodule update --init --reference ../B &&
> +	test_alternate_usage super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
>  '
>  
>  test_done

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

* Re: [PATCH 3/6] submodule--helper module-clone: allow multiple references
  2016-08-04 19:51 ` [PATCH 3/6] submodule--helper module-clone: allow multiple references Stefan Beller
@ 2016-08-05 20:54   ` Junio C Hamano
  0 siblings, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 20:54 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, mst, Jens.Lehmann

Stefan Beller <sbeller@google.com> writes:

> Allow users to pass in multiple references, just as clone accepts multiple
> references as well.

As these are passed-thru to the underlying "git clone", this change
makes perfect sense to me.

Will queue.


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

* Re: [PATCH 4/6] submodule--helper update-clone: allow multiple references
  2016-08-05 19:08   ` Stefan Beller
@ 2016-08-05 21:06     ` Junio C Hamano
  2016-08-05 21:19       ` Stefan Beller
  0 siblings, 1 reply; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 21:06 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org, mst, Jens Lehmann

Stefan Beller <sbeller@google.com> writes:

>> -               ${reference:+--reference "$reference"} \
>> +               ${reference:+"$reference"} \
>
> Note how this changed the API of the submodule--helper.
> Currently we pass in --reference $reference
> and $reference consists of the string "--reference" and the actual
> reference. So it looked like '--reference' '--reference=foo'

So this change is a strict bugfix.  The code without this patch
had cmd_update that places "--reference=foo" in $reference, but
the call to "git submodule--helper" it makes added an unnecessary
"--reference" in front of it.

I was wondering why there is no corresponding change to add
"--reference" on the code that calls cmd_update().  Thanks for
saving my time ;-)

Perhaps that needs to go into the log message, though.  Allowing
multiple references is not that interesting from the POV of the
codebase immediately after this step and only deserves a "by the
way" mention.

    Subject: submodule--helper: fix cmd_update()

    cmd_update places "--reference=foo" in $reference, but the call to
    "git submodule--helper" it makes adds an unnecessary "--reference"
    in front of it.  The underlying "git clone" was called with two
    command options "--reference" and "--reference=foo" because of
    this.

    While at it, prepare the code to accept multiple references, as
    the underlying "git clone" can happily take more than one.

or something like that.

Needless to say, "While at it" could become a separate step, and a
pure bugfix part may even want to become a separate and more urgent
topic that can go to 'maint', with a test to prevent regression.

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

* Re: [PATCH 5/6] submodule update: add super-reference flag
  2016-08-04 19:51 ` [PATCH 5/6] submodule update: add super-reference flag Stefan Beller
@ 2016-08-05 21:16   ` Junio C Hamano
  2016-08-06  0:22     ` Stefan Beller
  0 siblings, 1 reply; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 21:16 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, mst, Jens.Lehmann

Stefan Beller <sbeller@google.com> writes:

> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---

That's a bit sketchy description.  From the title, I expected that
we would see one additional 'unsigned super_reference : 1;' field in
some structure, but that is not what is happening.  The log message
needs to describe what these string list are and why they are needed
a bit better.

At least, please don't name a multiple_word field "multipleword" ;-)

> @@ -715,6 +716,15 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
>  		for_each_string_list_item(item, &suc->references)
>  			argv_array_pushl(&child->args, "--reference", item->string, NULL);
>  	}
> +	if (suc->superreferences.nr) {
> +		struct string_list_item *item;
> +		for_each_string_list_item(item, &suc->superreferences) {
> +			strbuf_reset(&sb);
> +			argv_array_pushf(&child->args, "--reference=%s/%s",
> +					 relative_path(item->string, suc->prefix, &sb),
> +					 sub->path);

The phrase "super reference" made me imagine it is some kind of
"reference" that is applicable to the superproject, but this code
smells like it is a "prefix to create reference suited for use in
submodule".  Whatever it is, it should be explained better (than "no
desciption" which is what we have here ;-), and given a name that
match the explanation.

Thanks.

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

* Re: [PATCH 4/6] submodule--helper update-clone: allow multiple references
  2016-08-05 21:06     ` Junio C Hamano
@ 2016-08-05 21:19       ` Stefan Beller
  2016-08-05 21:31         ` Junio C Hamano
  0 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-05 21:19 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, mst, Jens Lehmann

On Fri, Aug 5, 2016 at 2:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>>> -               ${reference:+--reference "$reference"} \
>>> +               ${reference:+"$reference"} \
>>
>> Note how this changed the API of the submodule--helper.
>> Currently we pass in --reference $reference
>> and $reference consists of the string "--reference" and the actual
>> reference. So it looked like '--reference' '--reference=foo'
>
> So this change is a strict bugfix.  The code without this patch
> had cmd_update that places "--reference=foo" in $reference, but
> the call to "git submodule--helper" it makes added an unnecessary
> "--reference" in front of it.

I thought about rolling it as a strict bugfix; but the bug is shaded by the
inverse bug in the helper, so the user would never see an issue.

It is more a cleanup of the internal communication between the shell
script and the helper written in C. (And that communication is
supposed to not be user visible or relevant)

>
> I was wondering why there is no corresponding change to add
> "--reference" on the code that calls cmd_update().  Thanks for
> saving my time ;-)

When I wrote the patch I cared more about the while-at-it part than
the bug fix as I do not consider the bug worth to merge down to maint
or even fast tracking it as a bug fix. It's just changing the internal
communication to be clearer.

>
> Perhaps that needs to go into the log message, though.  Allowing
> multiple references is not that interesting from the POV of the
> codebase immediately after this step and only deserves a "by the
> way" mention.
>
>     Subject: submodule--helper: fix cmd_update()
>
>     cmd_update places "--reference=foo" in $reference, but the call to
>     "git submodule--helper" it makes adds an unnecessary "--reference"
>     in front of it.  The underlying "git clone" was called with two
>     command options "--reference" and "--reference=foo" because of
>     this.
>
>     While at it, prepare the code to accept multiple references, as
>     the underlying "git clone" can happily take more than one.
>
> or something like that.
>
> Needless to say, "While at it" could become a separate step, and a
> pure bugfix part may even want to become a separate and more urgent
> topic that can go to 'maint', with a test to prevent regression.

Sure. I'll do so in a reroll.

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

* Re: [PATCH 0/6] git clone: Marry --recursive and --reference
  2016-08-05 19:47 ` [PATCH 0/6] git clone: Marry --recursive and --reference Junio C Hamano
@ 2016-08-05 21:23   ` Stefan Beller
  2016-08-05 21:47     ` Junio C Hamano
  0 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-05 21:23 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, mst, Jens Lehmann

On Fri, Aug 5, 2016 at 12:47 PM, Junio C Hamano <gitster@pobox.com> wrote:
>  * You want the "clone" command above with "--recursive" to do "the
>    right thing".  That is, the clone of the superproject borrows
>    from /var/cache/super.git local mirror, and the clone of xyzzy
>    that would be made at .git/modules/xyzzy in the superproject
>    would borrow from /var/cache/xyzzy.git local mirror.

This is not what I intend to solve here. The solution in 6/6 solves
the scenario as you outlined in [1].

>
> What I am not sure about is how /var/cache/xyzzy.git should be
> automatically derived from the information given from the command
> line of "clone" and what the clone of the superproject contains.

Generally speaking you cannot do that without assumptions.

The scenario in [1] can be done without assumptions of the locations
of the submodules. The only requirement for [1] is to have submodules
checked out, which is a rather strong requirement, as that doesn't
help you when you want to reference multiple superrpojects with
incomplete submodule checkout. (Given all of them together may or
may not produce the full set of references)

>
>     IOW, both layouts are equally sensible; what layout (either one
>     of the above two, or something entirely different) is your "at
>     the same paths" assumption meant to serve well, and what is the
>     plan to serve other layouts?
>

The plan for other layouts might be

    git submodule update --reference-dir /var/cache/

?

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

* Re: [PATCH 4/6] submodule--helper update-clone: allow multiple references
  2016-08-05 21:19       ` Stefan Beller
@ 2016-08-05 21:31         ` Junio C Hamano
  2016-08-05 21:33           ` Stefan Beller
  0 siblings, 1 reply; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 21:31 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org, mst, Jens Lehmann

Stefan Beller <sbeller@google.com> writes:

> I thought about rolling it as a strict bugfix; but the bug is shaded by the
> inverse bug in the helper, so the user would never see an issue.

Ahh, OK, because the helper accepts "--reference" "--reference=foo"
as a OPT_STRING whose value happens to be "--reference=foo", and
then uses

	if (suc->reference)
        	argv_array_push(&child->args, suc->reference)

where suc->reference _is_ "--reference=foo" when invoking the
underlying "git clone", it cancels out.

Then it is OK.

In fact there is NO bug.  It just is that update_clone subcommand
used a convention different from others that took the whole
--option=arg as a parameter to --reference option.  It could be
argued that it is an API bug between git-submodule.sh and
git-submodule--helper, but nobody else goes through this "weird"
interface, so it is not worth splitting the patch.

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

* Re: [PATCH 4/6] submodule--helper update-clone: allow multiple references
  2016-08-05 21:31         ` Junio C Hamano
@ 2016-08-05 21:33           ` Stefan Beller
  0 siblings, 0 replies; 25+ messages in thread
From: Stefan Beller @ 2016-08-05 21:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, mst, Jens Lehmann

On Fri, Aug 5, 2016 at 2:31 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> I thought about rolling it as a strict bugfix; but the bug is shaded by the
>> inverse bug in the helper, so the user would never see an issue.
>
> Ahh, OK, because the helper accepts "--reference" "--reference=foo"
> as a OPT_STRING whose value happens to be "--reference=foo", and
> then uses
>
>         if (suc->reference)
>                 argv_array_push(&child->args, suc->reference)
>
> where suc->reference _is_ "--reference=foo" when invoking the
> underlying "git clone", it cancels out.
>
> Then it is OK.
>
> In fact there is NO bug.  It just is that update_clone subcommand
> used a convention different from others that took the whole
> --option=arg as a parameter to --reference option.  It could be
> argued that it is an API bug between git-submodule.sh and
> git-submodule--helper, but nobody else goes through this "weird"
> interface, so it is not worth splitting the patch.


I'll mention the fix of the API bug in the reroll then.

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

* Re: [PATCH 6/6] clone: reference flag is used for submodules as well
  2016-08-04 19:51 ` [PATCH 6/6] clone: reference flag is used for submodules as well Stefan Beller
@ 2016-08-05 21:36   ` Junio C Hamano
  0 siblings, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 21:36 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, mst, Jens.Lehmann

Stefan Beller <sbeller@google.com> writes:

> When giving a --reference while also giving --recurse, the alternates
> for the submodules are assumed to be in the superproject as well.
>
> In case they are not, we error out when cloning the submodule.
> However the update command succeeds as usual (with no alternates).

I covered most of what I want to say on this in my reply to 0/6; I
do not have strong objection against what single layout you chose to
support, nor I have strong opinion on which single layout we should
support by default, or what mechanism, if any, we should give users
to specify different layout.

But please make sure the choice you made is explained for the users.
The end-user documentation should talk about the effect of giving
these two options together.

Thanks.

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

* Re: [PATCH 0/6] git clone: Marry --recursive and --reference
  2016-08-05 21:23   ` Stefan Beller
@ 2016-08-05 21:47     ` Junio C Hamano
  0 siblings, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 21:47 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org, mst, Jens Lehmann

Stefan Beller <sbeller@google.com> writes:

> The plan for other layouts might be
>
>     git submodule update --reference-dir /var/cache/

That is not a plan for "other layouts", but a plan for "the other
layout that was mentioned as a possibility".  As I said, both
layouts are equally plausible, and I do not know if we need to plan
for layouts other than these two, but we should consider if we want
to add one new option every time we find a new layout we need to
support, or we want a general framework that is more flexible and
allows us to make the "borrow from the $GIT_DIR/modules/ of the
repository the superproject borrows from" a mere special case of it.

Thanks.


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

* Re: [PATCH 2/6] t7408: merge short tests, factor out testing method
  2016-08-05 20:45   ` Junio C Hamano
@ 2016-08-05 22:45     ` Stefan Beller
  2016-08-05 23:09       ` Junio C Hamano
  0 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-05 22:45 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, mst, Jens Lehmann

On Fri, Aug 5, 2016 at 1:45 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> Tests consisting of one line each can be consolidated to have fewer tests
>> to run as well as fewer lines of code.
>>
>> When having just a few git commands, do not create a new shell but
>> use the -C flag in Git to execute in the correct directory.
>
> Good motivations.
>
>> Signed-off-by: Stefan Beller <sbeller@google.com>
>> ---
>>  t/t7408-submodule-reference.sh | 50 +++++++++++++++---------------------------
>>  1 file changed, 18 insertions(+), 32 deletions(-)
>>
>> diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
>> index afcc629..1416cbd 100755
>> --- a/t/t7408-submodule-reference.sh
>> +++ b/t/t7408-submodule-reference.sh
>> @@ -10,6 +10,16 @@ base_dir=$(pwd)
>>
>>  U=$base_dir/UPLOAD_LOG
>
> Is this line needed anywhere?
>
> We (perhaps unfortunately) still need $base_dir because we want to
> give an absolute file:/// URL to "submodule add", but I do not think
> we use $U, so let's get rid of it.
>
>> +test_alternate_usage()
>> +{
>
> According to Documentation/CodingGuidelines, this should be:
>
>     test_alternate_usage () {
>
> Somehow the helper name sounds as if it is testing if an alternate
> is used correctly (i.e. the machinery may attempt to use alternate
> but not in a correct way), not testing if an alternate is correctly
> used (i.e. the machinery incorrectly forgets to use an alternate at
> all), but maybe it is just me.
>
>> +     alternates_file=$1
>> +     working_dir=$2
>
> These are good (they can be on a single line), but you would
> want &&-chain just as other lines.
>
>> +     test_line_count = 1 $alternates_file &&
>
> This needs to quote "$alternates_file" especially in a helper
> function you have no control over future callers of.
>
> I wonder if we want to check the actual contents of the alternate;
> it may force us to worry about the infamous "should we expect
> $(pwd)/something or $PWD/something" if we did so, so it is not a
> strong suggestion.
>
>> +     echo "0 objects, 0 kilobytes" >expect &&
>> +     git -C $working_dir count-objects >current &&
>> +     diff expect current
>
> It is more customary to name two "expect" vs "actual", and compare
> them using "test_cmp" not "diff".
>
>> +}
>> +
>>  test_expect_success 'preparing first repository' '
>>       test_create_repo A &&
>>       (
>> @@ -42,44 +52,20 @@ test_expect_success 'preparing superproject' '
>>       )
>>  '
>>
>> -test_expect_success 'submodule add --reference' '
>> +test_expect_success 'submodule add --reference uses alternates' '
>>       (
>>               cd super &&
>>               git submodule add --reference ../B "file://$base_dir/A" sub &&
>>               git commit -m B-super-added
>> -     )
>> -'
>> -
>> -test_expect_success 'after add: existence of info/alternates' '
>> -     test_line_count = 1 super/.git/modules/sub/objects/info/alternates
>> -'
>> -
>> -test_expect_success 'that reference gets used with add' '
>> -     (
>> -             cd super/sub &&
>> -             echo "0 objects, 0 kilobytes" > expected &&
>> -             git count-objects > current &&
>> -             diff expected current

This is where the "diff" and "current" above came from.

>> -     )
>> -'
>
> Completely unrelated tangent, but after seeing the "how would we
> make a more intelligent choice of the diff boundary" topic, I
> wondered if we can notice that at this point there is a logical
> boundary and do something intelligent about it.  All the removed
> lines above have become "test_alternate" we see below, while all the
> removed lines below upto "test_alternate" correspond to the updated
> test at the end.

I guess that would require even more knowledge of the underlying
content that we track in Git.

Originally I started the diff boundary topic, as I assumed that the
new line detection is not doing harm. What Michael came up with
is impressive though I fear there might be a selection bias in the corpus,
i.e. we are missing some projects that get worse by it and these projects
would have had a great influence on the selection of the tuning parameters.
I guess we'll just wait until someone speaks up and points at worse
examples there.

What you're asking here is a complete new ballpark IMHO
as it takes diff to a whole new (syntactical) level. As of now
the world agrees that '\n' seems to be a good character to
put in text documents, so we use it as a splitting token
in our underlying diff driver, i.e. the diffs are primarily by line,
no matter how many characters change in that line. Sometimes
there is a "secondary" aspect such as coloring and pointing out
the characters that changed in a line[1].

[1] random example:
https://gerrit-review.googlesource.com/#/c/79354/3/project.py
Visually we focus on the changed characters, but the underlying
diff is still "by line".

We could write another "diff driver" that would not segment the
text by '\n' as a primary method and then showing the changed
hunks with +/-, but it would try to find rearrangements in the
underlying text:

As an example, this patch with such a diff driver could read partially as:
----8<----
***diff-driver: moved-text line 42 -> 14, length:7, post-operations: 1
 test_expect_success 'that reference gets used with add' '
      (
              cd super/sub &&
*             echo "0 objects, 0 kilobytes" > expected &&
*             git count-objects > current &&
*             diff expected current
      )
***diff-driver:post-operation 1:
*** modify moved text with:

+test_alternate_usage() {
+        alternates_file="$1" &&
+        working_dir="$2" &&
*             echo "0 objects, 0 kilobytes" > expected &&
*             git count-objects > current &&
*             diff expected current
+ }

***diff-driver: deletion 40,50

 -     )
 -'
 -
 -test_expect_success 'after add: existence of info/alternates' '
 -     test_line_count = 1 super/.git/modules/sub/objects/info/alternates
 -'
 -
----8<----

Thinking about this further, this would not require knowledge of
the underlying content, it is actually "just" an intra-file-rename
detection.

We have a rename detection from one blob to another, so we
could also have a similar thing to deduplicate within one blob,
which would track moving code around.


>
>> -test_expect_success 'cloning superproject' '
>> -     git clone super super-clone
>> -'
>> -
>> -test_expect_success 'update with reference' '
>> -     cd super-clone && git submodule update --init --reference ../B
>> -'
>> -
>> -test_expect_success 'after update: existence of info/alternates' '
>> -     test_line_count = 1 super-clone/.git/modules/sub/objects/info/alternates
>> +     ) &&
>> +     test_alternate_usage super/.git/modules/sub/objects/info/alternates super/sub
>>  '
>>
>> -test_expect_success 'that reference gets used with update' '
>> -     cd super-clone/sub &&
>> -     echo "0 objects, 0 kilobytes" > expected &&
>> -     git count-objects > current &&
>> -     diff expected current
>> +test_expect_success 'updating superproject keeps alternates' '
>> +     test_when_finished "rm -rf super-clone" &&
>
> This one is new; we do not remove A, B or super.  Does it matter if
> we leave super-clone behind?  Is super-clone so special?

"We need it in a later test."

It comes down to philosophy of how to write tests.

I spent some time in 740* and this is a surprising short test.
Compare to 7404 and 7400 for example. These are very long,
so when you want to add another test (no matter if testing for a
fixed regression or a new feature), you have lots of repos like

    super, super2, super3, sub, sub1, sumodule, anothersub,

and none of the names make sense. (Can I reuse them?
do they have some weird corner case configuration
that I need to undo? etc)

To stop that from happening again I want to have a clean slate,
i.e. all clones are deleted shortly after using, so it is obvious what
to use for testing.

>
>> +     git clone super super-clone &&
>> +     git -C super-clone submodule update --init --reference ../B &&
>> +     test_alternate_usage super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
>>  '
>>
>>  test_done

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

* Re: [PATCH 2/6] t7408: merge short tests, factor out testing method
  2016-08-05 22:45     ` Stefan Beller
@ 2016-08-05 23:09       ` Junio C Hamano
  0 siblings, 0 replies; 25+ messages in thread
From: Junio C Hamano @ 2016-08-05 23:09 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org, mst, Jens Lehmann

Stefan Beller <sbeller@google.com> writes:

>>> -test_expect_success 'that reference gets used with add' '
>>> -     (
>>> -             cd super/sub &&
>>> -             echo "0 objects, 0 kilobytes" > expected &&
>>> -             git count-objects > current &&
>>> -             diff expected current
>
> This is where the "diff" and "current" above came from.

I KNOW that, but I thought this effort is a continuation of the
modernise-and-make-it-maintainable effort started at 1/6.

> To stop that from happening again I want to have a clean slate,
> i.e. all clones are deleted shortly after using, so it is obvious what
> to use for testing.

OK.  So A, B and super (and super/sub) are the ones that survive
throughout the test, and individual test (including the "let's try
cloning the super into super-clone" at the end of existing tests)
would follow create-use-remove pattern?  Perhaps that can be left
as a comment before the last existing test, e.g. "A, B and super are
permanent, and from here on, if you create a clone of them for
testing, remove your clone once you are done", to inform the test
writers of this convention.

Thanks.

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

* Rename detection within in files WAS: [PATCH 2/6] t7408: merge short tests, factor out testing method
  2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
                   ` (6 preceding siblings ...)
  2016-08-05 19:47 ` [PATCH 0/6] git clone: Marry --recursive and --reference Junio C Hamano
@ 2016-08-05 23:26 ` Stefan Beller
  2016-08-07  9:24   ` René Scharfe
  7 siblings, 1 reply; 25+ messages in thread
From: Stefan Beller @ 2016-08-05 23:26 UTC (permalink / raw)
  To: gitster; +Cc: git, Stefan Beller

When moving code around, we usually get large chunks of text. If the contributor
is not 100% trustworthy, we need to review all the code without much intelectual
joy. Essentially the reviewer is just making sure the parts of the text are the
same.

I'd like to propose a new addition to the diff format that makes this use case
easier. The idea is to mark up lines that were just moved around in the file
instead of adding and removing them.

Currently we have 3 characters that
are allowed to start a line within a hunk:
' ' to indicate context
'+' to add a line
'-' to remove a line

I'd propose to add the following characters:
'*' which is the same as '+', but it indicates that the line was moved
    from somewhere else without change.
'X' The same as '-', with the addition that this line was moved to a different
    place without change.

The patch below uses these new '*' and 'X'. Each hunk that makes use of these
additions, is followed other sections, [moved-from, moved-to] that indicate
where the corresponding line is.

There are multiple things to tackle when going for such an addition:
* How to present this to the user (it's covered in this email)
* how to find the renamed lines algorithmically.
  (there are already approaches to that, e.g. https://github.com/stefanbeller/duplo
  which is http://duplo.sourceforge.net/ with no substantial additions)

Any comments welcome,

Thanks,
Stefan

---
 t/t7408-submodule-reference.sh | 50 +++++++++++++++---------------------------
 1 file changed, 15 insertions(+), 29 deletions(-), 6 moved lines

diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
index afcc629..1416cbd 100755
--- a/t/t7408-submodule-reference.sh
+++ b/t/t7408-submodule-reference.sh
@@ -10,6 +10,16 @@ base_dir=$(pwd)

 U=$base_dir/UPLOAD_LOG

+test_alternate_usage()
+{
+	alternates_file=$1
+	working_dir=$2
+	test_line_count = 1 $alternates_file &&
*	echo "0 objects, 0 kilobytes" >expect &&
*	git -C $working_dir count-objects >current &&
*	diff expect current
+}
+
 test_expect_success 'preparing first repository' '
 	test_create_repo A &&
 	(
@@ move-source 42,6 @@ test_expect_success 'that reference gets used with add' '
 test_expect_success 'that reference gets used with add' '
 	(
 		cd super/sub &&
X		echo "0 objects, 0 kilobytes" > expected &&
X		git count-objects > current &&
X		diff expected current
 	)
 '
@@ -42,44 +52,20 @@ test_expect_success 'preparing superproject' '
 	)
 '

-test_expect_success 'submodule add --reference' '
+test_expect_success 'submodule add --reference uses alternates' '
 	(
 		cd super &&
 		git submodule add --reference ../B "file://$base_dir/A" sub &&
 		git commit -m B-super-added
-	)
-'
-
-test_expect_success 'after add: existence of info/alternates' '
-	test_line_count = 1 super/.git/modules/sub/objects/info/alternates
-'
-
-test_expect_success 'that reference gets used with add' '
-	(
-		cd super/sub &&
X		echo "0 objects, 0 kilobytes" > expected &&
X		git count-objects > current &&
X		diff expected current
-	)
-'
-
-test_expect_success 'cloning superproject' '
-	git clone super super-clone
-'
-
@@ move-to 10,6 @@ test_alternate_usage
+	alternates_file=$1
+	working_dir=$2
+	test_line_count = 1 $alternates_file &&
*	echo "0 objects, 0 kilobytes" >expect &&
*	git -C $working_dir count-objects >current &&
*	diff expect current
+}
+
--
2.9.2.572.g9d9644e.dirty

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

* Re: [PATCH 5/6] submodule update: add super-reference flag
  2016-08-05 21:16   ` Junio C Hamano
@ 2016-08-06  0:22     ` Stefan Beller
  0 siblings, 0 replies; 25+ messages in thread
From: Stefan Beller @ 2016-08-06  0:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org, mst, Jens Lehmann

On Fri, Aug 5, 2016 at 2:16 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> Signed-off-by: Stefan Beller <sbeller@google.com>
>> ---
>
> That's a bit sketchy description.  From the title, I expected that
> we would see one additional 'unsigned super_reference : 1;' field in
> some structure, but that is not what is happening.  The log message
> needs to describe what these string list are and why they are needed
> a bit better.

A "--super-reference" allows giving a reference to a superproject instead
of a direct reference.

With --reference you had to point to the direct repository, e.g.

    git clone --reference /usr/share/foo git://xyxxz.example/foo

assumed that /usr/share/foo is either the working dir or the git dir
of said project.

When giving references in the submodule context (this part of the helper
is called from "git submodule update", which itself is called from
"git clone --recursive"  we do not know the place where the submodule
reference is living. As we do know where the superproject reference is
living (i.e. "git clone --recursive --reference <superproject>"),
we can construct one possible path where the submodules are located
at <superproject>/<submodule-path>. To differentiate the reference flag
from a direct reference this will be called "--super-reference" as it
references a super project.

The next patch makes use of it by just passing on the --reference
given to "git clone" as --super-reference to the "submodule update"
procedure, which then uses the code in this patch.

>
> At least, please don't name a multiple_word field "multipleword" ;-)

uh :( OK.

>
>> @@ -715,6 +716,15 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
>>               for_each_string_list_item(item, &suc->references)
>>                       argv_array_pushl(&child->args, "--reference", item->string, NULL);
>>       }
>> +     if (suc->superreferences.nr) {
>> +             struct string_list_item *item;
>> +             for_each_string_list_item(item, &suc->superreferences) {
>> +                     strbuf_reset(&sb);
>> +                     argv_array_pushf(&child->args, "--reference=%s/%s",
>> +                                      relative_path(item->string, suc->prefix, &sb),
>> +                                      sub->path);
>
> The phrase "super reference" made me imagine it is some kind of
> "reference" that is applicable to the superproject,

Oh I see. Except that from the superprojects point of view, it is not a
superproject; it is just a project with submodules. From a submodules point
of view you have a superproject however, so a super-reference is a reference
that points to another superproject, so we can find a sibling reference.

> but this code
> smells like it is a "prefix to create reference suited for use in
> submodule".

Yeah that's it.

> Whatever it is, it should be explained better (than "no
> desciption" which is what we have here ;-), and given a name that
> match the explanation.
>
> Thanks.

OK.

Thanks,
Stefan

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

* Re: Rename detection within in files WAS: [PATCH 2/6] t7408: merge short tests, factor out testing method
  2016-08-05 23:26 ` Rename detection within in files WAS: [PATCH 2/6] t7408: merge short tests, factor out testing method Stefan Beller
@ 2016-08-07  9:24   ` René Scharfe
  0 siblings, 0 replies; 25+ messages in thread
From: René Scharfe @ 2016-08-07  9:24 UTC (permalink / raw)
  To: Stefan Beller, gitster; +Cc: git

Am 06.08.2016 um 01:26 schrieb Stefan Beller:
> When moving code around, we usually get large chunks of text. If the contributor
> is not 100% trustworthy, we need to review all the code without much intelectual
> joy. Essentially the reviewer is just making sure the parts of the text are the
> same.
>
> I'd like to propose a new addition to the diff format that makes this use case
> easier. The idea is to mark up lines that were just moved around in the file
> instead of adding and removing them.
>
> Currently we have 3 characters that
> are allowed to start a line within a hunk:
> ' ' to indicate context
> '+' to add a line
> '-' to remove a line
>
> I'd propose to add the following characters:
> '*' which is the same as '+', but it indicates that the line was moved
>      from somewhere else without change.
> 'X' The same as '-', with the addition that this line was moved to a different
>      place without change.
>
> The patch below uses these new '*' and 'X'. Each hunk that makes use of these
> additions, is followed other sections, [moved-from, moved-to] that indicate
> where the corresponding line is.

Interesting idea. It should be easy to convert the result into a regular 
unified diff for consumption with patch(1) or git am/apply by replacing 
the new flags with + and - and removing the moved-* hunks.

Your example ignores whitespace changes at the start of the line and 
within it, the added "-C $working_dir", s/expected/expect/; is this all 
intended?  Only a single blank line was moved verbatim.

The moved-from and moved-to hunks make this diff quite verbose.

If multiple lines from different sources are moved to the same hunk then 
you'd get multiple moved-from hunks following that single destination, 
right?  (Same with lines moved from a single hunk to multiple 
destinations and moved-to.)

But does it even warrent a new format? It's a display problem; the 
necessary information is already in the diffs we have today.  A 
graphical diff viewer could connect moved blocks with lines, like 
http://www.araxis.com/merge/ does in its side-by-side view.  A 
Thunderbird extension (or a bookmarklet or browser extendiion for 
webmail users) could do that for an email-based workflow.

Still, what about adding information about moved lines as an extended 
header (like that index line)?  Line numbers are included in hunk 
headers and can serve as orientation.  A reader would have to do some 
mental arithmetic (ugh), but incompatible format changes would be 
avoided.  For your example it should look something like this:

	move from t/t7408-submodule-reference.sh:52,1
	move to t/t7408-submodule-reference.sh:22,1

>
> There are multiple things to tackle when going for such an addition:
> * How to present this to the user (it's covered in this email)
> * how to find the renamed lines algorithmically.
>    (there are already approaches to that, e.g. https://github.com/stefanbeller/duplo
>    which is http://duplo.sourceforge.net/ with no substantial additions)
>
> Any comments welcome,
>
> Thanks,
> Stefan
>
> ---
>   t/t7408-submodule-reference.sh | 50 +++++++++++++++---------------------------
>   1 file changed, 15 insertions(+), 29 deletions(-), 6 moved lines
>
> diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
> index afcc629..1416cbd 100755
> --- a/t/t7408-submodule-reference.sh
> +++ b/t/t7408-submodule-reference.sh
> @@ -10,6 +10,16 @@ base_dir=$(pwd)
>
>   U=$base_dir/UPLOAD_LOG
>
> +test_alternate_usage()
> +{
> +	alternates_file=$1
> +	working_dir=$2
> +	test_line_count = 1 $alternates_file &&
> *	echo "0 objects, 0 kilobytes" >expect &&
> *	git -C $working_dir count-objects >current &&
> *	diff expect current
> +}
> +

Post-image line 22.

>   test_expect_success 'preparing first repository' '
>   	test_create_repo A &&
>   	(
> @@ move-source 42,6 @@ test_expect_success 'that reference gets used with add' '
>   test_expect_success 'that reference gets used with add' '
>   	(
>   		cd super/sub &&
> X		echo "0 objects, 0 kilobytes" > expected &&
> X		git count-objects > current &&
> X		diff expected current
>   	)
>   '
> @@ -42,44 +52,20 @@ test_expect_success 'preparing superproject' '
>   	)
>   '
>
> -test_expect_success 'submodule add --reference' '
> +test_expect_success 'submodule add --reference uses alternates' '
>   	(
>   		cd super &&
>   		git submodule add --reference ../B "file://$base_dir/A" sub &&
>   		git commit -m B-super-added
> -	)
> -'
> -

Pre-image line 52.

> -test_expect_success 'after add: existence of info/alternates' '
> -	test_line_count = 1 super/.git/modules/sub/objects/info/alternates
> -'
> -
> -test_expect_success 'that reference gets used with add' '
> -	(
> -		cd super/sub &&
> X		echo "0 objects, 0 kilobytes" > expected &&
> X		git count-objects > current &&
> X		diff expected current
> -	)
> -'
> -
> -test_expect_success 'cloning superproject' '
> -	git clone super super-clone
> -'
> -
> @@ move-to 10,6 @@ test_alternate_usage
> +	alternates_file=$1
> +	working_dir=$2
> +	test_line_count = 1 $alternates_file &&
> *	echo "0 objects, 0 kilobytes" >expect &&
> *	git -C $working_dir count-objects >current &&
> *	diff expect current
> +}
> +
> --
> 2.9.2.572.g9d9644e.dirty
>


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

end of thread, other threads:[~2016-08-07  9:24 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-04 19:51 [PATCH 0/6] git clone: Marry --recursive and --reference Stefan Beller
2016-08-04 19:51 ` [PATCH 1/6] t7408: modernize style Stefan Beller
2016-08-05 20:30   ` Junio C Hamano
2016-08-04 19:51 ` [PATCH 2/6] t7408: merge short tests, factor out testing method Stefan Beller
2016-08-05 20:45   ` Junio C Hamano
2016-08-05 22:45     ` Stefan Beller
2016-08-05 23:09       ` Junio C Hamano
2016-08-04 19:51 ` [PATCH 3/6] submodule--helper module-clone: allow multiple references Stefan Beller
2016-08-05 20:54   ` Junio C Hamano
2016-08-04 19:51 ` [PATCH 4/6] submodule--helper update-clone: " Stefan Beller
2016-08-05 19:08   ` Stefan Beller
2016-08-05 21:06     ` Junio C Hamano
2016-08-05 21:19       ` Stefan Beller
2016-08-05 21:31         ` Junio C Hamano
2016-08-05 21:33           ` Stefan Beller
2016-08-04 19:51 ` [PATCH 5/6] submodule update: add super-reference flag Stefan Beller
2016-08-05 21:16   ` Junio C Hamano
2016-08-06  0:22     ` Stefan Beller
2016-08-04 19:51 ` [PATCH 6/6] clone: reference flag is used for submodules as well Stefan Beller
2016-08-05 21:36   ` Junio C Hamano
2016-08-05 19:47 ` [PATCH 0/6] git clone: Marry --recursive and --reference Junio C Hamano
2016-08-05 21:23   ` Stefan Beller
2016-08-05 21:47     ` Junio C Hamano
2016-08-05 23:26 ` Rename detection within in files WAS: [PATCH 2/6] t7408: merge short tests, factor out testing method Stefan Beller
2016-08-07  9:24   ` René Scharfe

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).