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

[PATCH v2 18/25] pack: move nth_packed_object_{sha1,oid}

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Aug 9, 2017, 01:22 UTC
Message-ID
<ea143618a51a8286a425137a870a636be6d95a35.1502241234.git.jonathantanmy@google.com>
In-Reply-To
<cover.1502241234.git.jonathantanmy@google.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 cache.h     | 14 --------------
 pack.h      | 14 ++++++++++++++
 packfile.c  | 31 +++++++++++++++++++++++++++++++
 sha1_file.c | 31 -------------------------------
 4 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/cache.h b/cache.h
index b14098bf1..f083d532e 100644
--- a/cache.h
+++ b/cache.h
@@ -1628,20 +1628,6 @@ extern int odb_pack_keep(const char *name);
  */
 extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
 
-/*
- * Return the SHA-1 of the nth object within the specified packfile.
- * Open the index if it is not already open.  The return value points
- * at the SHA-1 within the mmapped index.  Return NULL if there is an
- * error.
- */
-extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
-/*
- * Like nth_packed_object_sha1, but write the data into the object specified by
- * the the first argument.  Returns the first argument on success, and NULL on
- * error.
- */
-extern const struct object_id *nth_packed_object_oid(struct object_id *, struct packed_git *, uint32_t n);
-
 /*
  * Return the offset of the nth object within the specified packfile.
  * The index must already be opened.
diff --git a/pack.h b/pack.h
index 2e6f357c3..023c97b37 100644
--- a/pack.h
+++ b/pack.h
@@ -182,4 +182,18 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign
 extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
 extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
 
+/*
+ * Return the SHA-1 of the nth object within the specified packfile.
+ * Open the index if it is not already open.  The return value points
+ * at the SHA-1 within the mmapped index.  Return NULL if there is an
+ * error.
+ */
+extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
+/*
+ * Like nth_packed_object_sha1, but write the data into the object specified by
+ * the the first argument.  Returns the first argument on success, and NULL on
+ * error.
+ */
+extern const struct object_id *nth_packed_object_oid(struct object_id *, struct packed_git *, uint32_t n);
+
 #endif
diff --git a/packfile.c b/packfile.c
index a3745f9df..b16cf648a 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1634,3 +1634,34 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
 
 	return data;
 }
+
+const unsigned char *nth_packed_object_sha1(struct packed_git *p,
+					    uint32_t n)
+{
+	const unsigned char *index = p->index_data;
+	if (!index) {
+		if (open_pack_index(p))
+			return NULL;
+		index = p->index_data;
+	}
+	if (n >= p->num_objects)
+		return NULL;
+	index += 4 * 256;
+	if (p->index_version == 1) {
+		return index + 24 * n + 4;
+	} else {
+		index += 8;
+		return index + 20 * n;
+	}
+}
+
+const struct object_id *nth_packed_object_oid(struct object_id *oid,
+					      struct packed_git *p,
+					      uint32_t n)
+{
+	const unsigned char *hash = nth_packed_object_sha1(p, n);
+	if (!hash)
+		return NULL;
+	hashcpy(oid->hash, hash);
+	return oid;
+}
diff --git a/sha1_file.c b/sha1_file.c
index fe7e0db76..4cd2b1809 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1073,37 +1073,6 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
 	return parse_sha1_header_extended(hdr, &oi, 0);
 }
 
-const unsigned char *nth_packed_object_sha1(struct packed_git *p,
-					    uint32_t n)
-{
-	const unsigned char *index = p->index_data;
-	if (!index) {
-		if (open_pack_index(p))
-			return NULL;
-		index = p->index_data;
-	}
-	if (n >= p->num_objects)
-		return NULL;
-	index += 4 * 256;
-	if (p->index_version == 1) {
-		return index + 24 * n + 4;
-	} else {
-		index += 8;
-		return index + 20 * n;
-	}
-}
-
-const struct object_id *nth_packed_object_oid(struct object_id *oid,
-					      struct packed_git *p,
-					      uint32_t n)
-{
-	const unsigned char *hash = nth_packed_object_sha1(p, n);
-	if (!hash)
-		return NULL;
-	hashcpy(oid->hash, hash);
-	return oid;
-}
-
 void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
 {
 	const unsigned char *ptr = vptr;
-- 
2.14.0.434.g98096fd7a8-goog
Previous: Jonathan TanNext: Jonathan Tan
Message 36 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.