aboutsummaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 9589418c25..01512d50bd 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2213,17 +2213,15 @@ static const char *lstrip_ref_components(const char *refname, int len)
static const char *rstrip_ref_components(const char *refname, int len)
{
int remaining = normalize_component_count(refname, len);
- char *start = xstrdup(refname);
+ const char *end = refname + strlen(refname);
- while (remaining-- > 0) {
- char *p = strrchr(start, '/');
- if (!p) {
- free(start);
+ while (remaining > 0) {
+ if (end == refname)
return xstrdup("");
- } else
- p[0] = '\0';
+ if (*--end == '/')
+ remaining--;
}
- return start;
+ return xmemdupz(refname, end - refname);
}
static const char *show_ref(struct refname_atom *atom, const char *refname)