Re: [PATCH v2 27/28] submodule--helper: libify "must_die_on_failure" code paths (for die)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patches 19-20 and 22-27 are pretty much "show your work" for the same
libification, so I'll comment on them together.

Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> writes:

> Continue the libification of codepaths that previously relied on
> "must_die_on_failure". In these cases we've always been early aborting
> by calling die(), but as we know that these codpaths will properly
> handle return codes of 128 to mean an early abort let's have them use
> die_message() instead.
>
> This still isn't a complete migration away from die() for these
> codepaths, in particular this code in update_submodule() will still call die() in some cases:
>
> 	char *remote_name = get_default_remote_submodule(update_data->sm_path);
> 	const char *branch = remote_submodule_branch(update_data->sm_path);
>
> But as that code is used by other callers than the "update" code let's
> leave converting it for now.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
> ---
>  builtin/submodule--helper.c | 33 ++++++++++++++++++---------------
>  1 file changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 79a11992d1c..4f7ece6fb05 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -2263,9 +2263,9 @@ static int run_update_procedure(struct update_data *ud)
>  		 */
>  		if (!is_tip_reachable(ud->sm_path, &ud->oid) &&
>  		    fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, &ud->oid))
> -			die(_("Fetched in submodule path '%s', but it did not "
> -			      "contain %s. Direct fetching of that commit failed."),
> -			    ud->displaypath, oid_to_hex(&ud->oid));
> +			return die_message(_("Fetched in submodule path '%s', but it did not "
> +					     "contain %s. Direct fetching of that commit failed."),
> +					   ud->displaypath, oid_to_hex(&ud->oid));

Two things I really like about these changes:

- The intermediate return values are opaque, and we always return on
  error. As a result, the code looks quite uniform (instead of e.g.
  mixing return and exit()).
- The "return die_message()" pattern is pretty elegant and it's used
  often enough that there's no doubt that it's pretty clear that
  intermediate functions can and will return 128 to signify that we want
  the process to die.

So these look great to me :)

>  	}
>  
>  	return run_update_command(ud, subforce);
> @@ -2309,13 +2309,14 @@ static const char *remote_submodule_branch(const char *path)
>  	return branch;
>  }
>  
> -static void ensure_core_worktree(const char *path)
> +static int ensure_core_worktree(const char *path)
>  {
>  	const char *cw;
>  	struct repository subrepo;
>  
>  	if (repo_submodule_init(&subrepo, the_repository, path, null_oid()))
> -		die(_("could not get a repository handle for submodule '%s'"), path);
> +		return die_message(_("could not get a repository handle for submodule '%s'"),
> +				   path);
>  
>  	if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) {
>  		char *cfg_file, *abs_path;
> @@ -2333,6 +2334,8 @@ static void ensure_core_worktree(const char *path)
>  		free(abs_path);
>  		strbuf_release(&sb);
>  	}
> +
> +	return 0;
>  }
>  
>  static const char *submodule_update_type_to_label(enum submodule_update_type type)
> @@ -2408,7 +2411,9 @@ static int update_submodule(struct update_data *update_data)
>  {
>  	int ret;
>  
> -	ensure_core_worktree(update_data->sm_path);
> +	ret = ensure_core_worktree(update_data->sm_path);
> +	if (ret)
> +		return ret;
>  
>  	update_data->displaypath = get_submodule_displaypath(
>  		update_data->sm_path, update_data->prefix);
> @@ -2418,16 +2423,14 @@ static int update_submodule(struct update_data *update_data)
>  						  update_data->sm_path,
>  						  update_data->update_default,
>  						  &update_data->update_strategy);
> -	if (ret) {
> -		*must_die_on_failure = 1;
> +	if (ret)
>  		return ret;
> -	}
>  
>  	if (update_data->just_cloned)
>  		oidcpy(&update_data->suboid, null_oid());
>  	else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid))
> -		die(_("Unable to find current revision in submodule path '%s'"),
> -			update_data->displaypath);
> +		return die_message(_("Unable to find current revision in submodule path '%s'"),
> +				   update_data->displaypath);
>  
>  	if (update_data->remote) {
>  		char *remote_name = get_default_remote_submodule(update_data->sm_path);
> @@ -2437,13 +2440,13 @@ static int update_submodule(struct update_data *update_data)
>  		if (!update_data->nofetch) {
>  			if (fetch_in_submodule(update_data->sm_path, update_data->depth,
>  					      0, NULL))
> -				die(_("Unable to fetch in submodule path '%s'"),
> -				    update_data->sm_path);
> +				return die_message(_("Unable to fetch in submodule path '%s'"),
> +						   update_data->sm_path);
>  		}
>  
>  		if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid))
> -			die(_("Unable to find %s revision in submodule path '%s'"),
> -			    remote_ref, update_data->sm_path);
> +			return die_message(_("Unable to find %s revision in submodule path '%s'"),
> +					   remote_ref, update_data->sm_path);
>  
>  		free(remote_ref);
>  	}
> -- 
> 2.37.1.1233.ge8b09efaedc




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux