summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: db81e67)
raw | patch | inline | side by side (parent: db81e67)
author | Dana L. How <danahow@gmail.com> | |
Wed, 2 May 2007 16:13:14 +0000 (12:13 -0400) | ||
committer | Shawn O. Pearce <spearce@spearce.org> | |
Wed, 2 May 2007 17:24:18 +0000 (13:24 -0400) |
Include a generalized fixup_pack_header_footer() in this new file.
Needed by git-repack --max-pack-size feature in a later patchset.
[sp: Moved close(pack_fd) to callers, to support index-pack, and
changed name to better indicate it is for packfiles.]
Signed-off-by: Dana L. How <danahow@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Needed by git-repack --max-pack-size feature in a later patchset.
[sp: Moved close(pack_fd) to callers, to support index-pack, and
changed name to better indicate it is for packfiles.]
Signed-off-by: Dana L. How <danahow@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Makefile | patch | blob | history | |
fast-import.c | patch | blob | history | |
pack-write.c | [new file with mode: 0644] | patch | blob |
pack.h | patch | blob | history |
diff --git a/Makefile b/Makefile
index 2fea115919e2d1ba3cff5623858b38c8560f3e03..e0a1308c09e56262632d825fbfa6ab42a83409f8 100644 (file)
--- a/Makefile
+++ b/Makefile
interpolate.o \
lockfile.o \
patch-ids.o \
- object.o pack-check.o patch-delta.o path.o pkt-line.o sideband.o \
- reachable.o reflog-walk.o \
+ object.o pack-check.o pack-write.o patch-delta.o path.o pkt-line.o \
+ sideband.o reachable.o reflog-walk.o \
quote.o read-cache.o refs.o run-command.o dir.o object-refs.o \
server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
diff --git a/fast-import.c b/fast-import.c
index b4cbcd90118c47d47e8940322c8ec2161b33a92a..3a2d5ed8e667af06f97d2559b3cffb8a01f94565 100644 (file)
--- a/fast-import.c
+++ b/fast-import.c
all_packs[pack_id] = p;
}
-static void fixup_header_footer(void)
-{
- static const int buf_sz = 128 * 1024;
- int pack_fd = pack_data->pack_fd;
- 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_data->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 (;;) {
- ssize_t n = xread(pack_fd, buf, buf_sz);
- if (!n)
- break;
- if (n < 0)
- die("Failed to checksum %s", pack_data->pack_name);
- SHA1_Update(&c, buf, n);
- }
- free(buf);
-
- SHA1_Final(pack_data->sha1, &c);
- write_or_die(pack_fd, pack_data->sha1, sizeof(pack_data->sha1));
- close(pack_fd);
-}
-
static int oecmp (const void *a_, const void *b_)
{
struct object_entry *a = *((struct object_entry**)a_);
struct branch *b;
struct tag *t;
- fixup_header_footer();
+ fixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1,
+ pack_data->pack_name, object_count);
+ close(pack_data->pack_fd);
idx_name = keep_pack(create_index());
/* Register the packfile with core git's machinary. */
diff --git a/pack-write.c b/pack-write.c
--- /dev/null
+++ b/pack-write.c
@@ -0,0 +1,39 @@
+#include "cache.h"
+#include "pack.h"
+
+void fixup_pack_header_footer(int pack_fd,
+ unsigned char *pack_file_sha1,
+ const 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: %s", pack_name, strerror(errno));
+ 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: %s", pack_name, strerror(errno));
+ SHA1_Update(&c, buf, n);
+ }
+ free(buf);
+
+ SHA1_Final(pack_file_sha1, &c);
+ write_or_die(pack_fd, pack_file_sha1, 20);
+}
index d4d412ccbb403f1374d41a00791eec3c16ba64ef..d667fb8d5a49b4480beaa6f384f1f6f86b035806 100644 (file)
--- a/pack.h
+++ b/pack.h
extern int verify_pack(struct packed_git *, int);
+extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t);
#define PH_ERROR_EOF (-1)
#define PH_ERROR_PACK_SIGNATURE (-2)