#
# add_file "tests/t_ls_branches.at"
#
# patch "ChangeLog"
# from [a6a10a729cc99431681bc96230e2deccb5b750d7]
# to [52847a92b4932d7db3f30f961cc813ede6904486]
#
# patch "commands.cc"
# from [f9f438b353afcaa67b06616b0879e8668ecf9df4]
# to [755e27d10e9737caf42ab7f9243b56971a5f2d36]
#
# patch "database.cc"
# from [af083d716a4fd0871401e3e5942996e110e79e71]
# to [a33a4b5cc676465fcd91e4c7dd904e668f1fb562]
#
# patch "database.hh"
# from [a552166dfbfbd0474f1343a0bb848aad1379ec92]
# to [14ba00bff0d68669687755c58a3b35172333cfe1]
#
# patch "netsync.cc"
# from [ff29f04bb5cbf77926b9bfe05ba0780add131b26]
# to [960ce5ba76ced81ff99bbf6a4872da168a74bd42]
#
# patch "tests/t_ls_branches.at"
# from []
# to [5fb5cf84c420e5c7143a80b5c2b4e87356568615]
#
# patch "testsuite.at"
# from [fe9f0a7cff2f78a911d08ffb2830971a6e1a7b11]
# to [48a8654f19aff02b402bcf7e0469d4f5bf383ab1]
#
===============================================
--- ChangeLog a6a10a729cc99431681bc96230e2deccb5b750d7
+++ ChangeLog 52847a92b4932d7db3f30f961cc813ede6904486
@@ -1,3 +1,11 @@
+2005-07-20 Marcel van der Boom
+
+ * database.{cc,hh} (get_branches): New method.
+ * commands.cc (ls_branches): Use it.
+ * netsync.cc (get_branches): Likewise.
+ * tests/t_ls_branches.at: New test.
+ * testsuite.at: Add it.
+
2005-07-20 Nathaniel Smith
* commands.cc (db): Rename kill_branch_locally to
===============================================
--- commands.cc f9f438b353afcaa67b06616b0879e8668ecf9df4
+++ commands.cc 755e27d10e9737caf42ab7f9243b56971a5f2d36
@@ -1573,22 +1573,13 @@
static void
ls_branches(string name, app_state & app, vector const & args)
{
- vector< revision > certs;
- app.db.get_revision_certs(branch_cert_name, certs);
-
vector names;
- for (size_t i = 0; i < certs.size(); ++i)
- {
- cert_value name;
- decode_base64(idx(certs, i).inner().value, name);
- if (!app.lua.hook_ignore_branch(name()))
- names.push_back(name());
- }
+ app.db.get_branches(names);
sort(names.begin(), names.end());
- names.erase(std::unique(names.begin(), names.end()), names.end());
for (size_t i = 0; i < names.size(); ++i)
- cout << idx(names, i) << endl;
+ if (!app.lua.hook_ignore_branch(idx(names, i)))
+ cout << idx(names, i) << endl;
}
static void
===============================================
--- database.cc af083d716a4fd0871401e3e5942996e110e79e71
+++ database.cc a33a4b5cc676465fcd91e4c7dd904e668f1fb562
@@ -2412,6 +2412,24 @@
key.first().c_str(), name_encoded().c_str());
}
+// branches
+
+void
+database::get_branches(vector & names)
+{
+ results res;
+ string query="SELECT DISTINCT value FROM revision_certs WHERE name= ?";
+ string cert_name="branch";
+ fetch(res,one_col,any_rows,query.c_str(),cert_name.c_str());
+ for (size_t i = 0; i < res.size(); ++i)
+ {
+ base64 row_encoded(res[i][0]);
+ data name;
+ decode_base64(row_encoded, name);
+ names.push_back(name());
+ }
+}
+
// transaction guards
transaction_guard::transaction_guard(database & d) : committed(false), db(d)
===============================================
--- database.hh a552166dfbfbd0474f1343a0bb848aad1379ec92
+++ database.hh 14ba00bff0d68669687755c58a3b35172333cfe1
@@ -427,6 +427,9 @@
void clear_var(var_key const & key);
+ // branches
+ void get_branches(std::vector & names);
+
// completion stuff
void complete(std::string const & partial,
===============================================
--- netsync.cc ff29f04bb5cbf77926b9bfe05ba0780add131b26
+++ netsync.cc 960ce5ba76ced81ff99bbf6a4872da168a74bd42
@@ -1704,16 +1704,8 @@
void
get_branches(app_state & app, vector & names)
{
- vector< revision > certs;
- app.db.get_revision_certs(branch_cert_name, certs);
- for (size_t i = 0; i < certs.size(); ++i)
- {
- cert_value name;
- decode_base64(idx(certs, i).inner().value, name);
- names.push_back(name());
- }
+ app.db.get_branches(names);
sort(names.begin(), names.end());
- names.erase(std::unique(names.begin(), names.end()), names.end());
if (!names.size())
W(F("No branches found."));
}
===============================================
--- tests/t_ls_branches.at
+++ tests/t_ls_branches.at 5fb5cf84c420e5c7143a80b5c2b4e87356568615
@@ -0,0 +1,50 @@
+# -*- Autoconf -*-
+
+AT_SETUP([list branches])
+
+# Setup the environment
+MONOTONE_SETUP
+
+# ls branches on empty db should return successful and empty
+AT_CHECK(MONOTONE ls branches,[0],[stdout],[stderr])
+AT_CHECK(cmp /dev/null stdout,[],[ignore])
+AT_CHECK(cmp /dev/null stderr,[],[ignore])
+
+# Let's create some branches, so we have stuff to list
+AT_DATA(foo.testbranch, [this is the testbranch version
+])
+AT_DATA(foo.otherbranch, [this version goes in otherbranch
+])
+
+AT_CHECK(cp foo.testbranch foo)
+AT_CHECK(MONOTONE add foo, [], [ignore], [ignore])
+COMMIT(testbranch)
+
+AT_CHECK(cp -f foo.otherbranch foo)
+COMMIT(otherbranch)
+
+# ls branches should list 2 branches now
+AT_CHECK(MONOTONE ls branches,[0],[stdout],[stderr])
+AT_CHECK(CANONICALISE(stdout))
+AT_DATA(branches,[otherbranch
+testbranch
+])
+AT_CHECK(cmp branches stdout,[],[ignore])
+
+# Create an ignore_branch hook to pass in
+AT_DATA(ignore_branch.lua,[
+function ignore_branch(branchname)
+ if(branchname == "branch.to.be.ignored") then return true end
+ return false
+end
+])
+
+# if we make a change in the branch.to.be.ignored it should not turn up in the list
+AT_CHECK(cp foo.testbranch in_ignored)
+AT_CHECK(MONOTONE --rcfile=ignore_branch.lua add in_ignored, [], [ignore], [ignore])
+COMMIT(branch.to.be.ignored)
+AT_CHECK(MONOTONE --rcfile=ignore_branch.lua ls branches,[0],[stdout],[stderr])
+AT_CHECK(CANONICALISE(stdout))
+AT_CHECK(cmp branches stdout,[],[ignore])
+
+AT_CLEANUP
===============================================
--- testsuite.at fe9f0a7cff2f78a911d08ffb2830971a6e1a7b11
+++ testsuite.at 48a8654f19aff02b402bcf7e0469d4f5bf383ab1
@@ -675,3 +675,4 @@
m4_include(tests/t_selector_globbing.at)
m4_include(tests/t_diff_external.at)
m4_include(tests/t_migrate_broken_schema.at)
+m4_include(tests/t_ls_branches.at)