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 <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Clemens Buchacher committed
Nov 5, 2008 at 21:55 UTC
5bdd8d4a3062ac8f29ec511fecb85049f6ff3ecc
2 files changed
+11
-3
refs.c
+4
-3
@@ -788,10 +788,10 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
788
char *ref_file;
789
const char *orig_ref = ref;
790
struct ref_lock *lock;
791
- struct stat st;
791
int last_errno = 0;
792
int type, lflags;
793
int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
794
+ int missing = 0;
795
796
lock = xcalloc(1, sizeof(struct ref_lock));
797
lock->lock_fd = -1;
@@ -819,12 +819,13 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
819
orig_ref, strerror(errno));
820
goto error_return;
821
}
822
+ missing = is_null_sha1(lock->old_sha1);
823
/* When the ref did not exist and we are creating it,
824
* make sure there is no existing ref that is packed
825
* whose name begins with our refname, nor a ref whose
826
* name is a proper prefix of our refname.
827
*/
827
- if (is_null_sha1(lock->old_sha1) &&
828
+ if (missing &&
829
!is_refname_available(ref, NULL, get_packed_refs(), 0))
830
goto error_return;
831
@@ -838,7 +839,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
839
lock->ref_name = xstrdup(ref);
840
lock->orig_ref_name = xstrdup(orig_ref);
841
ref_file = git_path("%s", ref);
841
- if (lstat(ref_file, &st) && errno == ENOENT)
842
+ if (missing)
843
lock->force_write = 1;
844
if ((flags & REF_NODEREF) && (type & REF_ISSYMREF))
845
lock->force_write = 1;
t/t3210-pack-refs.sh
+7
@@ -96,6 +96,13 @@ test_expect_success \
96
git branch -d n/o/p &&
97
git branch n'
98
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
+
106
test_expect_success 'pack, prune and repack' '
107
git tag foo &&
108
git pack-refs --all --prune &&