From: Junio C Hamano <junkio@cox•net>
To: Johannes Schindelin <Johannes.Schindelin@gmx•de>
Cc: git@vger•kernel.org
Subject: [PATCH 1/2] Refactor the pack header reading function out of receive-pack.c
Date: Mon, 22 Jan 2007 22:47:49 -0800 [thread overview]
Message-ID: <7v64ayp7ca.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: Pine.LNX.4.63.0701212234520.22628@wbgn013.biozentrum.uni-wuerzburg.de
I'll be reusing it on the fetch-pack side as well.
Signed-off-by: Junio C Hamano <junkio@cox•net>
---
Johannes Schindelin <Johannes.Schindelin@gmx•de> writes:
>> - git-push more agressively keeps the transferred objects
>> packed. Earlier we recommended to monitor amount of loose
>> objects and repack regularly, but you should repack when you
>> accumulated too many small packs this way as well. Updated
>> git-count-objects helps you with this.
>
> It might make sense to enable something similar for git-fetch in time for
> 1.5.0.
I have two patches that could become the beginning of this, not
much tested. This is the first of the two.
pack.h | 5 +++++
receive-pack.c | 26 ++++++++++++++------------
sha1_file.c | 21 +++++++++++++++++++++
3 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/pack.h b/pack.h
index 821706f..deb427e 100644
--- a/pack.h
+++ b/pack.h
@@ -44,4 +44,9 @@ struct pack_header {
#define PACK_IDX_SIGNATURE 0xff744f63 /* "\377tOc" */
extern int verify_pack(struct packed_git *, int);
+
+#define PH_ERROR_EOF (-1)
+#define PH_ERROR_PACK_SIGNATURE (-2)
+#define PH_ERROR_PROTOCOL (-3)
+extern int read_pack_header(int fd, struct pack_header *);
#endif
diff --git a/receive-pack.c b/receive-pack.c
index 6333f00..b3a4552 100644
--- a/receive-pack.c
+++ b/receive-pack.c
@@ -250,20 +250,22 @@ static void read_head_info(void)
static const char *parse_pack_header(struct pack_header *hdr)
{
- char *c = (char*)hdr;
- ssize_t remaining = sizeof(struct pack_header);
- do {
- ssize_t r = xread(0, c, remaining);
- if (r <= 0)
- return "eof before pack header was fully read";
- remaining -= r;
- c += r;
- } while (remaining > 0);
- if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
+ switch (read_pack_header(0, hdr)) {
+ case PH_ERROR_EOF:
+ return "eof before pack header was fully read";
+
+ case PH_ERROR_PACK_SIGNATURE:
return "protocol error (pack signature mismatch detected)";
- if (!pack_version_ok(hdr->hdr_version))
+
+ case PH_ERROR_PROTOCOL:
return "protocol error (pack version unsupported)";
- return NULL;
+
+ default:
+ return "unknown error in parse_pack_header";
+
+ case 0:
+ return NULL;
+ }
}
static const char *pack_lockfile;
diff --git a/sha1_file.c b/sha1_file.c
index 43ff402..498665e 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;
+}
--
1.5.0.rc2.gc9a89
next prev parent reply other threads:[~2007-01-23 6:47 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-21 8:56 [Announce] GIT v1.5.0-rc2 Junio C Hamano
2007-01-21 9:40 ` Jakub Narebski
2007-01-21 10:52 ` Junio C Hamano
2007-01-21 11:08 ` Johannes Schindelin
2007-01-23 18:12 ` Bill Lear
2007-01-23 19:12 ` Johannes Schindelin
2007-01-23 20:12 ` Bill Lear
2007-01-23 20:22 ` Uwe Kleine-König
2007-01-23 20:31 ` Bill Lear
2007-01-24 10:06 ` Uwe Kleine-König
2007-01-23 20:22 ` Johannes Schindelin
2007-01-23 21:09 ` Peter Baumann
2007-01-23 21:54 ` Bill Lear
2007-01-23 20:32 ` Linus Torvalds
2007-01-24 17:54 ` Mark Nudelman
2007-01-24 18:18 ` Linus Torvalds
2007-01-24 19:21 ` Linus Torvalds
2007-01-24 23:23 ` Junio C Hamano
2007-03-27 0:07 ` Mark Nudelman
2007-01-21 11:20 ` Junio C Hamano
2007-01-21 13:42 ` Bill Lear
2007-01-21 13:52 ` Bill Lear
[not found] ` <20070121145805.735815@dial-up-mi-352.lombardiacom.it>
2007-01-21 15:02 ` Michael
2007-01-21 21:26 ` Johannes Schindelin
2007-01-21 21:33 ` Jakub Narebski
2007-01-21 22:01 ` Johannes Schindelin
2007-01-21 22:24 ` Jakub Narebski
2007-01-21 13:43 ` Willy Tarreau
2007-01-21 15:06 ` Jakub Narebski
2007-01-21 18:58 ` Junio C Hamano
2007-01-21 19:49 ` H. Peter Anvin
2007-01-22 17:23 ` Nicolas Pitre
2007-01-21 20:01 ` Horst H. von Brand
2007-01-22 1:27 ` Junio C Hamano
2007-01-21 19:46 ` Horst H. von Brand
2007-01-21 20:51 ` Junio C Hamano
2007-01-21 21:55 ` Johannes Schindelin
2007-01-21 22:45 ` Jakub Narebski
2007-01-21 22:52 ` Johannes Schindelin
2007-01-21 23:08 ` Jakub Narebski
2007-01-21 23:13 ` Johannes Schindelin
2007-01-21 23:36 ` Jakub Narebski
2007-01-22 0:55 ` Junio C Hamano
2007-01-22 6:25 ` Junio C Hamano
2007-01-23 6:47 ` Junio C Hamano [this message]
2007-01-23 6:47 ` [PATCH 2/2] Allow fetch-pack to decide keeping the fetched pack without exploding Junio C Hamano
2007-01-23 10:32 ` Johannes Schindelin
2007-01-23 10:55 ` Jakub Narebski
2007-01-23 11:07 ` code movements in diffs, was " Johannes Schindelin
2007-01-23 16:01 ` Nicolas Pitre
2007-01-25 1:14 ` [PATCH] fetch-pack: remove --keep-auto and make it the default Junio C Hamano
2007-01-25 8:23 ` Johannes Schindelin
2007-01-25 21:32 ` Junio C Hamano
2007-01-25 23:46 ` Johannes Schindelin
2007-01-26 3:05 ` Junio C Hamano
2007-01-26 3:30 ` [PATCH] Allow non-developer to clone, checkout and fetch easier Junio C Hamano
2007-01-26 14:20 ` Alex Riesen
2007-01-26 8:37 ` [PATCH] fetch-pack: remove --keep-auto and make it the default Johannes Sixt
2007-01-25 1:14 ` [PATCH] Consolidate {receive,fetch}.unpackLimit Junio C Hamano
2007-01-25 3:32 ` Nicolas Pitre
2007-01-25 5:14 ` Shawn O. Pearce
2007-01-23 16:15 ` [PATCH 2/2] Allow fetch-pack to decide keeping the fetched pack without exploding Linus Torvalds
2007-01-23 16:28 ` David Kågedal
2007-01-23 16:43 ` Johannes Schindelin
2007-01-23 17:22 ` Jakub Narebski
2007-01-22 18:08 ` [Announce] GIT v1.5.0-rc2 Carl Worth
2007-01-22 19:28 ` Junio C Hamano
2007-01-23 1:01 ` Carl Worth
2007-01-22 18:22 ` Jakub Narebski
2007-01-22 18:46 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v64ayp7ca.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox$(echo .)net \
--cc=Johannes.Schindelin@gmx$(echo .)de \
--cc=git@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox