git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Diane Gasselin <diane.gasselin@ensimag.imag.fr>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: git@vger.kernel.org,
	"Clément Poulain" <clement.poulain@ensimag.imag.fr>,
	"Axel Bonnet" <axel.bonnet@ensimag.imag.fr>
Subject: Re: [PATCH 2/5 v2] unpack_trees: group errors by type
Date: Tue, 15 Jun 2010 15:15:36 +0200	[thread overview]
Message-ID: <AANLkTin381eyaDabz3-z_8jB05N4CVKGmLOqVOprJMW2@mail.gmail.com> (raw)
In-Reply-To: <vpqljagzc39.fsf@bauges.imag.fr>

Le 15 juin 2010 14:58, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> a écrit :
> Diane Gasselin <diane.gasselin@ensimag.imag.fr> writes:
>
>> --- a/unpack-trees.c
>> +++ b/unpack-trees.c
>> @@ -60,6 +60,92 @@ static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
>>  }
>>
>>  /*
>> + * add error messages on path <path> and action <action>
>> + * corresponding to the type <e> with the message <msg>
>> + * indicating if it should be display in porcelain or not
>> + */
>> +static int add_rejected_path(struct unpack_trees_options *o,
>> +                          enum unpack_trees_error e,
>> +                          const char *path,
>> +                          const char *action,
>> +                          int porcelain,
>> +                          const char *msg)
>> +{
>> +     struct rejected_paths_list *newentry;
>> +     struct rejected_paths **rp;
>> +     /*
>> +      * simply display the given error message if in plumbing mode
>> +      */
>> +     if (!porcelain)
>> +             o->show_all_errors = 0;
>> +     if (!o->show_all_errors)
>> +             return error(msg, path, action);
>
> I don't fully understand what you're doing with show_all_errors and
> porcelain here. From the caller, "porcelain" is true iff the
> corresponding error message has been set in o. But if you can infer
> whether you're in porcelain from the error messages, why do you need
> show_all_errors in addition?
>
>>  static int reject_merge(struct cache_entry *ce, struct unpack_trees_options *o)
>>  {
>> -     return error(ERRORMSG(o, would_overwrite), ce->name);
>> +     return add_rejected_path(o, would_overwrite, ce->name, NULL,
>> +                              (o && (o)->msgs.would_overwrite),
>
> Parenthesis around (o) are distracting and useless. I guess you
> copy-pasted from a macro (for which parentheses should definitely be
> used in case the macro is called on an arbitrary expression).
>
>> @@ -874,8 +964,16 @@ static int verify_uptodate_1(struct cache_entry *ce,
>>       }
>>       if (errno == ENOENT)
>>               return 0;
>> -     return o->gently ? -1 :
>> -             error(error_msg, ce->name);
>> +     if (error == sparse_not_uptodate_file)
>> +             return o->gently ? -1 :
>> +                     add_rejected_path(o, sparse_not_uptodate_file, ce->name, NULL,
>> +                                       (o && (o)->msgs.sparse_not_uptodate_file),
>> +                                       ERRORMSG(o, sparse_not_uptodate_file));
>> +     else
>> +             return o->gently ? -1 :
>> +                     add_rejected_path(o, not_uptodate_file, ce->name, NULL,
>> +                                       (o && (o)->msgs.not_uptodate_file),
>> +                                       ERRORMSG(o, not_uptodate_file));
>>  }
>
> Isn't that a complex way of saying
>
>        int porcelain;
>        if (error == sparse_not_uptodate_file)
>                porcelain = o && o->msgs.sparse_not_uptodate_file;
>        else
>                porcelain = o && o->msgs.not_uptodate_file;
>        return o->gently ? -1 :
>                        add_rejected_path(o, error, ce->name, NULL,
>                                          porcelain, ERRORMSG(o, error));
>
> ?
>

The problem is that "error" is an enum unpack_trees_error, and
ERRORMSG takes the name of the field from unpack_trees_error_msgs.
If I try to do ERRORMSG(o, error), the compilator would say that the
"error" is not a field of unpack_trees_error_msgs.

> Also, I'm not sure I understand why you're attaching the error message
> string to each rejected_paths entry. Wouldn't it be more sensible to
> use o->msg in display_error_msgs() instead?
>

In display_error_msgs(), I cannot access o->msg because I would not
know which error I am treating.
In the same way as previously, I cannot use the enum
unpack_trees_error to access it.

I know it makes the code a bit "heavy" but I did not see a better way to do it.

> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
>

  reply	other threads:[~2010-06-15 13:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-15 12:22 [PATCH 0/5 v2] unpack_trees: nicer error messages Diane Gasselin
2010-06-15 12:22 ` [PATCH 1/5 v2] merge-recursive: porcelain messages for checkout Diane Gasselin
2010-06-15 12:22   ` [PATCH 2/5 v2] unpack_trees: group errors by type Diane Gasselin
2010-06-15 12:22     ` [PATCH 3/5 v2] unpack_trees_options: update porcelain messages Diane Gasselin
2010-06-15 12:22       ` [PATCH 4/5 v2] tests: update porcelain expected message Diane Gasselin
2010-06-15 12:22         ` [PATCH 5/5 v2] t7609: test merge and checkout error messages Diane Gasselin
2010-06-15 13:09           ` Matthieu Moy
2010-06-15 13:05       ` [PATCH 3/5 v2] unpack_trees_options: update porcelain messages Matthieu Moy
2010-06-15 12:58     ` [PATCH 2/5 v2] unpack_trees: group errors by type Matthieu Moy
2010-06-15 13:15       ` Diane Gasselin [this message]
2010-06-15 13:28         ` Matthieu Moy
2010-06-15 13:40           ` Diane Gasselin
2010-06-15 12:36   ` [PATCH 1/5 v2] merge-recursive: porcelain messages for checkout Matthieu Moy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTin381eyaDabz3-z_8jB05N4CVKGmLOqVOprJMW2@mail.gmail.com \
    --to=diane.gasselin@ensimag.imag.fr \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=axel.bonnet@ensimag.imag.fr \
    --cc=clement.poulain@ensimag.imag.fr \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).