monotone

monotone Mtn Source Tree

Root/project.cc

1// 2007 Timothy Brownawell <tbrownaw@gmail.com>
2// GNU GPL V2 or later
3
4#include <vector>
5
6#include "app_state.hh"
7#include "cert.hh"
8#include "packet.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 packet_consumer & pc)
126{
127 cert_revision_in_branch(id, cert_value(branch()), app, pc);
128}
129
130
131outdated_indicator
132project_t::get_revision_cert_hashes(revision_id const & rid,
133 std::vector<hexenc<id> > & hashes)
134{
135 return app.db.get_revision_certs(rid, hashes);
136}
137
138outdated_indicator
139project_t::get_revision_certs(revision_id const & id,
140 std::vector<revision<cert> > & certs)
141{
142 return app.db.get_revision_certs(id, certs);
143}
144
145outdated_indicator
146project_t::get_revision_certs_by_name(revision_id const & id,
147 cert_name const & name,
148 std::vector<revision<cert> > & certs)
149{
150 outdated_indicator i = app.db.get_revision_certs(id, name, certs);
151 erase_bogus_certs(certs, app);
152 return i;
153}
154
155outdated_indicator
156project_t::get_revision_branches(revision_id const & id,
157 std::set<branch_name> & branches)
158{
159 std::vector<revision<cert> > certs;
160 outdated_indicator i = get_revision_certs_by_name(id, branch_cert_name, certs);
161 branches.clear();
162 for (std::vector<revision<cert> >::const_iterator i = certs.begin();
163 i != certs.end(); ++i)
164 {
165 cert_value b;
166 decode_base64(i->inner().value, b);
167 branches.insert(branch_name(b()));
168 }
169 return i;
170}
171
172outdated_indicator
173project_t::get_branch_certs(branch_name const & branch,
174 std::vector<revision<cert> > & certs)
175{
176 base64<cert_value> branch_encoded;
177 encode_base64(cert_value(branch()), branch_encoded);
178
179 return app.db.get_revision_certs(branch_cert_name, branch_encoded, certs);
180}
181
182tag_t::tag_t(revision_id const & ident,
183 utf8 const & name,
184 rsa_keypair_id const & key)
185 : ident(ident), name(name), key(key)
186{}
187
188bool
189operator < (tag_t const & a, tag_t const & b)
190{
191 if (a.name < b.name)
192 return true;
193 else if (a.name == b.name)
194 {
195 if (a.ident < b.ident)
196 return true;
197 else if (a.ident == b.ident)
198 {
199 if (a.key < b.key)
200 return true;
201 }
202 }
203 return false;
204}
205
206outdated_indicator
207project_t::get_tags(set<tag_t> & tags)
208{
209 std::vector<revision<cert> > certs;
210 outdated_indicator i = app.db.get_revision_certs(tag_cert_name, certs);
211 erase_bogus_certs(certs, app);
212 tags.clear();
213 for (std::vector<revision<cert> >::const_iterator i = certs.begin();
214 i != certs.end(); ++i)
215 {
216 cert_value value;
217 decode_base64(i->inner().value, value);
218 tags.insert(tag_t(revision_id(i->inner().ident), utf8(value()), i->inner().key));
219 }
220 return i;
221}
222
223void
224project_t::put_tag(revision_id const & id,
225 string const & name,
226 packet_consumer & pc)
227{
228 cert_revision_tag(id, name, app, pc);
229}
230
231
232void
233project_t::put_standard_certs(revision_id const & id,
234 branch_name const & branch,
235 utf8 const & changelog,
236 date_t const & time,
237 utf8 const & author,
238 packet_consumer & pc)
239{
240 cert_revision_in_branch(id, cert_value(branch()), app, pc);
241 cert_revision_changelog(id, changelog, app, pc);
242 cert_revision_date_time(id, time, app, pc);
243 if (!author().empty())
244 cert_revision_author(id, author(), app, pc);
245 else
246 cert_revision_author_default(id, app, pc);
247}
248
249void
250project_t::put_standard_certs_from_options(revision_id const & id,
251 branch_name const & branch,
252 utf8 const & changelog,
253 packet_consumer & pc)
254{
255 put_standard_certs(id,
256 branch,
257 changelog,
258 app.opts.date_given ? app.opts.date : date_t::now(),
259 app.opts.author,
260 pc);
261}
262void
263project_t::put_cert(revision_id const & id,
264 cert_name const & name,
265 cert_value const & value,
266 packet_consumer & pc)
267{
268 put_simple_revision_cert(id, name, value, app, pc);
269}
270
271
272// Local Variables:
273// mode: C++
274// fill-column: 76
275// c-file-style: "gnu"
276// indent-tabs-mode: nil
277// End:
278// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
279

Archive Download this file

Branches

Tags

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