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

Re: [PATCH 2/5 v2] unpack_trees: group errors by type

From
DGDiane Gasselin <diane.gasselin@ensimag.imag.fr>
Date
Jun 15, 2010, 13:40 UTC
Message-ID
<AANLkTilPJRAqT4LUF4ps9YtK3bFwZiVTVXa6_xigdkTg@mail.gmail.com>
In-Reply-To
<vpq7hm0whkk.fsf@bauges.imag.fr>
Le 15 juin 2010 15:28, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> a écrit :
Show 50 quoted lines
> Diane Gasselin <diane.gasselin@ensimag.imag.fr> writes:
>
>> In display_error_msgs(), I cannot access o->msg because I would not
>> know which error I am treating.
>
> You do:
>
> static void display_error_msgs(struct unpack_trees_options *o)
> {
> ...
>        for (i = 0; i < NB_UNPACK_TREES_ERROR; i++) {
>                ...
>        }
>
> You know "i", so you know which error it is. The difficulty is that
> the rejected paths are in an array, while the error messages are in a
> struct, but you can either:
>
> * Turn the struct into an array, and say msgs[would_overwrite] instead
>  of msgs.would_overwrite (which would also simplify the code
>  elsewhere since you would be able to write "ERRORMSG(o, error)" and
>  such things).
>
> * Do
>
> switch (i) {
> case would_overwrite:
>        msg = o->msg.would_overwrite;
>        break;
> case not_uptodate_file:
>        msg = o->msg.not_uptodate_file;
>        break;
> case not_uptodate_dir:
>        msg = o->msg.not_uptodate_dir;
>        break;
> case would_lose_untracked_overwritten:
>        msg = o->msg.would_lose_untracked_overwritten;
>        break;
> case would_lose_untracked_removed:
>        msg = o->msg.would_lose_untracked_removed;
>        break;
> case sparse_not_uptodate_file:
>        msg = o->msg.sparse_not_uptodate_file;
>        break;
> }
>
> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
>

Thanks for your answers. I did the switch case at first but thought it was maybe a bit repetitive. That is why, I opted for giving directly the message in add_rejected_path().

Otherwise, I do agree an array would make things easier, especially for my patch. Does anyone has an objection into changing the struct unpack_trees_error_msgs into an array?

Previous: Matthieu MoyNext: Matthieu Moy
Message 12 of 13 in “unpack_trees: nicer error messages”
  1. 0/5 unpack_trees: nicer error messagesDiane Gasselin, Jun 15, 2010
  2. 1/5 merge-recursive: porcelain messages for checkoutDiane Gasselin, Jun 15, 2010
  3. 2/5 unpack_trees: group errors by typeDiane Gasselin, Jun 15, 2010
  4. 3/5 unpack_trees_options: update porcelain messagesDiane Gasselin, Jun 15, 2010
  5. 4/5 tests: update porcelain expected messageDiane Gasselin, Jun 15, 2010
  6. 5/5 t7609: test merge and checkout error messagesDiane Gasselin, Jun 15, 2010
  7. Matthieu MoyJun 15, 2010
  8. Matthieu MoyJun 15, 2010
  9. Matthieu MoyJun 15, 2010
  10. Diane GasselinJun 15, 2010
  11. Matthieu MoyJun 15, 2010
  12. Diane GasselinJun 15, 2010
  13. Matthieu MoyJun 15, 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.