fast-import: properly fanout notes when tree is imported

In typical uses of fast-import, trees are inherited from a parent
commit. In that case, the tree_entry for the branch looks like:

  .versions[1].sha1 = $some_sha1
  .tree = <tree structure loaded from $some_sha1>

However, when trees are imported, rather than inherited, that is not the
case. One can import a tree with a filemodify command, replacing the
root tree object.

e.g.
  "M 040000 $some_sha1 \n"

In this case, the tree_entry for the branch looks like:

  .versions[1].sha1 = $some_sha1
  .tree = NULL

When adding new notes with the notemodify command, do_change_note_fanout
is called to get a notes count, and to do so, it loops over the
tree_entry->tree, but doesn't do anything when the tree is NULL.

In the latter case above, it means do_change_note_fanout thinks the tree
contains no notes, and new notes are added with no fanout.

Interestingly, do_change_note_fanout does check whether subdirectories
have a NULL .tree, in which case it uses load_tree(). Which means the
right behaviour happens when using the filemodify command to import
subdirectories.

This change makes do_change_note_fanount call load_tree() whenever the
tree_entry it is given has no tree loaded, making all cases handled
equally.

Signed-off-by: Mike Hommey <mh@glandium.org>
Reviewed-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Mike Hommey
2016-12-21 06:04:48 +09:00
committed by Junio C Hamano
parent a274e0a036
commit 405d7f4af6
2 changed files with 47 additions and 3 deletions

View File

@ -483,6 +483,48 @@ test_expect_success 'verify that lots of notes trigger a fanout scheme' '
'
# Create another notes tree from the one above
SP=" "
cat >>input <<INPUT_END
commit refs/heads/other_commits
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
data <<COMMIT
commit #$(($num_commit + 1))
COMMIT
from refs/heads/many_commits
M 644 inline file
data <<EOF
file contents in commit #$(($num_commit + 1))
EOF
commit refs/notes/other_notes
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
data <<COMMIT
committing one more note on a tree imported from a previous notes tree
COMMIT
M 040000 $(git log --no-walk --format=%T refs/notes/many_notes)$SP
N inline :$(($num_commit + 1))
data <<EOF
note for commit #$(($num_commit + 1))
EOF
INPUT_END
test_expect_success 'verify that importing a notes tree respects the fanout scheme' '
git fast-import <input &&
# None of the entries in the top-level notes tree should be a full SHA1
git ls-tree --name-only refs/notes/other_notes |
while read path
do
if test $(expr length "$path") -ge 40
then
return 1
fi
done
'
cat >>expect_non-note1 << EOF
This is not a note, but rather a regular file residing in a notes tree
EOF