Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx> --- refs/files-backend.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 7e870fc..897ff4c 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2200,13 +2200,15 @@ static int pack_if_possible_fn(struct ref_entry *entry, void *cb_data) /* * Remove empty parents, but spare refs/ and immediate subdirs. - * Note: munges *refname. */ -static void try_remove_empty_parents(char *refname) +static void try_remove_empty_parents(const char *refname) { + struct strbuf buf = STRBUF_INIT; char *p, *q; int i; - p = refname; + + strbuf_addstr(&buf, refname); + p = buf.buf; for (i = 0; i < 2; i++) { /* refs/{heads,tags,...}/ */ while (*p && *p != '/') p++; @@ -2214,8 +2216,7 @@ static void try_remove_empty_parents(char *refname) while (*p == '/') p++; } - for (q = p; *q; q++) - ; + q = buf.buf + buf.len; while (1) { while (q > p && *q != '/') q--; @@ -2223,10 +2224,11 @@ static void try_remove_empty_parents(char *refname) q--; if (q == p) break; - *q = '\0'; - if (rmdir(git_path("%s", refname))) + strbuf_setlen(&buf, q - buf.buf); + if (rmdir(git_path("%s", buf.buf))) break; } + strbuf_release(&buf); } /* make sure nobody touched the ref, and unlink */ -- 2.7.0 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html