monotone

monotone Mtn Source Tree

Root/src/project.hh

1// Copyright (C) 2007 Timothy Brownawell <tbrownaw@gmail.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef __PROJECT_HH__
11#define __PROJECT_HH__
12
13#include <map>
14#include <set>
15
16#include "cert.hh"
17#include "outdated_indicator.hh"
18#include "vocab.hh"
19
20class arg_type;
21class database;
22class key_store;
23class options;
24class lua_hooks;
25struct globish;
26struct date_t;
27
28// "Special" certs have syntax and semantics essential to correct operation.
29// They add structure to the ancestry graph.
30
31#define branch_cert_name cert_name("branch")
32#define suspend_cert_name cert_name("suspend")
33#define tag_cert_name cert_name("tag")
34
35// "Standard" certs are largely for user information, but their values have
36// conventional syntax and semantics defined by the system, and the
37// revision-trust hook can use them to impose further structure on the
38// ancestry graph.
39
40#define date_cert_name cert_name("date")
41#define author_cert_name cert_name("author")
42#define changelog_cert_name cert_name("changelog")
43#define comment_cert_name cert_name("comment")
44#define testresult_cert_name cert_name("testresult")
45
46struct key_identity_info
47{
48 key_id id;
49 key_name given_name; // name given when creating the key
50 key_name official_name; // name returned by hooks or (once implented) policy
51};
52bool
53operator<(key_identity_info const & left,
54 key_identity_info const & right);
55std::ostream &
56operator<<(std::ostream & os,
57 key_identity_info const & identity);
58
59class tag_t
60{
61public:
62 revision_id const ident;
63 utf8 const name;
64 key_id key;
65 tag_t(revision_id const & ident, utf8 const & name, key_id const & key);
66};
67bool operator < (tag_t const & a, tag_t const & b);
68
69typedef bool suspended_indicator;
70
71class project_t
72{
73 // In the hypothetical future situation where one monotone process is
74 // using more than one database at a time, it will be essential to use a
75 // project object only with the database it was created from. To make it
76 // easy to get this right, we expose the database handle inside the
77 // project object, and make it a style rule that you pass around a
78 // database _or_ you pass around a project; not both.
79public:
80 database & db;
81
82private:
83 // These are caches of what's in the database. They are updated when
84 // they're noticed to be out of date, which will always be during a
85 // logically read-only operation.
86 mutable std::map<std::pair<branch_name, suspended_indicator>,
87 std::pair<outdated_indicator, std::set<revision_id> >
88 > branch_heads;
89 mutable std::set<branch_name> branches;
90 mutable outdated_indicator indicator;
91
92public:
93 project_t(database & db);
94
95 void get_branch_list(std::set<branch_name> & names,
96 bool check_heads = false) const;
97 void get_branch_list(globish const & glob, std::set<branch_name> & names,
98 bool check_heads = false) const;
99 void get_branch_heads(branch_name const & name, std::set<revision_id> & heads,
100 bool ignore_suspend_certs,
101 std::multimap<revision_id, revision_id> *inverse_graph_cache_ptr = NULL) const;
102
103 outdated_indicator get_tags(std::set<tag_t> & tags) const;
104 void put_tag(key_store & keys, revision_id const & id, std::string const & name);
105
106 bool revision_is_in_branch(revision_id const & id, branch_name const & branch) const;
107 void put_revision_in_branch(key_store & keys,
108 revision_id const & id,
109 branch_name const & branch);
110
111 bool revision_is_suspended_in_branch(revision_id const & id, branch_name const & branch) const;
112 void suspend_revision_in_branch(key_store & keys,
113 revision_id const & id,
114 branch_name const & branch);
115
116 outdated_indicator get_revision_cert_hashes(revision_id const & rid,
117 std::vector<id> & hashes) const;
118 outdated_indicator get_revision_certs(revision_id const & id,
119 std::vector<cert> & certs) const;
120 outdated_indicator get_revision_certs_by_name(revision_id const & id,
121 cert_name const & name,
122 std::vector<cert> & certs) const;
123 outdated_indicator get_revision_branches(revision_id const & id,
124 std::set<branch_name> & branches) const;
125 outdated_indicator get_branch_certs(branch_name const & branch,
126 std::vector<std::pair<id, cert> > & certs) const;
127
128 void put_standard_certs(key_store & keys,
129 revision_id const & id,
130 branch_name const & branch,
131 utf8 const & changelog,
132 date_t const & time,
133 std::string const & author);
134 void put_standard_certs_from_options(options const & opts,
135 lua_hooks & lua,
136 key_store & keys,
137 revision_id const & id,
138 branch_name const & branch,
139 utf8 const & changelog);
140
141 bool put_cert(key_store & keys,
142 revision_id const & id,
143 cert_name const & name,
144 cert_value const & value);
145
146 // "standard certs"
147 void put_revision_testresult(key_store & keys,
148 revision_id const & id,
149 std::string const & results);
150 void put_revision_comment(key_store & keys,
151 revision_id const & id,
152 utf8 const & comment);
153
154private:
155 // lookup the key ID associated with a particular key name
156 void lookup_key_by_name(key_store * const keys,
157 lua_hooks & lua,
158 key_name const & name,
159 key_id & id) const;
160 // get the name given when creating the key
161 void get_given_name_of_key(key_store * const keys,
162 key_id const & id,
163 key_name & name) const;
164 void complete_key_identity_from_id(key_store * const keys,
165 lua_hooks & lua,
166 key_identity_info & info) const;
167 void get_key_identity(key_store * const keys,
168 lua_hooks & lua,
169 external_key_name const & input,
170 key_identity_info & output) const;
171public:
172 void complete_key_identity_from_id(key_store & keys,
173 lua_hooks & lua,
174 key_identity_info & info) const;
175 void complete_key_identity_from_id(lua_hooks & lua,
176 key_identity_info & info) const;
177 void get_key_identity(key_store & keys,
178 lua_hooks & lua,
179 external_key_name const & input,
180 key_identity_info & output) const;
181 void get_key_identity(lua_hooks & lua,
182 external_key_name const & input,
183 key_identity_info & output) const;
184};
185
186std::string
187describe_revision(options const & opts, lua_hooks & lua,
188 project_t & project, revision_id const & id);
189
190void
191notify_if_multiple_heads(project_t & project, branch_name const & branchname,
192 bool ignore_suspend_certs);
193
194void
195guess_branch(options & opts, project_t & project, revision_id const & rev,
196 branch_name & branchname);
197void
198guess_branch(options & opts, project_t & project, revision_id const & rev);
199
200#endif
201
202// Local Variables:
203// mode: C++
204// fill-column: 76
205// c-file-style: "gnu"
206// indent-tabs-mode: nil
207// End:
208// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

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