@@ -134,15 +134,15 @@ static struct ref_entry *search_ref_array(struct ref_array *array, const char *n
134
134
* Future: need to be in "struct repository"
135
135
* when doing a full libification.
136
136
*/
137
- static struct cached_refs {
138
- struct cached_refs * next ;
137
+ static struct ref_cache {
138
+ struct ref_cache * next ;
139
139
char did_loose ;
140
140
char did_packed ;
141
141
struct ref_array loose ;
142
142
struct ref_array packed ;
143
143
/* The submodule name, or "" for the main repo. */
144
144
char name [FLEX_ARRAY ];
145
- } * cached_refs ;
145
+ } * ref_cache ;
146
146
147
147
static struct ref_entry * current_ref ;
148
148
@@ -158,36 +158,41 @@ static void free_ref_array(struct ref_array *array)
158
158
array -> refs = NULL ;
159
159
}
160
160
161
- static void clear_cached_refs (struct cached_refs * ca )
161
+ static void clear_packed_ref_cache (struct ref_cache * refs )
162
162
{
163
- if (ca -> did_loose )
164
- free_ref_array (& ca -> loose );
165
- if (ca -> did_packed )
166
- free_ref_array (& ca -> packed );
167
- ca -> did_loose = ca -> did_packed = 0 ;
163
+ if (refs -> did_packed )
164
+ free_ref_array (& refs -> packed );
165
+ refs -> did_packed = 0 ;
168
166
}
169
167
170
- static struct cached_refs * create_cached_refs (const char * submodule )
168
+ static void clear_loose_ref_cache (struct ref_cache * refs )
169
+ {
170
+ if (refs -> did_loose )
171
+ free_ref_array (& refs -> loose );
172
+ refs -> did_loose = 0 ;
173
+ }
174
+
175
+ static struct ref_cache * create_ref_cache (const char * submodule )
171
176
{
172
177
int len ;
173
- struct cached_refs * refs ;
178
+ struct ref_cache * refs ;
174
179
if (!submodule )
175
180
submodule = "" ;
176
181
len = strlen (submodule ) + 1 ;
177
- refs = xcalloc (1 , sizeof (struct cached_refs ) + len );
182
+ refs = xcalloc (1 , sizeof (struct ref_cache ) + len );
178
183
memcpy (refs -> name , submodule , len );
179
184
return refs ;
180
185
}
181
186
182
187
/*
183
- * Return a pointer to a cached_refs for the specified submodule. For
188
+ * Return a pointer to a ref_cache for the specified submodule. For
184
189
* the main repository, use submodule==NULL. The returned structure
185
190
* will be allocated and initialized but not necessarily populated; it
186
191
* should not be freed.
187
192
*/
188
- static struct cached_refs * get_cached_refs (const char * submodule )
193
+ static struct ref_cache * get_ref_cache (const char * submodule )
189
194
{
190
- struct cached_refs * refs = cached_refs ;
195
+ struct ref_cache * refs = ref_cache ;
191
196
if (!submodule )
192
197
submodule = "" ;
193
198
while (refs ) {
@@ -196,19 +201,17 @@ static struct cached_refs *get_cached_refs(const char *submodule)
196
201
refs = refs -> next ;
197
202
}
198
203
199
- refs = create_cached_refs (submodule );
200
- refs -> next = cached_refs ;
201
- cached_refs = refs ;
204
+ refs = create_ref_cache (submodule );
205
+ refs -> next = ref_cache ;
206
+ ref_cache = refs ;
202
207
return refs ;
203
208
}
204
209
205
- static void invalidate_cached_refs ( void )
210
+ void invalidate_ref_cache ( const char * submodule )
206
211
{
207
- struct cached_refs * refs = cached_refs ;
208
- while (refs ) {
209
- clear_cached_refs (refs );
210
- refs = refs -> next ;
211
- }
212
+ struct ref_cache * refs = get_ref_cache (submodule );
213
+ clear_packed_ref_cache (refs );
214
+ clear_loose_ref_cache (refs );
212
215
}
213
216
214
217
static void read_packed_refs (FILE * f , struct ref_array * array )
@@ -257,7 +260,7 @@ void clear_extra_refs(void)
257
260
258
261
static struct ref_array * get_packed_refs (const char * submodule )
259
262
{
260
- struct cached_refs * refs = get_cached_refs (submodule );
263
+ struct ref_cache * refs = get_ref_cache (submodule );
261
264
262
265
if (!refs -> did_packed ) {
263
266
const char * packed_refs_file ;
@@ -379,7 +382,7 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
379
382
380
383
static struct ref_array * get_loose_refs (const char * submodule )
381
384
{
382
- struct cached_refs * refs = get_cached_refs (submodule );
385
+ struct ref_cache * refs = get_ref_cache (submodule );
383
386
384
387
if (!refs -> did_loose ) {
385
388
get_ref_dir (submodule , "refs" , & refs -> loose );
@@ -1238,7 +1241,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
1238
1241
ret |= repack_without_ref (refname );
1239
1242
1240
1243
unlink_or_warn (git_path ("logs/%s" , lock -> ref_name ));
1241
- invalidate_cached_refs ( );
1244
+ invalidate_ref_cache ( NULL );
1242
1245
unlock_ref (lock );
1243
1246
return ret ;
1244
1247
}
@@ -1529,7 +1532,7 @@ int write_ref_sha1(struct ref_lock *lock,
1529
1532
unlock_ref (lock );
1530
1533
return -1 ;
1531
1534
}
1532
- invalidate_cached_refs ( );
1535
+ clear_loose_ref_cache ( get_ref_cache ( NULL ) );
1533
1536
if (log_ref_write (lock -> ref_name , lock -> old_sha1 , sha1 , logmsg ) < 0 ||
1534
1537
(strcmp (lock -> ref_name , lock -> orig_ref_name ) &&
1535
1538
log_ref_write (lock -> orig_ref_name , lock -> old_sha1 , sha1 , logmsg ) < 0 )) {
0 commit comments