refs.c: commit_packed_refs to return a meaningful errno on failure
Making errno when returning from commit_packed_refs() meaningful, which should fix * a bug in "git clone" where it prints strerror(errno) based on errno, despite errno possibly being zero and potentially having been clobbered by that point * the same kind of bug in "git pack-refs" and prepares for repack_without_refs() to get a meaningful error message when commit_packed_refs() fails without falling into the same bug. 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
d3f665550588d19d6d6c9f9064aa3d4685afdf4d
2 files changed
+10
-1
refs.c
+9
-1
@@ -2239,11 +2239,16 @@ int lock_packed_refs(int flags)
2239
return 0;
2240
}
2241
2242
+/*
2243
+ * Commit the packed refs changes.
2244
+ * On error we must make sure that errno contains a meaningful value.
2245
+ */
2246
int commit_packed_refs(void)
2247
{
2248
struct packed_ref_cache *packed_ref_cache =
2249
get_packed_ref_cache(&ref_cache);
2250
int error = 0;
2251
+ int save_errno = 0;
2252
2253
if (!packed_ref_cache->lock)
2254
die("internal error: packed-refs not locked");
@@ -2253,10 +2258,13 @@ int commit_packed_refs(void)
2258
do_for_each_entry_in_dir(get_packed_ref_dir(packed_ref_cache),
2259
0, write_packed_entry_fn,
2260
&packed_ref_cache->lock->fd);
2256
- if (commit_lock_file(packed_ref_cache->lock))
2261
+ if (commit_lock_file(packed_ref_cache->lock)) {
2262
+ save_errno = errno;
2263
error = -1;
2264
+ }
2265
packed_ref_cache->lock = NULL;
2266
release_packed_ref_cache(packed_ref_cache);
2267
+ errno = save_errno;
2268
return error;
2269
}
2270
refs.h
+1
@@ -98,6 +98,7 @@ extern void add_packed_ref(const char *refname, const unsigned char *sha1);
98
* Write the current version of the packed refs cache from memory to
99
* disk. The packed-refs file must already be locked for writing (see
100
* lock_packed_refs()). Return zero on success.
101
+ * Sets errno to something meaningful on error.
102
*/
103
extern int commit_packed_refs(void);
104