346
}
347
}
348
349
-static const char *odb_loose_path(const char *path, struct strbuf *buf,
349
+static const char *odb_loose_path(struct object_directory *odb,
350
+ struct strbuf *buf,
351
const unsigned char *sha1)
352
{
353
strbuf_reset(buf);
353
- strbuf_addstr(buf, path);
354
+ strbuf_addstr(buf, odb->path);
355
strbuf_addch(buf, '/');
356
fill_sha1_path(buf, sha1);
357
return buf->buf;
360
const char *loose_object_path(struct repository *r, struct strbuf *buf,
361
const unsigned char *sha1)
362
{
362
- return odb_loose_path(r->objects->objectdir, buf, sha1);
363
+ return odb_loose_path(r->objects->odb, buf, sha1);
364
}
365
366
/*
384
* Prevent the common mistake of listing the same
385
* thing twice, or object directory itself.
386
*/
386
- for (odb = o->alt_odb_list; odb; odb = odb->next) {
387
+ for (odb = o->odb; odb; odb = odb->next) {
388
if (!fspathcmp(path->buf, odb->path))
389
return 0;
390
}
443
return -1;
444
}
445
445
- ent = alloc_alt_odb(pathbuf.buf);
446
+ ent = xcalloc(1, sizeof(*ent));
447
+ ent->path = xstrdup(pathbuf.buf);
448
449
/* add the alternate entry */
448
- *r->objects->alt_odb_tail = ent;
449
- r->objects->alt_odb_tail = &(ent->next);
450
+ *r->objects->odb_tail = ent;
451
+ r->objects->odb_tail = &(ent->next);
452
ent->next = NULL;
453
454
/* recursively add alternates */
502
return;
503
}
504
503
- strbuf_add_absolute_path(&objdirbuf, r->objects->objectdir);
505
+ strbuf_add_absolute_path(&objdirbuf, r->objects->odb->path);
506
if (strbuf_normalize_path(&objdirbuf) < 0)
507
die(_("unable to normalize object directory: %s"),
508
objdirbuf.buf);
537
free(path);
538
}
539
538
-struct object_directory *alloc_alt_odb(const char *dir)
539
-{
540
- struct object_directory *ent;
541
-
542
- FLEX_ALLOC_STR(ent, path, dir);
543
-
544
- return ent;
545
-}
546
-
540
void add_to_alternates_file(const char *reference)
541
{
542
struct lock_file lock = LOCK_INIT;
573
fprintf_or_die(out, "%s\n", reference);
574
if (commit_lock_file(&lock))
575
die_errno(_("unable to move new alternates file into place"));
583
- if (the_repository->objects->alt_odb_tail)
576
+ if (the_repository->objects->loaded_alternates)
577
link_alt_odb_entries(the_repository, reference,
578
'\n', NULL, 0);
579
}
673
int r = 0;
674
675
prepare_alt_odb(the_repository);
683
- for (ent = the_repository->objects->alt_odb_list; ent; ent = ent->next) {
676
+ for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
677
r = fn(ent, cb);
678
if (r)
679
break;
683
684
void prepare_alt_odb(struct repository *r)
685
{
693
- if (r->objects->alt_odb_tail)
686
+ if (r->objects->loaded_alternates)
687
return;
688
696
- r->objects->alt_odb_tail = &r->objects->alt_odb_list;
689
link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
690
699
- read_info_alternates(r, r->objects->objectdir, 0);
691
+ read_info_alternates(r, r->objects->odb->path, 0);
692
+ r->objects->loaded_alternates = 1;
693
}
694
695
/* Returns 1 if we have successfully freshened the file, 0 otherwise. */
716
return 1;
717
}
718
726
-static int check_and_freshen_local(const struct object_id *oid, int freshen)
719
+static int check_and_freshen_odb(struct object_directory *odb,
720
+ const struct object_id *oid,
721
+ int freshen)
722
{
728
- static struct strbuf buf = STRBUF_INIT;
729
-
730
- loose_object_path(the_repository, &buf, oid->hash);
723
+ static struct strbuf path = STRBUF_INIT;
724
+ odb_loose_path(odb, &path, oid->hash);
725
+ return check_and_freshen_file(path.buf, freshen);
726
+}
727
732
- return check_and_freshen_file(buf.buf, freshen);
728
+static int check_and_freshen_local(const struct object_id *oid, int freshen)
729
+{
730
+ return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
731
}
732
733
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
734
{
735
struct object_directory *odb;
738
- static struct strbuf path = STRBUF_INIT;
736
737
prepare_alt_odb(the_repository);
741
- for (odb = the_repository->objects->alt_odb_list; odb; odb = odb->next) {
742
- odb_loose_path(odb->path, &path, oid->hash);
743
- if (check_and_freshen_file(path.buf, freshen))
738
+ for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
739
+ if (check_and_freshen_odb(odb, oid, freshen))
740
return 1;
741
}
742
return 0;
885
struct object_directory *odb;
886
static struct strbuf buf = STRBUF_INIT;
887
892
- *path = loose_object_path(r, &buf, sha1);
893
- if (!lstat(*path, st))
894
- return 0;
895
-
888
prepare_alt_odb(r);
897
- errno = ENOENT;
898
- for (odb = r->objects->alt_odb_list; odb; odb = odb->next) {
899
- *path = odb_loose_path(odb->path, &buf, sha1);
889
+ for (odb = r->objects->odb; odb; odb = odb->next) {
890
+ *path = odb_loose_path(odb, &buf, sha1);
891
if (!lstat(*path, st))
892
return 0;
893
}
904
{
905
int fd;
906
struct object_directory *odb;
916
- int most_interesting_errno;
907
+ int most_interesting_errno = ENOENT;
908
static struct strbuf buf = STRBUF_INIT;
909
919
- *path = loose_object_path(r, &buf, sha1);
920
- fd = git_open(*path);
921
- if (fd >= 0)
922
- return fd;
923
- most_interesting_errno = errno;
924
-
910
prepare_alt_odb(r);
926
- for (odb = r->objects->alt_odb_list; odb; odb = odb->next) {
927
- *path = odb_loose_path(odb->path, &buf, sha1);
911
+ for (odb = r->objects->odb; odb; odb = odb->next) {
912
+ *path = odb_loose_path(odb, &buf, sha1);
913
fd = git_open(*path);
914
if (fd >= 0)
915
return fd;
916
+
917
if (most_interesting_errno == ENOENT)
918
most_interesting_errno = errno;
919
}
2106
return r;
2107
}
2108
2123
-struct loose_alt_odb_data {
2124
- each_loose_object_fn *cb;
2125
- void *data;
2126
-};
2127
-
2128
-static int loose_from_alt_odb(struct object_directory *odb,
2129
- void *vdata)
2130
-{
2131
- struct loose_alt_odb_data *data = vdata;
2132
- struct strbuf buf = STRBUF_INIT;
2133
- int r;
2134
-
2135
- strbuf_addstr(&buf, odb->path);
2136
- r = for_each_loose_file_in_objdir_buf(&buf,
2137
- data->cb, NULL, NULL,
2138
- data->data);
2139
- strbuf_release(&buf);
2140
- return r;
2141
-}
2142
-
2109
int for_each_loose_object(each_loose_object_fn cb, void *data,
2110
enum for_each_object_flags flags)
2111
{
2146
- struct loose_alt_odb_data alt;
2147
- int r;
2112
+ struct object_directory *odb;
2113
2149
- r = for_each_loose_file_in_objdir(get_object_directory(),
2150
- cb, NULL, NULL, data);
2151
- if (r)
2152
- return r;
2114
+ prepare_alt_odb(the_repository);
2115
+ for (odb = the_repository->objects->odb; odb; odb = odb->next) {
2116
+ int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
2117
+ NULL, data);
2118
+ if (r)
2119
+ return r;
2120
2154
- if (flags & FOR_EACH_OBJECT_LOCAL_ONLY)
2155
- return 0;
2121
+ if (flags & FOR_EACH_OBJECT_LOCAL_ONLY)
2122
+ break;
2123
+ }
2124
2157
- alt.cb = cb;
2158
- alt.data = data;
2159
- return foreach_alt_odb(loose_from_alt_odb, &alt);
2125
+ return 0;
2126
}
2127
2128
static int check_stream_sha1(git_zstream *stream,