X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=pack-refs.c;h=23bbd00e3e542e844fce08156c5c1073e6437d43;hb=dbdc07fcbe3a951df8a3869b42edb6fffd466486;hp=7f43f8ac3398fb2dbe393f08811989b0a8d4e2dd;hpb=03f94ae9f909952ed5a78917ab319a312889354b;p=git.git diff --git a/pack-refs.c b/pack-refs.c index 7f43f8ac3..23bbd00e3 100644 --- a/pack-refs.c +++ b/pack-refs.c @@ -60,6 +60,37 @@ static int handle_one_ref(const char *path, const unsigned char *sha1, return 0; } +/* + * Remove empty parents, but spare refs/ and immediate subdirs. + * Note: munges *name. + */ +static void try_remove_empty_parents(char *name) +{ + char *p, *q; + int i; + p = name; + for (i = 0; i < 2; i++) { /* refs/{heads,tags,...}/ */ + while (*p && *p != '/') + p++; + /* tolerate duplicate slashes; see check_refname_format() */ + while (*p == '/') + p++; + } + for (q = p; *q; q++) + ; + while (1) { + while (q > p && *q != '/') + q--; + while (q > p && *(q-1) == '/') + q--; + if (q == p) + break; + *q = '\0'; + if (rmdir(git_path("%s", name))) + break; + } +} + /* make sure nobody touched the ref, and unlink */ static void prune_ref(struct ref_to_prune *r) { @@ -68,6 +99,7 @@ static void prune_ref(struct ref_to_prune *r) if (lock) { unlink_or_warn(git_path("%s", r->name)); unlock_ref(lock); + try_remove_empty_parents(r->name); } }