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

[PATCH 01/12] blame: use commit-slab for blame suspects instead of commit->util

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
May 12, 2018, 08:00 UTC
Message-ID
<20180512080028.29611-2-pclouds@gmail.com>
In-Reply-To
<20180512080028.29611-1-pclouds@gmail.com>

It's done so that commit->util can be removed. See more explanation in the commit that removes commit->util.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 blame.c         | 42 +++++++++++++++++++++++++++++++-----------
 blame.h         |  2 ++
 builtin/blame.c |  2 +-
 3 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/blame.c b/blame.c
index 78c9808bd1..18e8bd996a 100644
--- a/blame.c
+++ b/blame.c
@@ -6,6 +6,24 @@
 #include "diffcore.h"
 #include "tag.h"
 #include "blame.h"
+#include "commit-slab.h"
+
+define_commit_slab(blame_suspects, struct blame_origin *);
+static struct blame_suspects blame_suspects;
+
+struct blame_origin *get_blame_suspects(struct commit *commit)
+{
+	struct blame_origin **result;
+
+	result = blame_suspects_peek(&blame_suspects, commit);
+
+	return result ? *result : NULL;
+}
+
+static void set_blame_suspects(struct commit *commit, struct blame_origin *origin)
+{
+	*blame_suspects_at(&blame_suspects, commit) = origin;
+}
 
 void blame_origin_decref(struct blame_origin *o)
 {
@@ -15,12 +33,12 @@ void blame_origin_decref(struct blame_origin *o)
 			blame_origin_decref(o->previous);
 		free(o->file.ptr);
 		/* Should be present exactly once in commit chain */
-		for (p = o->commit->util; p; l = p, p = p->next) {
+		for (p = get_blame_suspects(o->commit); p; l = p, p = p->next) {
 			if (p == o) {
 				if (l)
 					l->next = p->next;
 				else
-					o->commit->util = p->next;
+					set_blame_suspects(o->commit, p->next);
 				free(o);
 				return;
 			}
@@ -41,8 +59,8 @@ static struct blame_origin *make_origin(struct commit *commit, const char *path)
 	FLEX_ALLOC_STR(o, path, path);
 	o->commit = commit;
 	o->refcnt = 1;
-	o->next = commit->util;
-	commit->util = o;
+	o->next = get_blame_suspects(commit);
+	set_blame_suspects(commit, o);
 	return o;
 }
 
@@ -54,13 +72,13 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
 {
 	struct blame_origin *o, *l;
 
-	for (o = commit->util, l = NULL; o; l = o, o = o->next) {
+	for (o = get_blame_suspects(commit), l = NULL; o; l = o, o = o->next) {
 		if (!strcmp(o->path, path)) {
 			/* bump to front */
 			if (l) {
 				l->next = o->next;
-				o->next = commit->util;
-				commit->util = o;
+				o->next = get_blame_suspects(commit);
+				set_blame_suspects(commit, o);
 			}
 			return blame_origin_incref(o);
 		}
@@ -478,7 +496,7 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
 		porigin->suspects = blame_merge(porigin->suspects, sorted);
 	else {
 		struct blame_origin *o;
-		for (o = porigin->commit->util; o; o = o->next) {
+		for (o = get_blame_suspects(porigin->commit); o; o = o->next) {
 			if (o->suspects) {
 				porigin->suspects = sorted;
 				return;
@@ -525,7 +543,7 @@ static struct blame_origin *find_origin(struct commit *parent,
 	const char *paths[2];
 
 	/* First check any existing origins */
-	for (porigin = parent->util; porigin; porigin = porigin->next)
+	for (porigin = get_blame_suspects(parent); porigin; porigin = porigin->next)
 		if (!strcmp(porigin->path, origin->path)) {
 			/*
 			 * The same path between origin and its parent
@@ -1550,7 +1568,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)
 
 	while (commit) {
 		struct blame_entry *ent;
-		struct blame_origin *suspect = commit->util;
+		struct blame_origin *suspect = get_blame_suspects(commit);
 
 		/* find one suspect to break down */
 		while (suspect && !suspect->suspects)
@@ -1752,6 +1770,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
 	struct commit *final_commit = NULL;
 	enum object_type type;
 
+	init_blame_suspects(&blame_suspects);
+
 	if (sb->reverse && sb->contents_from)
 		die(_("--contents and --reverse do not blend well."));
 
@@ -1815,7 +1835,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
 	}
 
 	if (is_null_oid(&sb->final->object.oid)) {
-		o = sb->final->util;
+		o = get_blame_suspects(sb->final);
 		sb->final_buf = xmemdupz(o->file.ptr, o->file.size);
 		sb->final_buf_size = o->file.size;
 	}
diff --git a/blame.h b/blame.h
index a6c915c277..2092f9529c 100644
--- a/blame.h
+++ b/blame.h
@@ -172,4 +172,6 @@ extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path, stru
 
 extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
 
+extern struct blame_origin *get_blame_suspects(struct commit *commit);
+
 #endif /* BLAME_H */
diff --git a/builtin/blame.c b/builtin/blame.c
index db38c0b307..969572810d 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -457,7 +457,7 @@ static void output(struct blame_scoreboard *sb, int option)
 			struct commit *commit = ent->suspect->commit;
 			if (commit->object.flags & MORE_THAN_ONE_PATH)
 				continue;
-			for (suspect = commit->util; suspect; suspect = suspect->next) {
+			for (suspect = get_blame_suspects(commit); suspect; suspect = suspect->next) {
 				if (suspect->guilty && count++) {
 					commit->object.flags |= MORE_THAN_ONE_PATH;
 					break;
-- 
2.17.0.705.g3525833791
Previous: Nguyễn Thái Ngọc DuyNext: Jeff King
Message 18 of 82 in “Die commit->util, die!”
  1. 00/12 Die commit->util, die!Nguyễn Thái Ngọc Duy, May 12, 2018
  2. 02/12 describe: use commit-slab for commit names instead of commit->utilNguyễn Thái Ngọc Duy, May 12, 2018
  3. 05/12 sequencer.c: use commit-slab to associate todo items to commitsNguyễn Thái Ngọc Duy, May 12, 2018
  4. Jeff KingMay 12, 2018
  5. 04/12 sequencer.c: use commit-slab to mark seen commitsNguyễn Thái Ngọc Duy, May 12, 2018
  6. Jeff KingMay 12, 2018
  7. Junio C HamanoMay 12, 2018
  8. Duy NguyenMay 12, 2018
  9. 06/12 revision.c: use commit-slab for show_sourceNguyễn Thái Ngọc Duy, May 12, 2018
  10. Jeff KingMay 12, 2018
  11. Junio C HamanoMay 12, 2018
  12. Duy NguyenMay 12, 2018
  13. Jeff KingMay 12, 2018
  14. 10/12 log: use commit-slab in prepare_bases() instead of commit->utilNguyễn Thái Ngọc Duy, May 12, 2018
  15. 12/12 commit.h: delete 'util' field in struct commitNguyễn Thái Ngọc Duy, May 12, 2018
  16. 11/12 merge: use commit-slab in merge remote desc instead of commit->utilNguyễn Thái Ngọc Duy, May 12, 2018
  17. 09/12 show-branch: use commit-slab for commit-name instead of commit->utilNguyễn Thái Ngọc Duy, May 12, 2018
  18. 01/12 blame: use commit-slab for blame suspects instead of commit->utilNguyễn Thái Ngọc Duy, May 12, 2018
  19. Jeff KingMay 12, 2018
  20. Duy NguyenMay 12, 2018
  21. 07/12 bisect.c: use commit-slab for commit weight instead of commit->utilNguyễn Thái Ngọc Duy, May 12, 2018
  22. Junio C HamanoMay 12, 2018
  23. 08/12 name-rev: use commit-slab for rev-name instead of commit->utilNguyễn Thái Ngọc Duy, May 12, 2018
  24. 03/12 shallow.c: use commit-slab for commit depth instead of commit->utilNguyễn Thái Ngọc Duy, May 12, 2018
  25. Jeff KingMay 12, 2018
  26. Jeff KingMay 12, 2018
  27. Duy NguyenMay 12, 2018
  28. Jeff KingMay 12, 2018
  29. Duy NguyenMay 12, 2018
  30. Jeff KingMay 12, 2018
  31. Jakub NarebskiMay 12, 2018
  32. Duy NguyenMay 13, 2018
  33. 00/14 Die commit->util, die!Nguyễn Thái Ngọc Duy, May 13, 2018
  34. 01/14 commit-slab.h: code splitNguyễn Thái Ngọc Duy, May 13, 2018
  35. Junio C HamanoMay 13, 2018
  36. 02/14 commit-slab: support shared commit-slabNguyễn Thái Ngọc Duy, May 13, 2018
  37. Junio C HamanoMay 13, 2018
  38. 03/14 blame: use commit-slab for blame suspects instead of commit->utilNguyễn Thái Ngọc Duy, May 13, 2018
  39. Junio C HamanoMay 13, 2018
  40. 06/14 sequencer.c: use commit-slab to mark seen commitsNguyễn Thái Ngọc Duy, May 13, 2018
  41. Junio C HamanoMay 14, 2018
  42. 12/14 log: use commit-slab in prepare_bases() instead of commit->utilNguyễn Thái Ngọc Duy, May 13, 2018
  43. 07/14 sequencer.c: use commit-slab to associate todo items to commitsNguyễn Thái Ngọc Duy, May 13, 2018
  44. 14/14 commit.h: delete 'util' field in struct commitNguyễn Thái Ngọc Duy, May 13, 2018
  45. Junio C HamanoMay 14, 2018
  46. Duy NguyenMay 14, 2018
  47. Duy NguyenMay 14, 2018
  48. Derrick StoleeMay 14, 2018
  49. Duy NguyenMay 19, 2018
  50. 08/14 revision.c: use commit-slab for show_sourceNguyễn Thái Ngọc Duy, May 13, 2018
  51. Junio C HamanoMay 14, 2018
  52. Junio C HamanoMay 14, 2018
  53. 13/14 merge: use commit-slab in merge remote desc instead of commit->utilNguyễn Thái Ngọc Duy, May 13, 2018
  54. Junio C HamanoMay 18, 2018
  55. Ramsay JonesMay 18, 2018
  56. 11/14 show-branch: use commit-slab for commit-name instead of commit->utilNguyễn Thái Ngọc Duy, May 13, 2018
  57. Junio C HamanoMay 14, 2018
  58. Duy NguyenMay 19, 2018
  59. 09/14 bisect.c: use commit-slab for commit weight instead of commit->utilNguyễn Thái Ngọc Duy, May 13, 2018
  60. Junio C HamanoMay 14, 2018
  61. 05/14 shallow.c: use commit-slab for commit depth instead of commit->utilNguyễn Thái Ngọc Duy, May 13, 2018
  62. 10/14 name-rev: use commit-slab for rev-name instead of commit->utilNguyễn Thái Ngọc Duy, May 13, 2018
  63. 04/14 describe: use commit-slab for commit names instead of commit->utilNguyễn Thái Ngọc Duy, May 13, 2018
  64. Junio C HamanoMay 13, 2018
  65. 00/15 Die commit->util, die!Nguyễn Thái Ngọc Duy, May 19, 2018
  66. 01/15 commit-slab.h: code splitNguyễn Thái Ngọc Duy, May 19, 2018
  67. Junio C HamanoMay 21, 2018
  68. 02/15 commit-slab: support shared commit-slabNguyễn Thái Ngọc Duy, May 19, 2018
  69. 04/15 describe: use commit-slab for commit names instead of commit->utilNguyễn Thái Ngọc Duy, May 19, 2018
  70. 08/15 revision.c: use commit-slab for show_sourceNguyễn Thái Ngọc Duy, May 19, 2018
  71. 09/15 bisect.c: use commit-slab for commit weight instead of commit->utilNguyễn Thái Ngọc Duy, May 19, 2018
  72. 07/15 sequencer.c: use commit-slab to associate todo items to commitsNguyễn Thái Ngọc Duy, May 19, 2018
  73. 13/15 log: use commit-slab in prepare_bases() instead of commit->utilNguyễn Thái Ngọc Duy, May 19, 2018
  74. 15/15 commit.h: delete 'util' field in struct commitNguyễn Thái Ngọc Duy, May 19, 2018
  75. 14/15 merge: use commit-slab in merge remote desc instead of commit->utilNguyễn Thái Ngọc Duy, May 19, 2018
  76. 06/15 sequencer.c: use commit-slab to mark seen commitsNguyễn Thái Ngọc Duy, May 19, 2018
  77. 12/15 show-branch: note about its object flags usageNguyễn Thái Ngọc Duy, May 19, 2018
  78. 11/15 show-branch: use commit-slab for commit-name instead of commit->utilNguyễn Thái Ngọc Duy, May 19, 2018
  79. 10/15 name-rev: use commit-slab for rev-name instead of commit->utilNguyễn Thái Ngọc Duy, May 19, 2018
  80. 03/15 blame: use commit-slab for blame suspects instead of commit->utilNguyễn Thái Ngọc Duy, May 19, 2018
  81. 05/15 shallow.c: use commit-slab for commit depth instead of commit->utilNguyễn Thái Ngọc Duy, May 19, 2018
  82. Stefan BellerMay 22, 2018

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.