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

[PATCH v3 13/23] pack: move get_size_from_delta()

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Aug 18, 2017, 22:20 UTC
Message-ID
<d9f1dba4357ef883d6425b6a51d57ba27c3e98ab.1503094448.git.jonathantanmy@google.com>
In-Reply-To
<cover.1503094448.git.jonathantanmy@google.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 cache.h     |  1 -
 packfile.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 packfile.h  |  1 +
 sha1_file.c | 39 ---------------------------------------
 4 files changed, 41 insertions(+), 40 deletions(-)
diff --git a/cache.h b/cache.h
index 75cc0c497..87f65aeea 100644
--- a/cache.h
+++ b/cache.h
@@ -1669,7 +1669,6 @@ extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *)
 
 extern int is_pack_valid(struct packed_git *);
 extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
-extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
 extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
 
 /*
diff --git a/packfile.c b/packfile.c
index 43b708812..fa90b643e 100644
--- a/packfile.c
+++ b/packfile.c
@@ -4,6 +4,7 @@
 #include "dir.h"
 #include "mergesort.h"
 #include "packfile.h"
+#include "delta.h"
 
 char *odb_pack_name(struct strbuf *buf,
 		    const unsigned char *sha1,
@@ -909,3 +910,42 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
 	*sizep = size;
 	return used;
 }
+
+unsigned long get_size_from_delta(struct packed_git *p,
+				  struct pack_window **w_curs,
+			          off_t curpos)
+{
+	const unsigned char *data;
+	unsigned char delta_head[20], *in;
+	git_zstream stream;
+	int st;
+
+	memset(&stream, 0, sizeof(stream));
+	stream.next_out = delta_head;
+	stream.avail_out = sizeof(delta_head);
+
+	git_inflate_init(&stream);
+	do {
+		in = use_pack(p, w_curs, curpos, &stream.avail_in);
+		stream.next_in = in;
+		st = git_inflate(&stream, Z_FINISH);
+		curpos += stream.next_in - in;
+	} while ((st == Z_OK || st == Z_BUF_ERROR) &&
+		 stream.total_out < sizeof(delta_head));
+	git_inflate_end(&stream);
+	if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
+		error("delta data unpack-initial failed");
+		return 0;
+	}
+
+	/* Examine the initial part of the delta to figure out
+	 * the result size.
+	 */
+	data = delta_head;
+
+	/* ignore base size */
+	get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
+
+	/* Read the result size */
+	return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
+}
diff --git a/packfile.h b/packfile.h
index 9f36e0112..9c3bce6b2 100644
--- a/packfile.h
+++ b/packfile.h
@@ -63,6 +63,7 @@ extern void unuse_pack(struct pack_window **);
 extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
 
 extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
+extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
 
 extern void release_pack_memory(size_t);
 
diff --git a/sha1_file.c b/sha1_file.c
index b999957b0..5d016ad6b 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1100,45 +1100,6 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
 	return parse_sha1_header_extended(hdr, &oi, 0);
 }
 
-unsigned long get_size_from_delta(struct packed_git *p,
-				  struct pack_window **w_curs,
-			          off_t curpos)
-{
-	const unsigned char *data;
-	unsigned char delta_head[20], *in;
-	git_zstream stream;
-	int st;
-
-	memset(&stream, 0, sizeof(stream));
-	stream.next_out = delta_head;
-	stream.avail_out = sizeof(delta_head);
-
-	git_inflate_init(&stream);
-	do {
-		in = use_pack(p, w_curs, curpos, &stream.avail_in);
-		stream.next_in = in;
-		st = git_inflate(&stream, Z_FINISH);
-		curpos += stream.next_in - in;
-	} while ((st == Z_OK || st == Z_BUF_ERROR) &&
-		 stream.total_out < sizeof(delta_head));
-	git_inflate_end(&stream);
-	if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
-		error("delta data unpack-initial failed");
-		return 0;
-	}
-
-	/* Examine the initial part of the delta to figure out
-	 * the result size.
-	 */
-	data = delta_head;
-
-	/* ignore base size */
-	get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
-
-	/* Read the result size */
-	return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
-}
-
 static off_t get_delta_base(struct packed_git *p,
 				    struct pack_window **w_curs,
 				    off_t *curpos,
-- 
2.14.1.480.gb18f417b89-goog
Previous: Jonathan TanNext: Jonathan Tan
Message 72 of 88 in “An attempt to move packfile funcs to its own file”
  1. 00/10 An attempt to move packfile funcs to its own fileJonathan Tan, Aug 8, 2017
  2. 01/10 pack: move pack name-related functionsJonathan Tan, Aug 8, 2017
  3. Stefan BellerAug 8, 2017
  4. Jonathan TanAug 8, 2017
  5. Christian CouderAug 9, 2017
  6. Jonathan TanAug 9, 2017
  7. Ben PeartAug 11, 2017
  8. Junio C HamanoAug 11, 2017
  9. Jonathan TanAug 16, 2017
  10. 02/10 pack: move static state variablesJonathan Tan, Aug 8, 2017
  11. 03/10 pack: move pack_report()Jonathan Tan, Aug 8, 2017
  12. 06/10 pack: move pack-closing functionsJonathan Tan, Aug 8, 2017
  13. 07/10 pack: move use_pack()Jonathan Tan, Aug 8, 2017
  14. 09/10 pack: move add_packed_git()Jonathan Tan, Aug 8, 2017
  15. 10/10 pack: move install_packed_git()Jonathan Tan, Aug 8, 2017
  16. 05/10 pack: move release_pack_memory()Jonathan Tan, Aug 8, 2017
  17. 04/10 pack: move open_pack_index(), parse_pack_index()Jonathan Tan, Aug 8, 2017
  18. Junio C HamanoAug 8, 2017
  19. Jonathan TanAug 8, 2017
  20. 08/10 pack: move unuse_pack()Jonathan Tan, Aug 8, 2017
  21. Junio C HamanoAug 8, 2017
  22. Jonathan TanAug 8, 2017
  23. Junio C HamanoAug 8, 2017
  24. 00/25 Move exported packfile funcs to its own fileJonathan Tan, Aug 9, 2017
  25. 01/25 pack: move pack name-related functionsJonathan Tan, Aug 9, 2017
  26. 02/25 pack: move static state variablesJonathan Tan, Aug 9, 2017
  27. 03/25 pack: move pack_report()Jonathan Tan, Aug 9, 2017
  28. 05/25 pack: move release_pack_memory()Jonathan Tan, Aug 9, 2017
  29. 04/25 pack: move open_pack_index(), parse_pack_index()Jonathan Tan, Aug 9, 2017
  30. 08/25 pack: move unuse_pack()Jonathan Tan, Aug 9, 2017
  31. 07/25 pack: move use_pack()Jonathan Tan, Aug 9, 2017
  32. 13/25 pack: move get_size_from_delta()Jonathan Tan, Aug 9, 2017
  33. 14/25 pack: move unpack_object_header()Jonathan Tan, Aug 9, 2017
  34. 17/25 pack: move packed_object_info(), unpack_entry()Jonathan Tan, Aug 9, 2017
  35. 15/25 sha1_file: set whence in storage-specific info fnJonathan Tan, Aug 9, 2017
  36. 18/25 pack: move nth_packed_object_{sha1,oid}Jonathan Tan, Aug 9, 2017
  37. 22/25 pack: move find_pack_entry() and make it globalJonathan Tan, Aug 9, 2017
  38. 25/25 pack: move for_each_packed_object()Jonathan Tan, Aug 9, 2017
  39. 24/25 pack: move has_pack_index()Jonathan Tan, Aug 9, 2017
  40. 16/25 sha1_file: remove read_packed_sha1()Jonathan Tan, Aug 9, 2017
  41. 23/25 pack: move has_sha1_pack()Jonathan Tan, Aug 9, 2017
  42. 21/25 pack: move find_sha1_pack()Jonathan Tan, Aug 9, 2017
  43. 20/25 pack: move find_pack_entry_one(), is_pack_valid()Jonathan Tan, Aug 9, 2017
  44. 19/25 pack: move check_pack_index_ptr(), nth_packed_object_offset()Jonathan Tan, Aug 9, 2017
  45. 10/25 pack: move install_packed_git()Jonathan Tan, Aug 9, 2017
  46. 06/25 pack: move pack-closing functionsJonathan Tan, Aug 9, 2017
  47. 09/25 pack: move add_packed_git()Jonathan Tan, Aug 9, 2017
  48. 11/25 pack: move {,re}prepare_packed_git and approximate_object_countJonathan Tan, Aug 9, 2017
  49. 12/25 pack: move unpack_object_header()Jonathan Tan, Aug 9, 2017
  50. Stefan BellerAug 10, 2017
  51. Junio C HamanoAug 10, 2017
  52. Jonathan TanAug 10, 2017
  53. Junio C HamanoAug 10, 2017
  54. 0/2 non-move patches in preparation for packfile.cJonathan Tan, Aug 11, 2017
  55. 1/2 sha1_file: set whence in storage-specific info fnJonathan Tan, Aug 11, 2017
  56. Junio C HamanoAug 11, 2017
  57. 2/2 sha1_file: remove read_packed_sha1()Jonathan Tan, Aug 11, 2017
  58. Junio C HamanoAug 11, 2017
  59. Ben PeartAug 11, 2017
  60. Jonathan TanAug 18, 2017
  61. 00/23 Move exported packfile funcs to its own fileJonathan Tan, Aug 18, 2017
  62. 01/23 pack: move pack name-related functionsJonathan Tan, Aug 18, 2017
  63. 02/23 pack: move static state variablesJonathan Tan, Aug 18, 2017
  64. 06/23 pack: move pack-closing functionsJonathan Tan, Aug 18, 2017
  65. 07/23 pack: move use_pack()Jonathan Tan, Aug 18, 2017
  66. 09/23 pack: move add_packed_git()Jonathan Tan, Aug 18, 2017
  67. 08/23 pack: move unuse_pack()Jonathan Tan, Aug 18, 2017
  68. 16/23 pack: move nth_packed_object_{sha1,oid}Jonathan Tan, Aug 18, 2017
  69. 14/23 pack: move unpack_object_header()Jonathan Tan, Aug 18, 2017
  70. 17/23 pack: move check_pack_index_ptr(), nth_packed_object_offset()Jonathan Tan, Aug 18, 2017
  71. 23/23 pack: move for_each_packed_object()Jonathan Tan, Aug 18, 2017
  72. 13/23 pack: move get_size_from_delta()Jonathan Tan, Aug 18, 2017
  73. 22/23 pack: move has_pack_index()Jonathan Tan, Aug 18, 2017
  74. 15/23 pack: move clear_delta_base_cache(), packed_object_info(), unpack_entry()Jonathan Tan, Aug 18, 2017
  75. 21/23 pack: move has_sha1_pack()Jonathan Tan, Aug 18, 2017
  76. 20/23 pack: move find_pack_entry() and make it globalJonathan Tan, Aug 18, 2017
  77. 18/23 pack: move find_pack_entry_one(), is_pack_valid()Jonathan Tan, Aug 18, 2017
  78. 19/23 pack: move find_sha1_pack()Jonathan Tan, Aug 18, 2017
  79. 03/23 pack: move pack_report()Jonathan Tan, Aug 18, 2017
  80. 05/23 pack: move release_pack_memory()Jonathan Tan, Aug 18, 2017
  81. 10/23 pack: move install_packed_git()Jonathan Tan, Aug 18, 2017
  82. 11/23 pack: move {,re}prepare_packed_git and approximate_object_countJonathan Tan, Aug 18, 2017
  83. 12/23 pack: move unpack_object_header_buffer()Jonathan Tan, Aug 18, 2017
  84. 04/23 pack: move open_pack_index(), parse_pack_index()Jonathan Tan, Aug 18, 2017
  85. Junio C HamanoAug 19, 2017
  86. Junio C HamanoAug 20, 2017
  87. Jonathan TanAug 21, 2017
  88. Junio C HamanoAug 21, 2017

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.