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 "app_state.hh"
31#include "cset.hh"
32#include "roster.hh"
33#include "vocab.hh"
34
35// between any two related revisions, A and B, there is a set of changes (a
36// cset) that describes the operations required to get from A to B. for example:
37//
38// revision A ... changes ... revision B
39//
40// a restriction is a means of masking off some of these changes to produce a
41// third revision, X that lies somewhere between A and B. changes included by
42// the restriction when applied to revision A would produce revision X. changes
43// excluded by the restriction when applied to revision X would produce revision
44// B.
45//
46// conceptually, a restriction allows for something like a sliding control for
47// selecting the changes between revisions A and B. when the control is "all the
48// way to the right" all changes are included and X == B. when then control is
49// "all the way to the left" no changes are included and X == A. when the
50// control is somewhere between these extremes X is a new revision.
51//
52// revision A ... included ... revision X ... excluded ... revision B
53
54namespace restricted_path
55{
56 enum status { included, excluded };
57}
58
59class restriction
60{
61 public:
62 bool empty() const { return included_paths.empty() && excluded_paths.empty(); }
63
64 protected:
65 restriction(app_state & a) : app(a) {}
66
67 restriction(std::vector<file_path> const & includes,
68 std::vector<file_path> const & excludes,
69 app_state & a);
70
71 app_state & app;
72 path_set included_paths, excluded_paths;
73};
74
75class node_restriction : public restriction
76{
77 public:
78 node_restriction(app_state & a) : restriction(a) {}
79
80 node_restriction(std::vector<file_path> const & includes,
81 std::vector<file_path> const & excludes,
82 roster_t const & roster,
83 app_state & a);
84
85 node_restriction(std::vector<file_path> const & includes,
86 std::vector<file_path> const & excludes,
87 roster_t const & roster1,
88 roster_t const & roster2,
89 app_state & a);
90
91 bool includes(roster_t const & roster, node_id nid) const;
92
93 node_restriction & operator=(node_restriction const & other)
94 {
95 included_paths = other.included_paths;
96 excluded_paths = other.excluded_paths;
97 known_paths = other.known_paths;
98 node_map = other.node_map;
99 return *this;
100 }
101
102 private:
103 path_set known_paths;
104 std::map<node_id, restricted_path::status> node_map;
105};
106
107class path_restriction : public restriction
108{
109 public:
110 path_restriction(app_state & a) : restriction(a) {}
111
112 path_restriction(std::vector<file_path> const & includes,
113 std::vector<file_path> const & excludes,
114 app_state & a);
115
116 bool includes(split_path const & sp) const;
117
118 private:
119 std::map<split_path, restricted_path::status> path_map;
120};
121
122// Local Variables:
123// mode: C++
124// fill-column: 76
125// c-file-style: "gnu"
126// indent-tabs-mode: nil
127// End:
128// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
129
130#endif // header guard

Archive Download this file

Branches

Tags

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