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

Re: [PATCH 1/5] Turn unpack_trees_options.msgs into an array + enum

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Aug 9, 2010, 20:49 UTC
Message-ID
<vpq8w4fse8w.fsf@bauges.imag.fr>
In-Reply-To
<7vwrrz4lgi.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 9 quoted lines
> Matthieu Moy <Matthieu.Moy@imag.fr> writes:
>
>> The list of error messages was introduced as a structure, but an array
>> indexed over an enum is more flexible, since it allows one to store a
>> type of error message (index in the array) in a variable.
>
> Hmm, the only example of the advantage "enum used as array index" offers
> that I can think of off the top of my head is that you can more easily
> iterate over it.

The portion of my message you cite give another: the ability to store the index easily in a variable (or to pass it as argument to a function). With a struct, you can easily pass field name to a macro, but not to a function.

The other is that you can have multiple arrays indexed over the same enum, which is what we do later: we'll have to manage an array of list of rejected paths, with one list per error kind.

(we'll also have to iterate over this second array)

The previous version of the patch serie was using both a struct and an enum + array, and I wanted to get rid of that.

> If you are to change them to enum, I would actually suggest renaming them
> a bit more to make them stand out.  Perhaps spell them all in caps,
> perhaps have them share the same short prefix (UTEM_ - unpack trees error
> messages), etc.

I'd say just "ERROR_*" (UTEM seems hard to read, and won't be used often enough for people to remember it), but I'm fine with all caps + prefix, yes. A quick grep shows this is how the rest of Git does.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Junio C HamanoNext: Matthieu Moy
Message 4 of 16 in “Better error messages for checkout and merge.”
  1. 0/5 Better error messages for checkout and merge.Matthieu Moy, Aug 9, 2010
  2. 1/5 Turn unpack_trees_options.msgs into an array + enumMatthieu Moy, Aug 9, 2010
  3. Junio C HamanoAug 9, 2010
  4. Matthieu MoyAug 9, 2010
  5. 1/5 Turn unpack_trees_options.msgs into an array + enumMatthieu Moy, Aug 11, 2010
  6. 2/5 merge-recursive: porcelain messages for checkoutMatthieu Moy, Aug 11, 2010
  7. 3/5 merge-recursive: distinguish "removed" and "overwritten" messagesMatthieu Moy, Aug 11, 2010
  8. 4/5 unpack_trees: group error messages by typeMatthieu Moy, Aug 11, 2010
  9. 5/5 t7609: test merge and checkout error messagesMatthieu Moy, Aug 11, 2010
  10. 2/5 merge-recursive: porcelain messages for checkoutMatthieu Moy, Aug 9, 2010
  11. Junio C HamanoAug 9, 2010
  12. Matthieu MoyAug 9, 2010
  13. Ævar Arnfjörð BjarmasonAug 9, 2010
  14. 3/5 merge-recursive: distinguish "removed" and "overwritten" messagesMatthieu Moy, Aug 9, 2010
  15. 4/5 unpack_trees: group error messages by typeMatthieu Moy, Aug 9, 2010
  16. 5/5 t7609: test merge and checkout error messagesMatthieu Moy, Aug 9, 2010

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.