135
* of the object ID, an extra slash for the first level indirection, and
136
* the terminating NUL.
137
*/
138
-static void read_info_alternates(struct repository *r,
138
+static void read_info_alternates(struct object_database *odb,
139
const char *relative_base,
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)
147
{
148
struct odb_source *alternate;
149
struct strbuf pathbuf = STRBUF_INIT;
171
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
172
strbuf_setlen(&pathbuf, pathbuf.len - 1);
173
170
- if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
174
+ if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
175
goto error;
176
177
CALLOC_ARRAY(alternate, 1);
178
+ alternate->odb = odb;
179
/* pathbuf.buf is already in r->objects->source_by_path */
180
alternate->path = strbuf_detach(&pathbuf, NULL);
181
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);
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;
188
189
/* recursively add alternates */
185
- read_info_alternates(r, alternate->path, depth + 1);
190
+ read_info_alternates(odb, alternate->path, depth + 1);
191
ret = 0;
192
error:
193
strbuf_release(&tmp);
224
return end;
225
}
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,
228
int sep, const char *relative_base, int depth)
229
{
230
struct strbuf objdirbuf = STRBUF_INIT;
239
return;
240
}
241
237
- strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
242
+ strbuf_realpath(&objdirbuf, odb->sources->path, 1);
243
244
while (*alt) {
245
alt = parse_alt_odb_entry(alt, sep, &entry);
246
if (!entry.len)
247
continue;
243
- link_alt_odb_entry(r, &entry,
248
+ link_alt_odb_entry(odb, &entry,
249
relative_base, depth, objdirbuf.buf);
250
}
251
strbuf_release(&entry);
252
strbuf_release(&objdirbuf);
253
}
254
250
-static void read_info_alternates(struct repository *r,
255
+static void read_info_alternates(struct object_database *odb,
256
const char *relative_base,
257
int depth)
258
{
266
return;
267
}
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);
270
strbuf_release(&buf);
271
free(path);
272
}
308
if (commit_lock_file(&lock))
309
die_errno(_("unable to move new alternates file into place"));
310
if (the_repository->objects->loaded_alternates)
306
- link_alt_odb_entries(the_repository, reference,
311
+ link_alt_odb_entries(the_repository->objects, reference,
312
'\n', NULL, 0);
313
}
314
free(alts);
322
*/
323
prepare_alt_odb(the_repository);
324
320
- link_alt_odb_entries(the_repository, reference,
325
+ link_alt_odb_entries(the_repository->objects, reference,
326
'\n', NULL, 0);
327
}
328
341
* alternate
342
*/
343
source = xcalloc(1, sizeof(*source));
344
+ source->odb = the_repository->objects;
345
source->path = xstrdup(dir);
346
347
/*
586
if (r->objects->loaded_alternates)
587
return;
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);
590
585
- read_info_alternates(r, r->objects->sources->path, 0);
591
+ read_info_alternates(r->objects, r->objects->sources->path, 0);
592
r->objects->loaded_alternates = 1;
593
}
594
956
type_name(expect));
957
}
958
953
-struct object_database *odb_new(void)
959
+struct object_database *odb_new(struct repository *repo)
960
{
961
struct object_database *o = xmalloc(sizeof(*o));
962
963
memset(o, 0, sizeof(*o));
964
+ o->repo = repo;
965
INIT_LIST_HEAD(&o->packed_git_mru);
966
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
967
pthread_mutex_init(&o->replace_mutex, NULL);