use xstrdup_or_null to replace ternary conditionals

This replaces "x ? xstrdup(x) : NULL" with xstrdup_or_null(x).
The change is fairly mechanical, with the exception of
resolve_refdup, which can eliminate a temporary variable.

There are still a few hits grepping for "?.*xstrdup", but
these are of slightly different forms and cannot be
converted (e.g., "x ? xstrdup(x->foo) : NULL").

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2015-01-12 20:59:09 -05:00
committed by Junio C Hamano
parent eaa541eb59
commit 8c53f0719b
7 changed files with 9 additions and 10 deletions

3
refs.c
View File

@ -1529,8 +1529,7 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag)
{
const char *ret = resolve_ref_unsafe(ref, sha1, reading, flag);
return ret ? xstrdup(ret) : NULL;
return xstrdup_or_null(resolve_ref_unsafe(ref, sha1, reading, flag));
}
/* The argument to filter_refs */