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

[PATCH 2/9] pack v4: move v2 tree entry generation code out of decode_entries

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Oct 9, 2013, 14:46 UTC
Message-ID
<1381329976-32082-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1381329976-32082-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 packv4-parse.c | 41 ++++++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/packv4-parse.c b/packv4-parse.c
index 31c89c7..7b096cb 100644
--- a/packv4-parse.c
+++ b/packv4-parse.c
@@ -443,6 +443,31 @@ static int tree_entry_prefix(unsigned char *buf, unsigned long size,
 	return len;
 }
 
+static int generate_tree_entry(struct packed_git *p,
+			       const unsigned char **bufp,
+			       unsigned char **dstp, unsigned long *sizep,
+			       int what)
+{
+	const unsigned char *path, *sha1;
+	unsigned mode;
+	int len, pathlen;
+
+	path = get_pathref(p, what >> 1, &pathlen);
+	sha1 = get_sha1ref(p, bufp);
+	if (!path || !sha1)
+		return -1;
+	mode = (path[0] << 8) | path[1];
+	len = tree_entry_prefix(*dstp, *sizep,
+				path + 2, pathlen - 2, mode);
+	if (!len || len + 20 > *sizep)
+		return -1;
+	hashcpy(*dstp + len, sha1);
+	len += 20;
+	*dstp += len;
+	*sizep -= len;
+	return 0;
+}
+
 static int decode_entries(struct packed_git *p, struct pack_window **w_curs,
 			  off_t obj_offset, unsigned int start, unsigned int count,
 			  unsigned char **dstp, unsigned long *sizep)
@@ -543,22 +568,8 @@ static int decode_entries(struct packed_git *p, struct pack_window **w_curs,
 			/*
 			 * This is an actual tree entry to recreate.
 			 */
-			const unsigned char *path, *sha1;
-			unsigned mode;
-			int len, pathlen;
-
-			path = get_pathref(p, what >> 1, &pathlen);
-			sha1 = get_sha1ref(p, &scp);
-			if (!path || !sha1)
-				return -1;
-			mode = (path[0] << 8) | path[1];
-			len = tree_entry_prefix(*dstp, *sizep,
-						path + 2, pathlen - 2, mode);
-			if (!len || len + 20 > *sizep)
+			if (generate_tree_entry(p, &scp, dstp, sizep, what))
 				return -1;
-			hashcpy(*dstp + len, sha1);
-			*dstp += len + 20;
-			*sizep -= len + 20;
 			count--;
 			curpos++;
 		} else if (what & 1) {
-- 
1.8.2.83.gc99314b
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 3 of 15 in “v4-aware tree walker API”
  1. 0/9 v4-aware tree walker APINguyễn Thái Ngọc Duy, Oct 9, 2013
  2. 1/9 sha1_file: provide real packed type in object_info_extendedNguyễn Thái Ngọc Duy, Oct 9, 2013
  3. 2/9 pack v4: move v2 tree entry generation code out of decode_entriesNguyễn Thái Ngọc Duy, Oct 9, 2013
  4. 3/9 pv4_tree_desc: introduce new struct for pack v4 tree walkerNguyễn Thái Ngọc Duy, Oct 9, 2013
  5. 4/9 pv4_tree_desc: use struct tree_desc from pv4_tree_descNguyễn Thái Ngọc Duy, Oct 9, 2013
  6. 5/9 pv4_tree_desc: allow decode_entries to return v4 trees, one at a timeNguyễn Thái Ngọc Duy, Oct 9, 2013
  7. 6/9 pv4_tree_desc: complete interfaceNguyễn Thái Ngọc Duy, Oct 9, 2013
  8. 7/9 pv4_tree_desc: don't bother looking for v4 trees if no v4 packs are presentNguyễn Thái Ngọc Duy, Oct 9, 2013
  9. 8/9 pv4_tree_desc: avoid lookup_object() when possibleNguyễn Thái Ngọc Duy, Oct 9, 2013
  10. 9/9 list-object.c: take "advantage" of new pv4_tree_desc interfaceNguyễn Thái Ngọc Duy, Oct 9, 2013
  11. Nicolas PitreOct 9, 2013
  12. Duy NguyenOct 11, 2013
  13. Duy NguyenOct 11, 2013
  14. Nicolas PitreOct 12, 2013
  15. Duy NguyenOct 12, 2013

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.