Re: [PATCH 2/5 v2] unpack_trees: group errors by type
- From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
- Date
- Jun 15, 2010, 13:28 UTC
- Message-ID
- <vpq7hm0whkk.fsf@bauges.imag.fr>
- In-Reply-To
- <AANLkTin381eyaDabz3-z_8jB05N4CVKGmLOqVOprJMW2@mail.gmail.com>
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/