public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH 4/8] git-repack --max-pack-size: add fixup_header_footer()
@ 2007-04-30 23:21 Dana How
  2007-05-01  5:06 ` Shawn O. Pearce
  0 siblings, 1 reply; 18+ messages in thread
From: Dana How @ 2007-04-30 23:21 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, danahow


Add our own version of the one in fast-import.c here.
Needed later to correct bad object count in header for split pack.

Signed-off-by: Dana L. How <danahow@gmail•com>
---
 builtin-pack-objects.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index bc45ca6..98066bf 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -562,6 +562,42 @@ static off_t write_one(struct sha1file *f,
 	return offset + size;
 }
 
+static void fixup_header_footer(int pack_fd, unsigned char *pack_file_sha1,
+				char *pack_name, uint32_t object_count)
+{
+	static const int buf_sz = 128 * 1024;
+	SHA_CTX c;
+	struct pack_header hdr;
+	char *buf;
+
+	if (lseek(pack_fd, 0, SEEK_SET) != 0)
+		die("Failed seeking to start: %s", strerror(errno));
+	if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))
+		die("Unable to reread header of %s", pack_name);
+	if (lseek(pack_fd, 0, SEEK_SET) != 0)
+		die("Failed seeking to start: %s", strerror(errno));
+	hdr.hdr_entries = htonl(object_count);
+	write_or_die(pack_fd, &hdr, sizeof(hdr));
+
+	SHA1_Init(&c);
+	SHA1_Update(&c, &hdr, sizeof(hdr));
+
+	buf = xmalloc(buf_sz);
+	for (;;) {
+		size_t n = xread(pack_fd, buf, buf_sz);
+		if (!n)
+			break;
+		if (n < 0)
+			die("Failed to checksum %s", pack_name);
+		SHA1_Update(&c, buf, n);
+	}
+	free(buf);
+
+	SHA1_Final(pack_file_sha1, &c);
+	write_or_die(pack_fd, pack_file_sha1, 20);
+	close(pack_fd);
+}
+
 /* forward declarations for write_pack_file */
 static void write_index_file(off_t last_obj_offset, unsigned char *sha1);
 static int adjust_perm(const char *path, mode_t mode);
-- 
1.5.2.rc0.766.gba60-dirty

^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [PATCH 4/8] git-repack --max-pack-size: add fixup_header_footer()
@ 2007-04-08 23:22 Dana How
  2007-04-09  0:04 ` Junio C Hamano
  0 siblings, 1 reply; 18+ messages in thread
From: Dana How @ 2007-04-08 23:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, danahow


Add our own version of the one in fast-import.c here.
Will need this later to correct an incorrect object
count in the pack header.

Signed-off-by: Dana How <how@deathvalley•cswitch.com>
---
 builtin-pack-objects.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 8415549..7ab0712 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -518,6 +518,46 @@ static off_t write_one(struct sha1file *f,
 	return offset + write_object(f, e);
 }
 
+/*
+ * Move this, the version in fast-import.c,
+ * and index_pack.c:readjust_pack_header_and_sha1 into sha1_file.c ?
+ */
+static void fixup_header_footer(int pack_fd, unsigned char *pack_file_sha1,
+				char *pack_name, uint32_t object_count)
+{
+	static const int buf_sz = 128 * 1024;
+	SHA_CTX c;
+	struct pack_header hdr;
+	char *buf;
+
+	if (lseek(pack_fd, 0, SEEK_SET) != 0)
+		die("Failed seeking to start: %s", strerror(errno));
+	if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))
+		die("Unable to reread header of %s", pack_name);
+	if (lseek(pack_fd, 0, SEEK_SET) != 0)
+		die("Failed seeking to start: %s", strerror(errno));
+	hdr.hdr_entries = htonl(object_count);
+	write_or_die(pack_fd, &hdr, sizeof(hdr));
+
+	SHA1_Init(&c);
+	SHA1_Update(&c, &hdr, sizeof(hdr));
+
+	buf = xmalloc(buf_sz);
+	for (;;) {
+		size_t n = xread(pack_fd, buf, buf_sz);
+		if (!n)
+			break;
+		if (n < 0)
+			die("Failed to checksum %s", pack_name);
+		SHA1_Update(&c, buf, n);
+	}
+	free(buf);
+
+	SHA1_Final(pack_file_sha1, &c);
+	write_or_die(pack_fd, pack_file_sha1, 20);
+	close(pack_fd);
+}
+
 typedef int (*entry_sort_t)(const struct object_entry *, const struct object_entry *);
 
 static entry_sort_t current_sort;
-- 
1.5.1.89.g8abf0

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2007-05-01 18:40 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-30 23:21 [PATCH 4/8] git-repack --max-pack-size: add fixup_header_footer() Dana How
2007-05-01  5:06 ` Shawn O. Pearce
2007-05-01  5:41   ` Dana How
2007-05-01  6:03     ` Shawn O. Pearce
2007-05-01  7:32       ` Johannes Schindelin
2007-05-01 17:48       ` Nicolas Pitre
2007-05-01 17:58         ` Dana How
2007-05-01 18:39           ` Nicolas Pitre
  -- strict thread matches above, loose matches on Subject: below --
2007-04-08 23:22 Dana How
2007-04-09  0:04 ` Junio C Hamano
2007-04-09  0:18   ` Nicolas Pitre
2007-04-09 17:38     ` Shawn O. Pearce
2007-04-09 18:30       ` Nicolas Pitre
2007-04-09 18:40         ` Shawn O. Pearce
2007-04-09 19:11           ` Dana How
2007-04-09 19:33             ` Nicolas Pitre
2007-04-09 21:38               ` Dana How
2007-04-09 23:22                 ` Nicolas Pitre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox