346
}
347
}
348
349
-void loose_object_path(struct repository *r, struct strbuf *buf,
350
- const unsigned char *sha1)
349
+static const char *odb_loose_path(const char *path, struct strbuf *buf,
350
+ const unsigned char *sha1)
351
{
352
strbuf_reset(buf);
353
- strbuf_addstr(buf, r->objects->objectdir);
353
+ strbuf_addstr(buf, path);
354
strbuf_addch(buf, '/');
355
fill_sha1_path(buf, sha1);
356
+ return buf->buf;
357
}
358
358
-struct strbuf *alt_scratch_buf(struct object_directory *odb)
359
+const char *loose_object_path(struct repository *r, struct strbuf *buf,
360
+ const unsigned char *sha1)
361
{
360
- strbuf_setlen(&odb->scratch, odb->base_len);
361
- return &odb->scratch;
362
-}
363
-
364
-static const char *alt_sha1_path(struct object_directory *odb,
365
- const unsigned char *sha1)
366
-{
367
- struct strbuf *buf = alt_scratch_buf(odb);
368
- fill_sha1_path(buf, sha1);
369
- return buf->buf;
362
+ return odb_loose_path(r->objects->objectdir, buf, sha1);
363
}
364
365
/*
540
struct object_directory *ent;
541
542
FLEX_ALLOC_STR(ent, path, dir);
550
- strbuf_init(&ent->scratch, 0);
551
- strbuf_addf(&ent->scratch, "%s/", dir);
552
- ent->base_len = ent->scratch.len;
543
544
return ent;
545
}
735
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
736
{
737
struct object_directory *odb;
738
+ static struct strbuf path = STRBUF_INIT;
739
+
740
prepare_alt_odb(the_repository);
741
for (odb = the_repository->objects->alt_odb_list; odb; odb = odb->next) {
750
- const char *path = alt_sha1_path(odb, oid->hash);
751
- if (check_and_freshen_file(path, freshen))
742
+ odb_loose_path(odb->path, &path, oid->hash);
743
+ if (check_and_freshen_file(path.buf, freshen))
744
return 1;
745
}
746
return 0;
881
*
882
* The "path" out-parameter will give the path of the object we found (if any).
883
* Note that it may point to static storage and is only valid until another
892
- * call to loose_object_path(), etc.
884
+ * call to stat_sha1_file().
885
*/
886
static int stat_sha1_file(struct repository *r, const unsigned char *sha1,
887
struct stat *st, const char **path)
889
struct object_directory *odb;
890
static struct strbuf buf = STRBUF_INIT;
891
900
- loose_object_path(r, &buf, sha1);
901
- *path = buf.buf;
902
-
892
+ *path = loose_object_path(r, &buf, sha1);
893
if (!lstat(*path, st))
894
return 0;
895
896
prepare_alt_odb(r);
897
errno = ENOENT;
898
for (odb = r->objects->alt_odb_list; odb; odb = odb->next) {
909
- *path = alt_sha1_path(odb, sha1);
899
+ *path = odb_loose_path(odb->path, &buf, sha1);
900
if (!lstat(*path, st))
901
return 0;
902
}
916
int most_interesting_errno;
917
static struct strbuf buf = STRBUF_INIT;
918
929
- loose_object_path(r, &buf, sha1);
930
- *path = buf.buf;
931
-
919
+ *path = loose_object_path(r, &buf, sha1);
920
fd = git_open(*path);
921
if (fd >= 0)
922
return fd;
924
925
prepare_alt_odb(r);
926
for (odb = r->objects->alt_odb_list; odb; odb = odb->next) {
939
- *path = alt_sha1_path(odb, sha1);
927
+ *path = odb_loose_path(odb->path, &buf, sha1);
928
fd = git_open(*path);
929
if (fd >= 0)
930
return fd;