Skip to content

Commit ec0cc70

Browse files
author
Junio C Hamano
committed
Propagate cache error internal to refresh_cache() via parameter.
The function refresh_cache() is the only user of cache_errno that switches its behaviour based on what internal function refresh_cache_entry() finds; pass the error status back in a parameter passed down to it, to get rid of the global variable cache_errno. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0424138 commit ec0cc70

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

read-cache.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ unsigned int active_nr, active_alloc, active_cache_changed;
2424

2525
struct cache_tree *active_cache_tree;
2626

27-
static int cache_errno;
28-
2927
static void *cache_mmap;
3028
static size_t cache_mmap_size;
3129

@@ -643,14 +641,15 @@ int add_cache_entry(struct cache_entry *ce, int option)
643641
* For example, you'd want to do this after doing a "git-read-tree",
644642
* to link up the stat cache details with the proper files.
645643
*/
646-
struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
644+
static struct cache_entry *refresh_cache_ent(struct cache_entry *ce, int really, int *err)
647645
{
648646
struct stat st;
649647
struct cache_entry *updated;
650648
int changed, size;
651649

652650
if (lstat(ce->name, &st) < 0) {
653-
cache_errno = errno;
651+
if (err)
652+
*err = errno;
654653
return NULL;
655654
}
656655

@@ -664,7 +663,8 @@ struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
664663
}
665664

666665
if (ce_modified(ce, &st, really)) {
667-
cache_errno = EINVAL;
666+
if (err)
667+
*err = EINVAL;
668668
return NULL;
669669
}
670670

@@ -696,6 +696,8 @@ int refresh_cache(unsigned int flags)
696696

697697
for (i = 0; i < active_nr; i++) {
698698
struct cache_entry *ce, *new;
699+
int cache_errno = 0;
700+
699701
ce = active_cache[i];
700702
if (ce_stage(ce)) {
701703
while ((i < active_nr) &&
@@ -709,7 +711,7 @@ int refresh_cache(unsigned int flags)
709711
continue;
710712
}
711713

712-
new = refresh_cache_entry(ce, really);
714+
new = refresh_cache_ent(ce, really, &cache_errno);
713715
if (new == ce)
714716
continue;
715717
if (!new) {
@@ -737,6 +739,11 @@ int refresh_cache(unsigned int flags)
737739
return has_errors;
738740
}
739741

742+
struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
743+
{
744+
return refresh_cache_ent(ce, really, NULL);
745+
}
746+
740747
static int verify_hdr(struct cache_header *hdr, unsigned long size)
741748
{
742749
SHA_CTX c;

0 commit comments

Comments
 (0)