Skip to content

Commit 2ddb5d1

Browse files
bradkinggitster
authored andcommitted
refs: factor delete_ref loose ref step into a helper
Factor loose ref deletion into helper function delete_ref_loose to allow later use elsewhere. Signed-off-by: Brad King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4738a33 commit 2ddb5d1

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

refs.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,24 +2450,31 @@ static int repack_without_ref(const char *refname)
24502450
return commit_packed_refs();
24512451
}
24522452

2453+
static int delete_ref_loose(struct ref_lock *lock, int flag)
2454+
{
2455+
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
2456+
/* loose */
2457+
int err, i = strlen(lock->lk->filename) - 5; /* .lock */
2458+
2459+
lock->lk->filename[i] = 0;
2460+
err = unlink_or_warn(lock->lk->filename);
2461+
lock->lk->filename[i] = '.';
2462+
if (err && errno != ENOENT)
2463+
return 1;
2464+
}
2465+
return 0;
2466+
}
2467+
24532468
int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
24542469
{
24552470
struct ref_lock *lock;
2456-
int err, i = 0, ret = 0, flag = 0;
2471+
int ret = 0, flag = 0;
24572472

24582473
lock = lock_ref_sha1_basic(refname, sha1, delopt, &flag);
24592474
if (!lock)
24602475
return 1;
2461-
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
2462-
/* loose */
2463-
i = strlen(lock->lk->filename) - 5; /* .lock */
2464-
lock->lk->filename[i] = 0;
2465-
err = unlink_or_warn(lock->lk->filename);
2466-
if (err && errno != ENOENT)
2467-
ret = 1;
2476+
ret |= delete_ref_loose(lock, flag);
24682477

2469-
lock->lk->filename[i] = '.';
2470-
}
24712478
/* removing the loose one could have resurrected an earlier
24722479
* packed one. Also, if it was not loose we need to repack
24732480
* without it.

0 commit comments

Comments
 (0)