[PATCH] for-each-ref: remove multiple xstrdup() in get_short_ref()
- From
Bert Wesarg <bert.wesarg@googlemail.com>
- Date
- Apr 7, 2009, 07:33 UTC
- Message-ID
- <1239089599-24760-1-git-send-email-bert.wesarg@googlemail.com>
- In-Reply-To
- <20090407070254.GA2870@coredump.intra.peff.net>
Now that get_short_ref() always return an malloced string, consolidate to one xstrcpy() call.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
--- Also an
Acked-by: Bert Wesarg <bert.wesarg@googlemail.com>
for Jeffs patch.
builtin-for-each-ref.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 4aaf75c..108c128 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -596,13 +596,13 @@ static char *get_short_ref(const char *ref) } } - /* bail out if there are no rules */ - if (!nr_rules) - return xstrdup(ref); - /* buffer for scanf result, at most ref must fit */ short_name = xstrdup(ref); + /* bail out if there are no rules */ + if (!nr_rules) + return short_name; + /* skip first rule, it will always match */ for (i = nr_rules - 1; i > 0 ; --i) { int j; @@ -641,8 +641,7 @@ static char *get_short_ref(const char *ref) return short_name; } - free(short_name); - return xstrdup(ref); + return strcpy(short_name, ref); }
-- tg: (e9786d7..) bw/ammend-jk/refactor-get_short_ref (depends on: jk/refactor-get_short_ref)