From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-5.6 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 730141FF76 for ; Tue, 20 Dec 2016 21:04:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753964AbcLTVE4 (ORCPT ); Tue, 20 Dec 2016 16:04:56 -0500 Received: from ns332406.ip-37-187-123.eu ([37.187.123.207]:46586 "EHLO glandium.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750927AbcLTVEz (ORCPT ); Tue, 20 Dec 2016 16:04:55 -0500 Received: from glandium by mitsuha.glandium.org with local (Exim 4.88) (envelope-from ) id 1cJRaa-0008OF-2q; Wed, 21 Dec 2016 06:04:48 +0900 From: Mike Hommey To: gitster@pobox.com Cc: git@vger.kernel.org, johan@herland.net Subject: [PATCH] fast-import: properly fanout notes when tree is imported Date: Wed, 21 Dec 2016 06:04:48 +0900 Message-Id: <20161220210448.32213-1-mh@glandium.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 = 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 --- fast-import.c | 8 +++++--- t/t9301-fast-import-notes.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/fast-import.c b/fast-import.c index cb545d7df5..5e528b1999 100644 --- a/fast-import.c +++ b/fast-import.c @@ -2220,13 +2220,17 @@ static uintmax_t do_change_note_fanout( char *fullpath, unsigned int fullpath_len, unsigned char fanout) { - struct tree_content *t = root->tree; + struct tree_content *t; 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]; + if (!root->tree) + load_tree(root); + t = root->tree; + for (i = 0; t && i < t->entry_count; i++) { e = t->entries[i]; tmp_hex_sha1_len = hex_sha1_len + e->name->str_len; @@ -2278,8 +2282,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); diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh index 83acf68bc3..dadc70b7d5 100755 --- a/t/t9301-fast-import-notes.sh +++ b/t/t9301-fast-import-notes.sh @@ -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 < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data <>expect_non-note1 << EOF This is not a note, but rather a regular file residing in a notes tree EOF -- 2.11.0