📄 fs-base-test.c
字号:
struct node_created_rev_args { const char *path; svn_revnum_t rev;};static svn_error_t *canonicalize_abspath(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ apr_size_t i; const char *paths[21][2] = /* in out */ { { NULL, NULL }, { "", "/" }, { "/", "/" }, { "//", "/" }, { "///", "/" }, { "foo", "/foo" }, { "foo/", "/foo" }, { "foo//", "/foo" }, { "/foo", "/foo" }, { "/foo/", "/foo" }, { "/foo//", "/foo" }, { "//foo//", "/foo" }, { "foo/bar", "/foo/bar" }, { "foo/bar/", "/foo/bar" }, { "foo/bar//", "/foo/bar" }, { "foo//bar", "/foo/bar" }, { "foo//bar/", "/foo/bar" }, { "foo//bar//", "/foo/bar" }, { "/foo//bar//", "/foo/bar" }, { "//foo//bar//", "/foo/bar" }, { "///foo///bar///baz///", "/foo/bar/baz" }, }; *msg = "test svn_fs_base__canonicalize_abspath"; if (msg_only) return SVN_NO_ERROR; for (i = 0; i < (sizeof(paths) / 2 / sizeof(const char *)); i++) { const char *input = paths[i][0]; const char *output = paths[i][1]; const char *actual = svn_fs_base__canonicalize_abspath(input, pool); if ((! output) && (! actual)) continue; if ((! output) && actual) return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, "expected NULL path; got '%s'", actual); if (output && (! actual)) return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, "expected '%s' path; got NULL", output); if (strcmp(output, actual)) return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, "expected '%s' path; got '%s'", output, actual); } return SVN_NO_ERROR;}static svn_error_t *create_within_copy(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ apr_pool_t *spool = svn_pool_create(pool); svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root, *rev_root; int i; svn_revnum_t youngest_rev = 0; *msg = "create new items within a copied directory"; if (msg_only) return SVN_NO_ERROR; /* Create a filesystem and repository. */ SVN_ERR(svn_test__create_fs(&fs, "test-repo-create-within-copy", "bdb", pool)); /*** Revision 1: Create the greek tree in revision. ***/ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, spool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, spool)); SVN_ERR(svn_test__create_greek_tree(txn_root, spool)); SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, spool)); svn_pool_clear(spool); /*** Revision 2: Copy A/D to A/D3 ***/ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, spool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, spool)); SVN_ERR(svn_fs_revision_root(&rev_root, fs, youngest_rev, spool)); SVN_ERR(svn_fs_copy(rev_root, "A/D", txn_root, "A/D3", spool)); SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, spool)); svn_pool_clear(spool); /*** Revision 3: Copy A/D/G to A/D/G2 ***/ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, spool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, spool)); SVN_ERR(svn_fs_revision_root(&rev_root, fs, youngest_rev, spool)); SVN_ERR(svn_fs_copy(rev_root, "A/D/G", txn_root, "A/D/G2", spool)); SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, spool)); svn_pool_clear(spool); /*** Revision 4: Copy A/D to A/D2 and create up and I in the existing A/D/G2, in the new A/D2, and in the nested, new A/D2/G2 ***/ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, spool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, spool)); SVN_ERR(svn_fs_revision_root(&rev_root, fs, youngest_rev, spool)); SVN_ERR(svn_fs_copy(rev_root, "A/D", txn_root, "A/D2", spool)); SVN_ERR(svn_fs_make_dir(txn_root, "A/D/G2/I", spool)); SVN_ERR(svn_fs_make_file(txn_root, "A/D/G2/up", spool)); SVN_ERR(svn_fs_make_dir(txn_root, "A/D2/I", spool)); SVN_ERR(svn_fs_make_file(txn_root, "A/D2/up", spool)); SVN_ERR(svn_fs_make_dir(txn_root, "A/D2/G2/I", spool)); SVN_ERR(svn_fs_make_file(txn_root, "A/D2/G2/up", spool)); SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, spool)); svn_pool_clear(spool); /*** Revision 5: Create A/D3/down and A/D3/J ***/ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, spool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, spool)); SVN_ERR(svn_fs_make_file(txn_root, "A/D3/down", spool)); SVN_ERR(svn_fs_make_dir(txn_root, "A/D3/J", spool)); SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, spool)); svn_pool_clear(spool); { /* New items should have same CopyID as their parent */ const char *pathgroup[4][3] = { { "A/D/G2", "A/D/G2/I", "A/D/G2/up" }, { "A/D2", "A/D2/I", "A/D2/up" }, { "A/D2/G2", "A/D2/G2/I", "A/D2/G2/up" }, { "A/D3", "A/D3/down", "A/D3/J" } }; SVN_ERR(svn_fs_revision_root(&rev_root, fs, youngest_rev, spool)); for (i = 0; i < 4; i++) { const svn_fs_id_t *lead_id; const char *lead_copy_id; int j; /* Get the FSIdentifier for the first path in each group... */ SVN_ERR(svn_fs_node_id(&lead_id, rev_root, pathgroup[i][0], spool)); lead_copy_id = svn_fs_base__id_copy_id(lead_id); for (j = 1; j < 3; j++) { const svn_fs_id_t *id; const char *copy_id; /* ... and make sure the other members of the group have the same copy_id component as the 'lead' member. */ SVN_ERR(svn_fs_node_id(&id, rev_root, pathgroup[i][j], spool)); copy_id = svn_fs_base__id_copy_id(id); if (strcmp(copy_id, lead_copy_id) != 0) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "'%s' id: expected copy_id '%s'; got copy_id '%s'", pathgroup[i][j], lead_copy_id, copy_id); } } svn_pool_clear(spool); } svn_pool_destroy(spool); return SVN_NO_ERROR;}/* Test the skip delta support by commiting so many changes to a file * that some of its older revisions become reachable by skip deltas, * then try retrieving those revisions. */static svn_error_t *skip_deltas(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root, *rev_root; apr_pool_t *subpool = svn_pool_create(pool); svn_revnum_t youngest_rev = 0; const char *one_line = "This is a line in file 'f'.\n"; svn_stringbuf_t *f = svn_stringbuf_create(one_line, pool); *msg = "test skip deltas"; if (msg_only) return SVN_NO_ERROR; /* Create a filesystem and repository. */ SVN_ERR(svn_test__create_fs(&fs, "test-repo-skip-deltas", "bdb", pool)); /* Create the file. */ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, subpool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, subpool)); SVN_ERR(svn_fs_make_file(txn_root, "f", subpool)); SVN_ERR(svn_test__set_file_contents(txn_root, "f", f->data, subpool)); SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, subpool)); SVN_ERR(svn_fs_deltify_revision(fs, youngest_rev, subpool)); svn_pool_clear(subpool); /* Now, commit changes to the file 128 times. */ while (youngest_rev <= 128) { /* Append another line to the ever-growing file contents. */ svn_stringbuf_appendcstr(f, one_line); /* Commit the new contents. */ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, subpool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, subpool)); SVN_ERR(svn_test__set_file_contents(txn_root, "f", f->data, subpool)); SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, subpool)); SVN_ERR(svn_fs_deltify_revision(fs, youngest_rev, subpool)); svn_pool_clear(subpool); } /* Now go back and check revision 1. */ SVN_ERR(svn_fs_revision_root(&rev_root, fs, 1, pool)); SVN_ERR(svn_test__get_file_contents(rev_root, "f", &f, pool)); if (strcmp(one_line, f->data) != 0) return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "Wrong contents. Expected:\n '%s'\nGot:\n '%s'\n", one_line, f->data); svn_pool_destroy(subpool); return SVN_NO_ERROR;}/* Trail-ish helpers for redundant_copy(). */struct get_txn_args{ transaction_t **txn; const char *txn_name; svn_fs_t *fs;};static svn_error_t *txn_body_get_txn(void *baton, trail_t *trail){ struct get_txn_args *args = baton; return svn_fs_bdb__get_txn(args->txn, args->fs, args->txn_name, trail, trail->pool);}static svn_error_t *redundant_copy(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ svn_fs_t *fs; svn_fs_txn_t *txn; const char *txn_name; transaction_t *transaction; svn_fs_root_t *txn_root, *rev_root; const svn_fs_id_t *old_D_id, *new_D_id; svn_revnum_t youngest_rev = 0; struct get_txn_args args; *msg = "ensure no-op for redundant copies"; if (msg_only) return SVN_NO_ERROR; /* Create a filesystem and repository. */ SVN_ERR(svn_test__create_fs(&fs, "test-repo-redundant-copy", "bdb", pool)); /* Create the greek tree in revision 1. */ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, pool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, pool)); SVN_ERR(svn_test__create_greek_tree(txn_root, pool)); SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, pool)); /* In a transaction, copy A to Z. */ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, pool)); SVN_ERR(svn_fs_txn_name(&txn_name, txn, pool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, pool)); SVN_ERR(svn_fs_revision_root(&rev_root, fs, youngest_rev, pool)); SVN_ERR(svn_fs_copy(rev_root, "A", txn_root, "Z", pool)); /* Now, examine the transaction. There should have been only one copy there. */ args.fs = fs; args.txn_name = txn_name; args.txn = &transaction; SVN_ERR(svn_fs_base__retry_txn(fs, txn_body_get_txn, &args, pool)); if (transaction->copies->nelts != 1) return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, "Expected 1 copy; got %d", transaction->copies->nelts); /* Get the node-rev-id for A/D (the reason will be clear a little later). */ SVN_ERR(svn_fs_node_id(&old_D_id, txn_root, "A/D", pool)); /* Now copy A/D/G Z/D/G. */ SVN_ERR(svn_fs_copy(rev_root, "A/D/G", txn_root, "Z/D/G", pool)); /* Now, examine the transaction. There should still only have been one copy operation that "took". */ SVN_ERR(svn_fs_base__retry_txn(fs, txn_body_get_txn, &args, pool)); if (transaction->copies->nelts != 1) return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, "Expected only 1 copy; got %d", transaction->copies->nelts); /* Finally, check the node-rev-id for "Z/D" -- it should never have been made mutable (since the second copy should not have taken place). */ SVN_ERR(svn_fs_node_id(&new_D_id, txn_root, "A/D", pool)); if (! svn_string_compare(svn_fs_unparse_id(old_D_id, pool), svn_fs_unparse_id(new_D_id, pool))) return svn_error_create (SVN_ERR_TEST_FAILED, NULL, "Expected equivalent node-rev-ids; got differing ones"); return SVN_NO_ERROR;}/* ------------------------------------------------------------------------ *//* The test table. */struct svn_test_descriptor_t test_funcs[] = { SVN_TEST_NULL, SVN_TEST_PASS(create_berkeley_filesystem), SVN_TEST_PASS(open_berkeley_filesystem), SVN_TEST_PASS(delete_mutables), SVN_TEST_PASS(delete), SVN_TEST_PASS(abort_txn), SVN_TEST_PASS(create_within_copy), SVN_TEST_PASS(canonicalize_abspath), SVN_TEST_PASS(skip_deltas), SVN_TEST_PASS(redundant_copy), SVN_TEST_NULL };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -