Skip to content

Commit 547d058

Browse files
René Scharfegitster
authored andcommitted
refs: lock symref that is to be deleted, not its target
When delete_ref is called on a symref then it locks its target and then either deletes the target or the symref, depending on whether the flag REF_NODEREF was set in the parameter delopt. Instead, simply pass the flag to lock_ref_sha1_basic, which will then either lock the target or the symref, and delete the locked ref. This reimplements part of eca35a2 (Fix git branch -m for symrefs.). Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ce2e39 commit 547d058

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

refs.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,26 +1753,18 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
17531753
struct ref_lock *lock;
17541754
int err, i = 0, ret = 0, flag = 0;
17551755

1756-
lock = lock_ref_sha1_basic(refname, sha1, 0, &flag);
1756+
lock = lock_ref_sha1_basic(refname, sha1, delopt, &flag);
17571757
if (!lock)
17581758
return 1;
17591759
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
17601760
/* loose */
1761-
const char *path;
1762-
1763-
if (!(delopt & REF_NODEREF)) {
1764-
i = strlen(lock->lk->filename) - 5; /* .lock */
1765-
lock->lk->filename[i] = 0;
1766-
path = lock->lk->filename;
1767-
} else {
1768-
path = git_path("%s", refname);
1769-
}
1770-
err = unlink_or_warn(path);
1761+
i = strlen(lock->lk->filename) - 5; /* .lock */
1762+
lock->lk->filename[i] = 0;
1763+
err = unlink_or_warn(lock->lk->filename);
17711764
if (err && errno != ENOENT)
17721765
ret = 1;
17731766

1774-
if (!(delopt & REF_NODEREF))
1775-
lock->lk->filename[i] = '.';
1767+
lock->lk->filename[i] = '.';
17761768
}
17771769
/* removing the loose one could have resurrected an earlier
17781770
* packed one. Also, if it was not loose we need to repack

0 commit comments

Comments
 (0)