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

Re: [PATCH 02/10] revert: Propogate errors upwards from do_pick_commit

From
Junio C Hamano <gitster@pobox.com>
Date
May 25, 2011, 22:44 UTC
Message-ID
<7v62oy1juh.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1306333025-29893-3-git-send-email-artagnon@gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 10 quoted lines
> +static int error_dirty_index(const char *me)
>  {
> +	if (read_cache_unmerged())
> +		return error_resolve_conflict(me);
> +
> +	int ret = error(_("Your local changes would be overwritten by %s.\n"), me);
> +	if (advice_commit_before_merge)
> +		advise(_("Please, commit your changes or stash them to proceed."));
> +	return ret;
>  }

I like this rewrite whose result is short-and-sweet, but you do not even need the "ret" variable. error() always yields -1, no?

Show 31 quoted lines
> @@ -594,14 +584,28 @@ static int revert_or_cherry_pick(int argc, const char **argv)
>  
>  int cmd_revert(int argc, const char **argv, const char *prefix)
>  {
> +	int res = 0;
>  	if (isatty(0))
>  		edit = 1;
>  	action = REVERT;
> -	return revert_or_cherry_pick(argc, argv);
> +	res = revert_or_cherry_pick(argc, argv);
> +	if (res > 0)
> +		/* Exit status from conflict */
> +		return res;
> +	if (res < 0)
> +		/* Other error */
> +		exit(128);
> +	return 0;
>  }
>  
>  int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
>  {
> +	int res = 0;
>  	action = CHERRY_PICK;
> -	return revert_or_cherry_pick(argc, argv);
> +	res = revert_or_cherry_pick(argc, argv);
> +	if (res > 0)
> +		return res;
> +	if (res < 0)
> +		exit(128);
> +	return 0;
>  }
This hunk is dubious.
 - Why initialize res to zero if it always is assigned the return value of
   revert_or_cherry_pick() before it is used?
 - The called function seems to return errors from various places but as
   far as I see they are all return value of error(), so it would be
   equivalent to
	if (r_o_c_p(...))
		exit(128);
	return 0;

If you are going to introduce different return values from r-o-c-p() in a later patch, these functions should be updated in that patch, I think.

Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 4 of 37 in “Sequencer Foundations”
  1. 00/10 Sequencer FoundationsRamkumar Ramachandra, May 25, 2011
  2. 01/10 advice: Introduce error_resolve_conflictRamkumar Ramachandra, May 25, 2011
  3. 02/10 revert: Propogate errors upwards from do_pick_commitRamkumar Ramachandra, May 25, 2011
  4. Junio C HamanoMay 25, 2011
  5. Ramkumar RamachandraMay 26, 2011
  6. 03/10 revert: Eliminate global "commit" variableRamkumar Ramachandra, May 25, 2011
  7. Junio C HamanoMay 25, 2011
  8. 04/10 revert: Rename no_replay to record_originRamkumar Ramachandra, May 25, 2011
  9. 05/10 revert: Introduce struct to keep command-line optionsRamkumar Ramachandra, May 25, 2011
  10. 06/10 revert: Separate cmdline parsing from functional codeRamkumar Ramachandra, May 25, 2011
  11. 07/10 revert: Catch incompatible command-line options earlyRamkumar Ramachandra, May 25, 2011
  12. 08/10 revert: Introduce HEAD, TODO files to persist state, planRamkumar Ramachandra, May 25, 2011
  13. 09/10 revert: Implement parsing --continue, --abort and --skipRamkumar Ramachandra, May 25, 2011
  14. 10/10 revert: Implement --abort processingRamkumar Ramachandra, May 25, 2011
  15. Junio C HamanoMay 25, 2011
  16. 00/10 Sequencer FoundationsRamkumar Ramachandra, May 26, 2011
  17. 01/10 advice: Introduce error_resolve_conflictRamkumar Ramachandra, May 26, 2011
  18. 02/10 revert: Propogate errors upwards from do_pick_commitRamkumar Ramachandra, May 26, 2011
  19. 03/10 revert: Eliminate global "commit" variableRamkumar Ramachandra, May 26, 2011
  20. 04/10 revert: Rename no_replay to record_originRamkumar Ramachandra, May 26, 2011
  21. 05/10 revert: Introduce struct to keep command-line optionsRamkumar Ramachandra, May 26, 2011
  22. 06/10 revert: Separate cmdline parsing from functional codeRamkumar Ramachandra, May 26, 2011
  23. 07/10 revert: Catch incompatible command-line options earlyRamkumar Ramachandra, May 26, 2011
  24. 08/10 revert: Introduce HEAD, TODO files to persist state, planRamkumar Ramachandra, May 26, 2011
  25. Jonathan NiederMay 26, 2011
  26. Ramkumar RamachandraMay 26, 2011
  27. Ramkumar RamachandraMay 26, 2011
  28. Junio C HamanoMay 26, 2011
  29. Ramkumar RamachandraJun 1, 2011
  30. Jonathan NiederJun 1, 2011
  31. Ramkumar RamachandraJun 2, 2011
  32. Jeff KingJun 2, 2011
  33. Ramkumar RamachandraJun 8, 2011
  34. 09/10 revert: Implement parsing --continue, --abort and --skipRamkumar Ramachandra, May 26, 2011
  35. 10/10 revert: Implement --abort processingRamkumar Ramachandra, May 26, 2011
  36. Junio C HamanoMay 26, 2011
  37. Ramkumar RamachandraMay 27, 2011

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.