Skip to content

Commit 4a67e25

Browse files
pks-tgitster
authored andcommitted
odb: store locality in object database sources
Object database sources are classified either as: - Local, which means that the source is the repository's primary source. This is typically ".git/objects". - Non-local, which is everything else. Most importantly this includes alternates and quarantine directories. This locality is often computed ad-hoc by checking whether a given object source is the first one. This works, but it is quite roundabout. Refactor the code so that we store locality when creating the sources in the first place. This makes it both more accessible and robust. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 70b7b03 commit 4a67e25

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

midx.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id)
723723
return 0;
724724
}
725725

726-
int prepare_multi_pack_index_one(struct odb_source *source, int local)
726+
int prepare_multi_pack_index_one(struct odb_source *source)
727727
{
728728
struct repository *r = source->odb->repo;
729729

@@ -734,7 +734,8 @@ int prepare_multi_pack_index_one(struct odb_source *source, int local)
734734
if (source->midx)
735735
return 1;
736736

737-
source->midx = load_multi_pack_index(r, source->path, local);
737+
source->midx = load_multi_pack_index(r, source->path,
738+
source->local);
738739

739740
return !!source->midx;
740741
}

midx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pa
122122
int midx_contains_pack(struct multi_pack_index *m,
123123
const char *idx_or_pack_name);
124124
int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
125-
int prepare_multi_pack_index_one(struct odb_source *source, int local);
125+
int prepare_multi_pack_index_one(struct odb_source *source);
126126

127127
/*
128128
* Variant of write_midx_file which writes a MIDX containing only the packs

odb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static int link_alt_odb_entry(struct object_database *odb,
176176

177177
CALLOC_ARRAY(alternate, 1);
178178
alternate->odb = odb;
179+
alternate->local = false;
179180
/* pathbuf.buf is already in r->objects->source_by_path */
180181
alternate->path = strbuf_detach(&pathbuf, NULL);
181182

odb.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ struct odb_source {
6363
*/
6464
struct multi_pack_index *midx;
6565

66+
/*
67+
* Figure out whether this is the local alternate of the owning
68+
* repository, which would typically be its ".git/objects" directory.
69+
* This local object directory is usually where objects would be
70+
* written to.
71+
*/
72+
bool local;
73+
6674
/*
6775
* This is a temporary object store created by the tmp_objdir
6876
* facility. Disable ref updates since the objects in the store

packfile.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -935,14 +935,14 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
935935
report_garbage(PACKDIR_FILE_GARBAGE, full_name);
936936
}
937937

938-
static void prepare_packed_git_one(struct odb_source *source, int local)
938+
static void prepare_packed_git_one(struct odb_source *source)
939939
{
940940
struct string_list garbage = STRING_LIST_INIT_DUP;
941941
struct prepare_pack_data data = {
942942
.m = source->midx,
943943
.r = source->odb->repo,
944944
.garbage = &garbage,
945-
.local = local,
945+
.local = source->local,
946946
};
947947

948948
for_each_file_in_pack_dir(source->path, prepare_pack, &data);
@@ -1037,9 +1037,8 @@ static void prepare_packed_git(struct repository *r)
10371037

10381038
odb_prepare_alternates(r->objects);
10391039
for (source = r->objects->sources; source; source = source->next) {
1040-
int local = (source == r->objects->sources);
1041-
prepare_multi_pack_index_one(source, local);
1042-
prepare_packed_git_one(source, local);
1040+
prepare_multi_pack_index_one(source);
1041+
prepare_packed_git_one(source);
10431042
}
10441043
rearrange_packed_git(r);
10451044

repository.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ void repo_set_gitdir(struct repository *repo,
168168
if (!repo->objects->sources) {
169169
CALLOC_ARRAY(repo->objects->sources, 1);
170170
repo->objects->sources->odb = repo->objects;
171+
repo->objects->sources->local = true;
171172
repo->objects->sources_tail = &repo->objects->sources->next;
172173
}
173174
expand_base_dir(&repo->objects->sources->path, o->object_dir,

0 commit comments

Comments
 (0)