commit | d64ea0f83bd7e676778f833c57f969a94518a28d | [log] [tgz] |
---|---|---|
author | Jeff King <peff@peff.net> | Mon Jan 12 20:57:37 2015 -0500 |
committer | Junio C Hamano <gitster@pobox.com> | Tue Jan 13 10:03:30 2015 -0800 |
tree | a823ee7016046bdd3f6d2d9454b6a07260f28182 | |
parent | 1da1e07c835e900337714cfad6c32a8dc0b36ac3 [diff] |
git-compat-util: add xstrdup_or_null helper It's a common idiom to duplicate a string if it is non-NULL, or pass a literal NULL through. This is already a one-liner in C, but you do have to repeat the name of the string twice. So if there's a function call, you must write: const char *x = some_fun(...); return x ? xstrdup(x) : NULL; instead of (with this patch) just: return xstrdup_or_null(some_fun(...)); Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>