Skip to content

Commit 5bdd8d4

Browse files
Clemens Buchachergitster
authored andcommitted
do not force write of packed refs
We force writing a ref if it does not exist. Originally, we only had to look for the ref file to check if it existed. Now we have to look for a packed ref as well. Luckily, resolve_ref already does all the work for us. Signed-off-by: Clemens Buchacher <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16088d8 commit 5bdd8d4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

refs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,10 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
788788
char *ref_file;
789789
const char *orig_ref = ref;
790790
struct ref_lock *lock;
791-
struct stat st;
792791
int last_errno = 0;
793792
int type, lflags;
794793
int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
794+
int missing = 0;
795795

796796
lock = xcalloc(1, sizeof(struct ref_lock));
797797
lock->lock_fd = -1;
@@ -819,12 +819,13 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
819819
orig_ref, strerror(errno));
820820
goto error_return;
821821
}
822+
missing = is_null_sha1(lock->old_sha1);
822823
/* When the ref did not exist and we are creating it,
823824
* make sure there is no existing ref that is packed
824825
* whose name begins with our refname, nor a ref whose
825826
* name is a proper prefix of our refname.
826827
*/
827-
if (is_null_sha1(lock->old_sha1) &&
828+
if (missing &&
828829
!is_refname_available(ref, NULL, get_packed_refs(), 0))
829830
goto error_return;
830831

@@ -838,7 +839,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
838839
lock->ref_name = xstrdup(ref);
839840
lock->orig_ref_name = xstrdup(orig_ref);
840841
ref_file = git_path("%s", ref);
841-
if (lstat(ref_file, &st) && errno == ENOENT)
842+
if (missing)
842843
lock->force_write = 1;
843844
if ((flags & REF_NODEREF) && (type & REF_ISSYMREF))
844845
lock->force_write = 1;

t/t3210-pack-refs.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ test_expect_success \
9696
git branch -d n/o/p &&
9797
git branch n'
9898

99+
test_expect_success \
100+
'see if up-to-date packed refs are preserved' \
101+
'git branch q &&
102+
git pack-refs --all --prune &&
103+
git update-ref refs/heads/q refs/heads/q &&
104+
! test -f .git/refs/heads/q'
105+
99106
test_expect_success 'pack, prune and repack' '
100107
git tag foo &&
101108
git pack-refs --all --prune &&

0 commit comments

Comments
 (0)