monotone

monotone Mtn Source Tree

Root/project.cc

1// 2007 Timothy Brownawell <tbrownaw@gmail.com>
2// GNU GPL V2 or later
3
4#include "base.hh"
5#include <vector>
6
7#include "app_state.hh"
8#include "cert.hh"
9#include "project.hh"
10#include "revision.hh"
11#include "transforms.hh"
12
13using std::string;
14using std::set;
15using std::vector;
16
17project_t::project_t(app_state & app)
18 : app(app)
19{}
20
21void
22project_t::get_branch_list(std::set<branch_name> & names)
23{
24 if (indicator.outdated())
25 {
26 std::vector<std::string> got;
27 indicator = app.db.get_branches(got);
28 branches.clear();
29 for (std::vector<std::string>::iterator i = got.begin();
30 i != got.end(); ++i)
31 {
32 branches.insert(branch_name(*i));
33 }
34 }
35
36 names = branches;
37}
38
39void
40project_t::get_branch_list(globish const & glob,
41 std::set<branch_name> & names)
42{
43 std::vector<std::string> got;
44 app.db.get_branches(glob(), got);
45 names.clear();
46 for (std::vector<std::string>::iterator i = got.begin();
47 i != got.end(); ++i)
48 {
49 names.insert(branch_name(*i));
50 }
51}
52
53namespace
54{
55 struct not_in_branch : public is_failure
56 {
57 app_state & app;
58 base64<cert_value > const & branch_encoded;
59 not_in_branch(app_state & app,
60 base64<cert_value> const & branch_encoded)
61 : app(app), branch_encoded(branch_encoded)
62 {}
63 virtual bool operator()(revision_id const & rid)
64 {
65 vector< revision<cert> > certs;
66 app.db.get_revision_certs(rid,
67 cert_name(branch_cert_name),
68 branch_encoded,
69 certs);
70 erase_bogus_certs(certs, app);
71 return certs.empty();
72 }
73 };
74}
75
76void
77project_t::get_branch_heads(branch_name const & name, std::set<revision_id> & heads)
78{
79 std::pair<outdated_indicator, std::set<revision_id> > & branch = branch_heads[name];
80 if (branch.first.outdated())
81 {
82 L(FL("getting heads of branch %s") % name);
83 base64<cert_value> branch_encoded;
84 encode_base64(cert_value(name()), branch_encoded);
85
86 outdated_indicator stamp;
87 branch.first = app.db.get_revisions_with_cert(cert_name(branch_cert_name),
88 branch_encoded,
89 branch.second);
90
91 not_in_branch p(app, branch_encoded);
92 erase_ancestors_and_failures(branch.second, p, app);
93 L(FL("found heads of branch %s (%s heads)")
94 % name % branch.second.size());
95 }
96 heads = branch.second;
97}
98
99bool
100project_t::revision_is_in_branch(revision_id const & id,
101 branch_name const & branch)
102{
103 base64<cert_value> branch_encoded;
104 encode_base64(cert_value(branch()), branch_encoded);
105
106 vector<revision<cert> > certs;
107 app.db.get_revision_certs(id, branch_cert_name, branch_encoded, certs);
108
109 int num = certs.size();
110
111 erase_bogus_certs(certs, app);
112
113 L(FL("found %d (%d valid) %s branch certs on revision %s")
114 % num
115 % certs.size()
116 % branch
117 % id);
118
119 return !certs.empty();
120}
121
122void
123project_t::put_revision_in_branch(revision_id const & id,
124 branch_name const & branch)
125{
126 cert_revision_in_branch(id, branch, app);
127}
128
129
130outdated_indicator
131project_t::get_revision_cert_hashes(revision_id const & rid,
132 std::vector<hexenc<id> > & hashes)
133{
134 return app.db.get_revision_certs(rid, hashes);
135}
136
137outdated_indicator
138project_t::get_revision_certs(revision_id const & id,
139 std::vector<revision<cert> > & certs)
140{
141 return app.db.get_revision_certs(id, certs);
142}
143
144outdated_indicator
145project_t::get_revision_certs_by_name(revision_id const & id,
146 cert_name const & name,
147 std::vector<revision<cert> > & certs)
148{
149 outdated_indicator i = app.db.get_revision_certs(id, name, certs);
150 erase_bogus_certs(certs, app);
151 return i;
152}
153
154outdated_indicator
155project_t::get_revision_branches(revision_id const & id,
156 std::set<branch_name> & branches)
157{
158 std::vector<revision<cert> > certs;
159 outdated_indicator i = get_revision_certs_by_name(id, branch_cert_name, certs);
160 branches.clear();
161 for (std::vector<revision<cert> >::const_iterator i = certs.begin();
162 i != certs.end(); ++i)
163 {
164 cert_value b;
165 decode_base64(i->inner().value, b);
166 branches.insert(branch_name(b()));
167 }
168 return i;
169}
170
171outdated_indicator
172project_t::get_branch_certs(branch_name const & branch,
173 std::vector<revision<cert> > & certs)
174{
175 base64<cert_value> branch_encoded;
176 encode_base64(cert_value(branch()), branch_encoded);
177
178 return app.db.get_revision_certs(branch_cert_name, branch_encoded, certs);
179}
180
181tag_t::tag_t(revision_id const & ident,
182 utf8 const & name,
183 rsa_keypair_id const & key)
184 : ident(ident), name(name), key(key)
185{}
186
187bool
188operator < (tag_t const & a, tag_t const & b)
189{
190 if (a.name < b.name)
191 return true;
192 else if (a.name == b.name)
193 {
194 if (a.ident < b.ident)
195 return true;
196 else if (a.ident == b.ident)
197 {
198 if (a.key < b.key)
199 return true;
200 }
201 }
202 return false;
203}
204
205outdated_indicator
206project_t::get_tags(set<tag_t> & tags)
207{
208 std::vector<revision<cert> > certs;
209 outdated_indicator i = app.db.get_revision_certs(tag_cert_name, certs);
210 erase_bogus_certs(certs, app);
211 tags.clear();
212 for (std::vector<revision<cert> >::const_iterator i = certs.begin();
213 i != certs.end(); ++i)
214 {
215 cert_value value;
216 decode_base64(i->inner().value, value);
217 tags.insert(tag_t(revision_id(i->inner().ident), utf8(value()), i->inner().key));
218 }
219 return i;
220}
221
222void
223project_t::put_tag(revision_id const & id,
224 string const & name)
225{
226 cert_revision_tag(id, name, app);
227}
228
229
230void
231project_t::put_standard_certs(revision_id const & id,
232 branch_name const & branch,
233 utf8 const & changelog,
234 date_t const & time,
235 utf8 const & author)
236{
237 cert_revision_in_branch(id, branch, app);
238 cert_revision_changelog(id, changelog, app);
239 cert_revision_date_time(id, time, app);
240 if (!author().empty())
241 cert_revision_author(id, author(), app);
242 else
243 cert_revision_author_default(id, app);
244}
245
246void
247project_t::put_standard_certs_from_options(revision_id const & id,
248 branch_name const & branch,
249 utf8 const & changelog)
250{
251 put_standard_certs(id,
252 branch,
253 changelog,
254 app.opts.date_given ? app.opts.date : date_t::now(),
255 app.opts.author);
256}
257void
258project_t::put_cert(revision_id const & id,
259 cert_name const & name,
260 cert_value const & value)
261{
262 put_simple_revision_cert(id, name, value, app);
263}
264
265
266// Local Variables:
267// mode: C++
268// fill-column: 76
269// c-file-style: "gnu"
270// indent-tabs-mode: nil
271// End:
272// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
273

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status