167
}
168
169
/*
170
- * Find "oid" as a loose object in the local repository or in an alternate.
170
+ * Find "oid" as a loose object in given source.
171
* Returns 0 on success, negative on failure.
172
*
173
* The "path" out-parameter will give the path of the object we found (if any).
174
* Note that it may point to static storage and is only valid until another
175
* call to stat_loose_object().
176
*/
177
-static int stat_loose_object(struct repository *r, const struct object_id *oid,
177
+static int stat_loose_object(struct odb_source_loose *loose,
178
+ const struct object_id *oid,
179
struct stat *st, const char **path)
180
{
180
- struct odb_source *source;
181
static struct strbuf buf = STRBUF_INIT;
182
183
- odb_prepare_alternates(r->objects);
184
- for (source = r->objects->sources; source; source = source->next) {
185
- *path = odb_loose_path(source, &buf, oid);
186
- if (!lstat(*path, st))
187
- return 0;
188
- }
183
+ *path = odb_loose_path(loose->source, &buf, oid);
184
+ if (!lstat(*path, st))
185
+ return 0;
186
187
return -1;
188
}
191
* Like stat_loose_object(), but actually open the object and return the
192
* descriptor. See the caveats on the "path" parameter above.
193
*/
197
-static int open_loose_object(struct repository *r,
194
+static int open_loose_object(struct odb_source_loose *loose,
195
const struct object_id *oid, const char **path)
196
{
200
- int fd;
201
- struct odb_source *source;
202
- int most_interesting_errno = ENOENT;
197
static struct strbuf buf = STRBUF_INIT;
198
+ int fd;
199
205
- odb_prepare_alternates(r->objects);
206
- for (source = r->objects->sources; source; source = source->next) {
207
- *path = odb_loose_path(source, &buf, oid);
208
- fd = git_open(*path);
209
- if (fd >= 0)
210
- return fd;
200
+ *path = odb_loose_path(loose->source, &buf, oid);
201
+ fd = git_open(*path);
202
+ if (fd >= 0)
203
+ return fd;
204
212
- if (most_interesting_errno == ENOENT)
213
- most_interesting_errno = errno;
214
- }
215
- errno = most_interesting_errno;
205
return -1;
206
}
207
219
-static int quick_has_loose(struct repository *r,
208
+static int quick_has_loose(struct odb_source_loose *loose,
209
const struct object_id *oid)
210
{
222
- struct odb_source *source;
223
-
224
- odb_prepare_alternates(r->objects);
225
- for (source = r->objects->sources; source; source = source->next) {
226
- if (oidtree_contains(odb_source_loose_cache(source, oid), oid))
227
- return 1;
228
- }
229
- return 0;
211
+ return !!oidtree_contains(odb_source_loose_cache(loose->source, oid), oid);
212
}
213
214
/*
234
return map;
235
}
236
255
-void *map_loose_object(struct repository *r,
256
- const struct object_id *oid,
257
- unsigned long *size)
237
+void *odb_source_loose_map_object(struct odb_source *source,
238
+ const struct object_id *oid,
239
+ unsigned long *size)
240
{
241
const char *p;
260
- int fd = open_loose_object(r, oid, &p);
242
+ int fd = open_loose_object(source->loose, oid, &p);
243
244
if (fd < 0)
245
return NULL;
389
return 0;
390
}
391
410
-int loose_object_info(struct repository *r,
411
- const struct object_id *oid,
412
- struct object_info *oi, int flags)
392
+int odb_source_loose_read_object_info(struct odb_source *source,
393
+ const struct object_id *oid,
394
+ struct object_info *oi, int flags)
395
{
396
int status = 0;
397
int fd;
404
enum object_type type_scratch;
405
406
if (oi->delta_base_oid)
425
- oidclr(oi->delta_base_oid, r->hash_algo);
407
+ oidclr(oi->delta_base_oid, source->odb->repo->hash_algo);
408
409
/*
410
* If we don't care about type or size, then we don't
417
if (!oi->typep && !oi->sizep && !oi->contentp) {
418
struct stat st;
419
if (!oi->disk_sizep && (flags & OBJECT_INFO_QUICK))
438
- return quick_has_loose(r, oid) ? 0 : -1;
439
- if (stat_loose_object(r, oid, &st, &path) < 0)
420
+ return quick_has_loose(source->loose, oid) ? 0 : -1;
421
+ if (stat_loose_object(source->loose, oid, &st, &path) < 0)
422
return -1;
423
if (oi->disk_sizep)
424
*oi->disk_sizep = st.st_size;
425
return 0;
426
}
427
446
- fd = open_loose_object(r, oid, &path);
428
+ fd = open_loose_object(source->loose, oid, &path);
429
if (fd < 0) {
430
if (errno != ENOENT)
431
error_errno(_("unable to open loose object %s"), oid_to_hex(oid));