Re: [PATCH] blame.c: fix garbled error message
- From
Jeff King <peff@peff.net>
- Date
- Jan 13, 2015, 01:54 UTC
- Message-ID
- <20150113015427.GA5497@peff.net>
- In-Reply-To
- <xmqqzj9n4k11.fsf@gitster.dls.corp.google.com>
On Mon, Jan 12, 2015 at 04:11:06PM -0800, Junio C Hamano wrote:
Show 12 quoted lines
> Jeff King <peff@peff.net> writes: > > > As an aside, I have often been tempted to have xstrdup silently > > propagate a NULL. It would have been the right thing to do here, but > > maybe there are cases where the segfault is preferable for catching a > > mistake early (otherwise you might store the NULL and then segfault much > > later). > > Great minds think alike. The sentence after "but maybe ..." was > what I had in mind as a response in anticipation that somebody might > suggest that; a separate xstrdup_or_null() might be fine, but I'd > rather not to have xstrdup() that is _too_ magical.
Yeah. Of course, it is not _that_ many more characters to do a ternary conditional. I guess the main benefit is that you do not have to repeat the name of the variable (which lets you reuse a function result directly, avoiding an explicit temporary).
Here's my attempt. Some cases are a little nicer, but overall, it does not feel significantly more readable to me. I dunno. I could go either way. I stuck Lukas's patch on top (modified to use xstrdup_or_null), if we do want to go that route. Otherwise it needs the ?: treatment.
[1/5]: git-compat-util: add xstrdup_or_null helper [2/5]: builtin/apply.c: use xstrdup_or_null instead of null_strdup [3/5]: builtin/commit.c: use xstrdup_or_null instead of envdup [4/5]: use xstrdup_or_null to replace ternary conditionals [5/5]: blame.c: fix garbled error message