From 2a113aee9ba6ba55fc9a4c714efc958ab0de6510 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Mon, 7 Dec 2009 12:27:24 +0100 Subject: fast-import: Proper notes tree manipulation This patch teaches 'git fast-import' to automatically organize note objects in a fast-import stream into an appropriate fanout structure. The notes API in notes.h is NOT used to accomplish this, because trying to keep the fast-import and notes data structures in sync would yield a significantly larger patch with higher complexity. Note objects are added with the 'N' command, and accounted for with a per-branch counter, which is used to trigger fanout restructuring when needed. Note that when restructuring the branch tree, _any_ entry whose path consists of 40 hex chars (not including directory separators) will be recognized as a note object. It is therefore not advisable to manipulate note entries with M/D/R/C commands. Since note objects are stored in the same tree structure as other objects, the unloading and reloading of a fast-import branches handle note objects transparently. This patch has been improved by the following contributions: - Shawn O. Pearce: Several style- and logic-related improvements Cc: Shawn O. Pearce Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- fast-import.c | 134 ++++++++++++++++++++++++++++++++++++++++-- t/t9300-fast-import.sh | 156 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 272 insertions(+), 18 deletions(-) diff --git a/fast-import.c b/fast-import.c index dd3c99d60..f04cd1751 100644 --- a/fast-import.c +++ b/fast-import.c @@ -245,6 +245,7 @@ struct branch const char *name; struct tree_entry branch_tree; uintmax_t last_commit; + uintmax_t num_notes; unsigned active : 1; unsigned pack_id : PACK_ID_BITS; unsigned char sha1[20]; @@ -693,6 +694,7 @@ static struct branch *new_branch(const char *name) b->table_next_branch = branch_table[hc]; b->branch_tree.versions[0].mode = S_IFDIR; b->branch_tree.versions[1].mode = S_IFDIR; + b->num_notes = 0; b->active = 0; b->pack_id = MAX_PACK_ID; branch_table[hc] = b; @@ -1860,6 +1862,109 @@ static void load_branch(struct branch *b) } } +static unsigned char convert_num_notes_to_fanout(uintmax_t num_notes) +{ + unsigned char fanout = 0; + while ((num_notes >>= 8)) + fanout++; + return fanout; +} + +static void construct_path_with_fanout(const char *hex_sha1, + unsigned char fanout, char *path) +{ + unsigned int i = 0, j = 0; + if (fanout >= 20) + die("Too large fanout (%u)", fanout); + while (fanout) { + path[i++] = hex_sha1[j++]; + path[i++] = hex_sha1[j++]; + path[i++] = '/'; + fanout--; + } + memcpy(path + i, hex_sha1 + j, 40 - j); + path[i + 40 - j] = '\0'; +} + +static uintmax_t do_change_note_fanout( + struct tree_entry *orig_root, struct tree_entry *root, + char *hex_sha1, unsigned int hex_sha1_len, + 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]; + tmp_hex_sha1_len = hex_sha1_len + e->name->str_len; + tmp_fullpath_len = fullpath_len; + + /* + * We're interested in EITHER existing note entries (entries + * with exactly 40 hex chars in path, not including directory + * separators), OR directory entries that may contain note + * entries (with < 40 hex chars in path). + * Also, each path component in a note entry must be a multiple + * of 2 chars. + */ + if (!e->versions[1].mode || + tmp_hex_sha1_len > 40 || + e->name->str_len % 2) + continue; + + /* This _may_ be a note entry, or a subdir containing notes */ + memcpy(hex_sha1 + hex_sha1_len, e->name->str_dat, + e->name->str_len); + if (tmp_fullpath_len) + fullpath[tmp_fullpath_len++] = '/'; + memcpy(fullpath + tmp_fullpath_len, e->name->str_dat, + e->name->str_len); + tmp_fullpath_len += e->name->str_len; + fullpath[tmp_fullpath_len] = '\0'; + + if (tmp_hex_sha1_len == 40 && !get_sha1_hex(hex_sha1, sha1)) { + /* This is a note entry */ + construct_path_with_fanout(hex_sha1, fanout, realpath); + if (!strcmp(fullpath, realpath)) { + /* Note entry is in correct location */ + num_notes++; + continue; + } + + /* Rename fullpath to realpath */ + if (!tree_content_remove(orig_root, fullpath, &leaf)) + die("Failed to remove path %s", fullpath); + tree_content_set(orig_root, realpath, + leaf.versions[1].sha1, + leaf.versions[1].mode, + 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); + } + + /* The above may have reallocated the current tree_content */ + t = root->tree; + } + return num_notes; +} + +static uintmax_t change_note_fanout(struct tree_entry *root, + unsigned char fanout) +{ + char hex_sha1[40], path[60]; + return do_change_note_fanout(root, root, hex_sha1, 0, path, 0, fanout); +} + static void file_change_m(struct branch *b) { const char *p = command_buf.buf + 2; @@ -2010,14 +2115,16 @@ static void file_change_cr(struct branch *b, int rename) leaf.tree); } -static void note_change_n(struct branch *b) +static void note_change_n(struct branch *b, unsigned char old_fanout) { const char *p = command_buf.buf + 2; static struct strbuf uq = STRBUF_INIT; struct object_entry *oe = oe; struct branch *s; unsigned char sha1[20], commit_sha1[20]; + char path[60]; uint16_t inline_data = 0; + unsigned char new_fanout; /* or 'inline' */ if (*p == ':') { @@ -2071,7 +2178,7 @@ static void note_change_n(struct branch *b) if (oe->type != OBJ_BLOB) die("Not a blob (actually a %s): %s", typename(oe->type), command_buf.buf); - } else { + } else if (!is_null_sha1(sha1)) { enum object_type type = sha1_object_info(sha1, NULL); if (type < 0) die("Blob not found: %s", command_buf.buf); @@ -2080,8 +2187,17 @@ static void note_change_n(struct branch *b) typename(type), command_buf.buf); } - tree_content_set(&b->branch_tree, sha1_to_hex(commit_sha1), sha1, - S_IFREG | 0644, NULL); + construct_path_with_fanout(sha1_to_hex(commit_sha1), old_fanout, path); + if (tree_content_remove(&b->branch_tree, path, NULL)) + b->num_notes--; + + if (is_null_sha1(sha1)) + return; /* nothing to insert */ + + b->num_notes++; + new_fanout = convert_num_notes_to_fanout(b->num_notes); + construct_path_with_fanout(sha1_to_hex(commit_sha1), new_fanout, path); + tree_content_set(&b->branch_tree, path, sha1, S_IFREG | 0644, NULL); } static void file_change_deleteall(struct branch *b) @@ -2090,6 +2206,7 @@ static void file_change_deleteall(struct branch *b) hashclr(b->branch_tree.versions[0].sha1); hashclr(b->branch_tree.versions[1].sha1); load_tree(&b->branch_tree); + b->num_notes = 0; } static void parse_from_commit(struct branch *b, char *buf, unsigned long size) @@ -2213,6 +2330,7 @@ static void parse_new_commit(void) char *committer = NULL; struct hash_list *merge_list = NULL; unsigned int merge_count; + unsigned char prev_fanout, new_fanout; /* Obtain the branch name from the rest of our command */ sp = strchr(command_buf.buf, ' ') + 1; @@ -2243,6 +2361,8 @@ static void parse_new_commit(void) load_branch(b); } + prev_fanout = convert_num_notes_to_fanout(b->num_notes); + /* file_change* */ while (command_buf.len > 0) { if (!prefixcmp(command_buf.buf, "M ")) @@ -2254,7 +2374,7 @@ static void parse_new_commit(void) else if (!prefixcmp(command_buf.buf, "C ")) file_change_cr(b, 0); else if (!prefixcmp(command_buf.buf, "N ")) - note_change_n(b); + note_change_n(b, prev_fanout); else if (!strcmp("deleteall", command_buf.buf)) file_change_deleteall(b); else { @@ -2265,6 +2385,10 @@ static void parse_new_commit(void) break; } + new_fanout = convert_num_notes_to_fanout(b->num_notes); + if (new_fanout != prev_fanout) + b->num_notes = change_note_fanout(&b->branch_tree, new_fanout); + /* build the tree and the commit */ store_tree(&b->branch_tree); hashcpy(b->branch_tree.versions[0].sha1, diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index b49815d10..bf8c50902 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -1092,9 +1092,12 @@ test_expect_success 'P: fail on blob mark in gitlink' ' ### series Q (notes) ### -note1_data="Note for the first commit" -note2_data="Note for the second commit" -note3_data="Note for the third commit" +note1_data="The first note for the first commit" +note2_data="The first note for the second commit" +note3_data="The first note for the third commit" +note1b_data="The second note for the first commit" +note1c_data="The third note for the first commit" +note2b_data="The second note for the second commit" test_tick cat >input < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE notes (:9) EOF test_expect_success \ - 'Q: verify notes commit' \ - 'git cat-file commit refs/notes/foobar | sed 1d >actual && + 'Q: verify first notes commit' \ + 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual && test_cmp expect actual' cat >expect.unsorted <expect.unsorted <expect test_expect_success \ - 'Q: verify notes tree' \ - 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual && + 'Q: verify first notes tree' \ + 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual' echo "$note1_data" >expect test_expect_success \ - 'Q: verify note for first commit' \ - 'git cat-file blob refs/notes/foobar:$commit1 >actual && test_cmp expect actual' + 'Q: verify first note for first commit' \ + 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual' echo "$note2_data" >expect test_expect_success \ - 'Q: verify note for second commit' \ - 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual' + 'Q: verify first note for second commit' \ + 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual' + +echo "$note3_data" >expect +test_expect_success \ + 'Q: verify first note for third commit' \ + 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual' + +cat >expect < $GIT_COMMITTER_DATE +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + +notes (:10) +EOF +test_expect_success \ + 'Q: verify second notes commit' \ + 'git cat-file commit refs/notes/foobar^ | sed 1d >actual && + test_cmp expect actual' + +cat >expect.unsorted <expect +test_expect_success \ + 'Q: verify second notes tree' \ + 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual && + test_cmp expect actual' + +echo "$note1b_data" >expect +test_expect_success \ + 'Q: verify second note for first commit' \ + 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual' + +echo "$note2_data" >expect +test_expect_success \ + 'Q: verify first note for second commit' \ + 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual' echo "$note3_data" >expect test_expect_success \ - 'Q: verify note for third commit' \ - 'git cat-file blob refs/notes/foobar:$commit3 >actual && test_cmp expect actual' + 'Q: verify first note for third commit' \ + 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual' + +cat >expect < $GIT_COMMITTER_DATE +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + +notes (:11) +EOF +test_expect_success \ + 'Q: verify third notes commit' \ + 'git cat-file commit refs/notes/foobar2 | sed 1d >actual && + test_cmp expect actual' + +cat >expect.unsorted <expect +test_expect_success \ + 'Q: verify third notes tree' \ + 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual && + test_cmp expect actual' + +echo "$note1c_data" >expect +test_expect_success \ + 'Q: verify third note for first commit' \ + 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual' + +cat >expect < $GIT_COMMITTER_DATE +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + +notes (:12) +EOF +test_expect_success \ + 'Q: verify fourth notes commit' \ + 'git cat-file commit refs/notes/foobar | sed 1d >actual && + test_cmp expect actual' + +cat >expect.unsorted <expect +test_expect_success \ + 'Q: verify fourth notes tree' \ + 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual && + test_cmp expect actual' + +echo "$note2b_data" >expect +test_expect_success \ + 'Q: verify second note for second commit' \ + 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual' test_done -- cgit v1.2.1 From b2d6b1feafb6a4604b1207c8a6837633de59fdec Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Mon, 7 Dec 2009 12:27:25 +0100 Subject: Rename t9301 to t9350, to make room for more fast-import tests Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- t/t9301-fast-export.sh | 374 ------------------------------------------------- t/t9350-fast-export.sh | 374 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 374 insertions(+), 374 deletions(-) delete mode 100755 t/t9301-fast-export.sh create mode 100755 t/t9350-fast-export.sh diff --git a/t/t9301-fast-export.sh b/t/t9301-fast-export.sh deleted file mode 100755 index 356964e53..000000000 --- a/t/t9301-fast-export.sh +++ /dev/null @@ -1,374 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2007 Johannes E. Schindelin -# - -test_description='git fast-export' -. ./test-lib.sh - -test_expect_success 'setup' ' - - echo break it > file0 && - git add file0 && - test_tick && - echo Wohlauf > file && - git add file && - test_tick && - git commit -m initial && - echo die Luft > file && - echo geht frisch > file2 && - git add file file2 && - test_tick && - git commit -m second && - echo und > file2 && - test_tick && - git commit -m third file2 && - test_tick && - git tag rein && - git checkout -b wer HEAD^ && - echo lange > file2 - test_tick && - git commit -m sitzt file2 && - test_tick && - git tag -a -m valentin muss && - git merge -s ours master - -' - -test_expect_success 'fast-export | fast-import' ' - - MASTER=$(git rev-parse --verify master) && - REIN=$(git rev-parse --verify rein) && - WER=$(git rev-parse --verify wer) && - MUSS=$(git rev-parse --verify muss) && - mkdir new && - git --git-dir=new/.git init && - git fast-export --all | - (cd new && - git fast-import && - test $MASTER = $(git rev-parse --verify refs/heads/master) && - test $REIN = $(git rev-parse --verify refs/tags/rein) && - test $WER = $(git rev-parse --verify refs/heads/wer) && - test $MUSS = $(git rev-parse --verify refs/tags/muss)) - -' - -test_expect_success 'fast-export master~2..master' ' - - git fast-export master~2..master | - sed "s/master/partial/" | - (cd new && - git fast-import && - test $MASTER != $(git rev-parse --verify refs/heads/partial) && - git diff --exit-code master partial && - git diff --exit-code master^ partial^ && - test_must_fail git rev-parse partial~2) - -' - -test_expect_success 'iso-8859-1' ' - - git config i18n.commitencoding ISO8859-1 && - # use author and committer name in ISO-8859-1 to match it. - . "$TEST_DIRECTORY"/t3901-8859-1.txt && - test_tick && - echo rosten >file && - git commit -s -m den file && - git fast-export wer^..wer | - sed "s/wer/i18n/" | - (cd new && - git fast-import && - git cat-file commit i18n | grep "Áéí óú") - -' -test_expect_success 'import/export-marks' ' - - git checkout -b marks master && - git fast-export --export-marks=tmp-marks HEAD && - test -s tmp-marks && - test $(wc -l < tmp-marks) -eq 3 && - test $( - git fast-export --import-marks=tmp-marks\ - --export-marks=tmp-marks HEAD | - grep ^commit | - wc -l) \ - -eq 0 && - echo change > file && - git commit -m "last commit" file && - test $( - git fast-export --import-marks=tmp-marks \ - --export-marks=tmp-marks HEAD | - grep ^commit\ | - wc -l) \ - -eq 1 && - test $(wc -l < tmp-marks) -eq 4 - -' - -cat > signed-tag-import << EOF -tag sign-your-name -from $(git rev-parse HEAD) -tagger C O Mitter 1112911993 -0700 -data 210 -A message for a sign ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.5 (GNU/Linux) - -fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign -aturefakedsignaturefake= -=/59v ------END PGP SIGNATURE----- -EOF - -test_expect_success 'set up faked signed tag' ' - - cat signed-tag-import | git fast-import - -' - -test_expect_success 'signed-tags=abort' ' - - test_must_fail git fast-export --signed-tags=abort sign-your-name - -' - -test_expect_success 'signed-tags=verbatim' ' - - git fast-export --signed-tags=verbatim sign-your-name > output && - grep PGP output - -' - -test_expect_success 'signed-tags=strip' ' - - git fast-export --signed-tags=strip sign-your-name > output && - ! grep PGP output - -' - -test_expect_success 'setup submodule' ' - - git checkout -f master && - mkdir sub && - cd sub && - git init && - echo test file > file && - git add file && - git commit -m sub_initial && - cd .. && - git submodule add "`pwd`/sub" sub && - git commit -m initial && - test_tick && - cd sub && - echo more data >> file && - git add file && - git commit -m sub_second && - cd .. && - git add sub && - git commit -m second - -' - -test_expect_success 'submodule fast-export | fast-import' ' - - SUBENT1=$(git ls-tree master^ sub) && - SUBENT2=$(git ls-tree master sub) && - rm -rf new && - mkdir new && - git --git-dir=new/.git init && - git fast-export --signed-tags=strip --all | - (cd new && - git fast-import && - test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" && - test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" && - git checkout master && - git submodule init && - git submodule update && - cmp sub/file ../sub/file) - -' - -GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME -GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME - -test_expect_success 'setup copies' ' - - git config --unset i18n.commitencoding && - git checkout -b copy rein && - git mv file file3 && - git commit -m move1 && - test_tick && - cp file2 file4 && - git add file4 && - git mv file2 file5 && - git commit -m copy1 && - test_tick && - cp file3 file6 && - git add file6 && - git commit -m copy2 && - test_tick && - echo more text >> file6 && - echo even more text >> file6 && - git add file6 && - git commit -m modify && - test_tick && - cp file6 file7 && - echo test >> file7 && - git add file7 && - git commit -m copy_modify - -' - -test_expect_success 'fast-export -C -C | fast-import' ' - - ENTRY=$(git rev-parse --verify copy) && - rm -rf new && - mkdir new && - git --git-dir=new/.git init && - git fast-export -C -C --signed-tags=strip --all > output && - grep "^C \"file6\" \"file7\"\$" output && - cat output | - (cd new && - git fast-import && - test $ENTRY = $(git rev-parse --verify refs/heads/copy)) - -' - -test_expect_success 'fast-export | fast-import when master is tagged' ' - - git tag -m msg last && - git fast-export -C -C --signed-tags=strip --all > output && - test $(grep -c "^tag " output) = 3 - -' - -cat > tag-content << EOF -object $(git rev-parse HEAD) -type commit -tag rosten -EOF - -test_expect_success 'cope with tagger-less tags' ' - - TAG=$(git hash-object -t tag -w tag-content) && - git update-ref refs/tags/sonnenschein $TAG && - git fast-export -C -C --signed-tags=strip --all > output && - test $(grep -c "^tag " output) = 4 && - ! grep "Unspecified Tagger" output && - git fast-export -C -C --signed-tags=strip --all \ - --fake-missing-tagger > output && - test $(grep -c "^tag " output) = 4 && - grep "Unspecified Tagger" output - -' - -test_expect_success 'setup for limiting exports by PATH' ' - mkdir limit-by-paths && - cd limit-by-paths && - git init && - echo hi > there && - git add there && - git commit -m "First file" && - echo foo > bar && - git add bar && - git commit -m "Second file" && - git tag -a -m msg mytag && - echo morefoo >> bar && - git add bar && - git commit -m "Change to second file" && - cd .. -' - -cat > limit-by-paths/expected << EOF -blob -mark :1 -data 3 -hi - -reset refs/tags/mytag -commit refs/tags/mytag -mark :2 -author A U Thor 1112912713 -0700 -committer C O Mitter 1112912713 -0700 -data 11 -First file -M 100644 :1 there - -EOF - -test_expect_success 'dropping tag of filtered out object' ' - cd limit-by-paths && - git fast-export --tag-of-filtered-object=drop mytag -- there > output && - test_cmp output expected && - cd .. -' - -cat >> limit-by-paths/expected << EOF -tag mytag -from :2 -tagger C O Mitter 1112912713 -0700 -data 4 -msg - -EOF - -test_expect_success 'rewriting tag of filtered out object' ' - cd limit-by-paths && - git fast-export --tag-of-filtered-object=rewrite mytag -- there > output && - test_cmp output expected && - cd .. -' - -cat > limit-by-paths/expected << EOF -blob -mark :1 -data 4 -foo - -blob -mark :2 -data 3 -hi - -reset refs/heads/master -commit refs/heads/master -mark :3 -author A U Thor 1112912713 -0700 -committer C O Mitter 1112912713 -0700 -data 12 -Second file -M 100644 :1 bar -M 100644 :2 there - -EOF - -test_expect_failure 'no exact-ref revisions included' ' - cd limit-by-paths && - git fast-export master~2..master~1 > output && - test_cmp output expected && - cd .. -' - - -test_expect_success 'set-up a few more tags for tag export tests' ' - git checkout -f master && - HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` && - git tag tree_tag -m "tagging a tree" $HEAD_TREE && - git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE && - git tag tag-obj_tag -m "tagging a tag" tree_tag-obj && - git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj -' - -test_expect_success 'tree_tag' ' - mkdir result && - (cd result && git init) && - git fast-export tree_tag > fe-stream && - (cd result && git fast-import < ../fe-stream) -' - -# NEEDSWORK: not just check return status, but validate the output -test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj' -test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag' -test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj' - -test_done diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh new file mode 100755 index 000000000..356964e53 --- /dev/null +++ b/t/t9350-fast-export.sh @@ -0,0 +1,374 @@ +#!/bin/sh +# +# Copyright (c) 2007 Johannes E. Schindelin +# + +test_description='git fast-export' +. ./test-lib.sh + +test_expect_success 'setup' ' + + echo break it > file0 && + git add file0 && + test_tick && + echo Wohlauf > file && + git add file && + test_tick && + git commit -m initial && + echo die Luft > file && + echo geht frisch > file2 && + git add file file2 && + test_tick && + git commit -m second && + echo und > file2 && + test_tick && + git commit -m third file2 && + test_tick && + git tag rein && + git checkout -b wer HEAD^ && + echo lange > file2 + test_tick && + git commit -m sitzt file2 && + test_tick && + git tag -a -m valentin muss && + git merge -s ours master + +' + +test_expect_success 'fast-export | fast-import' ' + + MASTER=$(git rev-parse --verify master) && + REIN=$(git rev-parse --verify rein) && + WER=$(git rev-parse --verify wer) && + MUSS=$(git rev-parse --verify muss) && + mkdir new && + git --git-dir=new/.git init && + git fast-export --all | + (cd new && + git fast-import && + test $MASTER = $(git rev-parse --verify refs/heads/master) && + test $REIN = $(git rev-parse --verify refs/tags/rein) && + test $WER = $(git rev-parse --verify refs/heads/wer) && + test $MUSS = $(git rev-parse --verify refs/tags/muss)) + +' + +test_expect_success 'fast-export master~2..master' ' + + git fast-export master~2..master | + sed "s/master/partial/" | + (cd new && + git fast-import && + test $MASTER != $(git rev-parse --verify refs/heads/partial) && + git diff --exit-code master partial && + git diff --exit-code master^ partial^ && + test_must_fail git rev-parse partial~2) + +' + +test_expect_success 'iso-8859-1' ' + + git config i18n.commitencoding ISO8859-1 && + # use author and committer name in ISO-8859-1 to match it. + . "$TEST_DIRECTORY"/t3901-8859-1.txt && + test_tick && + echo rosten >file && + git commit -s -m den file && + git fast-export wer^..wer | + sed "s/wer/i18n/" | + (cd new && + git fast-import && + git cat-file commit i18n | grep "Áéí óú") + +' +test_expect_success 'import/export-marks' ' + + git checkout -b marks master && + git fast-export --export-marks=tmp-marks HEAD && + test -s tmp-marks && + test $(wc -l < tmp-marks) -eq 3 && + test $( + git fast-export --import-marks=tmp-marks\ + --export-marks=tmp-marks HEAD | + grep ^commit | + wc -l) \ + -eq 0 && + echo change > file && + git commit -m "last commit" file && + test $( + git fast-export --import-marks=tmp-marks \ + --export-marks=tmp-marks HEAD | + grep ^commit\ | + wc -l) \ + -eq 1 && + test $(wc -l < tmp-marks) -eq 4 + +' + +cat > signed-tag-import << EOF +tag sign-your-name +from $(git rev-parse HEAD) +tagger C O Mitter 1112911993 -0700 +data 210 +A message for a sign +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.5 (GNU/Linux) + +fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign +aturefakedsignaturefake= +=/59v +-----END PGP SIGNATURE----- +EOF + +test_expect_success 'set up faked signed tag' ' + + cat signed-tag-import | git fast-import + +' + +test_expect_success 'signed-tags=abort' ' + + test_must_fail git fast-export --signed-tags=abort sign-your-name + +' + +test_expect_success 'signed-tags=verbatim' ' + + git fast-export --signed-tags=verbatim sign-your-name > output && + grep PGP output + +' + +test_expect_success 'signed-tags=strip' ' + + git fast-export --signed-tags=strip sign-your-name > output && + ! grep PGP output + +' + +test_expect_success 'setup submodule' ' + + git checkout -f master && + mkdir sub && + cd sub && + git init && + echo test file > file && + git add file && + git commit -m sub_initial && + cd .. && + git submodule add "`pwd`/sub" sub && + git commit -m initial && + test_tick && + cd sub && + echo more data >> file && + git add file && + git commit -m sub_second && + cd .. && + git add sub && + git commit -m second + +' + +test_expect_success 'submodule fast-export | fast-import' ' + + SUBENT1=$(git ls-tree master^ sub) && + SUBENT2=$(git ls-tree master sub) && + rm -rf new && + mkdir new && + git --git-dir=new/.git init && + git fast-export --signed-tags=strip --all | + (cd new && + git fast-import && + test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" && + test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" && + git checkout master && + git submodule init && + git submodule update && + cmp sub/file ../sub/file) + +' + +GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME +GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME + +test_expect_success 'setup copies' ' + + git config --unset i18n.commitencoding && + git checkout -b copy rein && + git mv file file3 && + git commit -m move1 && + test_tick && + cp file2 file4 && + git add file4 && + git mv file2 file5 && + git commit -m copy1 && + test_tick && + cp file3 file6 && + git add file6 && + git commit -m copy2 && + test_tick && + echo more text >> file6 && + echo even more text >> file6 && + git add file6 && + git commit -m modify && + test_tick && + cp file6 file7 && + echo test >> file7 && + git add file7 && + git commit -m copy_modify + +' + +test_expect_success 'fast-export -C -C | fast-import' ' + + ENTRY=$(git rev-parse --verify copy) && + rm -rf new && + mkdir new && + git --git-dir=new/.git init && + git fast-export -C -C --signed-tags=strip --all > output && + grep "^C \"file6\" \"file7\"\$" output && + cat output | + (cd new && + git fast-import && + test $ENTRY = $(git rev-parse --verify refs/heads/copy)) + +' + +test_expect_success 'fast-export | fast-import when master is tagged' ' + + git tag -m msg last && + git fast-export -C -C --signed-tags=strip --all > output && + test $(grep -c "^tag " output) = 3 + +' + +cat > tag-content << EOF +object $(git rev-parse HEAD) +type commit +tag rosten +EOF + +test_expect_success 'cope with tagger-less tags' ' + + TAG=$(git hash-object -t tag -w tag-content) && + git update-ref refs/tags/sonnenschein $TAG && + git fast-export -C -C --signed-tags=strip --all > output && + test $(grep -c "^tag " output) = 4 && + ! grep "Unspecified Tagger" output && + git fast-export -C -C --signed-tags=strip --all \ + --fake-missing-tagger > output && + test $(grep -c "^tag " output) = 4 && + grep "Unspecified Tagger" output + +' + +test_expect_success 'setup for limiting exports by PATH' ' + mkdir limit-by-paths && + cd limit-by-paths && + git init && + echo hi > there && + git add there && + git commit -m "First file" && + echo foo > bar && + git add bar && + git commit -m "Second file" && + git tag -a -m msg mytag && + echo morefoo >> bar && + git add bar && + git commit -m "Change to second file" && + cd .. +' + +cat > limit-by-paths/expected << EOF +blob +mark :1 +data 3 +hi + +reset refs/tags/mytag +commit refs/tags/mytag +mark :2 +author A U Thor 1112912713 -0700 +committer C O Mitter 1112912713 -0700 +data 11 +First file +M 100644 :1 there + +EOF + +test_expect_success 'dropping tag of filtered out object' ' + cd limit-by-paths && + git fast-export --tag-of-filtered-object=drop mytag -- there > output && + test_cmp output expected && + cd .. +' + +cat >> limit-by-paths/expected << EOF +tag mytag +from :2 +tagger C O Mitter 1112912713 -0700 +data 4 +msg + +EOF + +test_expect_success 'rewriting tag of filtered out object' ' + cd limit-by-paths && + git fast-export --tag-of-filtered-object=rewrite mytag -- there > output && + test_cmp output expected && + cd .. +' + +cat > limit-by-paths/expected << EOF +blob +mark :1 +data 4 +foo + +blob +mark :2 +data 3 +hi + +reset refs/heads/master +commit refs/heads/master +mark :3 +author A U Thor 1112912713 -0700 +committer C O Mitter 1112912713 -0700 +data 12 +Second file +M 100644 :1 bar +M 100644 :2 there + +EOF + +test_expect_failure 'no exact-ref revisions included' ' + cd limit-by-paths && + git fast-export master~2..master~1 > output && + test_cmp output expected && + cd .. +' + + +test_expect_success 'set-up a few more tags for tag export tests' ' + git checkout -f master && + HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` && + git tag tree_tag -m "tagging a tree" $HEAD_TREE && + git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE && + git tag tag-obj_tag -m "tagging a tag" tree_tag-obj && + git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj +' + +test_expect_success 'tree_tag' ' + mkdir result && + (cd result && git init) && + git fast-export tree_tag > fe-stream && + (cd result && git fast-import < ../fe-stream) +' + +# NEEDSWORK: not just check return status, but validate the output +test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj' +test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag' +test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj' + +test_done -- cgit v1.2.1 From a8b59ef578df2b06a89fecd46f3d379895e77e8f Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Mon, 7 Dec 2009 12:27:26 +0100 Subject: Add more testcases to test fast-import of notes This patch adds testcases verifying correct behaviour in several scenarios regarding fast-import of notes: - using a mixture of 'N' and 'M' commands - updating existing notes - concatenation of notes - 'deleteall' also removes notes - fanout schemes is added/removed when needed - git-fast-import's branch unload/reload preserves notes - non-notes are not clobbered in the presence of notes Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- t/t9301-fast-import-notes.sh | 623 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 623 insertions(+) create mode 100755 t/t9301-fast-import-notes.sh diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh new file mode 100755 index 000000000..a5c99d850 --- /dev/null +++ b/t/t9301-fast-import-notes.sh @@ -0,0 +1,623 @@ +#!/bin/sh +# +# Copyright (c) 2009 Johan Herland +# + +test_description='test git fast-import of notes objects' +. ./test-lib.sh + + +test_tick +cat >input < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data <input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +# Write fast-import commands to create the given number of commits +fast_import_commits () { + my_ref=$1 + my_num_commits=$2 + my_append_to_file=$3 + my_i=0 + while test $my_i -lt $my_num_commits + do + my_i=$(($my_i + 1)) + test_tick + cat >>"$my_append_to_file" < $GIT_COMMITTER_DATE +data <>"$my_append_to_file" < $GIT_COMMITTER_DATE +data <>"$my_append_to_file" <>input < $GIT_COMMITTER_DATE +data <>expect < actual && + test_cmp expect actual + +' + +test_expect_success 'verify that lots of notes trigger a fanout scheme' ' + + # None of the entries in the top-level notes tree should be a full SHA1 + git ls-tree --name-only refs/notes/many_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 + +cat >>expect_non-note2 << EOF +Non-note file +EOF + +cat >>expect_non-note3 << EOF +Another non-note file +EOF + +test_expect_success 'verify that non-notes are untouched by a fanout change' ' + + git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual && + test_cmp expect_non-note1 actual && + git cat-file -p refs/notes/many_notes:deadbeef > actual && + test_cmp expect_non-note2 actual && + git cat-file -p refs/notes/many_notes:de/adbeef > actual && + test_cmp expect_non-note3 actual + +' +remaining_notes=10 +test_tick +cat >>input < $GIT_COMMITTER_DATE +data <>input <>expect <>expect < actual && + test_cmp expect actual + +' + +test_expect_success 'verify that removing notes trigger fanout consolidation' ' + + # All entries in the top-level notes tree should be a full SHA1 + git ls-tree --name-only -r refs/notes/many_notes | + while read path + do + # Explicitly ignore the non-note paths + test "$path" = "foobar/non-note.txt" && continue + test "$path" = "deadbeef" && continue + test "$path" = "de/adbeef" && continue + + if test $(expr length "$path") -ne 40 + then + return 1 + fi + done + +' + +test_expect_success 'verify that non-notes are untouched by a fanout change' ' + + git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual && + test_cmp expect_non-note1 actual && + git cat-file -p refs/notes/many_notes:deadbeef > actual && + test_cmp expect_non-note2 actual && + git cat-file -p refs/notes/many_notes:de/adbeef > actual && + test_cmp expect_non-note3 actual + +' + + +rm input expect +num_notes_refs=10 +num_commits=16 +some_commits=8 +# Create commits +fast_import_commits "refs/heads/more_commits" $num_commits input +# Create one note per above commit per notes ref +i=0 +while test $i -lt $num_notes_refs +do + i=$(($i + 1)) + fast_import_notes "refs/notes/more_notes_$i" $num_commits input +done +# Trigger branch reloading in git-fast-import by repeating the note creation +i=0 +while test $i -lt $num_notes_refs +do + i=$(($i + 1)) + fast_import_notes "refs/notes/more_notes_$i" $some_commits input " (2)" +done +# Finally create the expected output from the notes in refs/notes/more_notes_1 +i=$num_commits +while test $i -gt 0 +do + note_data="note for commit #$i" + if test $i -le $some_commits + then + note_data="$note_data (2)" + fi + cat >>expect < actual && + test_cmp expect actual + +' + +test_done -- cgit v1.2.1