Skip to content

Commit

Permalink
add a "oid numbers chunk again
Browse files Browse the repository at this point in the history
Similar to my 87zhobr4fl.fsf@evledraar.gmail.com, but it works this
time.
  • Loading branch information
avar committed May 1, 2019
1 parent 83232e3 commit 3fca63e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
8 changes: 8 additions & 0 deletions builtin/commit-graph.c
Expand Up @@ -127,6 +127,14 @@ static int graph_read(int argc, const char **argv)
printf(" commit_metadata");
if (graph->chunk_extra_edges)
printf(" extra_edges");
if (getenv("CG_DEBUG") && graph->chunk_oid_numbers)
printf(" oid_numbers");
if (getenv("CG_DEBUG") && graph->chunk_oid_numbers) {
int i;
printf("\n");
for (i = 0; i < 5; i++)
printf(" oid number #%d: %d\n", i, get_be32(graph->chunk_oid_numbers + i * 4));
}
printf("\n");

UNLEAK(graph);
Expand Down
32 changes: 28 additions & 4 deletions commit-graph.c
Expand Up @@ -22,6 +22,7 @@
#define GRAPH_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
#define GRAPH_CHUNKID_DATA 0x43444154 /* "CDAT" */
#define GRAPH_CHUNKID_EXTRAEDGES 0x45444745 /* "EDGE" */
#define GRAPH_CHUNKID_OIDNUMBERS 0x4f49444e /* "OIDN" */

#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)

Expand All @@ -37,6 +38,7 @@
#define GRAPH_HEADER_SIZE 8
#define GRAPH_FANOUT_SIZE (4 * 256)
#define GRAPH_CHUNKLOOKUP_WIDTH 12
#define GRAPH_OIDNUMBERS_SIZE (4 * 5)
#define GRAPH_MIN_SIZE (GRAPH_HEADER_SIZE + 4 * GRAPH_CHUNKLOOKUP_WIDTH \
+ GRAPH_FANOUT_SIZE + the_hash_algo->rawsz)

Expand Down Expand Up @@ -190,6 +192,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,

graph->hash_len = the_hash_algo->rawsz;
graph->num_chunks = *(unsigned char*)(data + 6);
if (getenv("CG_DEBUG"))
fprintf(stderr, "have %d chunks\n", graph->num_chunks);
graph->graph_fd = fd;
graph->data = graph_map;
graph->data_len = graph_size;
Expand All @@ -210,6 +214,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
}

chunk_id = get_be32(chunk_lookup + 0);
if (getenv("CG_DEBUG"))
fprintf(stderr, "looking at chunk %d with id 0x%X\n", i, chunk_id);
chunk_offset = get_be64(chunk_lookup + 4);

chunk_lookup += GRAPH_CHUNKLOOKUP_WIDTH;
Expand Down Expand Up @@ -249,6 +255,12 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
else
graph->chunk_extra_edges = data + chunk_offset;
break;
case GRAPH_CHUNKID_OIDNUMBERS:
if (graph->chunk_oid_numbers)
chunk_repeated = 1;
else
graph->chunk_oid_numbers = data + chunk_offset;
break;
}

if (chunk_repeated) {
Expand Down Expand Up @@ -558,6 +570,14 @@ static void write_graph_chunk_oids(struct hashfile *f, int hash_len,
}
}

static void write_graph_chunk_numbers(struct hashfile *f, int hash_len)
{
int i;
for (i = 0; i < GRAPH_OIDNUMBERS_SIZE / 4; i++) {
hashwrite_be32(f, 1234 + i);
}
}

static const unsigned char *commit_to_sha1(size_t index, void *table)
{
struct commit **commits = table;
Expand Down Expand Up @@ -873,8 +893,8 @@ void write_commit_graph(const char *obj_dir,
uint32_t i, count_distinct = 0;
char *graph_name;
struct lock_file lk = LOCK_INIT;
uint32_t chunk_ids[5];
uint64_t chunk_offsets[5];
uint32_t chunk_ids[6];
uint64_t chunk_offsets[6];
int num_chunks;
int num_extra_edges;
struct commit_list *parent;
Expand Down Expand Up @@ -1036,7 +1056,7 @@ void write_commit_graph(const char *obj_dir,

commits.nr++;
}
num_chunks = num_extra_edges ? 4 : 3;
num_chunks = num_extra_edges ? 5 : 4;
stop_progress(&progress);

if (commits.nr >= GRAPH_EDGE_LAST_MASK)
Expand Down Expand Up @@ -1068,13 +1088,16 @@ void write_commit_graph(const char *obj_dir,
chunk_ids[3] = GRAPH_CHUNKID_EXTRAEDGES;
else
chunk_ids[3] = 0;
chunk_ids[4] = 0;
chunk_ids[4] = GRAPH_CHUNKID_OIDNUMBERS;
chunk_ids[5] = 0;

chunk_offsets[0] = 8 + (num_chunks + 1) * GRAPH_CHUNKLOOKUP_WIDTH;
chunk_offsets[1] = chunk_offsets[0] + GRAPH_FANOUT_SIZE;
chunk_offsets[2] = chunk_offsets[1] + hashsz * commits.nr;
chunk_offsets[3] = chunk_offsets[2] + (hashsz + 16) * commits.nr;
chunk_offsets[4] = chunk_offsets[3] + 4 * num_extra_edges;
chunk_offsets[5] = chunk_offsets[4] + GRAPH_OIDNUMBERS_SIZE;


for (i = 0; i <= num_chunks; i++) {
uint32_t chunk_write[3];
Expand All @@ -1100,6 +1123,7 @@ void write_commit_graph(const char *obj_dir,
write_graph_chunk_data(f, hashsz, commits.list, commits.nr, progress, &progress_cnt);
if (num_extra_edges)
write_graph_chunk_extra_edges(f, commits.list, commits.nr, progress, &progress_cnt);
write_graph_chunk_numbers(f, hashsz);
stop_progress(&progress);
strbuf_release(&progress_title);

Expand Down
1 change: 1 addition & 0 deletions commit-graph.h
Expand Up @@ -52,6 +52,7 @@ struct commit_graph {
const unsigned char *chunk_oid_lookup;
const unsigned char *chunk_commit_data;
const unsigned char *chunk_extra_edges;
const unsigned char *chunk_oid_numbers;
};

struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st);
Expand Down
10 changes: 6 additions & 4 deletions t/t5318-commit-graph.sh
Expand Up @@ -58,11 +58,11 @@ graph_git_behavior 'no graph' full commits/3 commits/1

graph_read_expect() {
OPTIONAL=""
NUM_CHUNKS=3
NUM_CHUNKS=4
if test ! -z $2
then
OPTIONAL=" $2"
NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
NUM_CHUNKS=$((4 + $(echo "$2" | wc -w)))
fi
cat >expect <<- EOF
header: 43475048 1 1 $NUM_CHUNKS 0
Expand Down Expand Up @@ -340,7 +340,8 @@ GRAPH_BYTE_HASH=5
GRAPH_BYTE_CHUNK_COUNT=6
GRAPH_CHUNK_LOOKUP_OFFSET=8
GRAPH_CHUNK_LOOKUP_WIDTH=12
GRAPH_CHUNK_LOOKUP_ROWS=5
GRAPH_CHUNK_OID_NUMBERS_WIDTH=20
GRAPH_CHUNK_LOOKUP_ROWS=6
GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
Expand All @@ -364,7 +365,8 @@ GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
$GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES + \
$GRAPH_CHUNK_OID_NUMBERS_WIDTH))

corrupt_graph_setup() {
cd "$TRASH_DIRECTORY/full" &&
Expand Down

0 comments on commit 3fca63e

Please sign in to comment.