git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] submodule--helper.c: remove duplicate code
@ 2017-03-08 17:44 me
  2017-03-08 18:53 ` Stefan Beller
  0 siblings, 1 reply; 24+ messages in thread
From: me @ 2017-03-08 17:44 UTC (permalink / raw)
  To: git; +Cc: Valery Tolstov

From: Valery Tolstov <me@vtolstov.org>

Remove code fragment from module_clone that duplicates functionality
of connect_work_tree_and_git_dir in dir.c

Signed-off-by: Valery Tolstov <me@vtolstov.org>
---
>> I think we can reuse code from module_clone that writes .git link.
>> Possibly this code fragment needs to be factored out from module_clone
>
> That fragment already exists, see dir.h:
> connect_work_tree_and_git_dir(work_tree, git_dir);
> Maybe another good microproject is to use that in module_clone.

By suggestion of Stefan Beller I would like to make this micro
improvement as my microproject for GSoc.

 builtin/submodule--helper.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 899dc334e..cda8a3bc1 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -579,7 +579,6 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	const char *name = NULL, *url = NULL, *depth = NULL;
 	int quiet = 0;
 	int progress = 0;
-	FILE *submodule_dot_git;
 	char *p, *path = NULL, *sm_gitdir;
 	struct strbuf rel_path = STRBUF_INIT;
 	struct strbuf sb = STRBUF_INIT;
@@ -653,27 +652,12 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 		strbuf_reset(&sb);
 	}
 
-	/* Write a .git file in the submodule to redirect to the superproject. */
-	strbuf_addf(&sb, "%s/.git", path);
-	if (safe_create_leading_directories_const(sb.buf) < 0)
-		die(_("could not create leading directories of '%s'"), sb.buf);
-	submodule_dot_git = fopen(sb.buf, "w");
-	if (!submodule_dot_git)
-		die_errno(_("cannot open file '%s'"), sb.buf);
-
-	fprintf_or_die(submodule_dot_git, "gitdir: %s\n",
-		       relative_path(sm_gitdir, path, &rel_path));
-	if (fclose(submodule_dot_git))
-		die(_("could not close file %s"), sb.buf);
-	strbuf_reset(&sb);
-	strbuf_reset(&rel_path);
-
-	/* Redirect the worktree of the submodule in the superproject's config */
 	p = git_pathdup_submodule(path, "config");
 	if (!p)
 		die(_("could not get submodule directory for '%s'"), path);
-	git_config_set_in_file(p, "core.worktree",
-			       relative_path(path, sm_gitdir, &rel_path));
+
+	/* Connect module worktree and git dir */
+	connect_work_tree_and_git_dir(path, sm_gitdir);
 
 	/* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */
 	git_config_get_string("submodule.alternateLocation", &sm_alternate);
-- 
2.12.0.190.g250ed7eaf


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

end of thread, other threads:[~2017-03-10 20:48 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-08 17:44 [PATCH] submodule--helper.c: remove duplicate code me
2017-03-08 18:53 ` Stefan Beller
2017-03-08 19:59   ` Valery Tolstov
2017-03-08 20:25     ` Stefan Beller
2017-03-08 23:05       ` Valery Tolstov
2017-03-08 23:15         ` Stefan Beller
2017-03-08 23:24           ` Junio C Hamano
2017-03-08 23:34             ` Stefan Beller
2017-03-09  0:03       ` [PATCH v2 0/2] Remove duplicate code from module_clone() Valery Tolstov
2017-03-09  0:03         ` [PATCH v2 1/2] connect_work_tree_and_git_dir: safely create leading directories Valery Tolstov
2017-03-09  0:03         ` [PATCH v2 2/2] submodule--helper.c: remove duplicate code Valery Tolstov
2017-03-09  0:38           ` Brandon Williams
2017-03-09  1:27             ` [PATCH v3 0/2] Remove duplicate code from module_clone() Valery Tolstov
2017-03-09  1:27               ` [PATCH v3 1/2] connect_work_tree_and_git_dir: safely create leading directories Valery Tolstov
2017-03-09  1:27               ` [PATCH v3 2/2] submodule--helper.c: remove duplicate code Valery Tolstov
2017-03-09 18:18                 ` Brandon Williams
2017-03-10 19:42                   ` Junio C Hamano
2017-03-10 19:49                     ` Stefan Beller
2017-03-10 20:40                       ` Junio C Hamano
2017-03-10 20:48                         ` Stefan Beller
2017-03-09 22:54                 ` Valery Tolstov
2017-03-09  0:28         ` [PATCH v2 0/2] Remove duplicate code from module_clone() Brandon Williams
2017-03-09  0:56           ` Valery Tolstov
2017-03-09 18:19             ` Brandon Williams

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 NNTP newsgroup(s).