monotone

monotone Mtn Source Tree

Root/restrictions.hh

1#ifndef __RESTRICTIONS_HH__
2#define __RESTRICTIONS_HH__
3
4// Copyright (C) 2005 Derek Scherger <derek@echologic.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13// the following commands accept file arguments and --exclude and --depth
14// options used to define a restriction on the files that will be processed:
15//
16// ls unknown
17// ls ignored
18// ls missing
19// ls known
20// status
21// diff
22// commit
23// revert
24//
25// it is important that these commands operate on the same set of files given
26// the same restriction specification. this allows for destructive commands
27// (commit and revert) to be "tested" first with non-destructive commands
28// (ls unknown/ignored/missing/known, status, diff)
29
30#include <set>
31#include "vocab.hh"
32#include "rev_types.hh"
33// XXX needed for gcc 3.3 which will otherwise complain that struct file_path
34// is just a forward in rev_types.hh and therefor leads to an incomplete type
35#include "paths.hh"
36
37class workspace;
38
39// between any two related revisions, A and B, there is a set of changes (a
40// cset) that describes the operations required to get from A to B. for example:
41//
42// revision A ... changes ... revision B
43//
44// a restriction is a means of masking off some of these changes to produce a
45// third revision, X that lies somewhere between A and B. changes included by
46// the restriction when applied to revision A would produce revision X. changes
47// excluded by the restriction when applied to revision X would produce revision
48// B.
49//
50// conceptually, a restriction allows for something like a sliding control for
51// selecting the changes between revisions A and B. when the control is "all the
52// way to the right" all changes are included and X == B. when then control is
53// "all the way to the left" no changes are included and X == A. when the
54// control is somewhere between these extremes X is a new revision.
55//
56// revision A ... included ... revision X ... excluded ... revision B
57
58namespace restricted_path
59{
60 enum status { included, excluded };
61}
62
63class restriction
64{
65 public:
66 bool empty() const { return included_paths.empty() && excluded_paths.empty(); }
67
68 protected:
69 restriction() : depth(-1) {}
70
71 restriction(std::vector<file_path> const & includes,
72 std::vector<file_path> const & excludes,
73 long depth);
74
75 std::set<file_path> included_paths, excluded_paths;
76 long depth;
77};
78
79class node_restriction : public restriction
80{
81 public:
82 node_restriction() : restriction() {}
83
84 node_restriction(std::vector<file_path> const & includes,
85 std::vector<file_path> const & excludes,
86 long depth,
87 roster_t const & roster);
88
89 node_restriction(std::vector<file_path> const & includes,
90 std::vector<file_path> const & excludes,
91 long depth,
92 roster_t const & roster1,
93 roster_t const & roster2);
94
95 node_restriction(std::vector<file_path> const & includes,
96 std::vector<file_path> const & excludes,
97 long depth,
98 parent_map const & rosters1,
99 roster_t const & roster2);
100
101#ifndef BUILD_UNIT_TESTS
102 node_restriction(workspace & work,
103 std::vector<file_path> const & includes,
104 std::vector<file_path> const & excludes,
105 long depth,
106 roster_t const & roster);
107
108 node_restriction(workspace & work,
109 std::vector<file_path> const & includes,
110 std::vector<file_path> const & excludes,
111 long depth,
112 roster_t const & roster1,
113 roster_t const & roster2);
114
115 node_restriction(workspace & work,
116 std::vector<file_path> const & includes,
117 std::vector<file_path> const & excludes,
118 long depth,
119 parent_map const & rosters1,
120 roster_t const & roster2);
121#endif
122
123 bool includes(roster_t const & roster, node_id nid) const;
124
125 node_restriction & operator=(node_restriction const & other)
126 {
127 included_paths = other.included_paths;
128 excluded_paths = other.excluded_paths;
129 depth = other.depth;
130 known_paths = other.known_paths;
131 node_map = other.node_map;
132 return *this;
133 }
134
135 private:
136 std::set<file_path> known_paths;
137 std::map<node_id, restricted_path::status> node_map;
138};
139
140class path_restriction : public restriction
141{
142 public:
143 enum validity_check { check_paths = 0, skip_check };
144
145 path_restriction() : restriction() {}
146
147 path_restriction(std::vector<file_path> const & includes,
148 std::vector<file_path> const & excludes,
149 long depth,
150 validity_check vc = check_paths);
151
152#ifndef BUILD_UNIT_TESTS
153 path_restriction(workspace & work,
154 std::vector<file_path> const & includes,
155 std::vector<file_path> const & excludes,
156 long depth,
157 validity_check vc = check_paths);
158#endif
159
160 bool includes(file_path const & sp) const;
161
162 private:
163 std::map<file_path, restricted_path::status> path_map;
164};
165
166// Local Variables:
167// mode: C++
168// fill-column: 76
169// c-file-style: "gnu"
170// indent-tabs-mode: nil
171// End:
172// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
173
174#endif // header guard

Archive Download this file

Branches

Tags

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