monotone

monotone Mtn Source Tree

Root/work.hh

1#ifndef __WORK_HH__
2#define __WORK_HH__
3
4// Copyright (C) 2002 Graydon Hoare <graydon@pobox.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#include <set>
14#include <map>
15
16#include "vocab.hh"
17#include "paths.hh"
18#include "roster.hh"
19#include "database.hh"
20
21//
22// this file defines structures to deal with the "workspace" of a tree
23//
24
25//
26// workspace book-keeping files are stored in a directory called _MTN, off
27// the root of the workspace source tree (analogous to the CVS or .svn
28// directories). there is no hierarchy of _MTN directories; only one exists,
29// and it is always at the root. it contains the following files:
30//
31
32// _MTN/revision -- this file can be thought of as an approximation to the
33// revision that would be added to the database if one
34// were to execute 'mtn commit' with the current set of
35// changes. it records the id of the revision that was
36// checked out (the "parent revision") plus a cset
37// describing pathname and attribute modifications
38// relative to that revision. if the workspace is the
39// result of a merge, the revision will have more than
40// one parent and thus more than one cset. files
41// changed solely in content do not appear in
42// _MTN/revision; this is the major difference between
43// the revision in this file and the revision that 'mtn
44// commit' adds to the database.
45// _MTN/options -- the database, branch and key options currently in use
46// _MTN/log -- user edited log file
47// _MTN/inodeprints -- file fingerprint cache, see below
48//
49// as work proceeds, the files in the workspace either change their
50// sha1 fingerprints from those listed in the revision's manifest, or else are
51// added or deleted or renamed (and the paths of those changes recorded in
52// '_MTN/revision').
53//
54// many operations need to work with a revision that accurately describes
55// both pathname and content changes. constructing this revision is the
56// function of update_current_roster_from_filesystem(). this operation
57// intrinsically requires reading every file in the workspace, which can be
58// slow. _MTN/inodeprints, if present, is used to speed up this process; it
59// records information accessible via stat() that is expected to change
60// whenever a file is modified. this expectation is not true under all
61// conditions, but works in practice (it is, for instance, the same
62// expectation used by "make"). nonetheless, this mode is off by default.
63
64class path_restriction;
65class node_restriction;
66struct content_merge_adaptor;
67class lua_hooks;
68
69struct workspace
70{
71 void find_missing(roster_t const & new_roster_shape,
72 node_restriction const & mask,
73 std::set<file_path> & missing);
74
75 void find_unknown_and_ignored(path_restriction const & mask,
76 std::vector<file_path> const & roots,
77 std::set<file_path> & unknown,
78 std::set<file_path> & ignored);
79
80 void perform_additions(std::set<file_path> const & targets,
81 bool recursive = false,
82 bool respect_ignore = true);
83
84 void perform_deletions(std::set<file_path> const & targets, bool recursive,
85 bool bookkeep_only);
86
87 void perform_rename(std::set<file_path> const & src_paths,
88 file_path const & dst_dir,
89 bool bookkeep_only);
90
91 void perform_pivot_root(file_path const & new_root,
92 file_path const & put_old,
93 bool bookkeep_only);
94
95 void perform_content_update(cset const & cs,
96 content_merge_adaptor const & ca,
97 bool messages = true);
98
99 void update_any_attrs();
100
101
102 // write out a new (partial) revision describing the current workspace;
103 // the important pieces of this are the base revision id and the "shape"
104 // changeset (representing tree rearrangements).
105 void put_work_rev(revision_t const & rev);
106
107 // read the (partial) revision describing the current workspace.
108 void get_work_rev(revision_t & rev);
109
110 // convenience wrappers around the above functions.
111
112 // This returns the current roster, except it does not bother updating the
113 // hashes in that roster -- the "shape" is correct, all files and dirs
114 // exist and under the correct names -- but do not trust file content
115 // hashes. If you need the current roster with correct file content
116 // hashes, call update_current_roster_from_filesystem on the result of
117 // this function. Under almost all conditions, NIS should be a
118 // temp_node_id_source.
119 void get_current_roster_shape(roster_t & ros, node_id_source & nis);
120
121 // This returns a map whose keys are revision_ids and whose values are
122 // rosters, there being one such pair for each parent of the current
123 // revision.
124 void get_parent_rosters(parent_map & parents);
125
126 // Inspect the workspace and classify all the paths in it according to
127 // what ROS thinks of them.
128 void classify_roster_paths(roster_t const & ros,
129 std::set<file_path> & unchanged,
130 std::set<file_path> & changed,
131 std::set<file_path> & missing);
132
133 // This updates the file-content hashes in ROSTER, which is assumed to be
134 // the "current" roster returned by one of the above get_*_roster_shape
135 // functions. If a node_restriction is provided, only the files matching
136 // the restriction have their hashes updated.
137 void update_current_roster_from_filesystem(roster_t & ros);
138 void update_current_roster_from_filesystem(roster_t & ros,
139 node_restriction const & mask);
140
141
142 // the "user log" is a file the user can edit as they program to record
143 // changes they make to their source code. Upon commit the file is read
144 // and passed to the edit_comment lua hook. If the commit is a success,
145 // the user log is then blanked. If the commit does not succeed, no
146 // change is made to the user log file.
147
148 void get_user_log_path(bookkeeping_path & ul_path);
149 void read_user_log(utf8 & dat);
150 void write_user_log(utf8 const & dat);
151 void blank_user_log();
152 bool has_contents_user_log();
153
154 // the "options map" is another administrative file, stored in
155 // _MTN/options. it keeps a list of name/value pairs which are considered
156 // "persistent options", associated with a particular workspace and
157 // implied unless overridden on the command line. the set of valid keys
158 // corresponds exactly to the argument list of these functions.
159
160 static bool get_ws_options_from_path(system_path const & workspace,
161 system_path & database_option,
162 branch_name & branch_option,
163 rsa_keypair_id & key_option,
164 system_path & keydir_option);
165 void get_ws_options(system_path & database_option,
166 branch_name & branch_option,
167 rsa_keypair_id & key_option,
168 system_path & keydir_option);
169 void set_ws_options(system_path & database_option,
170 branch_name & branch_option,
171 rsa_keypair_id & key_option,
172 system_path & keydir_option);
173
174 // the "workspace format version" is a nonnegative integer value, stored
175 // in _MTN/format as an unadorned decimal number. at any given time
176 // monotone supports actual use of only one workspace format.
177 // check_ws_format throws an error if the workspace's format number is not
178 // equal to the currently supported format number. it is automatically
179 // called for all commands defined with CMD() (not CMD_NO_WORKSPACE()).
180 // migrate_ws_format is called only on explicit user request (mtn ws
181 // migrate) and will convert a workspace from any older format to the new
182 // one. unlike most routines in this class, it is defined in its own
183 // file, work_migration.cc. finally, write_ws_format is called only when
184 // a workspace is created, and simply writes the current workspace format
185 // number to _MTN/format.
186 void check_ws_format();
187 void migrate_ws_format();
188 void write_ws_format();
189
190 // the "local dump file' is a debugging file, stored in _MTN/debug. if we
191 // crash, we save some debugging information here.
192
193 void get_local_dump_path(bookkeeping_path & d_path);
194
195 // the 'inodeprints file' contains inode fingerprints
196
197 void enable_inodeprints();
198 void maybe_update_inodeprints();
199
200 // constructor and locals. by caching pointers to the database and the
201 // lua hooks, we don't have to know about app_state.
202 workspace(database & db, lua_hooks & lua) : db(db), lua(lua) {};
203private:
204 database & db;
205 lua_hooks & lua;
206};
207
208// Local Variables:
209// mode: C++
210// fill-column: 76
211// c-file-style: "gnu"
212// indent-tabs-mode: nil
213// End:
214// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
215
216#endif // __WORK_HH__

Archive Download this file

Branches

Tags

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