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 eca35a25 (Fix git branch -m for symrefs.). Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 16, 2012 at 12:22 UTC
547d058fb6fefad147675a6d3fdb9439c57916a1
1 file changed
+5
-13
refs.c
+5
-13
@@ -1753,26 +1753,18 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
1753
struct ref_lock *lock;
1754
int err, i = 0, ret = 0, flag = 0;
1755
1756
- lock = lock_ref_sha1_basic(refname, sha1, 0, &flag);
1756
+ lock = lock_ref_sha1_basic(refname, sha1, delopt, &flag);
1757
if (!lock)
1758
return 1;
1759
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
1760
/* 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);
1764
if (err && errno != ENOENT)
1765
ret = 1;
1766
1774
- if (!(delopt & REF_NODEREF))
1775
- lock->lk->filename[i] = '.';
1767
+ lock->lk->filename[i] = '.';
1768
}
1769
/* removing the loose one could have resurrected an earlier
1770
* packed one. Also, if it was not loose we need to repack