From ccb181d0f053100a988ee0a240e3c0c0bb962d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 6 Sep 2020 10:39:23 +0200 Subject: [PATCH 1/3] fast-import: use write_pack_header() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call write_pack_header() to hash and write a pack header instead of open-coding this function. This gets rid of duplicate code and of the magic version number 2 -- which has been used here since c90be46abd (Changed fast-import's pack header creation to use pack.h, 2006-08-16) and in pack.h (again) since 29f049a0c2 (Revert "move pack creation to version 3", 2006-10-14). Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- builtin/fast-import.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 1c85eafe43..1bf50a73dc 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -739,7 +739,6 @@ static void start_packfile(void) { struct strbuf tmp_file = STRBUF_INIT; struct packed_git *p; - struct pack_header hdr; int pack_fd; pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX"); @@ -750,13 +749,8 @@ static void start_packfile(void) p->do_not_close = 1; pack_file = hashfd(pack_fd, p->pack_name); - hdr.hdr_signature = htonl(PACK_SIGNATURE); - hdr.hdr_version = htonl(2); - hdr.hdr_entries = 0; - hashwrite(pack_file, &hdr, sizeof(hdr)); - pack_data = p; - pack_size = sizeof(hdr); + pack_size = write_pack_header(pack_file, 0); object_count = 0; REALLOC_ARRAY(all_packs, pack_id + 1); From 014f1447f0382b323b53006a65dd2b8383427dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 6 Sep 2020 10:59:02 +0200 Subject: [PATCH 2/3] midx: use hashwrite_u8() in write_midx_header() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Emit byte-sized values using hashwrite_u8() instead of buffering them locally first. The hashwrite functions already do their own buffering, so this double-buffering does not reduce the number of system calls. Getting rid of it shortens and simplifies the code a bit. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- midx.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/midx.c b/midx.c index e9b2e1253a..6326ae17c6 100644 --- a/midx.c +++ b/midx.c @@ -428,14 +428,11 @@ static size_t write_midx_header(struct hashfile *f, unsigned char num_chunks, uint32_t num_packs) { - unsigned char byte_values[4]; - hashwrite_be32(f, MIDX_SIGNATURE); - byte_values[0] = MIDX_VERSION; - byte_values[1] = oid_version(); - byte_values[2] = num_chunks; - byte_values[3] = 0; /* unused */ - hashwrite(f, byte_values, sizeof(byte_values)); + hashwrite_u8(f, MIDX_VERSION); + hashwrite_u8(f, oid_version()); + hashwrite_u8(f, num_chunks); + hashwrite_u8(f, 0); /* unused */ hashwrite_be32(f, num_packs); return MIDX_HEADER_SIZE; From 7744a5d6921c457a05224cd7f5554e972df634b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 6 Sep 2020 10:59:06 +0200 Subject: [PATCH 3/3] pack-bitmap-write: use hashwrite_be32() in write_hash_cache() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call hashwrite_be32() instead of open-coding it. This is shorter and easier to read. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- pack-bitmap-write.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index a7a4964b50..5e998bdaa7 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -503,8 +503,7 @@ static void write_hash_cache(struct hashfile *f, for (i = 0; i < index_nr; ++i) { struct object_entry *entry = (struct object_entry *)index[i]; - uint32_t hash_value = htonl(entry->hash); - hashwrite(f, &hash_value, sizeof(hash_value)); + hashwrite_be32(f, entry->hash); } }