@@ -135,11 +135,15 @@ static int alt_odb_usable(struct object_database *o,
135
135
* of the object ID, an extra slash for the first level indirection, and
136
136
* the terminating NUL.
137
137
*/
138
- static void read_info_alternates (struct repository * r ,
138
+ static void read_info_alternates (struct object_database * odb ,
139
139
const char * relative_base ,
140
140
int depth );
141
- static int link_alt_odb_entry (struct repository * r , const struct strbuf * entry ,
142
- const char * relative_base , int depth , const char * normalized_objdir )
141
+
142
+ static int link_alt_odb_entry (struct object_database * odb ,
143
+ const struct strbuf * entry ,
144
+ const char * relative_base ,
145
+ int depth ,
146
+ const char * normalized_objdir )
143
147
{
144
148
struct odb_source * alternate ;
145
149
struct strbuf pathbuf = STRBUF_INIT ;
@@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
167
171
while (pathbuf .len && pathbuf .buf [pathbuf .len - 1 ] == '/' )
168
172
strbuf_setlen (& pathbuf , pathbuf .len - 1 );
169
173
170
- if (!alt_odb_usable (r -> objects , & pathbuf , normalized_objdir , & pos ))
174
+ if (!alt_odb_usable (odb , & pathbuf , normalized_objdir , & pos ))
171
175
goto error ;
172
176
173
177
CALLOC_ARRAY (alternate , 1 );
174
- /* pathbuf.buf is already in r->objects->source_by_path */
178
+ alternate -> odb = odb ;
179
+ /* pathbuf.buf is already in r->objects->alternate_by_path */
175
180
alternate -> path = strbuf_detach (& pathbuf , NULL );
176
181
177
182
/* add the alternate entry */
178
- * r -> objects -> sources_tail = alternate ;
179
- r -> objects -> sources_tail = & (alternate -> next );
183
+ * odb -> sources_tail = alternate ;
184
+ odb -> sources_tail = & (alternate -> next );
180
185
alternate -> next = NULL ;
181
- assert (r -> objects -> source_by_path );
182
- kh_value (r -> objects -> source_by_path , pos ) = alternate ;
186
+ assert (odb -> source_by_path );
187
+ kh_value (odb -> source_by_path , pos ) = alternate ;
183
188
184
189
/* recursively add alternates */
185
- read_info_alternates (r , alternate -> path , depth + 1 );
190
+ read_info_alternates (odb , alternate -> path , depth + 1 );
186
191
ret = 0 ;
187
192
error :
188
193
strbuf_release (& tmp );
@@ -219,7 +224,7 @@ static const char *parse_alt_odb_entry(const char *string,
219
224
return end ;
220
225
}
221
226
222
- static void link_alt_odb_entries (struct repository * r , const char * alt ,
227
+ static void link_alt_odb_entries (struct object_database * odb , const char * alt ,
223
228
int sep , const char * relative_base , int depth )
224
229
{
225
230
struct strbuf objdirbuf = STRBUF_INIT ;
@@ -234,20 +239,20 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
234
239
return ;
235
240
}
236
241
237
- strbuf_realpath (& objdirbuf , r -> objects -> sources -> path , 1 );
242
+ strbuf_realpath (& objdirbuf , odb -> sources -> path , 1 );
238
243
239
244
while (* alt ) {
240
245
alt = parse_alt_odb_entry (alt , sep , & entry );
241
246
if (!entry .len )
242
247
continue ;
243
- link_alt_odb_entry (r , & entry ,
248
+ link_alt_odb_entry (odb , & entry ,
244
249
relative_base , depth , objdirbuf .buf );
245
250
}
246
251
strbuf_release (& entry );
247
252
strbuf_release (& objdirbuf );
248
253
}
249
254
250
- static void read_info_alternates (struct repository * r ,
255
+ static void read_info_alternates (struct object_database * odb ,
251
256
const char * relative_base ,
252
257
int depth )
253
258
{
@@ -261,7 +266,7 @@ static void read_info_alternates(struct repository *r,
261
266
return ;
262
267
}
263
268
264
- link_alt_odb_entries (r , buf .buf , '\n' , relative_base , depth );
269
+ link_alt_odb_entries (odb , buf .buf , '\n' , relative_base , depth );
265
270
strbuf_release (& buf );
266
271
free (path );
267
272
}
@@ -303,7 +308,7 @@ void add_to_alternates_file(const char *reference)
303
308
if (commit_lock_file (& lock ))
304
309
die_errno (_ ("unable to move new alternates file into place" ));
305
310
if (the_repository -> objects -> loaded_alternates )
306
- link_alt_odb_entries (the_repository , reference ,
311
+ link_alt_odb_entries (the_repository -> objects , reference ,
307
312
'\n' , NULL , 0 );
308
313
}
309
314
free (alts );
@@ -317,7 +322,7 @@ void add_to_alternates_memory(const char *reference)
317
322
*/
318
323
prepare_alt_odb (the_repository );
319
324
320
- link_alt_odb_entries (the_repository , reference ,
325
+ link_alt_odb_entries (the_repository -> objects , reference ,
321
326
'\n' , NULL , 0 );
322
327
}
323
328
@@ -336,6 +341,7 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
336
341
* alternate
337
342
*/
338
343
source = xcalloc (1 , sizeof (* source ));
344
+ source -> odb = the_repository -> objects ;
339
345
source -> path = xstrdup (dir );
340
346
341
347
/*
@@ -580,9 +586,9 @@ void prepare_alt_odb(struct repository *r)
580
586
if (r -> objects -> loaded_alternates )
581
587
return ;
582
588
583
- link_alt_odb_entries (r , r -> objects -> alternate_db , PATH_SEP , NULL , 0 );
589
+ link_alt_odb_entries (r -> objects , r -> objects -> alternate_db , PATH_SEP , NULL , 0 );
584
590
585
- read_info_alternates (r , r -> objects -> sources -> path , 0 );
591
+ read_info_alternates (r -> objects , r -> objects -> sources -> path , 0 );
586
592
r -> objects -> loaded_alternates = 1 ;
587
593
}
588
594
@@ -950,11 +956,12 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
950
956
type_name (expect ));
951
957
}
952
958
953
- struct object_database * odb_new (void )
959
+ struct object_database * odb_new (struct repository * repo )
954
960
{
955
961
struct object_database * o = xmalloc (sizeof (* o ));
956
962
957
963
memset (o , 0 , sizeof (* o ));
964
+ o -> repo = repo ;
958
965
INIT_LIST_HEAD (& o -> packed_git_mru );
959
966
hashmap_init (& o -> pack_map , pack_map_entry_cmp , NULL , 0 );
960
967
pthread_mutex_init (& o -> replace_mutex , NULL );
0 commit comments