# # add_file "tests/t_db_kill_branch_locally.at" # # patch "AUTHORS" # from [18efd7462a60094848537d1248f3e668742bfe8e] # to [30e965bc57edd221eb6aa30839a20299ab66991f] # # patch "ChangeLog" # from [9e0ee021f2b1d81700e96ab1f2705ee47ab7723f] # to [2657f73f93b99a7c85d08d4c133fb8ebac9fdc4b] # # patch "commands.cc" # from [0219fa13f31351d209832ea210bb1e7a46bef761] # to [0cf7a8ed8de6fb5814f857366c892b5b48a07b6e] # # patch "database.cc" # from [181e7b79e4435b2ffa1561ce8b9162a41563ed72] # to [bf6b4c7a79a67f4922bdfa738da490f0064cbab9] # # patch "database.hh" # from [402c6310d759c4934fc19ba823f2536ca3251d46] # to [8eff7740768dec012533217d6771853b705a3254] # # patch "monotone.texi" # from [6fb3fe1d81b2cc330e4dc04e54df634721817965] # to [d5a3fc65738c06b2405df1245da00cf8195fddbc] # # patch "tests/t_db_kill_branch_locally.at" # from [] # to [dc67769b12aea0c26b6d4e3b2347c56ee99cde4b] # # patch "testsuite.at" # from [2635480ab5d48f5eae96909a5e59ef20a7b0c36d] # to [adcf7de64bda07e00bbeb9dd8aed1bcb85ef77c5] # --- AUTHORS +++ AUTHORS @@ -59,6 +59,7 @@ Timothy Brownawell Matthew Gregan Riccardo Ghetta + Brian Campbell supporting files: ----------------- --- ChangeLog +++ ChangeLog @@ -1,3 +1,17 @@ +2005-06-25 Brian Campbell + + * commands.cc (CMD(db)): Added db kill_branch_locally command. + * database.cc, database.hh (delete_branch_named): New function to + delete all branch certs with a given branch name. + * monotone.texi (Database): Added documentation for db + kill_branch_locally. + * tests/t_db_kill_branch_locally.at: New test for db + kill_branch_locally. + * testsuite.at: Add the test. + * AUTHORS: Add myself. + * ChangeLog: Change my email address on an old contribution to + match my pubkey. + 2005-06-15 Richard Levitte * netsync.cc (struct session): Add a pattern regex cache. @@ -919,7 +933,7 @@ * work.cc: Use attr_file_name rather than hardcoded strings. -2005-05-04 Brian Campbell +2005-05-04 Brian Campbell * contrib/monotone.el (monotone-vc-register): Fix arguments to monotone-cmd-buf, to make work. --- commands.cc +++ commands.cc @@ -2103,7 +2103,8 @@ "load\n" "migrate\n" "execute\n" - "kill_rev_locally \n" + "kill_rev_locally ID\n" + "kill_branch_locally BRANCH\n" "check\n" "changesetify\n" "rebuild\n" @@ -2142,6 +2143,8 @@ kill_rev_locally(app,idx(args, 1)()); else if (idx(args, 0)() == "clear_epoch") app.db.clear_epoch(cert_value(idx(args, 1)())); + else if (idx(args, 0)() == "kill_branch_locally") + app.db.delete_branch_named(cert_value(idx(args, 1)())); else throw usage(name); } --- database.cc +++ database.cc @@ -1500,6 +1500,19 @@ execute("DELETE from revisions WHERE id = '%s'",rid.inner()().c_str()); } +/// Deletes all certs referring to a particular branch. +void +database::delete_branch_named(cert_value const & branch) +{ + base64 encoded; + encode_base64(branch, encoded); + L(F("Deleting all references to branch %s\n") % branch); + execute("DELETE FROM revision_certs WHERE name='branch' AND value ='%s'", + encoded().c_str()); + execute("DELETE FROM branch_epochs WHERE branch='%s'", + encoded().c_str()); +} + // crypto key management void --- database.hh +++ database.hh @@ -289,6 +289,8 @@ void delete_existing_revs_and_certs(); void delete_existing_rev_and_certs(revision_id const & rid); + + void delete_branch_named(cert_value const & branch); // crypto key / cert operations --- monotone.texi +++ monotone.texi @@ -4398,6 +4398,21 @@ work you can extract @var{id}'s data. @end itemize address@hidden monotone db kill_branch_locally @var{branch} + +This command ``kills'' a branch by deleting all branch certs with that +branch name. You should consider carefully whether you want to use it, +because it can irrevocably delete important information. It does not +modify or delete any revisions or any of the other certificates on +revisions in the branch; it simply removes the branch certificates +matching the given branch name. Because of this, it can leave +revisions without any branch certificate at all. As with @command{db +kill_rev_locally}, it only deletes the information from your local +database; if there are other databases that you sync with which have +revisions in this branch, the branch certificates will reappear when +you sync, unless the owners of those databases also delete those +certificates locally. + @item monotone db execute @var{sql-statement} This is a debugging command which executes @var{sql-statement} against --- tests/t_db_kill_branch_locally.at +++ tests/t_db_kill_branch_locally.at @@ -0,0 +1,26 @@ +AT_SETUP([db kill_branch_locally command]) +MONOTONE_SETUP + +# This tests the db kill_branch_locally command + +# Prepare a db with a couple of branches +ADD_FILE(foo, [file named foo +]) +COMMIT(good) +REVISION=`BASE_REVISION` +AT_CHECK(MONOTONE cert $REVISION branch bad, [], ignore, ignore) +AT_CHECK(MONOTONE ls branches, [], stdout, ignore) +AT_CHECK(grep -q good stdout) +AT_CHECK(grep -q bad stdout) + +# Now we delete the branch, and make sure it's gone +AT_CHECK(MONOTONE db kill_branch_locally bad, [], ignore, ignore) +AT_CHECK(MONOTONE ls branches, [], stdout, ignore) +AT_CHECK(grep -q good stdout) +AT_CHECK(grep -q bad stdout, [1]) + +# And lets make sure our database is still OK +AT_CHECK(MONOTONE db check, [], ignore, ignore) + +AT_CLEANUP +(END) --- testsuite.at +++ testsuite.at @@ -659,4 +659,4 @@ m4_include(tests/t_merge_manual.at) m4_include(tests/t_revert_restrict.at) m4_include(tests/t_status.at) +m4_include(tests/t_db_kill_branch_locally.at) -