summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fbdc056)
raw | patch | inline | side by side (parent: fbdc056)
author | Jeff King <peff@peff.net> | |
Tue, 7 Apr 2009 07:05:01 +0000 (03:05 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 8 Apr 2009 05:06:12 +0000 (22:06 -0700) |
This function took a "refinfo" object which is unnecessarily
restrictive; it only ever looked at the refname field. This
patch refactors it to take just the ref name as a string.
While we're touching the relevant lines, let's give it
consistent memory semantics. Previously, some code paths
would return an allocated string and some would return the
original string; now it will always return a malloc'd
string.
This doesn't actually fix a bug or a leak, because
for-each-ref doesn't clean up its memory, but it makes the
function a lot less surprising for reuse (which will
happen in a later patch).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
restrictive; it only ever looked at the refname field. This
patch refactors it to take just the ref name as a string.
While we're touching the relevant lines, let's give it
consistent memory semantics. Previously, some code paths
would return an allocated string and some would return the
original string; now it will always return a malloc'd
string.
This doesn't actually fix a bug or a leak, because
for-each-ref doesn't clean up its memory, but it makes the
function a lot less surprising for reuse (which will
happen in a later patch).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-for-each-ref.c | patch | blob | history |
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 5cbb4b081d63b52393a5f85716ba6961a18fa59e..4aaf75c779a281e0886d727aace9dc33f5ea3833 100644 (file)
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
/*
* Shorten the refname to an non-ambiguous form
*/
-static char *get_short_ref(struct refinfo *ref)
+static char *get_short_ref(const char *ref)
{
int i;
static char **scanf_fmts;
/* bail out if there are no rules */
if (!nr_rules)
- return ref->refname;
+ return xstrdup(ref);
- /* buffer for scanf result, at most ref->refname must fit */
- short_name = xstrdup(ref->refname);
+ /* buffer for scanf result, at most ref must fit */
+ short_name = xstrdup(ref);
/* skip first rule, it will always match */
for (i = nr_rules - 1; i > 0 ; --i) {
int j;
int short_name_len;
- if (1 != sscanf(ref->refname, scanf_fmts[i], short_name))
+ if (1 != sscanf(ref, scanf_fmts[i], short_name))
continue;
short_name_len = strlen(short_name);
}
free(short_name);
- return ref->refname;
+ return xstrdup(ref);
}
if (formatp) {
formatp++;
if (!strcmp(formatp, "short"))
- refname = get_short_ref(ref);
+ refname = get_short_ref(ref->refname);
else
die("unknown refname format %s",
formatp);