Skip to content

Commit afd11d3

Browse files
peffgitster
authored andcommitted
pack-refs: prune top-level refs like "refs/foo"
After we have packed all refs, we prune any loose refs that correspond to what we packed. We do so by first taking a lock with lock_ref_sha1, and then deleting the loose ref file. However, lock_ref_sha1 will refuse to take a lock on any refs that exist at the top-level of the "refs/" directory, and we skip pruning the ref. This is almost certainly not what we want to happen here. The criteria to be pruned should not differ from that to be packed; if a ref makes it to prune_ref, it's because we want it both packed and pruned (if there are refs you do not want to be packed, they should be omitted much earlier by pack_ref_is_possible, which we do in this case if --all is not given). We can fix this by switching to lock_any_ref_for_update. This behaves exactly the same with the exception of this top-level check. Signed-off-by: Jeff King <[email protected]> Reviewed-by: Michael Haggerty <[email protected]> Reviewed-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32f5660 commit afd11d3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

refs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,8 @@ static void try_remove_empty_parents(char *name)
23532353
/* make sure nobody touched the ref, and unlink */
23542354
static void prune_ref(struct ref_to_prune *r)
23552355
{
2356-
struct ref_lock *lock = lock_ref_sha1(r->name + 5, r->sha1);
2356+
struct ref_lock *lock = lock_any_ref_for_update(r->name, r->sha1,
2357+
0, NULL);
23572358

23582359
if (lock) {
23592360
unlink_or_warn(git_path("%s", r->name));

t/t3210-pack-refs.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,11 @@ test_expect_success 'delete ref while another dangling packed ref' '
151151
test_cmp /dev/null result
152152
'
153153

154+
test_expect_success 'pack ref directly below refs/' '
155+
git update-ref refs/top HEAD &&
156+
git pack-refs --all --prune &&
157+
grep refs/top .git/packed-refs &&
158+
test_path_is_missing .git/refs/top
159+
'
160+
154161
test_done

0 commit comments

Comments
 (0)