git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Refactor the pack header reading function out of receive-pack.c

From
Junio C Hamano <junkio@cox.net>
Date
Jan 23, 2007, 06:47 UTC
Message-ID
<7v64ayp7ca.fsf@assigned-by-dhcp.cox.net>
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
Previous: Junio C HamanoNext: Junio C Hamano
Message 45 of 70 in “[Announce] GIT v1.5.0-rc2”
  1. Junio C HamanoJan 21, 2007
  2. Jakub NarebskiJan 21, 2007
  3. Junio C HamanoJan 21, 2007
  4. Johannes SchindelinJan 21, 2007
  5. Bill LearJan 23, 2007
  6. Johannes SchindelinJan 23, 2007
  7. Bill LearJan 23, 2007
  8. Uwe Kleine-KönigJan 23, 2007
  9. Bill LearJan 23, 2007
  10. Uwe Kleine-KönigJan 24, 2007
  11. Johannes SchindelinJan 23, 2007
  12. Peter BaumannJan 23, 2007
  13. Bill LearJan 23, 2007
  14. Linus TorvaldsJan 23, 2007
  15. Mark NudelmanJan 24, 2007
  16. Linus TorvaldsJan 24, 2007
  17. Linus TorvaldsJan 24, 2007
  18. Junio C HamanoJan 24, 2007
  19. Mark NudelmanMar 27, 2007
  20. Junio C HamanoJan 21, 2007
  21. Bill LearJan 21, 2007
  22. Bill LearJan 21, 2007
  23. MichaelJan 21, 2007
  24. Johannes SchindelinJan 21, 2007
  25. Jakub NarebskiJan 21, 2007
  26. Johannes SchindelinJan 21, 2007
  27. Jakub NarebskiJan 21, 2007
  28. Willy TarreauJan 21, 2007
  29. Jakub NarebskiJan 21, 2007
  30. Junio C HamanoJan 21, 2007
  31. H. Peter AnvinJan 21, 2007
  32. Nicolas PitreJan 22, 2007
  33. Horst H. von BrandJan 21, 2007
  34. Junio C HamanoJan 22, 2007
  35. Horst H. von BrandJan 21, 2007
  36. Junio C HamanoJan 21, 2007
  37. Johannes SchindelinJan 21, 2007
  38. Jakub NarebskiJan 21, 2007
  39. Johannes SchindelinJan 21, 2007
  40. Jakub NarebskiJan 21, 2007
  41. Johannes SchindelinJan 21, 2007
  42. Jakub NarebskiJan 21, 2007
  43. Junio C HamanoJan 22, 2007
  44. Junio C HamanoJan 22, 2007
  45. 1/2 Refactor the pack header reading function out of receive-pack.cJunio C Hamano, Jan 23, 2007
  46. 2/2 Allow fetch-pack to decide keeping the fetched pack without explodingJunio C Hamano, Jan 23, 2007
  47. Johannes SchindelinJan 23, 2007
  48. Jakub NarebskiJan 23, 2007
  49. code movements in diffs, was Re: [PATCH 2/2] Allow fetch-pack to decide keeping the fetched pack without explodingJohannes Schindelin, Jan 23, 2007
  50. Nicolas PitreJan 23, 2007
  51. fetch-pack: remove --keep-auto and make it the default.Junio C Hamano, Jan 25, 2007
  52. Johannes SchindelinJan 25, 2007
  53. Junio C HamanoJan 25, 2007
  54. Johannes SchindelinJan 25, 2007
  55. Junio C HamanoJan 26, 2007
  56. Allow non-developer to clone, checkout and fetch easier.Junio C Hamano, Jan 26, 2007
  57. Alex RiesenJan 26, 2007
  58. Johannes SixtJan 26, 2007
  59. Consolidate {receive,fetch}.unpackLimitJunio C Hamano, Jan 25, 2007
  60. Nicolas PitreJan 25, 2007
  61. Shawn O. PearceJan 25, 2007
  62. Linus TorvaldsJan 23, 2007
  63. David KågedalJan 23, 2007
  64. Johannes SchindelinJan 23, 2007
  65. Jakub NarebskiJan 23, 2007
  66. Carl WorthJan 22, 2007
  67. Junio C HamanoJan 22, 2007
  68. Carl WorthJan 23, 2007
  69. Jakub NarebskiJan 22, 2007
  70. Junio C HamanoJan 22, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.