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

[PATCH 3/4] index-pack: Track the object_entry that creates each base_data

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 14, 2008, 02:07 UTC
Message-ID
<1216001267-33235-4-git-send-email-spearce@spearce.org>
In-Reply-To
<1216001267-33235-3-git-send-email-spearce@spearce.org>

If we free the data stored within a base_data we need the struct object_entry to get the data back again for use with another dependent delta. Storing the object_entry* makes it simple to call get_data_from_pack() to recover the compressed information.

This however means we must add the missing baes object to the end of our packfile prior to calling resolve_delta() on each of the dependent deltas. Adding the base first ensures we can read the base back from the pack we indexing, as if it had been included by the remote side.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 index-pack.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/index-pack.c b/index-pack.c
index 6c59fd3..7239e89 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -29,6 +29,7 @@ union delta_base {
 struct base_data {
 	struct base_data *base;
 	struct base_data *child;
+	struct object_entry *obj;
 	void *data;
 	unsigned long size;
 };
@@ -476,6 +477,7 @@ static void resolve_delta(struct object_entry *delta_obj,
 	sha1_object(result.data, result.size, type, delta_obj->idx.sha1);
 	nr_resolved_deltas++;
 
+	result.obj = delta_obj;
 	link_base_data(base_obj, &result);
 
 	hashcpy(delta_base.sha1, delta_obj->idx.sha1);
@@ -588,6 +590,7 @@ static void parse_pack_objects(unsigned char *sha1)
 			continue;
 		base_obj.data = get_data_from_pack(obj);
 		base_obj.size = obj->size;
+		base_obj.obj = obj;
 		link_base_data(NULL, &base_obj);
 
 		if (ref)
@@ -633,7 +636,8 @@ static int write_compressed(int fd, void *in, unsigned int size, uint32_t *obj_c
 	return size;
 }
 
-static void append_obj_to_pack(const unsigned char *sha1, void *buf,
+static struct object_entry *append_obj_to_pack(
+			       const unsigned char *sha1, void *buf,
 			       unsigned long size, enum object_type type)
 {
 	struct object_entry *obj = &objects[nr_objects++];
@@ -654,6 +658,7 @@ static void append_obj_to_pack(const unsigned char *sha1, void *buf,
 	obj[1].idx.offset = obj[0].idx.offset + n;
 	obj[1].idx.offset += write_compressed(output_fd, buf, size, &obj[0].idx.crc32);
 	hashcpy(obj->idx.sha1, sha1);
+	return obj;
 }
 
 static int delta_pos_compare(const void *_a, const void *_b)
@@ -697,6 +702,12 @@ static void fix_unresolved_deltas(int nr_unresolved)
 		base_obj.data = read_sha1_file(d->base.sha1, &type, &base_obj.size);
 		if (!base_obj.data)
 			continue;
+
+		if (check_sha1_signature(d->base.sha1, base_obj.data,
+				base_obj.size, typename(type)))
+			die("local object %s is corrupt", sha1_to_hex(d->base.sha1));
+		base_obj.obj = append_obj_to_pack(d->base.sha1, base_obj.data,
+			base_obj.size, type);
 		link_base_data(NULL, &base_obj);
 
 		find_delta_children(&d->base, &first, &last);
@@ -706,11 +717,6 @@ static void fix_unresolved_deltas(int nr_unresolved)
 				resolve_delta(child, &base_obj, type);
 		}
 
-		if (check_sha1_signature(d->base.sha1, base_obj.data,
-				base_obj.size, typename(type)))
-			die("local object %s is corrupt", sha1_to_hex(d->base.sha1));
-		append_obj_to_pack(d->base.sha1, base_obj.data,
-			base_obj.size, type);
 		unlink_base_data(&base_obj);
 		display_progress(progress, nr_resolved_deltas);
 	}
-- 
1.5.6.2.393.g45096
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 19 of 51 in “git pull is slow”
  1. Stephan HennigJul 10, 2008
  2. Martin LanghoffJul 10, 2008
  3. Petr BaudisJul 10, 2008
  4. Johannes SixtJul 10, 2008
  5. Stephan HennigJul 10, 2008
  6. Petr BaudisJul 10, 2008
  7. Stephan HennigJul 10, 2008
  8. Stephan HennigJul 11, 2008
  9. Andreas EricssonJul 11, 2008
  10. Johannes SchindelinJul 11, 2008
  11. Stephan HennigJul 12, 2008
  12. Johannes SchindelinJul 12, 2008
  13. Shawn O. PearceJul 13, 2008
  14. Johannes SchindelinJul 13, 2008
  15. Shawn O. PearceJul 13, 2008
  16. 0/4 Honor core.deltaBaseCacheLimit during index-packShawn O. Pearce, Jul 14, 2008
  17. 1/4 index-pack: Refactor base arguments of resolve_delta into a structShawn O. Pearce, Jul 14, 2008
  18. 2/4 index-pack: Chain the struct base_data on the stack for traversalShawn O. Pearce, Jul 14, 2008
  19. 3/4 index-pack: Track the object_entry that creates each base_dataShawn O. Pearce, Jul 14, 2008
  20. 4/4 index-pack: Honor core.deltaBaseCacheLimit when resolving deltasShawn O. Pearce, Jul 14, 2008
  21. Nicolas PitreJul 15, 2008
  22. Shawn O. PearceJul 15, 2008
  23. index-pack: Honor core.deltaBaseCacheLimit when resolving deltasShawn O. Pearce, Jul 15, 2008
  24. Nicolas PitreJul 15, 2008
  25. Junio C HamanoJul 15, 2008
  26. Johannes SchindelinJul 14, 2008
  27. Nicolas PitreJul 15, 2008
  28. Shawn O. PearceJul 15, 2008
  29. Nicolas PitreJul 15, 2008
  30. Nicolas PitreJul 15, 2008
  31. Nicolas PitreJul 15, 2008
  32. Nicolas PitreJul 14, 2008
  33. Shawn O. PearceJul 14, 2008
  34. Johannes SchindelinJul 14, 2008
  35. Jakub NarebskiJul 14, 2008
  36. Johannes SchindelinJul 14, 2008
  37. Andreas EricssonJul 14, 2008
  38. Johannes SchindelinJul 14, 2008
  39. Andreas EricssonJul 14, 2008
  40. Johannes SchindelinJul 14, 2008
  41. Nicolas PitreJul 15, 2008
  42. Shawn O. PearceJul 15, 2008
  43. Nicolas PitreJul 15, 2008
  44. Stephan HennigJul 17, 2008
  45. Nicolas PitreJul 17, 2008
  46. Shawn O. PearceJul 17, 2008
  47. index-pack: Issue a warning if deltaBaseCacheLimit is too smallShawn O. Pearce, Jul 17, 2008
  48. Nicolas PitreJul 17, 2008
  49. Shawn O. PearceJul 15, 2008
  50. Stephan HennigJul 13, 2008
  51. Stephan HennigJul 11, 2008

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.