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 bool has_changes();
102
103 // write out a new (partial) revision describing the current workspace;
104 // the important pieces of this are the base revision id and the "shape"
105 // changeset (representing tree rearrangements).
106 void put_work_rev(revision_t const & rev);
107
108 // read the (partial) revision describing the current workspace.
109 void get_work_rev(revision_t & rev);
110
111 // convenience wrappers around the above functions.
112
113 // This returns the current roster, except it does not bother updating the
114 // hashes in that roster -- the "shape" is correct, all files and dirs
115 // exist and under the correct names -- but do not trust file content
116 // hashes. If you need the current roster with correct file content
117 // hashes, call update_current_roster_from_filesystem on the result of
118 // this function. Under almost all conditions, NIS should be a
119 // temp_node_id_source.
120 void get_current_roster_shape(roster_t & ros, node_id_source & nis);
121
122 // This returns a map whose keys are revision_ids and whose values are
123 // rosters, there being one such pair for each parent of the current
124 // revision.
125 void get_parent_rosters(parent_map & parents);
126
127 // This updates the file-content hashes in ROSTER, which is assumed to be
128 // the "current" roster returned by one of the above get_*_roster_shape
129 // functions. If a node_restriction is provided, only the files matching
130 // the restriction have their hashes updated.
131 void update_current_roster_from_filesystem(roster_t & ros);
132 void update_current_roster_from_filesystem(roster_t & ros,
133 node_restriction const & mask);
134
135
136 // the "user log" is a file the user can edit as they program to record
137 // changes they make to their source code. Upon commit the file is read
138 // and passed to the edit_comment lua hook. If the commit is a success,
139 // the user log is then blanked. If the commit does not succeed, no
140 // change is made to the user log file.
141
142 void get_user_log_path(bookkeeping_path & ul_path);
143 void read_user_log(utf8 & dat);
144 void write_user_log(utf8 const & dat);
145 void blank_user_log();
146 bool has_contents_user_log();
147
148 // the "options map" is another administrative file, stored in
149 // _MTN/options. it keeps a list of name/value pairs which are considered
150 // "persistent options", associated with a particular workspace and
151 // implied unless overridden on the command line. the set of valid keys
152 // corresponds exactly to the argument list of these functions.
153
154 static bool get_ws_options_from_path(system_path const & workspace,
155 system_path & database_option,
156 branch_name & branch_option,
157 rsa_keypair_id & key_option,
158 system_path & keydir_option);
159 void get_ws_options(system_path & database_option,
160 branch_name & branch_option,
161 rsa_keypair_id & key_option,
162 system_path & keydir_option);
163 void set_ws_options(system_path & database_option,
164 branch_name & branch_option,
165 rsa_keypair_id & key_option,
166 system_path & keydir_option);
167
168 // the "workspace format version" is a nonnegative integer value, stored
169 // in _MTN/format as an unadorned decimal number. at any given time
170 // monotone supports actual use of only one workspace format.
171 // check_ws_format throws an error if the workspace's format number is not
172 // equal to the currently supported format number. it is automatically
173 // called for all commands defined with CMD() (not CMD_NO_WORKSPACE()).
174 // migrate_ws_format is called only on explicit user request (mtn ws
175 // migrate) and will convert a workspace from any older format to the new
176 // one. unlike most routines in this class, it is defined in its own
177 // file, work_migration.cc. finally, write_ws_format is called only when
178 // a workspace is created, and simply writes the current workspace format
179 // number to _MTN/format.
180 void check_ws_format();
181 void migrate_ws_format();
182 void write_ws_format();
183
184 // the "local dump file' is a debugging file, stored in _MTN/debug. if we
185 // crash, we save some debugging information here.
186
187 void get_local_dump_path(bookkeeping_path & d_path);
188
189 // the 'inodeprints file' contains inode fingerprints
190
191 bool in_inodeprints_mode();
192 void read_inodeprints(data & dat);
193 void write_inodeprints(data const & dat);
194
195 void enable_inodeprints();
196 void maybe_update_inodeprints();
197
198 // constructor and locals. by caching pointers to the database and the
199 // lua hooks, we don't have to know about app_state.
200 workspace(database & db, lua_hooks & lua) : db(db), lua(lua) {};
201private:
202 database & db;
203 lua_hooks & lua;
204};
205
206// Local Variables:
207// mode: C++
208// fill-column: 76
209// c-file-style: "gnu"
210// indent-tabs-mode: nil
211// End:
212// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
213
214#endif // __WORK_HH__

Archive Download this file

Branches

Tags

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