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

Re: [PATCH v2 4/4] diff-lib: parallelize run_diff_files for submodules

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 12, 2022, 08:31 UTC
Message-ID
<221012.86v8opmntc.gmgdl@evledraar.gmail.com>
In-Reply-To
<20221011232604.839941-5-calvinwan@google.com>
On Tue, Oct 11 2022, Calvin Wan wrote:
Mostly style comments, but also others.:
> +				     unsigned *dirty_submodule, int *defer_submodule_status,
> +					 int *ignore_untracked_in_submodules)
If you can think of a (much) shorter name for this new paremeter, then...
Show 7 quoted lines
> +		if (defer_submodule_status && *defer_submodule_status) {
> +			defer = 1;
> +			*ignore_untracked_in_submodules =
> +							diffopt->flags.ignore_untracked_in_submodules;
> +		} else {
> +			*dirty_submodule = is_submodule_modified(ce->name,
> +							diffopt->flags.ignore_untracked_in_submodules);

...code like this becomes a lot less verbose and doesn't need this much indentation...

> +			if (defer_submodule_status) {
> +				struct string_list_item *item =
> +								string_list_append(&submodules, ce->name);
And e.g. here splittng up the two:
	struct string_list_item *item;
	item = ...
Makes for easier reading IMO.
Show 6 quoted lines
> +				struct submodule_status_util *util = xmalloc(sizeof(*util));
> +				util->changed = changed;
> +				util->dirty_submodule = 0;
> +				util->ignore_untracked = ignore_untracked_in_submodules;
> +				util->newmode = newmode;
> +				util->ce = ce;
Maybe easier to read as:
	struct submodule_status_util tmp = {
		.changed = ...,
		.dirty_submodule =...,
	};
Then a single memcpy() to copy that data over to the malloc'd region.
> +				item->util = util;
And you can also do this idiomatically as:
	string_list_append(...)->util = util;
> +				continue;
> +		int parallel_jobs = 1;
> +		git_config_get_int("submodule.diffjobs", &parallel_jobs);
> +		if (parallel_jobs < 0) {
> +			die(_("submodule.diffjobs cannot be negative"));
Maybe we want something that uses git_parse_unsigned()?
> +		}
This should be cuddled with the "else if"
Show 6 quoted lines
> +		else if (!parallel_jobs) {
> +			/*
> +			 * TODO: Decide what a reasonable default for parallel_jobs
> +			 * is. Currently mimics what other parallel config options
> +			 * default to.
> +			 */
It's OK to just drop this comment IMO.
> +			parallel_jobs = online_cpus();
> +		}
And as these are both one statement you can drop the {}'s altogether.
I think this would probably be more idiomatic as (untested):
	if (git_config_get_int(..., &v) || !v)
		jobs = online_cpus();
	else if (v < 0) /* or some API checks it for us? */
		die(...);
	else
		jobs = v;
I.e. we'd be explicitly using the "does the key exist" return value.
> +
> +		if (get_submodules_status(revs->repo, &submodules, parallel_jobs))
> +			BUG("Submodule status failed");
s/Sub/sub/, lower-case for bug(), die() etc.
> +		for (i = 0; i < submodules.nr; i++) {

You're iterating a string_list, so that "i" earlier should be size_t, but better yet I think you can use for_each_string_list_item() here

> +struct submodule_parallel_status {
> +	int index_count;
Here you have an int...
> +	int result;
> +
> +	struct string_list *submodule_names;

..that'll be tracking the "nr" of this, which is size_t, let's have them match.

Also, can we remove the "*" there and just have submodule.c populate this struct directly, maybe not worth making it public, just a thought...

..I didn't read further than this, ran out of time..
Previous: Calvin Wan
Message 11 of 11 in “submodule: parallelize diff”
  1. 0/4 submodule: parallelize diffCalvin Wan, Oct 11, 2022
  2. Junio C HamanoOct 12, 2022
  3. Calvin WanOct 14, 2022
  4. 1/4 run-command: add pipe_output_fn to run_processes_parallel_optsCalvin Wan, Oct 11, 2022
  5. Ævar Arnfjörð BjarmasonOct 12, 2022
  6. 2/4 submodule: move status parsing into functionCalvin Wan, Oct 11, 2022
  7. Ævar Arnfjörð BjarmasonOct 12, 2022
  8. Ævar Arnfjörð BjarmasonOct 12, 2022
  9. 3/4 diff-lib: refactor match_stat_with_submoduleCalvin Wan, Oct 11, 2022
  10. 4/4 diff-lib: parallelize run_diff_files for submodulesCalvin Wan, Oct 11, 2022
  11. Ævar Arnfjörð BjarmasonOct 12, 2022

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.