git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 4/4] notes: only append a blob to a blob
Date: Thu, 10 May 2012 11:45:19 -0400	[thread overview]
Message-ID: <20120510154519.GB23941@sigill.intra.peff.net> (raw)
In-Reply-To: <CACsJy8ADE1PBYsQcJnO6U4OFoWQjaEW7=6=3V_UO=t5KNinDCA@mail.gmail.com>

On Thu, May 10, 2012 at 10:31:23PM +0700, Nguyen Thai Ngoc Duy wrote:

> >> +static const char *type_name(enum object_type type)
> >> +{
> >> +     switch (type) {
> >> +     case OBJ_BLOB: return _("a blob");
> >> +     case OBJ_TAG: return _("a tag");
> >> +     case OBJ_COMMIT: return _("a commit");
> >> +     case OBJ_TREE: return _("a tree");
> >> +     default:
> >> +             die("BUG: put a new string for type %d here", type);
> >> +     }
> >> +}
> >
> > Don't we have object.c:typename for this
> 
> The key difference here is _() with an article. It's i18n friendly. I
> wanted to make 15 combinations (blob/blob cannot happen) of "cannot
> append %s to %s", which is best for translators but probably too much
> for C developers.

I do not pay much attention to the translation details, but I would
think that we would keep terms like "tree" and "blob" universal, as they
are technical terms. IOW, you would not expect the "blob" in "git
cat-file blob $sha1" to be internationalized, and this seems like the
same level of technical detail.

> >> @@ -204,8 +216,12 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
> >>               strbuf_grow(&(msg->buf), size + 1);
> >>               if (msg->buf.len && prev_buf && size)
> >>                       strbuf_insert(&(msg->buf), 0, "\n", 1);
> >> -             if (prev_buf && size)
> >> +             if (prev_buf && size) {
> >> +                     if (type != OBJ_BLOB || msg->type != OBJ_BLOB)
> >> +                             die(_("cannot append %s to %s"),
> >> +                                 type_name(type), type_name(msg->type));
> >>                       strbuf_insert(&(msg->buf), 0, prev_buf, size);
> >> +             }
> >
> > I think this is wrong for the reasons above. You would not want to
> > concatenate a tree to a tree.
> 
> Hmm.. that would become "if (tree != blob || tree != blob) die();",
> exactly your point.

Oh, I totally misread this as "type != msg->type" for some reason.
Sorry.

I think the behavior is correct, but the message confused me. If I see
"cannot append a foo to a bar", it implies to me that it is the
combination of the elements that is the limiting factor. But it is not.
It is that one (or more) of the elements is not a blob, regardless of
what the other element is. So I think this would be more accurate:

  if (type != OBJ_BLOB)
          die(_("cannot append to a non-blob note"));
  if (msg->type != OBJ_BLOB)
          die(_("cannot append a non-blob object to a note"));

-Peff

  reply	other threads:[~2012-05-10 15:45 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-08 13:11 [PATCH] notes: do not accept non-blobs as new notes Nguyễn Thái Ngọc Duy
2012-05-08 16:03 ` Jeff King
2012-05-08 16:26   ` Junio C Hamano
2012-05-09  8:19   ` Nguyen Thai Ngoc Duy
2012-05-09 17:37     ` Jeff King
2012-05-09 17:52       ` Junio C Hamano
2012-05-09 18:43         ` Jeff King
2012-05-10 14:04 ` [PATCH 0/4] git-notes ui fixes regarding non-blobs notes Nguyễn Thái Ngọc Duy
2012-05-10 14:04   ` [PATCH 1/4] notes: preserve object type given by "add -C" Nguyễn Thái Ngọc Duy
2012-05-10 14:04   ` [PATCH 2/4] notes: "add -c" refuses to open an editor with non-blobs Nguyễn Thái Ngọc Duy
2012-05-10 15:26     ` Johannes Sixt
2012-05-11  1:11       ` Nguyen Thai Ngoc Duy
2012-05-10 14:05   ` [PATCH 3/4] notes: refuse to edit non-blobs Nguyễn Thái Ngọc Duy
2012-05-10 14:05   ` [PATCH 4/4] notes: refuse to append to non-blob notes Nguyễn Thái Ngọc Duy
2012-05-10 14:43     ` [PATCH 4/4] notes: only append a blob to a blob Nguyễn Thái Ngọc Duy
2012-05-10 15:19       ` Jeff King
2012-05-10 15:31         ` Nguyen Thai Ngoc Duy
2012-05-10 15:45           ` Jeff King [this message]
2012-05-11  3:57             ` Junio C Hamano
2012-05-10 14:29   ` [PATCH 0/4] git-notes ui fixes regarding non-blobs notes Jeff King
2012-05-11  1:25   ` [PATCH v2 0/4] non-blob notes fixes Nguyễn Thái Ngọc Duy
2012-05-11  1:25   ` [PATCH v2 1/4] notes: preserve object type given by "add -C" Nguyễn Thái Ngọc Duy
2012-05-11 21:16     ` Junio C Hamano
2012-05-12  5:20       ` Nguyen Thai Ngoc Duy
2012-05-12  6:12         ` Junio C Hamano
2012-05-12  6:58           ` Nguyen Thai Ngoc Duy
2012-05-11  1:25   ` [PATCH v2 2/4] notes: "add -c" refuses to open an editor with non-blobs Nguyễn Thái Ngọc Duy
2012-05-11  1:25   ` [PATCH v2 3/4] notes: refuse to edit non-blobs Nguyễn Thái Ngọc Duy
2012-05-11  1:25   ` [PATCH v2 4/4] notes: only allow to append a blob to a blob Nguyễn Thái Ngọc Duy

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=20120510154519.GB23941@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /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).