From: Matthieu Moy Date: Tue, 15 Jun 2010 13:28:43 GMT Subject: Re: [PATCH 2/5 v2] unpack_trees: group errors by type Message-ID: In-Reply-To: Diane Gasselin 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/