git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Herland <johan@herland.net>
To: Mike Hommey <mh@glandium.org>
Cc: Git mailing list <git@vger.kernel.org>,
	Johan Herland <johan@herland.net>
Subject: [RFC/PATCHv0 1/4] fast-import.c:do_change_note_fanout(): Remove unneeded local var 't'
Date: Mon,  5 Jan 2015 04:39:35 +0100	[thread overview]
Message-ID: <1420429178-20336-1-git-send-email-johan@herland.net> (raw)
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

  reply	other threads:[~2015-01-05  3:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-23  0:06 fast-import's notemodify doesn't work the same as git notes Mike Hommey
2015-01-05  3:37 ` Johan Herland
2015-01-05  3:39   ` Johan Herland [this message]
2015-01-05  3:39     ` [RFC/PATCHv0 2/4] fast-import.c:do_change_note_fanout(): Also apply load_tree() to initial root Johan Herland
2015-01-05  3:39     ` [RFC/PATCHv0 3/4] fast-import: Support adding notes to non-commits Johan Herland
2015-01-05  3:39     ` [RFC/PATCHv0 4/4] fast-import.c:note_change_n(): Rename commit_* to target_* Johan Herland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420429178-20336-1-git-send-email-johan@herland.net \
    --to=johan@herland.net \
    --cc=git@vger.kernel.org \
    --cc=mh@glandium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).