summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-07-08 17:17:09 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2022-07-08 17:17:09 -0400
commite598432b3109ff8a5a7ece933da7b2214c35da8d (patch)
tree78fffa30ec75ac428fb286aa071157a18669f0d2
parent151d4218149fc3bdada3b9b15d463f8635598273 (diff)
downloadlibgit2-e598432b3109ff8a5a7ece933da7b2214c35da8d.tar.gz
packfile: checkpoint
-rw-r--r--src/libgit2/commit_graph.c2
-rw-r--r--src/libgit2/indexer.c16
-rw-r--r--src/libgit2/midx.c2
-rw-r--r--src/libgit2/odb_pack.c18
-rw-r--r--src/libgit2/pack.c28
-rw-r--r--src/libgit2/pack.h16
-rw-r--r--tests/libgit2/odb/loose.c12
7 files changed, 57 insertions, 37 deletions
diff --git a/src/libgit2/commit_graph.c b/src/libgit2/commit_graph.c
index 2edf51a58..d4cb93eb4 100644
--- a/src/libgit2/commit_graph.c
+++ b/src/libgit2/commit_graph.c
@@ -524,7 +524,7 @@ int git_commit_graph_entry_find(
hi = ntohl(file->oid_fanout[(int)short_oid->id[0]]);
lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(file->oid_fanout[(int)short_oid->id[0] - 1]));
- pos = git_pack__lookup_sha1(file->oid_lookup, GIT_OID_SHA1_SIZE, lo, hi, short_oid->id);
+ pos = git_pack__lookup_id(file->oid_lookup, GIT_OID_SHA1_SIZE, lo, hi, short_oid->id);
if (pos >= 0) {
/* An object matching exactly the oid was found */
diff --git a/src/libgit2/indexer.c b/src/libgit2/indexer.c
index ace73386c..60625b6c4 100644
--- a/src/libgit2/indexer.c
+++ b/src/libgit2/indexer.c
@@ -468,16 +468,16 @@ static int store_object(git_indexer *idx)
goto on_error;
}
- git_oid_cpy(&pentry->sha1, &oid);
+ git_oid_cpy(&pentry->id, &oid);
pentry->offset = entry_start;
- if (git_oidmap_exists(idx->pack->idx_cache, &pentry->sha1)) {
- git_error_set(GIT_ERROR_INDEXER, "duplicate object %s found in pack", git_oid_tostr_s(&pentry->sha1));
+ if (git_oidmap_exists(idx->pack->idx_cache, &pentry->id)) {
+ git_error_set(GIT_ERROR_INDEXER, "duplicate object %s found in pack", git_oid_tostr_s(&pentry->id));
git__free(pentry);
goto on_error;
}
- if ((error = git_oidmap_set(idx->pack->idx_cache, &pentry->sha1, pentry)) < 0) {
+ if ((error = git_oidmap_set(idx->pack->idx_cache, &pentry->id, pentry)) < 0) {
git__free(pentry);
git_error_set_oom();
goto on_error;
@@ -522,8 +522,8 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent
pentry->offset = entry_start;
- if (git_oidmap_exists(idx->pack->idx_cache, &pentry->sha1) ||
- git_oidmap_set(idx->pack->idx_cache, &pentry->sha1, pentry) < 0) {
+ if (git_oidmap_exists(idx->pack->idx_cache, &pentry->id) ||
+ git_oidmap_set(idx->pack->idx_cache, &pentry->id, pentry) < 0) {
git_error_set(GIT_ERROR_INDEXER, "cannot insert object into pack");
return -1;
}
@@ -557,7 +557,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start)
pentry = git__calloc(1, sizeof(struct git_pack_entry));
GIT_ERROR_CHECK_ALLOC(pentry);
- git_oid_cpy(&pentry->sha1, &oid);
+ git_oid_cpy(&pentry->id, &oid);
git_oid_cpy(&entry->oid, &oid);
entry->crc = crc32(0L, Z_NULL, 0);
@@ -987,7 +987,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
pentry = git__calloc(1, sizeof(struct git_pack_entry));
GIT_ERROR_CHECK_ALLOC(pentry);
- git_oid_cpy(&pentry->sha1, id);
+ git_oid_cpy(&pentry->id, id);
git_oid_cpy(&entry->oid, id);
idx->off = entry_start + hdr_len + len;
diff --git a/src/libgit2/midx.c b/src/libgit2/midx.c
index 8c0b8df40..37de58ccd 100644
--- a/src/libgit2/midx.c
+++ b/src/libgit2/midx.c
@@ -392,7 +392,7 @@ int git_midx_entry_find(
hi = ntohl(idx->oid_fanout[(int)short_oid->id[0]]);
lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(idx->oid_fanout[(int)short_oid->id[0] - 1]));
- pos = git_pack__lookup_sha1(idx->oid_lookup, GIT_OID_SHA1_SIZE, lo, hi, short_oid->id);
+ pos = git_pack__lookup_id(idx->oid_lookup, GIT_OID_SHA1_SIZE, lo, hi, short_oid->id);
if (pos >= 0) {
/* An object matching exactly the oid was found */
diff --git a/src/libgit2/odb_pack.c b/src/libgit2/odb_pack.c
index 49a655b44..d6243cd93 100644
--- a/src/libgit2/odb_pack.c
+++ b/src/libgit2/odb_pack.c
@@ -276,7 +276,7 @@ static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backen
git_midx_entry_find(&midx_entry, backend->midx, oid, GIT_OID_SHA1_HEXSIZE) == 0 &&
midx_entry.pack_index < git_vector_length(&backend->midx_packs)) {
e->offset = midx_entry.offset;
- git_oid_cpy(&e->sha1, &midx_entry.sha1);
+ git_oid_cpy(&e->id, &midx_entry.sha1);
e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index);
return 0;
}
@@ -318,9 +318,9 @@ static int pack_entry_find_prefix(
return error;
if (!error && midx_entry.pack_index < git_vector_length(&backend->midx_packs)) {
e->offset = midx_entry.offset;
- git_oid_cpy(&e->sha1, &midx_entry.sha1);
+ git_oid_cpy(&e->id, &midx_entry.sha1);
e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index);
- git_oid_cpy(&found_full_oid, &e->sha1);
+ git_oid_cpy(&found_full_oid, &e->id);
found = true;
}
}
@@ -330,9 +330,9 @@ static int pack_entry_find_prefix(
if (error == GIT_EAMBIGUOUS)
return error;
if (!error) {
- if (found && git_oid_cmp(&e->sha1, &found_full_oid))
+ if (found && git_oid_cmp(&e->id, &found_full_oid))
return git_odb__error_ambiguous("found multiple pack entries");
- git_oid_cpy(&found_full_oid, &e->sha1);
+ git_oid_cpy(&found_full_oid, &e->id);
found = true;
}
}
@@ -345,9 +345,9 @@ static int pack_entry_find_prefix(
if (error == GIT_EAMBIGUOUS)
return error;
if (!error) {
- if (found && git_oid_cmp(&e->sha1, &found_full_oid))
+ if (found && git_oid_cmp(&e->id, &found_full_oid))
return git_odb__error_ambiguous("found multiple pack entries");
- git_oid_cpy(&found_full_oid, &e->sha1);
+ git_oid_cpy(&found_full_oid, &e->id);
found = true;
backend->last_found = p;
}
@@ -621,7 +621,7 @@ static int pack_backend__read_prefix(
*buffer_p = raw.data;
*len_p = raw.len;
*type_p = raw.type;
- git_oid_cpy(out_oid, &e.sha1);
+ git_oid_cpy(out_oid, &e.id);
}
}
@@ -642,7 +642,7 @@ static int pack_backend__exists_prefix(
struct git_pack_entry e = {0};
error = pack_entry_find_prefix(&e, pb, short_id, len);
- git_oid_cpy(out, &e.sha1);
+ git_oid_cpy(out, &e.id);
return error;
}
diff --git a/src/libgit2/pack.c b/src/libgit2/pack.c
index 18f51d107..4ea6b5909 100644
--- a/src/libgit2/pack.c
+++ b/src/libgit2/pack.c
@@ -186,9 +186,9 @@ static int cache_add(
static void pack_index_free(struct git_pack_file *p)
{
- if (p->oids) {
- git__free(p->oids);
- p->oids = NULL;
+ if (p->ids) {
+ git__free(p->ids);
+ p->ids = NULL;
}
if (p->index_map.data) {
git_futils_mmap_free(&p->index_map);
@@ -1070,7 +1070,7 @@ void git_packfile_free(struct git_pack_file *p, bool unlink_packfile)
pack_index_free(p);
- git__free(p->bad_object_sha1);
+ git__free(p->bad_object_ids);
git_mutex_free(&p->bases.lock);
git_mutex_free(&p->mwf.lock);
@@ -1312,7 +1312,7 @@ int git_pack_foreach_entry(
index += 4 * 256;
- if (p->oids == NULL) {
+ if (p->ids == NULL) {
git_vector offsets, oids;
if ((error = git_vector_init(&oids, p->num_objects, NULL))) {
@@ -1341,7 +1341,7 @@ int git_pack_foreach_entry(
}
git_vector_free(&offsets);
- p->oids = (unsigned char **)git_vector_detach(NULL, NULL, &oids);
+ p->ids = (unsigned char **)git_vector_detach(NULL, NULL, &oids);
}
/*
@@ -1362,7 +1362,7 @@ int git_pack_foreach_entry(
git_array_clear(oids);
GIT_ERROR_CHECK_ALLOC(oid);
}
- git_oid_fromraw(oid, p->oids[i], GIT_OID_SHA1);
+ git_oid_fromraw(oid, p->ids[i], GIT_OID_SHA1);
}
git_mutex_unlock(&p->lock);
@@ -1450,8 +1450,12 @@ cleanup:
return error;
}
-int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo,
- unsigned hi, const unsigned char *oid_prefix)
+int git_pack__lookup_id(
+ const void *oid_lookup_table,
+ size_t stride,
+ unsigned lo,
+ unsigned hi,
+ const unsigned char *oid_prefix)
{
const unsigned char *base = oid_lookup_table;
@@ -1523,7 +1527,7 @@ static int pack_entry_find_offset(
short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects);
#endif
- pos = git_pack__lookup_sha1(index, stride, lo, hi, short_oid->id);
+ pos = git_pack__lookup_id(index, stride, lo, hi, short_oid->id);
if (pos >= 0) {
/* An object matching exactly the oid was found */
@@ -1597,7 +1601,7 @@ int git_pack_entry_find(
if (len == GIT_OID_SHA1_HEXSIZE && p->num_bad_objects) {
unsigned i;
for (i = 0; i < p->num_bad_objects; i++)
- if (git_oid__cmp(short_oid, &p->bad_object_sha1[i]) == 0)
+ if (git_oid__cmp(short_oid, &p->bad_object_ids[i]) == 0)
return packfile_error("bad object found in packfile");
}
@@ -1630,6 +1634,6 @@ int git_pack_entry_find(
e->offset = offset;
e->p = p;
- git_oid_cpy(&e->sha1, &found_oid);
+ git_oid_cpy(&e->id, &found_oid);
return 0;
}
diff --git a/src/libgit2/pack.h b/src/libgit2/pack.h
index f87249ba6..c8dc5df43 100644
--- a/src/libgit2/pack.h
+++ b/src/libgit2/pack.h
@@ -99,13 +99,13 @@ struct git_pack_file {
uint32_t num_objects;
uint32_t num_bad_objects;
- git_oid *bad_object_sha1; /* array of git_oid */
+ git_oid *bad_object_ids; /* array of git_oid */
int index_version;
git_time_t mtime;
unsigned pack_local:1, pack_keep:1, has_cache:1;
git_oidmap *idx_cache;
- unsigned char **oids;
+ unsigned char **ids;
git_pack_cache bases; /* delta base cache */
@@ -125,12 +125,16 @@ struct git_pack_file {
* file (stride = 24), whereas files with version 2 store them in a contiguous
* flat array (stride = 20).
*/
-int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo,
- unsigned hi, const unsigned char *oid_prefix);
+int git_pack__lookup_id(
+ const void *id_lookup_table,
+ size_t stride,
+ unsigned lo,
+ unsigned hi,
+ const unsigned char *id_prefix);
struct git_pack_entry {
off64_t offset;
- git_oid sha1;
+ git_oid id;
struct git_pack_file *p;
};
@@ -179,7 +183,7 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path);
int git_pack_entry_find(
struct git_pack_entry *e,
struct git_pack_file *p,
- const git_oid *short_oid,
+ const git_oid *short_id,
size_t len);
int git_pack_foreach_entry(
struct git_pack_file *p,
diff --git a/tests/libgit2/odb/loose.c b/tests/libgit2/odb/loose.c
index 9651ebab6..93895deb5 100644
--- a/tests/libgit2/odb/loose.c
+++ b/tests/libgit2/odb/loose.c
@@ -188,6 +188,18 @@ void test_odb_loose__exists_sha256(void)
#endif
}
+void test_odb_loose__zzz(void)
+{
+ write_object_files(&one_sha256);
+ write_object_files(&commit_sha256);
+ write_object_files(&tree_sha256);
+ write_object_files(&tag_sha256);
+ write_object_files(&zero_sha256);
+ write_object_files(&two_sha256);
+ write_object_files(&some_sha256);
+ abort();
+}
+
void test_odb_loose__simple_reads_sha1(void)
{
test_read_object(&commit);