@@ -26,8 +26,11 @@ static char *merge_rr_path;
26
26
static int rerere_dir_nr ;
27
27
static int rerere_dir_alloc ;
28
28
29
+ #define RR_HAS_POSTIMAGE 1
30
+ #define RR_HAS_PREIMAGE 2
29
31
static struct rerere_dir {
30
32
unsigned char sha1 [20 ];
33
+ unsigned char status ;
31
34
} * * rerere_dir ;
32
35
33
36
static void free_rerere_dirs (void )
@@ -58,6 +61,27 @@ const char *rerere_path(const struct rerere_id *id, const char *file)
58
61
return git_path ("rr-cache/%s/%s" , rerere_id_hex (id ), file );
59
62
}
60
63
64
+ static int is_rr_file (const char * name , const char * filename )
65
+ {
66
+ return !strcmp (name , filename );
67
+ }
68
+
69
+ static void scan_rerere_dir (struct rerere_dir * rr_dir )
70
+ {
71
+ struct dirent * de ;
72
+ DIR * dir = opendir (git_path ("rr-cache/%s" , sha1_to_hex (rr_dir -> sha1 )));
73
+
74
+ if (!dir )
75
+ return ;
76
+ while ((de = readdir (dir )) != NULL ) {
77
+ if (is_rr_file (de -> d_name , "postimage" ))
78
+ rr_dir -> status |= RR_HAS_POSTIMAGE ;
79
+ else if (is_rr_file (de -> d_name , "preimage" ))
80
+ rr_dir -> status |= RR_HAS_PREIMAGE ;
81
+ }
82
+ closedir (dir );
83
+ }
84
+
61
85
static const unsigned char * rerere_dir_sha1 (size_t i , void * table )
62
86
{
63
87
struct rerere_dir * * rr_dir = table ;
@@ -76,6 +100,7 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
76
100
if (pos < 0 ) {
77
101
rr_dir = xmalloc (sizeof (* rr_dir ));
78
102
hashcpy (rr_dir -> sha1 , sha1 );
103
+ rr_dir -> status = 0 ;
79
104
pos = -1 - pos ;
80
105
81
106
/* Make sure the array is big enough ... */
@@ -85,15 +110,14 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
85
110
memmove (rerere_dir + pos + 1 , rerere_dir + pos ,
86
111
(rerere_dir_nr - pos - 1 ) * sizeof (* rerere_dir ));
87
112
rerere_dir [pos ] = rr_dir ;
113
+ scan_rerere_dir (rr_dir );
88
114
}
89
115
return rerere_dir [pos ];
90
116
}
91
117
92
118
static int has_rerere_resolution (const struct rerere_id * id )
93
119
{
94
- struct stat st ;
95
-
96
- return !stat (rerere_path (id , "postimage" ), & st );
120
+ return (id -> collection -> status & RR_HAS_POSTIMAGE );
97
121
}
98
122
99
123
static struct rerere_id * new_rerere_id_hex (char * hex )
@@ -737,6 +761,7 @@ static void do_rerere_one_path(struct string_list_item *rr_item,
737
761
} else if (!handle_file (path , NULL , NULL )) {
738
762
/* The user has resolved it. */
739
763
copy_file (rerere_path (id , "postimage" ), path , 0666 );
764
+ id -> collection -> status |= RR_HAS_POSTIMAGE ;
740
765
fprintf (stderr , "Recorded resolution for '%s'.\n" , path );
741
766
} else {
742
767
return ;
@@ -797,6 +822,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
797
822
* normalized contents to the "preimage" file.
798
823
*/
799
824
handle_file (path , NULL , rerere_path (id , "preimage" ));
825
+ id -> collection -> status |= RR_HAS_PREIMAGE ;
800
826
fprintf (stderr , "Recorded preimage for '%s'\n" , path );
801
827
}
802
828
0 commit comments