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

[RFC/PATCHv0 1/4] fast-import.c:do_change_note_fanout(): Remove unneeded local var 't'

From
Johan Herland <johan@herland.net>
Date
Jan 5, 2015, 03:39 UTC
Message-ID
<1420429178-20336-1-git-send-email-johan@herland.net>
In-Reply-To
<CALKQrgdVp7cLER2DQxwdFT82Y=Pamrx6=oa3bY=X7mWy_r3QWA@mail.gmail.com>

The struct tree_content *t variable was used as a shorthand for the given root->tree, but it was only used in the first two lines of the for loop, so the shorthand itself does not add much value. Furthermore, since the for loop body might end up reallocating root->tree we had to reinitialize t at the end of the for loop body, which is ugly and brittle.

Simply use root->tree directly instead, and remote the t shorthand.
Signed-off-by: Johan Herland <johan@herland.net>
---
 fast-import.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index d0bd285..04dfd50 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2153,15 +2153,14 @@ static uintmax_t do_change_note_fanout(
 		char *fullpath, unsigned int fullpath_len,
 		unsigned char fanout)
 {
-	struct tree_content *t = root->tree;
 	struct tree_entry *e, leaf;
 	unsigned int i, tmp_hex_sha1_len, tmp_fullpath_len;
 	uintmax_t num_notes = 0;
 	unsigned char sha1[20];
 	char realpath[60];
 
-	for (i = 0; t && i < t->entry_count; i++) {
-		e = t->entries[i];
+	for (i = 0; root->tree && i < root->tree->entry_count; i++) {
+		e = root->tree->entries[i];
 		tmp_hex_sha1_len = hex_sha1_len + e->name->str_len;
 		tmp_fullpath_len = fullpath_len;
 
@@ -2217,9 +2216,6 @@ static uintmax_t do_change_note_fanout(
 				hex_sha1, tmp_hex_sha1_len,
 				fullpath, tmp_fullpath_len, fanout);
 		}
-
-		/* The above may have reallocated the current tree_content */
-		t = root->tree;
 	}
 	return num_notes;
 }
-- 
2.1.1.392.g062cc5d
Previous: Johan HerlandNext: Johan Herland
Message 2 of 5 in “Re: fast-import's notemodify doesn't work the same as git notes”
  1. Johan HerlandJan 5, 2015
  2. 1/4 fast-import.c:do_change_note_fanout(): Remove unneeded local var 't'Johan Herland, Jan 5, 2015
  3. 2/4 fast-import.c:do_change_note_fanout(): Also apply load_tree() to initial rootJohan Herland, Jan 5, 2015
  4. 3/4 fast-import: Support adding notes to non-commitsJohan Herland, Jan 5, 2015
  5. 4/4 fast-import.c:note_change_n(): Rename commit_* to target_*Johan Herland, Jan 5, 2015

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.