mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Merge branch 'ps/object-wo-the-repository'
The object layer has been updated to take an explicit repository instance as a parameter in more code paths. * ps/object-wo-the-repository: hash: stop depending on `the_repository` in `null_oid()` hash: fix "-Wsign-compare" warnings object-file: split out logic regarding hash algorithms delta-islands: stop depending on `the_repository` object-file-convert: stop depending on `the_repository` pack-bitmap-write: stop depending on `the_repository` pack-revindex: stop depending on `the_repository` pack-check: stop depending on `the_repository` environment: move access to "core.bigFileThreshold" into repo settings pack-write: stop depending on `the_repository` and `the_hash_algo` object: stop depending on `the_repository` csum-file: stop depending on `the_repository`
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
#define USE_THE_REPOSITORY_VARIABLE
|
||||
|
||||
#include "git-compat-util.h"
|
||||
#include "gettext.h"
|
||||
#include "pack-revindex.h"
|
||||
@@ -9,6 +7,7 @@
|
||||
#include "strbuf.h"
|
||||
#include "trace2.h"
|
||||
#include "parse.h"
|
||||
#include "repository.h"
|
||||
#include "midx.h"
|
||||
#include "csum-file.h"
|
||||
|
||||
@@ -137,7 +136,7 @@ static void create_pack_revindex(struct packed_git *p)
|
||||
const unsigned num_ent = p->num_objects;
|
||||
unsigned i;
|
||||
const char *index = p->index_data;
|
||||
const unsigned hashsz = the_hash_algo->rawsz;
|
||||
const unsigned hashsz = p->repo->hash_algo->rawsz;
|
||||
|
||||
ALLOC_ARRAY(p->revindex, num_ent + 1);
|
||||
index += 4 * 256;
|
||||
@@ -193,7 +192,11 @@ static char *pack_revindex_filename(struct packed_git *p)
|
||||
}
|
||||
|
||||
#define RIDX_HEADER_SIZE (12)
|
||||
#define RIDX_MIN_SIZE (RIDX_HEADER_SIZE + (2 * the_hash_algo->rawsz))
|
||||
|
||||
static size_t ridx_min_size(const struct git_hash_algo *algo)
|
||||
{
|
||||
return RIDX_HEADER_SIZE + (2 * algo->rawsz);
|
||||
}
|
||||
|
||||
struct revindex_header {
|
||||
uint32_t signature;
|
||||
@@ -201,7 +204,8 @@ struct revindex_header {
|
||||
uint32_t hash_id;
|
||||
};
|
||||
|
||||
static int load_revindex_from_disk(char *revindex_name,
|
||||
static int load_revindex_from_disk(const struct git_hash_algo *algo,
|
||||
char *revindex_name,
|
||||
uint32_t num_objects,
|
||||
const uint32_t **data_p, size_t *len_p)
|
||||
{
|
||||
@@ -228,12 +232,12 @@ static int load_revindex_from_disk(char *revindex_name,
|
||||
|
||||
revindex_size = xsize_t(st.st_size);
|
||||
|
||||
if (revindex_size < RIDX_MIN_SIZE) {
|
||||
if (revindex_size < ridx_min_size(algo)) {
|
||||
ret = error(_("reverse-index file %s is too small"), revindex_name);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (revindex_size - RIDX_MIN_SIZE != st_mult(sizeof(uint32_t), num_objects)) {
|
||||
if (revindex_size - ridx_min_size(algo) != st_mult(sizeof(uint32_t), num_objects)) {
|
||||
ret = error(_("reverse-index file %s is corrupt"), revindex_name);
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -279,7 +283,8 @@ int load_pack_revindex_from_disk(struct packed_git *p)
|
||||
|
||||
revindex_name = pack_revindex_filename(p);
|
||||
|
||||
ret = load_revindex_from_disk(revindex_name,
|
||||
ret = load_revindex_from_disk(p->repo->hash_algo,
|
||||
revindex_name,
|
||||
p->num_objects,
|
||||
&p->revindex_map,
|
||||
&p->revindex_size);
|
||||
@@ -322,7 +327,8 @@ int verify_pack_revindex(struct packed_git *p)
|
||||
if (!p->revindex_map || !p->revindex_data)
|
||||
return res;
|
||||
|
||||
if (!hashfile_checksum_valid((const unsigned char *)p->revindex_map, p->revindex_size)) {
|
||||
if (!hashfile_checksum_valid(p->repo->hash_algo,
|
||||
(const unsigned char *)p->revindex_map, p->revindex_size)) {
|
||||
error(_("invalid checksum"));
|
||||
res = -1;
|
||||
}
|
||||
@@ -374,13 +380,13 @@ int load_midx_revindex(struct multi_pack_index *m)
|
||||
* not want to accidentally call munmap() in the middle of the
|
||||
* MIDX.
|
||||
*/
|
||||
trace2_data_string("load_midx_revindex", the_repository,
|
||||
trace2_data_string("load_midx_revindex", m->repo,
|
||||
"source", "midx");
|
||||
m->revindex_data = (const uint32_t *)m->chunk_revindex;
|
||||
return 0;
|
||||
}
|
||||
|
||||
trace2_data_string("load_midx_revindex", the_repository,
|
||||
trace2_data_string("load_midx_revindex", m->repo,
|
||||
"source", "rev");
|
||||
|
||||
if (m->has_chain)
|
||||
@@ -392,7 +398,8 @@ int load_midx_revindex(struct multi_pack_index *m)
|
||||
m->object_dir, get_midx_checksum(m),
|
||||
MIDX_EXT_REV);
|
||||
|
||||
ret = load_revindex_from_disk(revindex_name.buf,
|
||||
ret = load_revindex_from_disk(m->repo->hash_algo,
|
||||
revindex_name.buf,
|
||||
m->num_objects,
|
||||
&m->revindex_map,
|
||||
&m->revindex_len);
|
||||
@@ -424,7 +431,7 @@ int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
|
||||
{
|
||||
unsigned lo, hi;
|
||||
|
||||
if (load_pack_revindex(the_repository, p) < 0)
|
||||
if (load_pack_revindex(p->repo, p) < 0)
|
||||
return -1;
|
||||
|
||||
lo = 0;
|
||||
@@ -470,7 +477,7 @@ off_t pack_pos_to_offset(struct packed_git *p, uint32_t pos)
|
||||
if (p->revindex)
|
||||
return p->revindex[pos].offset;
|
||||
else if (pos == p->num_objects)
|
||||
return p->pack_size - the_hash_algo->rawsz;
|
||||
return p->pack_size - p->repo->hash_algo->rawsz;
|
||||
else
|
||||
return nth_packed_object_offset(p, pack_pos_to_index(p, pos));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user