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

Re: git annotate runs out of memory

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 11, 2007, 21:54 UTC
Message-ID
<7vprxcdhis.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.LFD.0.9999.0712111300440.25032@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 23 quoted lines
>  builtin-blame.c |   10 ++++++++++
>  1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/builtin-blame.c b/builtin-blame.c
> index c158d31..18f9924 100644
> --- a/builtin-blame.c
> +++ b/builtin-blame.c
> @@ -87,6 +87,14 @@ struct origin {
>  	char path[FLEX_ARRAY];
>  };
>  
>  /*
>   * Given an origin, prepare mmfile_t structure to be used by the
>   * diff machinery
> @@ -558,6 +566,8 @@ static struct patch *get_patch(struct origin *parent, struct origin *origin)
>  	if (!file_p.ptr || !file_o.ptr)
>  		return NULL;
>  	patch = compare_buffer(&file_p, &file_o, 0);
> +	drop_origin_blob(parent);
> +	drop_origin_blob(origin);
>  	num_get_patch++;
>  	return patch;
>  }

While this should be safe (because the user of blob lazily re-fetches), it feels a bit too aggressive, especially when -C or other "retry and try harder to assign blame elsewhere" option is used.

Instead, how about discarding after we are done with each origin, like this?

---
 builtin-blame.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/builtin-blame.c b/builtin-blame.c
index c158d31..eda79d0 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -130,6 +130,14 @@ static void origin_decref(struct origin *o)
 	}
 }
 
+static void drop_origin_blob(struct origin *o)
+{
+	if (o->file.ptr) {
+		free(o->file.ptr);
+		o->file.ptr = NULL;
+	}
+}
+
 /*
  * Each group of lines is described by a blame_entry; it can be split
  * as we pass blame to the parents.  They form a linked list in the
@@ -1274,8 +1282,13 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
 		}
 
  finish:
-	for (i = 0; i < MAXPARENT; i++)
-		origin_decref(parent_origin[i]);
+	for (i = 0; i < MAXPARENT; i++) {
+		if (parent_origin[i]) {
+			drop_origin_blob(parent_origin[i]);
+			origin_decref(parent_origin[i]);
+		}
+	}
+	drop_origin_blob(origin);
 }
 
 /*
Previous: Linus TorvaldsNext: Linus Torvalds
Message 33 of 51 in “git annotate runs out of memory”
  1. Daniel BerlinDec 11, 2007
  2. Nicolas PitreDec 11, 2007
  3. Daniel BerlinDec 11, 2007
  4. Nicolas PitreDec 11, 2007
  5. Marco CostalbaDec 11, 2007
  6. Daniel BerlinDec 11, 2007
  7. Marco CostalbaDec 11, 2007
  8. Jason SewallDec 11, 2007
  9. Daniel BarkalowDec 11, 2007
  10. Marco CostalbaDec 11, 2007
  11. Linus TorvaldsDec 11, 2007
  12. Matthieu MoyDec 11, 2007
  13. Linus TorvaldsDec 11, 2007
  14. Daniel BerlinDec 11, 2007
  15. Pierre HabouzitDec 11, 2007
  16. Daniel BerlinDec 11, 2007
  17. Matthieu MoyDec 11, 2007
  18. Linus TorvaldsDec 11, 2007
  19. Nicolas PitreDec 11, 2007
  20. Jon SmirlDec 11, 2007
  21. Daniel BerlinDec 11, 2007
  22. Daniel BarkalowDec 11, 2007
  23. Pierre HabouzitDec 11, 2007
  24. Junio C HamanoDec 11, 2007
  25. Linus TorvaldsDec 11, 2007
  26. Linus TorvaldsDec 11, 2007
  27. Daniel BerlinDec 11, 2007
  28. Linus TorvaldsDec 11, 2007
  29. Jeff KingDec 12, 2007
  30. Jan HudecDec 17, 2007
  31. Linus TorvaldsDec 18, 2007
  32. Linus TorvaldsDec 11, 2007
  33. Junio C HamanoDec 11, 2007
  34. Linus TorvaldsDec 11, 2007
  35. Linus TorvaldsDec 12, 2007
  36. Davide LibenziDec 12, 2007
  37. Linus TorvaldsDec 12, 2007
  38. Davide LibenziDec 12, 2007
  39. Linus TorvaldsDec 12, 2007
  40. Linus TorvaldsDec 12, 2007
  41. Junio C HamanoDec 12, 2007
  42. Linus TorvaldsDec 12, 2007
  43. Linus TorvaldsDec 12, 2007
  44. Daniel BerlinDec 12, 2007
  45. Junio C HamanoDec 12, 2007
  46. Daniel BerlinDec 11, 2007
  47. Shawn O. PearceDec 12, 2007
  48. Marco CostalbaDec 11, 2007
  49. Steven GrimmDec 11, 2007
  50. Jakub NarebskiDec 11, 2007
  51. Florian WeimerDec 12, 2007

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.