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 2/4] fast-import.c:do_change_note_fanout(): Also apply load_tree() to initial root
Date: Mon, 5 Jan 2015 04:39:36 +0100 [thread overview]
Message-ID: <1420429178-20336-2-git-send-email-johan@herland.net> (raw)
In-Reply-To: <1420429178-20336-1-git-send-email-johan@herland.net>
TODO: tests!
do_change_note_fanout() recursively traverses a "struct tree_entry" data
structure. Before recursively traversing into a subtree, we make sure to
call load_tree() on that subtree. However, for the initial/root struct
tree_entry object, we assumed that load_tree() had already been invoked by
our caller. This is true, except in the following case:
If we load a previously written notes tree using 'filemodify' instead of
'from' [1], then we do not pass the notes ref to load_branch() (which
takes care of calling load_tree() on the root tree_entry).
When load_tree(root) has not been called before the first 'notemodify'
command is parsed, the for loop in do_change_note_fanout() does nothing,
and we end up not counting the existing notes, which ends up producing
a notes tree with mixed/insufficient fanout.
Fix this by always making sure to call load_tree() at the start of
do_change_note_fanout(). Since load_tree() is now called before the for loop,
we no longer need to call load_tree() on a subtree before recursing into it,
the recursive call will take care of its own load_tree().
[1]: Usually, when adding notes to an existing notes tree, one would use a
'from' command like this:
from refs/notes/foo^0
However, if one does not want to retain notes history (i.e. one wants
the current refs/notes/foo commit to be build without any parents),
then one can replace the 'from' command with the following 'filemodify'
"hack" to pre-load the existing notes tree without using it as a parent:
M 040000 refs/notes/foo^{tree} \n
Discovered-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Johan Herland <johan@herland.net>
---
fast-import.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 04dfd50..aa7b64e 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2159,6 +2159,9 @@ static uintmax_t do_change_note_fanout(
unsigned char sha1[20];
char realpath[60];
+ if (!root->tree)
+ load_tree(root);
+
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;
@@ -2210,8 +2213,6 @@ static uintmax_t do_change_note_fanout(
leaf.tree);
} else if (S_ISDIR(e->versions[1].mode)) {
/* This is a subdir that may contain note entries */
- if (!e->tree)
- load_tree(e);
num_notes += do_change_note_fanout(orig_root, e,
hex_sha1, tmp_hex_sha1_len,
fullpath, tmp_fullpath_len, fanout);
--
2.1.1.392.g062cc5d
next prev parent 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 ` [RFC/PATCHv0 1/4] fast-import.c:do_change_note_fanout(): Remove unneeded local var 't' Johan Herland
2015-01-05 3:39 ` Johan Herland [this message]
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-2-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).