[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Monotone-devel] Re: renaming branches
From: |
Olivier Andrieu |
Subject: |
Re: [Monotone-devel] Re: renaming branches |
Date: |
Tue, 13 Apr 2004 20:41:29 +0200 (CEST) |
graydon hoare [Tue, 06 Apr 2004]:
> Gerhard Schuck wrote:
>
> > simple question: Is it possible to rename (or delete) branches? The
> > output of 'list branches' is getting too chaotic, I need to reorganize
> > it a little bit. I guess it will be possible on database level, but how?
>
> it's possible, yes. you'd need to reissue new branch certs with the new
> names, and delete branch certs with the old names. there's no command to
> do this at the moment. it's possible to add one. doing it by hand at the
> moment would be a bit of a pain, unfortunately; the cert values (branch
> names) are all base64 encoded (with a trailing \n), so you need to do
> something awful like:
>
> FROM=$(echo -n $OLD_BRANCH | mimencode)
> IDS=$(monotone debug "$(printf "select id from manifest_certs where
> name='branch' and value='%s\n'" $FROM)" | grep -v row)
> monotone debug "$(printf "delete from manifest_certs where name='branch'
> and value='%s\n'" $FROM)"
> for i in $IDS
> do
> monotone cert manifest manifest $i branch $NEW_BRANCH
> done
>
> it'll probably be more sensible to make a "monotone branch rename"
> command which does this internally, since it's so awful.
How about this patch ?
Beware, my skills in C++ and SQL are pretty thin, so it may contain
some glaring mistakes. Yet it seems to work for me ...
--
Olivier
# Old manifest: 9cc6a827f09a1d0036ede0e117f2010846abd9b5
# New manifest: 06714985cfacffccaa9acd51bf3590c479cf0201
# Summary of changes:
#
# patch commands.cc
# from f727664605c5effe9ec2427c47f4fe289168a29e
# to 1ce33e337e62bc523f20547dd6550f7df47f614c
#
# patch database.cc
# from 121cc8cdd452a5f56a9d61e3c85a4e7aee0886af
# to 394f034ac2016cee41d914349cd2bfdc69b96b6f
#
# patch database.hh
# from cad47ab273ff531752d98bf371785cdf9ba5ca99
# to 7734819e5a429e8aa02d8529efd522ac509d8c78
#
--- commands.cc
+++ commands.cc
@@ -2511,5 +2511,50 @@
throw usage(name);
}
+CMD (branch, "branch", "rename FROM TO", "manipulate branch certs")
+{
+ if (args.size() != 3)
+ throw usage(name);
+ if (idx(args, 0)() == "rename") {
+ base64<cert_value> from_branch_encoded;
+ encode_base64(cert_value(idx(args,1)()),
+ from_branch_encoded);
+
+ base64<cert_value> to_branch_encoded;
+ encode_base64(cert_value(idx(args,2)()),
+ to_branch_encoded);
+
+ transaction_guard guard(app.db);
+
+ set<manifest_id> ids_to_recert;
+ app.db.branch_rename_get_ids(from_branch_encoded, ids_to_recert);
+
+ app.db.branch_rename_cleanup (from_branch_encoded);
+
+ rsa_keypair_id key;
+ if (app.signing_key() != "")
+ key = app.signing_key;
+ else
+ N(guess_default_key(key, app),
+ F("no unique private key found, and no key specified"));
+
+ packet_db_writer dbw(app);
+
+ for (set<manifest_id>::const_iterator i = ids_to_recert.begin();
+ i != ids_to_recert.end(); ++i)
+ {
+ cert t(i->inner(), branch_cert_name, to_branch_encoded, key);
+
+ calculate_cert(app, t);
+ dbw.consume_manifest_cert(manifest<cert>(t));
+ }
+
+ guard.commit();
+ }
+ else
+ throw usage(name);
+}
+
+
}; // namespace commands
--- database.cc
+++ database.cc
@@ -1804,6 +1804,35 @@
type.c_str(), collection().c_str());
}
+void
+database::branch_rename_get_ids(base64<cert_value> const & from,
+ set<manifest_id> & mcerts)
+{
+ results res;
+ mcerts.clear();
+
+ fetch(res, one_col, any_rows,
+ "SELECT id FROM manifest_certs "
+ "WHERE name = '%q' "
+ "AND value = '%q'",
+ branch_cert_name.c_str(),
+ from().c_str());
+
+ for (size_t i = 0; i < res.size(); ++i)
+ mcerts.insert(manifest_id(res[i][0]));
+}
+
+void
+database::branch_rename_cleanup(base64<cert_value> const & from)
+{
+ execute("DELETE FROM manifest_certs "
+ "WHERE name = '%q' "
+ "AND value = '%q'",
+ branch_cert_name.c_str(),
+ from().c_str());
+
+}
+
// transaction guards
transaction_guard::transaction_guard(database & d) : committed(false), db(d)
--- database.hh
+++ database.hh
@@ -355,6 +355,12 @@
std::string> > const & limit,
std::set<std::string> & completions);
+ // whole branch manipulation
+ void branch_rename_get_ids(base64<cert_value> const & from,
+ std::set<manifest_id> & mcerts);
+ void branch_rename_cleanup(base64<cert_value> const & from);
+
+
~database();
};