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

Re: [PATCH v3 1/7] stash: use an enum for create status

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Oct 22, 2026, 15:57 UTC
Message-ID
<7ffce2cb-07de-4bd3-a9b4-81fd27b920f5@gmail.com>
In-Reply-To
<xmqq5wyvsi2j.fsf@gitster.g>
On 21/10/2026 07:07, Junio C Hamano wrote:
Show 13 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> >> +enum create_result {
>> +	CREATE_ERROR = -1,
>> +	CREATE_SUCCESS,
>> +	/* No changes were stashed */
>> +	CREATE_EMPTY,
>> +};
> > SUCCESS immediatly following ERROR that is explicitly defined to be
> (-1) may qualify as explicitly defined to be 0, but personally I
> probably prefer to be extra explicit here, like
> > 	CREATE_ERROR = -1,
> 	CREATE_SUCCESS = 0,
> > even though this is not worth rerolling the series for.
I can do that, though we really shouldn't be relying on the value for any of the member other than CREATE_ERROR which we want to match the return value of error(...).
Show 7 quoted lines
> >> +static enum create_result stash_staged(struct stash_info *info,
>> +				  struct strbuf *out_patch, int quiet)
>>   {
>> -	int ret = 0;
>> +	enum create_result ret = 0;
> > Not CREATE_SUCCESS?  This can be returned if various checks in the
> function assigns different values to this variable, right?
Yes, I forgot to convert the initializer when I changed the type, will fix.
Show 16 quoted lines
>>   	if (patch_mode) {
>>   		ret = stash_patch(info, ps, patch, quiet, interactive_opts);
>> -		if (ret < 0) {
>> +		if (ret == CREATE_ERROR) {
>>   			if (!quiet)
>>   				fprintf_ln(stderr, _("Cannot save the current "
>>   						     "worktree state"));
>>   			goto done;
>> -		} else if (ret > 0) {
>> +		} else if (ret != CREATE_SUCCESS) {
>>   			goto done;
>>   		}
> > I wonder if switch/case is easier to read for these users of these
> enum return values.  Some check explicitly against CREATE_ERROR
> (like the one above), some treat anything other than CREATE_SUCCESS
> as undesirable, etc.
I've had a play with this and I think the enum is better here
Show 14 quoted lines
>>   	} else if (only_staged) {
>>   		ret = stash_staged(info, patch, quiet);
>> -		if (ret < 0) {
>> +		if (ret == CREATE_ERROR) {
>>   			if (!quiet)
>>   				fprintf_ln(stderr, _("Cannot save the current "
>>   						     "staged state"));
>>   			goto done;
>> -		} else if (ret > 0) {
>> +		} else if (ret != CREATE_SUCCESS) {
>>   			goto done;
>>   		}
>>   	} else {
> > Ditto.
and here
Show 13 quoted lines
> >> @@ -1660,12 +1667,13 @@ static int create_stash(int argc, const char **argv, const char *prefix UNUSED,
>>   >>   	ret = do_create_stash(&ps, &stash_msg_buf, 0, 0, NULL, 0, &info,
>>   			      NULL, 0);
>> -	if (!ret)
>> +	if (ret == CREATE_SUCCESS)
>>   		printf_ln("%s", oid_to_hex(&info.w_commit));
>>   >>   	free_stash_info(&info);
>>   	strbuf_release(&stash_msg_buf);
>> -	return ret;
>> +	/* Do not return an error if there are no changes */
>> +	return ret == CREATE_ERROR ? -1 : 0;
>>   }
> > Ditto.
but here we're checking for a single value, so using a switch seems like overkill.
I'll try and push out a new version tomorrow
Thanks
Phillip
Previous: Junio C HamanoNext: Junio C Hamano
Message 25 of 47 in “stash: stop checking for changes twice”
  1. 0/2 stash: stop checking for changes twicePhillip Wood, Oct 5, 2026
  2. 1/2 stash create: remove duplicate changes detectionPhillip Wood, Oct 5, 2026
  3. Junio C HamanoOct 6, 2026
  4. Phillip WoodOct 7, 2026
  5. 2/2 stash push: remove duplicate changes detectionPhillip Wood, Oct 5, 2026
  6. Junio C HamanoOct 6, 2026
  7. Phillip WoodOct 7, 2026
  8. Junio C HamanoOct 7, 2026
  9. Phillip WoodOct 8, 2026
  10. 0/7 stash creation: avoid unecessary index loads and refreshesPhillip Wood, Oct 14, 2026
  11. 1/7 stash: use an enum for create statusPhillip Wood, Oct 14, 2026
  12. 2/7 stash create: remove duplicate changes detectionPhillip Wood, Oct 14, 2026
  13. 3/7 stash push: remove duplicate changes detectionPhillip Wood, Oct 14, 2026
  14. 4/7 stash push: avoid duplicate calls to preload_index()Phillip Wood, Oct 14, 2026
  15. Junio C HamanoOct 14, 2026
  16. 5/7 stash create: rework temporary index creationPhillip Wood, Oct 14, 2026
  17. Junio C HamanoOct 14, 2026
  18. Phillip WoodOct 20, 2026
  19. 6/7 stash create: remove unnecessary index load and refreshPhillip Wood, Oct 14, 2026
  20. Junio C HamanoOct 14, 2026
  21. 7/7 stash: simplify reset_tree() function signaturePhillip Wood, Oct 14, 2026
  22. 0/7 stash creation: avoid unecessary index loads and refreshesPhillip Wood, Oct 20, 2026
  23. 1/7 stash: use an enum for create statusPhillip Wood, Oct 20, 2026
  24. Junio C HamanoOct 21, 2026
  25. Phillip WoodOct 22, 2026
  26. Junio C HamanoOct 22, 2026
  27. Phillip WoodOct 22, 2026
  28. 2/7 stash create: remove duplicate changes detectionPhillip Wood, Oct 20, 2026
  29. 3/7 stash push: remove duplicate changes detectionPhillip Wood, Oct 20, 2026
  30. 4/7 stash push: avoid duplicate calls to preload_index()Phillip Wood, Oct 20, 2026
  31. 5/7 stash create: rework temporary index creationPhillip Wood, Oct 20, 2026
  32. Junio C HamanoOct 20, 2026
  33. 6/7 stash create: remove unnecessary index load and refreshPhillip Wood, Oct 20, 2026
  34. 7/7 stash: simplify reset_tree() function signaturePhillip Wood, Oct 20, 2026
  35. Junio C HamanoOct 21, 2026
  36. 0/7 stash creation: avoid unecessary index loads and refreshesPhillip Wood, Oct 23, 2026
  37. 1/7 stash: use an enum for create statusPhillip Wood, Oct 23, 2026
  38. 2/7 stash create: remove duplicate changes detectionPhillip Wood, Oct 23, 2026
  39. 3/7 stash push: remove duplicate changes detectionPhillip Wood, Oct 23, 2026
  40. 4/7 stash push: avoid duplicate calls to preload_index()Phillip Wood, Oct 23, 2026
  41. 5/7 stash create: rework temporary index creationPhillip Wood, Oct 23, 2026
  42. Junio C HamanoNov 5, 2026
  43. 6/7 stash create: remove unnecessary index load and refreshPhillip Wood, Oct 23, 2026
  44. Junio C HamanoNov 6, 2026
  45. 7/7 stash: simplify reset_tree() function signaturePhillip Wood, Oct 23, 2026
  46. Junio C HamanoNov 6, 2026
  47. Junio C HamanoNov 5, 2026

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.