refs.c: verify_lock should set errno to something meaningful
Making errno when returning from verify_lock() meaningful, which should almost but not completely fix * a bug in "git fetch"'s s_update_ref, which trusts the result of an errno == ENOTDIR check to detect D/F conflicts ENOTDIR makes sense as a sign that a file was in the way of a directory we wanted to create. Should "git fetch" also look for ENOTEMPTY or EEXIST to catch cases where a directory was in the way of a file to be created? Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Michael Haggerty <mhagger@alum.mit.edu>
Ronnie Sahlberg committed
Jun 20, 2014 at 07:42 UTC
835e3c992fd453d172466be29283b55a792cac76
2 files changed
+9
-1
refs.c
+4
@@ -1932,18 +1932,22 @@ int refname_match(const char *abbrev_name, const char *full_name)
1932
return 0;
1933
}
1934
1935
+/* This function should make sure errno is meaningful on error */
1936
static struct ref_lock *verify_lock(struct ref_lock *lock,
1937
const unsigned char *old_sha1, int mustexist)
1938
{
1939
if (read_ref_full(lock->ref_name, lock->old_sha1, mustexist, NULL)) {
1940
+ int save_errno = errno;
1941
error("Can't verify ref %s", lock->ref_name);
1942
unlock_ref(lock);
1943
+ errno = save_errno;
1944
return NULL;
1945
}
1946
if (hashcmp(lock->old_sha1, old_sha1)) {
1947
error("Ref %s is at %s but expected %s", lock->ref_name,
1948
sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
1949
unlock_ref(lock);
1950
+ errno = EBUSY;
1951
return NULL;
1952
}
1953
return lock;
refs.h
+5
-1
@@ -137,11 +137,15 @@ extern int ref_exists(const char *);
137
*/
138
extern int peel_ref(const char *refname, unsigned char *sha1);
139
140
-/** Locks a "refs/" ref returning the lock on success and NULL on failure. **/
140
+/*
141
+ * Locks a "refs/" ref returning the lock on success and NULL on failure.
142
+ * On failure errno is set to something meaningful.
143
+ */
144
extern struct ref_lock *lock_ref_sha1(const char *refname, const unsigned char *old_sha1);
145
146
/** Locks any ref (for 'HEAD' type refs). */
147
#define REF_NODEREF 0x01
148
+/* errno is set to something meaningful on failure */
149
extern struct ref_lock *lock_any_ref_for_update(const char *refname,
150
const unsigned char *old_sha1,
151
int flags, int *type_p);