git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 3/3] submodule: simplify decision tree whether to or not to fetch

From
BWBrandon Williams <bmwill@google.com>
Date
Oct 19, 2017, 19:16 UTC
Message-ID
<20171019191638.GA84767@google.com>
In-Reply-To
<20171019153844.GA41283@book.hvoigt.net>
On 10/19, Heiko Voigt wrote:
Show 108 quoted lines
> On Thu, Oct 19, 2017 at 09:36:47AM +0900, Junio C Hamano wrote:
> > Brandon Williams <bmwill@google.com> writes:
> > 
> > > On 10/16, Heiko Voigt wrote:
> > >> To make extending this logic later easier.
> > >
> > > This makes things so much clearer, thanks!
> > 
> > I agree that it is clear to see what the code after the patch does,
> > but the code before the patch is so convoluted to follow that it is
> > a bit hard to see if the code before and after are doing the same
> > thing, though ;-)
> 
> That is why I would appreciate some extra pairs of eyes on this :) I
> tried to be as careful as possible when refactoring this, but since it
> is quite convoluted something might have slipped through. The testsuite
> does not show anything, but there might be corner cases that are not
> tested I guess.
> 
> Will hopefully have time to look into the comments to the main patch of
> this series tomorrow. Did not get around to properly do that yet.
> 
> Cheers Heiko
> 
> > >> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> > >> ---
> > >>  submodule.c | 74 ++++++++++++++++++++++++++++++-------------------------------
> > >>  1 file changed, 37 insertions(+), 37 deletions(-)
> > >> 
> > >> diff --git a/submodule.c b/submodule.c
> > >> index 71d1773e2e..82d206eb65 100644
> > >> --- a/submodule.c
> > >> +++ b/submodule.c
> > >> @@ -1187,6 +1187,31 @@ struct submodule_parallel_fetch {
> > >>  };
> > >>  #define SPF_INIT {0, ARGV_ARRAY_INIT, NULL, NULL, 0, 0, 0, 0}
> > >>  
> > >> +static int get_fetch_recurse_config(const struct submodule *submodule,
> > >> +				    struct submodule_parallel_fetch *spf)
> > >> +{
> > >> +	if (spf->command_line_option != RECURSE_SUBMODULES_DEFAULT)
> > >> +		return spf->command_line_option;
> > >> +
> > >> +	if (submodule) {
> > >> +		char *key;
> > >> +		const char *value;
> > >> +
> > >> +		int fetch_recurse = submodule->fetch_recurse;
> > >> +		key = xstrfmt("submodule.%s.fetchRecurseSubmodules", submodule->name);
> > >> +		if (!repo_config_get_string_const(the_repository, key, &value)) {
> > >> +			fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
> > >> +		}
> > >> +		free(key);
> > >> +
> > >> +		if (fetch_recurse != RECURSE_SUBMODULES_NONE)
> > >> +			/* local config overrules everything except commandline */
> > >> +			return fetch_recurse;
> > >> +	}
> > >> +
> > >> +	return spf->default_option;
> > >> +}
> > >> +
> > >>  static int get_next_submodule(struct child_process *cp,
> > >>  			      struct strbuf *err, void *data, void **task_cb)
> > >>  {
> > >> @@ -1214,46 +1239,21 @@ static int get_next_submodule(struct child_process *cp,
> > >>  			}
> > >>  		}
> > >>  
> > >> -		default_argv = "yes";
> > >> -		if (spf->command_line_option == RECURSE_SUBMODULES_DEFAULT) {
> > >> -			int fetch_recurse = RECURSE_SUBMODULES_NONE;
> > >> -
> > >> -			if (submodule) {
> > >> -				char *key;
> > >> -				const char *value;
> > >> -
> > >> -				fetch_recurse = submodule->fetch_recurse;
> > >> -				key = xstrfmt("submodule.%s.fetchRecurseSubmodules", submodule->name);
> > >> -				if (!repo_config_get_string_const(the_repository, key, &value)) {
> > >> -					fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
> > >> -				}
> > >> -				free(key);
> > >> -			}
> > >> -
> > >> -			if (fetch_recurse != RECURSE_SUBMODULES_NONE) {
> > >> -				if (fetch_recurse == RECURSE_SUBMODULES_OFF)
> > >> -					continue;
> > >> -				if (fetch_recurse == RECURSE_SUBMODULES_ON_DEMAND) {
> > >> -					if (!unsorted_string_list_lookup(&changed_submodule_names,
> > >> -									 submodule->name))
> > >> -						continue;
> > >> -					default_argv = "on-demand";
> > >> -				}
> > >> -			} else {
> > >> -				if (spf->default_option == RECURSE_SUBMODULES_OFF)
> > >> -					continue;
> > >> -				if (spf->default_option == RECURSE_SUBMODULES_ON_DEMAND) {
> > >> -					if (!unsorted_string_list_lookup(&changed_submodule_names,
> > >> -									  submodule->name))
> > >> -						continue;
> > >> -					default_argv = "on-demand";
> > >> -				}
> > >> -			}
> > >> -		} else if (spf->command_line_option == RECURSE_SUBMODULES_ON_DEMAND) {
> > >> -			if (!unsorted_string_list_lookup(&changed_submodule_names,
> > >> +		switch (get_fetch_recurse_config(submodule, spf))
> > >> +		{

I looked through this one more time and I was able to convince myself again that it's doing the same thing. Instead of repeating the same logic over and over again (via copy and paste of code) in deeply nested if's, you are first determining what the value of fetch_recurse is and then based on that doing a set of specific things.

Only nit would be to move this brace onto the previous line :)
Show 19 quoted lines
> > >> +		default:
> > >> +		case RECURSE_SUBMODULES_DEFAULT:
> > >> +		case RECURSE_SUBMODULES_ON_DEMAND:
> > >> +			if (!submodule || !unsorted_string_list_lookup(&changed_submodule_names,
> > >>  							 submodule->name))
> > >>  				continue;
> > >>  			default_argv = "on-demand";
> > >> +			break;
> > >> +		case RECURSE_SUBMODULES_ON:
> > >> +			default_argv = "yes";
> > >> +			break;
> > >> +		case RECURSE_SUBMODULES_OFF:
> > >> +			continue;
> > >>  		}
> > >>  
> > >>  		strbuf_addf(&submodule_path, "%s/%s", spf->work_tree, ce->name);
> > >> -- 
> > >> 2.14.1.145.gb3622a4
> > >> 
-- 
Brandon Williams
Previous: Heiko VoigtNext: Heiko Voigt
Message 10 of 24 in “implement fetching of moved submodules”
  1. 0/3 implement fetching of moved submodulesHeiko Voigt, Oct 16, 2017
  2. 1/3 fetch: add test to make sure we stay backwards compatibleHeiko Voigt, Oct 16, 2017
  3. Stefan BellerOct 17, 2017
  4. 3/3 submodule: simplify decision tree whether to or not to fetchHeiko Voigt, Oct 16, 2017
  5. Stefan BellerOct 17, 2017
  6. Junio C HamanoOct 18, 2017
  7. Brandon WilliamsOct 18, 2017
  8. Junio C HamanoOct 19, 2017
  9. Heiko VoigtOct 19, 2017
  10. Brandon WilliamsOct 19, 2017
  11. 2/3 implement fetching of moved submodulesHeiko Voigt, Oct 16, 2017
  12. Stefan BellerOct 17, 2017
  13. Junio C HamanoOct 18, 2017
  14. Stefan BellerOct 18, 2017
  15. Junio C HamanoOct 19, 2017
  16. 1/2 t5526: check for name/path collision in submodule fetchStefan Beller, Oct 19, 2017
  17. 2/2 fetch, push: keep separate lists of submodules and gitlinksStefan Beller, Oct 19, 2017
  18. Heiko VoigtOct 23, 2017
  19. Stefan BellerOct 23, 2017
  20. Junio C HamanoOct 24, 2017
  21. Heiko VoigtOct 23, 2017
  22. Stefan BellerOct 23, 2017
  23. Stefan BellerOct 19, 2017
  24. Junio C HamanoOct 17, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.