summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-01-22 21:55:18 -0800
committerJunio C Hamano <junkio@cox.net>2007-01-24 18:08:02 -0800
commita69e542989d0aa1576a4b6820454b9b0d2636796 (patch)
tree1793fa49a60bc1bb827755100f4e2baca5238c55 /sha1_file.c
parent196055c2dbbd8ee41b4afb1c2d035d0c05c963b8 (diff)
downloadgit-a69e542989d0aa1576a4b6820454b9b0d2636796.tar.gz
Refactor the pack header reading function out of receive-pack.c
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 43ff402380..498665e50c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2048,3 +2048,24 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
}
return 0;
}
+
+int read_pack_header(int fd, struct pack_header *header)
+{
+ char *c = (char*)header;
+ ssize_t remaining = sizeof(struct pack_header);
+ do {
+ ssize_t r = xread(fd, c, remaining);
+ if (r <= 0)
+ /* "eof before pack header was fully read" */
+ return PH_ERROR_EOF;
+ remaining -= r;
+ c += r;
+ } while (remaining > 0);
+ if (header->hdr_signature != htonl(PACK_SIGNATURE))
+ /* "protocol error (pack signature mismatch detected)" */
+ return PH_ERROR_PACK_SIGNATURE;
+ if (!pack_version_ok(header->hdr_version))
+ /* "protocol error (pack version unsupported)" */
+ return PH_ERROR_PROTOCOL;
+ return 0;
+}