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

[PATCH v2 3/3] index-pack: eliminate unlimited recursion in get_delta_base()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 9, 2012, 03:59 UTC
Message-ID
<1326081546-29320-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1324901080-23215-1-git-send-email-pclouds@gmail.com>

Revert the order of delta applying so that by the time a delta is applied, its base is either non-delta or already inflated. get_delta_base() is still recursive, but because base's data is always ready, the inner get_delta_base() call never has any chance to call itself again.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/index-pack.c |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 38ff03a..8c1f5d9 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -519,10 +519,25 @@ static void *get_base_data(struct base_data *c)
 {
 	if (!c->data) {
 		struct object_entry *obj = c->obj;
+		struct base_data **delta = NULL;
+		int delta_nr = 0, delta_alloc = 0;
 
-		if (is_delta_type(obj->type)) {
-			void *base = get_base_data(c->base);
-			void *raw = get_data_from_pack(obj);
+		for (; is_delta_type(c->obj->type); c = c->base) {
+			ALLOC_GROW(delta, delta_nr + 1, delta_alloc);
+			delta[delta_nr++] = c;
+		}
+		if (!delta_nr) {
+			c->data = get_data_from_pack(obj);
+			c->size = obj->size;
+			base_cache_used += c->size;
+			prune_base_data(c);
+		}
+		for (; delta_nr > 0; delta_nr--) {
+			void *base, *raw;
+			c = delta[delta_nr - 1];
+			obj = c->obj;
+			base = get_base_data(c->base);
+			raw = get_data_from_pack(obj);
 			c->data = patch_delta(
 				base, c->base->size,
 				raw, obj->size,
@@ -530,13 +545,10 @@ static void *get_base_data(struct base_data *c)
 			free(raw);
 			if (!c->data)
 				bad_object(obj->idx.offset, "failed to apply delta");
-		} else {
-			c->data = get_data_from_pack(obj);
-			c->size = obj->size;
+			base_cache_used += c->size;
+			prune_base_data(c);
 		}
-
-		base_cache_used += c->size;
-		prune_base_data(c);
+		free(delta);
 	}
 	return c->data;
 }
-- 
1.7.3.1.256.g2539c.dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 21 in “Eliminate recursion in setting/clearing marks in commit list”
  1. 1/3 Eliminate recursion in setting/clearing marks in commit listNguyễn Thái Ngọc Duy, Dec 26, 2011
  2. 2/3 index-pack: eliminate recursion in find_unresolved_deltasNguyễn Thái Ngọc Duy, Dec 26, 2011
  3. 3/3 index-pack: eliminate unlimited recursion in get_delta_base()Nguyễn Thái Ngọc Duy, Dec 26, 2011
  4. 0/3 nd/index-pack-no-recurseNguyễn Thái Ngọc Duy, Jan 9, 2012
  5. Junio C HamanoJan 9, 2012
  6. 0/3 nd/index-pack-no-recurseNguyễn Thái Ngọc Duy, Jan 14, 2012
  7. 1/3 Eliminate recursion in setting/clearing marks in commit listNguyễn Thái Ngọc Duy, Jan 14, 2012
  8. Peter BaumannJan 14, 2012
  9. Nguyen Thai Ngoc DuyJan 15, 2012
  10. 2/3 index-pack: eliminate recursion in find_unresolved_deltasNguyễn Thái Ngọc Duy, Jan 14, 2012
  11. 3/3 index-pack: eliminate unlimited recursion in get_base_data()Nguyễn Thái Ngọc Duy, Jan 14, 2012
  12. 1/3 Eliminate recursion in setting/clearing marks in commit listNguyễn Thái Ngọc Duy, Jan 9, 2012
  13. Junio C HamanoJan 9, 2012
  14. 2/3 index-pack: eliminate recursion in find_unresolved_deltasNguyễn Thái Ngọc Duy, Jan 9, 2012
  15. Junio C HamanoJan 9, 2012
  16. Nguyen Thai Ngoc DuyJan 10, 2012
  17. Junio C HamanoJan 12, 2012
  18. 3/3 index-pack: eliminate unlimited recursion in get_delta_base()Nguyễn Thái Ngọc Duy, Jan 9, 2012
  19. Junio C HamanoJan 9, 2012
  20. Nguyen Thai Ngoc DuyJan 10, 2012
  21. Nguyen Thai Ngoc DuyJan 10, 2012

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.