monotone

monotone Mtn Source Tree

Root/restrictions.hh

1// Copyright (C) 2005 Derek Scherger <derek@echologic.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 __RESTRICTIONS_HH__
11#define __RESTRICTIONS_HH__
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// log
25//
26// it is important that these commands operate on the same set of files given
27// the same restriction specification. this allows for destructive commands
28// (commit and revert) to be "tested" first with non-destructive commands
29// (ls unknown/ignored/missing/known, status, diff)
30
31#include <set>
32#include "vocab.hh"
33#include "rev_types.hh"
34#include "paths.hh"
35
36// between any two related revisions, A and B, there is a set of changes (a
37// cset) that describes the operations required to get from A to B. for
38// example:
39//
40// revision A ... changes ... revision B
41//
42// a restriction is a means of masking off some of these changes to produce
43// a third revision, X that lies somewhere between A and B. changes
44// included by the restriction when applied to revision A would produce
45// revision X. changes excluded by the restriction when applied to revision
46// X would produce revision B.
47//
48// conceptually, a restriction allows for something like a sliding control
49// for selecting the changes between revisions A and B. when the control is
50// "all the way to the right" all changes are included and X == B. when then
51// control is "all the way to the left" no changes are included and
52// X == A. when the control is somewhere between these extremes X is a new
53// revision.
54//
55// revision A ... included ... revision X ... excluded ... revision B
56
57namespace restricted_path
58{
59 enum status
60 {
61 included,
62 excluded,
63 required,
64 included_required,
65 excluded_required
66 };
67}
68
69class restriction
70{
71 public:
72 bool empty() const
73 { return included_paths.empty() && excluded_paths.empty(); }
74
75 enum include_rules
76 {
77 explicit_includes,
78 implicit_includes
79 };
80
81 protected:
82 restriction() : depth(-1) {}
83
84 restriction(std::vector<file_path> const & includes,
85 std::vector<file_path> const & excludes,
86 long depth);
87
88 std::set<file_path> included_paths, excluded_paths;
89 long depth;
90};
91
92class node_restriction : public restriction
93{
94 public:
95 node_restriction() : restriction() {}
96
97 node_restriction(std::vector<file_path> const & includes,
98 std::vector<file_path> const & excludes,
99 long depth,
100 roster_t const & roster,
101 path_predicate<file_path> const & ignore_file
102 = path_always_false<file_path>(),
103 include_rules const & rules = implicit_includes);
104
105 node_restriction(std::vector<file_path> const & includes,
106 std::vector<file_path> const & excludes,
107 long depth,
108 roster_t const & roster1,
109 roster_t const & roster2,
110 path_predicate<file_path> const & ignore_file
111 = path_always_false<file_path>(),
112 include_rules const & rules = implicit_includes);
113
114 node_restriction(std::vector<file_path> const & includes,
115 std::vector<file_path> const & excludes,
116 long depth,
117 parent_map const & rosters1,
118 roster_t const & roster2,
119 path_predicate<file_path> const & ignore_file
120 = path_always_false<file_path>(),
121 include_rules const & rules = implicit_includes);
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 skip_check_t { 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 path_predicate<file_path> const & ignore_file
151 = path_always_false<file_path>());
152
153 // Skipping validity checks makes the path_predicate irrelevant.
154 path_restriction(std::vector<file_path> const & includes,
155 std::vector<file_path> const & excludes,
156 long depth,
157 skip_check_t);
158
159 bool includes(file_path const & sp) const;
160
161 private:
162 std::map<file_path, restricted_path::status> path_map;
163};
164
165#endif // header guard
166
167// Local Variables:
168// mode: C++
169// fill-column: 76
170// c-file-style: "gnu"
171// indent-tabs-mode: nil
172// End:
173// 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