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