]>
git.ipfire.org Git - thirdparty/git.git/blob - midx.c
6 #define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
8 #define MIDX_HASH_VERSION 1
9 #define MIDX_HEADER_SIZE 12
11 static char *get_midx_filename(const char *object_dir
)
13 return xstrfmt("%s/pack/multi-pack-index", object_dir
);
16 static size_t write_midx_header(struct hashfile
*f
,
17 unsigned char num_chunks
,
20 unsigned char byte_values
[4];
22 hashwrite_be32(f
, MIDX_SIGNATURE
);
23 byte_values
[0] = MIDX_VERSION
;
24 byte_values
[1] = MIDX_HASH_VERSION
;
25 byte_values
[2] = num_chunks
;
26 byte_values
[3] = 0; /* unused */
27 hashwrite(f
, byte_values
, sizeof(byte_values
));
28 hashwrite_be32(f
, num_packs
);
30 return MIDX_HEADER_SIZE
;
33 int write_midx_file(const char *object_dir
)
35 unsigned char num_chunks
= 0;
37 struct hashfile
*f
= NULL
;
40 midx_name
= get_midx_filename(object_dir
);
41 if (safe_create_leading_directories(midx_name
)) {
43 die_errno(_("unable to create leading directories of %s"),
47 hold_lock_file_for_update(&lk
, midx_name
, LOCK_DIE_ON_ERROR
);
48 f
= hashfd(lk
.tempfile
->fd
, lk
.tempfile
->filename
.buf
);
49 FREE_AND_NULL(midx_name
);
51 write_midx_header(f
, num_chunks
, 0);
53 finalize_hashfile(f
, NULL
, CSUM_FSYNC
| CSUM_HASH_IN_STREAM
);
54 commit_lock_file(&lk
);