git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 3/6] builtin/submodule--helper: factor out submodule updating
  2018-07-12 19:47 [PATCH 0/6] git-submodule.sh: convert part of cmd_update to C Stefan Beller
@ 2018-07-12 19:47 ` Stefan Beller
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-12 19:47 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Separate the command line parsing from the actual execution of the command
within the repository. For now there is not a lot of execution as
most of it is still in git-submodule.sh.

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

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ebcfe85bfa9..96929ba1096 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1472,6 +1472,8 @@ struct submodule_update_clone {
 	/* failed clones to be retried again */
 	const struct cache_entry **failed_clones;
 	int failed_clones_nr, failed_clones_alloc;
+
+	int max_jobs;
 };
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
 	SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
@@ -1714,11 +1716,36 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
 	return 0;
 }
 
+static int update_submodules(struct submodule_update_clone *suc)
+{
+	struct string_list_item *item;
+
+	run_processes_parallel(suc->max_jobs,
+			       update_clone_get_next_task,
+			       update_clone_start_failure,
+			       update_clone_task_finished,
+			       suc);
+
+	/*
+	 * We saved the output and put it out all at once now.
+	 * That means:
+	 * - the listener does not have to interleave their (checkout)
+	 *   work with our fetching.  The writes involved in a
+	 *   checkout involve more straightforward sequential I/O.
+	 * - the listener can avoid doing any work if fetching failed.
+	 */
+	if (suc->quickstop)
+		return 1;
+
+	for_each_string_list_item(item, &suc->projectlines)
+		fprintf(stdout, "%s", item->string);
+
+	return 0;
+}
+
 static int update_clone(int argc, const char **argv, const char *prefix)
 {
 	const char *update = NULL;
-	int max_jobs = 1;
-	struct string_list_item *item;
 	struct pathspec pathspec;
 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
 
@@ -1740,7 +1767,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "depth", &suc.depth, "<depth>",
 			   N_("Create a shallow clone truncated to the "
 			      "specified number of revisions")),
-		OPT_INTEGER('j', "jobs", &max_jobs,
+		OPT_INTEGER('j', "jobs", &suc.max_jobs,
 			    N_("parallel jobs")),
 		OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
 			    N_("whether the initial clone should follow the shallow recommendation")),
@@ -1756,8 +1783,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	};
 	suc.prefix = prefix;
 
-	config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
-	git_config(gitmodules_update_clone_config, &max_jobs);
+	config_from_gitmodules(gitmodules_update_clone_config, &suc.max_jobs);
+	git_config(gitmodules_update_clone_config, &suc.max_jobs);
 
 	argc = parse_options(argc, argv, prefix, module_update_clone_options,
 			     git_submodule_helper_usage, 0);
@@ -1772,27 +1799,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	if (pathspec.nr)
 		suc.warn_if_uninitialized = 1;
 
-	run_processes_parallel(max_jobs,
-			       update_clone_get_next_task,
-			       update_clone_start_failure,
-			       update_clone_task_finished,
-			       &suc);
-
-	/*
-	 * We saved the output and put it out all at once now.
-	 * That means:
-	 * - the listener does not have to interleave their (checkout)
-	 *   work with our fetching.  The writes involved in a
-	 *   checkout involve more straightforward sequential I/O.
-	 * - the listener can avoid doing any work if fetching failed.
-	 */
-	if (suc.quickstop)
-		return 1;
-
-	for_each_string_list_item(item, &suc.projectlines)
-		fprintf(stdout, "%s", item->string);
-
-	return 0;
+	return update_submodules(&suc);
 }
 
 static int resolve_relative_path(int argc, const char **argv, const char *prefix)
-- 
2.18.0.203.gfac676dfb9-goog


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

* [PATCH 0/6] Resend of origin/sb/submodule-update-in-c
@ 2018-07-18 19:48 Stefan Beller
  2018-07-18 19:48 ` [PATCH 1/6] git-submodule.sh: align error reporting for update mode to use path Stefan Beller
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-18 19:48 UTC (permalink / raw)
  To: git; +Cc: gitster, szeder.dev, stolee, Stefan Beller

This fixes the compilation issue raised by SZEDER and Stolee,


6:  3c156c79ae7 ! 6:  f82f24e73b6 submodule--helper: introduce new update-module-mode helper
    @@ -10,7 +10,6 @@
         for arbitrary repositories.
     
         Signed-off-by: Stefan Beller <sbeller@google.com>
    -    Signed-off-by: Junio C Hamano <gitster@pobox.com>
     
     diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
     --- a/builtin/submodule--helper.c
    @@ -74,7 +73,7 @@
     +	determine_submodule_update_strategy(the_repository,
     +					    just_cloned, path, update,
     +					    &update_strategy);
    -+	fprintf(stdout, submodule_strategy_to_string(&update_strategy));
    ++	fputs(submodule_strategy_to_string(&update_strategy), stdout);
     +
     +	return 0;
     +}

Thanks,
Stefan

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

* [PATCH 1/6] git-submodule.sh: align error reporting for update mode to use path
  2018-07-18 19:48 [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Stefan Beller
@ 2018-07-18 19:48 ` Stefan Beller
  2018-07-18 19:48 ` [PATCH 2/6] git-submodule.sh: rename unused variables Stefan Beller
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-18 19:48 UTC (permalink / raw)
  To: git; +Cc: gitster, szeder.dev, stolee, Stefan Beller

All other error messages in cmd_update are reporting the submodule based
on its path, so let's do that for invalid update modes, too.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 git-submodule.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 5f9d9f6ea37..8a611865397 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -627,7 +627,7 @@ cmd_update()
 				must_die_on_failure=yes
 				;;
 			*)
-				die "$(eval_gettext "Invalid update mode '$update_module' for submodule '$name'")"
+				die "$(eval_gettext "Invalid update mode '$update_module' for submodule path '$path'")"
 			esac
 
 			if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1")
-- 
2.18.0.233.g985f88cf7e-goog


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

* [PATCH 2/6] git-submodule.sh: rename unused variables
  2018-07-18 19:48 [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Stefan Beller
  2018-07-18 19:48 ` [PATCH 1/6] git-submodule.sh: align error reporting for update mode to use path Stefan Beller
@ 2018-07-18 19:48 ` Stefan Beller
  2018-07-18 19:48 ` [PATCH 3/6] builtin/submodule--helper: factor out submodule updating Stefan Beller
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-18 19:48 UTC (permalink / raw)
  To: git; +Cc: gitster, szeder.dev, stolee, Stefan Beller

The 'mode' variable is not used in cmd_update for its original purpose,
rename it to 'dummy' as it only serves the purpose to abort quickly
documenting this knowledge.

The variable 'stage' is also not used any more in cmd_update, so remove it.

This went unnoticed as first each function used the commonly used
submodule listing, which was converted in 74703a1e4df (submodule: rewrite
`module_list` shell function in C, 2015-09-02). When cmd_update was
using its own function starting in 48308681b07 (git submodule update:
have a dedicated helper for cloning, 2016-02-29), its removal was missed.

A later patch in this series also touches the communication between
the submodule helper and git-submodule.sh, but let's have this as
a preparatory patch, as it eases the next patch, which stores the
raw data instead of the line printed for this communication.

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

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 20ae9191ca3..ebcfe85bfa9 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1571,9 +1571,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 	needs_cloning = !file_exists(sb.buf);
 
 	strbuf_reset(&sb);
-	strbuf_addf(&sb, "%06o %s %d %d\t%s\n", ce->ce_mode,
-			oid_to_hex(&ce->oid), ce_stage(ce),
-			needs_cloning, ce->name);
+	strbuf_addf(&sb, "dummy %s %d\t%s\n",
+		    oid_to_hex(&ce->oid), needs_cloning, ce->name);
 	string_list_append(&suc->projectlines, sb.buf);
 
 	if (!needs_cloning)
diff --git a/git-submodule.sh b/git-submodule.sh
index 8a611865397..56588aa304d 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -531,9 +531,9 @@ cmd_update()
 		"$@" || echo "#unmatched" $?
 	} | {
 	err=
-	while read -r mode sha1 stage just_cloned sm_path
+	while read -r quickabort sha1 just_cloned sm_path
 	do
-		die_if_unmatched "$mode" "$sha1"
+		die_if_unmatched "$quickabort" "$sha1"
 
 		name=$(git submodule--helper name "$sm_path") || exit
 		if ! test -z "$update"
-- 
2.18.0.233.g985f88cf7e-goog


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

* [PATCH 3/6] builtin/submodule--helper: factor out submodule updating
  2018-07-18 19:48 [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Stefan Beller
  2018-07-18 19:48 ` [PATCH 1/6] git-submodule.sh: align error reporting for update mode to use path Stefan Beller
  2018-07-18 19:48 ` [PATCH 2/6] git-submodule.sh: rename unused variables Stefan Beller
@ 2018-07-18 19:48 ` Stefan Beller
  2018-07-18 19:48 ` [PATCH 4/6] builtin/submodule--helper: store update_clone information in a struct Stefan Beller
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-18 19:48 UTC (permalink / raw)
  To: git; +Cc: gitster, szeder.dev, stolee, Stefan Beller

Separate the command line parsing from the actual execution of the command
within the repository. For now there is not a lot of execution as
most of it is still in git-submodule.sh.

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

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ebcfe85bfa9..96929ba1096 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1472,6 +1472,8 @@ struct submodule_update_clone {
 	/* failed clones to be retried again */
 	const struct cache_entry **failed_clones;
 	int failed_clones_nr, failed_clones_alloc;
+
+	int max_jobs;
 };
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
 	SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
@@ -1714,11 +1716,36 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
 	return 0;
 }
 
+static int update_submodules(struct submodule_update_clone *suc)
+{
+	struct string_list_item *item;
+
+	run_processes_parallel(suc->max_jobs,
+			       update_clone_get_next_task,
+			       update_clone_start_failure,
+			       update_clone_task_finished,
+			       suc);
+
+	/*
+	 * We saved the output and put it out all at once now.
+	 * That means:
+	 * - the listener does not have to interleave their (checkout)
+	 *   work with our fetching.  The writes involved in a
+	 *   checkout involve more straightforward sequential I/O.
+	 * - the listener can avoid doing any work if fetching failed.
+	 */
+	if (suc->quickstop)
+		return 1;
+
+	for_each_string_list_item(item, &suc->projectlines)
+		fprintf(stdout, "%s", item->string);
+
+	return 0;
+}
+
 static int update_clone(int argc, const char **argv, const char *prefix)
 {
 	const char *update = NULL;
-	int max_jobs = 1;
-	struct string_list_item *item;
 	struct pathspec pathspec;
 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
 
@@ -1740,7 +1767,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "depth", &suc.depth, "<depth>",
 			   N_("Create a shallow clone truncated to the "
 			      "specified number of revisions")),
-		OPT_INTEGER('j', "jobs", &max_jobs,
+		OPT_INTEGER('j', "jobs", &suc.max_jobs,
 			    N_("parallel jobs")),
 		OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
 			    N_("whether the initial clone should follow the shallow recommendation")),
@@ -1756,8 +1783,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	};
 	suc.prefix = prefix;
 
-	config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
-	git_config(gitmodules_update_clone_config, &max_jobs);
+	config_from_gitmodules(gitmodules_update_clone_config, &suc.max_jobs);
+	git_config(gitmodules_update_clone_config, &suc.max_jobs);
 
 	argc = parse_options(argc, argv, prefix, module_update_clone_options,
 			     git_submodule_helper_usage, 0);
@@ -1772,27 +1799,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	if (pathspec.nr)
 		suc.warn_if_uninitialized = 1;
 
-	run_processes_parallel(max_jobs,
-			       update_clone_get_next_task,
-			       update_clone_start_failure,
-			       update_clone_task_finished,
-			       &suc);
-
-	/*
-	 * We saved the output and put it out all at once now.
-	 * That means:
-	 * - the listener does not have to interleave their (checkout)
-	 *   work with our fetching.  The writes involved in a
-	 *   checkout involve more straightforward sequential I/O.
-	 * - the listener can avoid doing any work if fetching failed.
-	 */
-	if (suc.quickstop)
-		return 1;
-
-	for_each_string_list_item(item, &suc.projectlines)
-		fprintf(stdout, "%s", item->string);
-
-	return 0;
+	return update_submodules(&suc);
 }
 
 static int resolve_relative_path(int argc, const char **argv, const char *prefix)
-- 
2.18.0.233.g985f88cf7e-goog


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

* [PATCH 4/6] builtin/submodule--helper: store update_clone information in a struct
  2018-07-18 19:48 [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Stefan Beller
                   ` (2 preceding siblings ...)
  2018-07-18 19:48 ` [PATCH 3/6] builtin/submodule--helper: factor out submodule updating Stefan Beller
@ 2018-07-18 19:48 ` Stefan Beller
  2018-07-18 19:48 ` [PATCH 5/6] builtin/submodule--helper: factor out method to update a single submodule Stefan Beller
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-18 19:48 UTC (permalink / raw)
  To: git; +Cc: gitster, szeder.dev, stolee, Stefan Beller

The information that is printed for update_submodules in
'submodule--helper update-clone' and consumed by 'git submodule update'
is stored as a string per submodule. This made sense at the time of
48308681b07 (git submodule update: have a dedicated helper for cloning,
2016-02-29), but as we want to migrate the rest of the submodule update
into C, we're better off having access to the raw information in a helper
struct.

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

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 96929ba1096..fb54936efc7 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1444,6 +1444,12 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+struct update_clone_data {
+	const struct submodule *sub;
+	struct object_id oid;
+	unsigned just_cloned;
+};
+
 struct submodule_update_clone {
 	/* index into 'list', the list of submodules to look into for cloning */
 	int current;
@@ -1463,8 +1469,9 @@ struct submodule_update_clone {
 	const char *recursive_prefix;
 	const char *prefix;
 
-	/* Machine-readable status lines to be consumed by git-submodule.sh */
-	struct string_list projectlines;
+	/* to be consumed by git-submodule.sh */
+	struct update_clone_data *update_clone;
+	int update_clone_nr; int update_clone_alloc;
 
 	/* If we want to stop as fast as possible and return an error */
 	unsigned quickstop : 1;
@@ -1478,7 +1485,7 @@ struct submodule_update_clone {
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
 	SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
 	NULL, NULL, NULL, \
-	STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
+	NULL, 0, 0, 0, NULL, 0, 0, 0}
 
 
 static void next_submodule_warn_missing(struct submodule_update_clone *suc,
@@ -1572,10 +1579,12 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 	strbuf_addf(&sb, "%s/.git", ce->name);
 	needs_cloning = !file_exists(sb.buf);
 
-	strbuf_reset(&sb);
-	strbuf_addf(&sb, "dummy %s %d\t%s\n",
-		    oid_to_hex(&ce->oid), needs_cloning, ce->name);
-	string_list_append(&suc->projectlines, sb.buf);
+	ALLOC_GROW(suc->update_clone, suc->update_clone_nr + 1,
+		   suc->update_clone_alloc);
+	oidcpy(&suc->update_clone[suc->update_clone_nr].oid, &ce->oid);
+	suc->update_clone[suc->update_clone_nr].just_cloned = needs_cloning;
+	suc->update_clone[suc->update_clone_nr].sub = sub;
+	suc->update_clone_nr++;
 
 	if (!needs_cloning)
 		goto cleanup;
@@ -1718,7 +1727,8 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
 
 static int update_submodules(struct submodule_update_clone *suc)
 {
-	struct string_list_item *item;
+	int i;
+	struct strbuf sb = STRBUF_INIT;
 
 	run_processes_parallel(suc->max_jobs,
 			       update_clone_get_next_task,
@@ -1737,9 +1747,16 @@ static int update_submodules(struct submodule_update_clone *suc)
 	if (suc->quickstop)
 		return 1;
 
-	for_each_string_list_item(item, &suc->projectlines)
-		fprintf(stdout, "%s", item->string);
+	for (i = 0; i < suc->update_clone_nr; i++) {
+		strbuf_addf(&sb, "dummy %s %d\t%s\n",
+			oid_to_hex(&suc->update_clone[i].oid),
+			suc->update_clone[i].just_cloned,
+			suc->update_clone[i].sub->path);
+		fprintf(stdout, "%s", sb.buf);
+		strbuf_reset(&sb);
+	}
 
+	strbuf_release(&sb);
 	return 0;
 }
 
-- 
2.18.0.233.g985f88cf7e-goog


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

* [PATCH 5/6] builtin/submodule--helper: factor out method to update a single submodule
  2018-07-18 19:48 [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Stefan Beller
                   ` (3 preceding siblings ...)
  2018-07-18 19:48 ` [PATCH 4/6] builtin/submodule--helper: store update_clone information in a struct Stefan Beller
@ 2018-07-18 19:48 ` Stefan Beller
  2018-07-18 19:48 ` [PATCH 6/6] submodule--helper: introduce new update-module-mode helper Stefan Beller
  2018-07-18 22:24 ` [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Junio C Hamano
  6 siblings, 0 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-18 19:48 UTC (permalink / raw)
  To: git; +Cc: gitster, szeder.dev, stolee, Stefan Beller

In a later patch we'll find this method handy.

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

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index fb54936efc7..034ba1bb2e0 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1725,10 +1725,17 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
 	return 0;
 }
 
+static void update_submodule(struct update_clone_data *ucd)
+{
+	fprintf(stdout, "dummy %s %d\t%s\n",
+		oid_to_hex(&ucd->oid),
+		ucd->just_cloned,
+		ucd->sub->path);
+}
+
 static int update_submodules(struct submodule_update_clone *suc)
 {
 	int i;
-	struct strbuf sb = STRBUF_INIT;
 
 	run_processes_parallel(suc->max_jobs,
 			       update_clone_get_next_task,
@@ -1747,16 +1754,9 @@ static int update_submodules(struct submodule_update_clone *suc)
 	if (suc->quickstop)
 		return 1;
 
-	for (i = 0; i < suc->update_clone_nr; i++) {
-		strbuf_addf(&sb, "dummy %s %d\t%s\n",
-			oid_to_hex(&suc->update_clone[i].oid),
-			suc->update_clone[i].just_cloned,
-			suc->update_clone[i].sub->path);
-		fprintf(stdout, "%s", sb.buf);
-		strbuf_reset(&sb);
-	}
+	for (i = 0; i < suc->update_clone_nr; i++)
+		update_submodule(&suc->update_clone[i]);
 
-	strbuf_release(&sb);
 	return 0;
 }
 
-- 
2.18.0.233.g985f88cf7e-goog


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

* [PATCH 6/6] submodule--helper: introduce new update-module-mode helper
  2018-07-18 19:48 [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Stefan Beller
                   ` (4 preceding siblings ...)
  2018-07-18 19:48 ` [PATCH 5/6] builtin/submodule--helper: factor out method to update a single submodule Stefan Beller
@ 2018-07-18 19:48 ` Stefan Beller
  2018-07-18 22:24 ` [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Junio C Hamano
  6 siblings, 0 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-18 19:48 UTC (permalink / raw)
  To: git; +Cc: gitster, szeder.dev, stolee, Stefan Beller

This chews off a bit of the shell part of the update command in
git-submodule.sh. When writing the C code, keep in mind that the
submodule--helper part will go away eventually and we want to have
a C function that is able to determine the submodule update strategy,
it as a nicety, make determine_submodule_update_strategy accessible
for arbitrary repositories.

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

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 034ba1bb2e0..c7de5d1e0a0 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1444,6 +1444,66 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+static void determine_submodule_update_strategy(struct repository *r,
+						int just_cloned,
+						const char *path,
+						const char *update,
+						struct submodule_update_strategy *out)
+{
+	const struct submodule *sub = submodule_from_path(r, &null_oid, path);
+	char *key;
+	const char *val;
+
+	key = xstrfmt("submodule.%s.update", sub->name);
+
+	if (update) {
+		trace_printf("parsing update");
+		if (parse_submodule_update_strategy(update, out) < 0)
+			die(_("Invalid update mode '%s' for submodule path '%s'"),
+				update, path);
+	} else if (!repo_config_get_string_const(r, key, &val)) {
+		if (parse_submodule_update_strategy(val, out) < 0)
+			die(_("Invalid update mode '%s' configured for submodule path '%s'"),
+				val, path);
+	} else if (sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
+		trace_printf("loaded thing");
+		out->type = sub->update_strategy.type;
+		out->command = sub->update_strategy.command;
+	} else
+		out->type = SM_UPDATE_CHECKOUT;
+
+	if (just_cloned &&
+	    (out->type == SM_UPDATE_MERGE ||
+	     out->type == SM_UPDATE_REBASE ||
+	     out->type == SM_UPDATE_NONE))
+		out->type = SM_UPDATE_CHECKOUT;
+
+	free(key);
+}
+
+static int module_update_module_mode(int argc, const char **argv, const char *prefix)
+{
+	const char *path, *update = NULL;
+	int just_cloned;
+	struct submodule_update_strategy update_strategy = { .type = SM_UPDATE_CHECKOUT };
+
+	if (argc < 3 || argc > 4)
+		die("submodule--helper update-module-clone expects <just-cloned> <path> [<update>]");
+
+	just_cloned = git_config_int("just_cloned", argv[1]);
+	path = argv[2];
+
+	if (argc == 4)
+		update = argv[3];
+
+	determine_submodule_update_strategy(the_repository,
+					    just_cloned, path, update,
+					    &update_strategy);
+	fputs(submodule_strategy_to_string(&update_strategy), stdout);
+
+	return 0;
+}
+
 struct update_clone_data {
 	const struct submodule *sub;
 	struct object_id oid;
@@ -2039,6 +2099,7 @@ static struct cmd_struct commands[] = {
 	{"list", module_list, 0},
 	{"name", module_name, 0},
 	{"clone", module_clone, 0},
+	{"update-module-mode", module_update_module_mode, 0},
 	{"update-clone", update_clone, 0},
 	{"relative-path", resolve_relative_path, 0},
 	{"resolve-relative-url", resolve_relative_url, 0},
diff --git a/git-submodule.sh b/git-submodule.sh
index 56588aa304d..215760898ce 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -535,27 +535,13 @@ cmd_update()
 	do
 		die_if_unmatched "$quickabort" "$sha1"
 
-		name=$(git submodule--helper name "$sm_path") || exit
-		if ! test -z "$update"
-		then
-			update_module=$update
-		else
-			update_module=$(git config submodule."$name".update)
-			if test -z "$update_module"
-			then
-				update_module="checkout"
-			fi
-		fi
+		update_module=$(git submodule--helper update-module-mode $just_cloned "$sm_path" $update)
 
 		displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
 
 		if test $just_cloned -eq 1
 		then
 			subsha1=
-			case "$update_module" in
-			merge | rebase | none)
-				update_module=checkout ;;
-			esac
 		else
 			subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
 				git rev-parse --verify HEAD) ||
-- 
2.18.0.233.g985f88cf7e-goog


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

* Re: [PATCH 0/6] Resend of origin/sb/submodule-update-in-c
  2018-07-18 19:48 [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Stefan Beller
                   ` (5 preceding siblings ...)
  2018-07-18 19:48 ` [PATCH 6/6] submodule--helper: introduce new update-module-mode helper Stefan Beller
@ 2018-07-18 22:24 ` Junio C Hamano
  2018-07-18 23:11   ` Stefan Beller
  6 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2018-07-18 22:24 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, szeder.dev, stolee

Stefan Beller <sbeller@google.com> writes:

> This fixes the compilation issue raised by SZEDER and Stolee,
>
>
> 6:  3c156c79ae7 ! 6:  f82f24e73b6 submodule--helper: introduce new update-module-mode helper
>     @@ -10,7 +10,6 @@
>          for arbitrary repositories.
>      
>          Signed-off-by: Stefan Beller <sbeller@google.com>
>     -    Signed-off-by: Junio C Hamano <gitster@pobox.com>
>      
>      diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
>      --- a/builtin/submodule--helper.c
>     @@ -74,7 +73,7 @@
>      +	determine_submodule_update_strategy(the_repository,
>      +					    just_cloned, path, update,
>      +					    &update_strategy);
>     -+	fprintf(stdout, submodule_strategy_to_string(&update_strategy));
>     ++	fputs(submodule_strategy_to_string(&update_strategy), stdout);
>      +
>      +	return 0;
>      +}
>
> Thanks,
> Stefan

Thanks.  

This time not from GGG?  I don't particularly care which direction
patches come from, though ;-)

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

* Re: [PATCH 0/6] Resend of origin/sb/submodule-update-in-c
  2018-07-18 22:24 ` [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Junio C Hamano
@ 2018-07-18 23:11   ` Stefan Beller
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Beller @ 2018-07-18 23:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, SZEDER Gábor, Derrick Stolee

On Wed, Jul 18, 2018 at 3:24 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Stefan Beller <sbeller@google.com> writes:
>
> > This fixes the compilation issue raised by SZEDER and Stolee,
> >
> >
> > 6:  3c156c79ae7 ! 6:  f82f24e73b6 submodule--helper: introduce new update-module-mode helper
> >     @@ -10,7 +10,6 @@
> >          for arbitrary repositories.
> >
> >          Signed-off-by: Stefan Beller <sbeller@google.com>
> >     -    Signed-off-by: Junio C Hamano <gitster@pobox.com>
> >
> >      diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> >      --- a/builtin/submodule--helper.c
> >     @@ -74,7 +73,7 @@
> >      +        determine_submodule_update_strategy(the_repository,
> >      +                                            just_cloned, path, update,
> >      +                                            &update_strategy);
> >     -+        fprintf(stdout, submodule_strategy_to_string(&update_strategy));
> >     ++        fputs(submodule_strategy_to_string(&update_strategy), stdout);
> >      +
> >      +        return 0;
> >      +}
> >
> > Thanks,
> > Stefan
>
> Thanks.
>
> This time not from GGG?

GGG = GitGitGadget?
I have yet to try out that tool, I am still stuck on git-send-email.
(old habits die hard)

It is even based off your branch (with all your sign offs).

I just cut down aggressively on the range diff (and short stat),
as I want to highlight the important part.

>  I don't particularly care which direction
> patches come from, though ;-)

Cool.

Thanks,
Stefan

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

end of thread, other threads:[~2018-07-18 23:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-18 19:48 [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Stefan Beller
2018-07-18 19:48 ` [PATCH 1/6] git-submodule.sh: align error reporting for update mode to use path Stefan Beller
2018-07-18 19:48 ` [PATCH 2/6] git-submodule.sh: rename unused variables Stefan Beller
2018-07-18 19:48 ` [PATCH 3/6] builtin/submodule--helper: factor out submodule updating Stefan Beller
2018-07-18 19:48 ` [PATCH 4/6] builtin/submodule--helper: store update_clone information in a struct Stefan Beller
2018-07-18 19:48 ` [PATCH 5/6] builtin/submodule--helper: factor out method to update a single submodule Stefan Beller
2018-07-18 19:48 ` [PATCH 6/6] submodule--helper: introduce new update-module-mode helper Stefan Beller
2018-07-18 22:24 ` [PATCH 0/6] Resend of origin/sb/submodule-update-in-c Junio C Hamano
2018-07-18 23:11   ` Stefan Beller
  -- strict thread matches above, loose matches on Subject: below --
2018-07-12 19:47 [PATCH 0/6] git-submodule.sh: convert part of cmd_update to C Stefan Beller
2018-07-12 19:47 ` [PATCH 3/6] builtin/submodule--helper: factor out submodule updating Stefan Beller

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