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 <string>
14#include <set>
15#include <map>
16
17#include "cset.hh"
18#include "paths.hh"
19#include "roster.hh"
20#include "vocab.hh"
21#include "file_io.hh"
22
23//
24// this file defines structures to deal with the "workspace" of a tree
25//
26
27//
28// workspace book-keeping files are stored in a directory called _MTN, off
29// the root of the workspace source tree (analogous to the CVS or .svn
30// directories). there is no hierarchy of _MTN directories; only one exists,
31// and it is always at the root. it contains the following files:
32//
33// _MTN/revision -- contains the id of the checked out revision
34// _MTN/work -- (optional) a set of added, deleted or moved pathnames
35// this file is, syntactically, a cset
36// _MTN/options -- the database, branch and key options currently in use
37// _MTN/log -- user edited log file
38// _MTN/inodeprints -- file fingerprint cache, presence turns on "reckless"
39// mode
40//
41// as work proceeds, the files in the workspace either change their
42// sha1 fingerprints from those listed in the revision's manifest, or else are
43// added or deleted or renamed (and the paths of those changes recorded in
44// '_MTN/work').
45//
46// when it comes time to commit, the cset in _MTN/work (which can have no
47// deltas) is applied to the base roster, then a new roster is built by
48// analyzing the content of every file in the roster, as it appears in the
49// workspace. a final cset is calculated which contains the requisite
50// deltas, and placed in a rev, which is written to the db.
51//
52// _MTN/inodeprints, if present, can be used to speed up this last step.
53
54class path_restriction;
55
56struct file_itemizer : public tree_walker
57{
58 app_state & app;
59 path_set & known;
60 path_set & unknown;
61 path_set & ignored;
62 path_restriction const & mask;
63 file_itemizer(app_state & a, path_set & k, path_set & u, path_set & i,
64 path_restriction const & r)
65 : app(a), known(k), unknown(u), ignored(i), mask(r) {}
66 virtual void visit_dir(file_path const & path);
67 virtual void visit_file(file_path const & path);
68};
69
70void
71find_missing(roster_t const & new_roster_shape, node_restriction const & mask,
72 path_set & missing);
73
74void
75find_unknown_and_ignored(app_state & app, path_restriction const & mask,
76 path_set & unknown, path_set & ignored);
77
78void
79perform_additions(path_set const & targets, app_state & app, bool recursive = true);
80
81void
82perform_deletions(path_set const & targets, app_state & app);
83
84void
85perform_rename(std::set<file_path> const & src_paths,
86 file_path const & dst_dir,
87 app_state & app);
88
89void
90perform_pivot_root(file_path const & new_root, file_path const & put_old,
91 app_state & app);
92
93// the "work" file contains the current cset representing uncommitted
94// add/drop/rename operations (not deltas)
95
96void get_work_cset(cset & w);
97void remove_work_cset();
98void put_work_cset(cset & w);
99
100// the "revision" file contains the base revision id that the current working
101// copy was checked out from
102
103void get_revision_id(revision_id & c);
104void put_revision_id(revision_id const & rev);
105void get_base_revision(app_state & app,
106 revision_id & rid,
107 roster_t & ros,
108 marking_map & mm);
109void get_base_revision(app_state & app,
110 revision_id & rid,
111 roster_t & ros);
112void get_base_roster(app_state & app, roster_t & ros);
113
114// This returns the current roster, except it does not bother updating the
115// hashes in that roster -- the "shape" is correct, all files and dirs exist
116// and under the correct names -- but do not trust file content hashes.
117void get_current_roster_shape(roster_t & ros, node_id_source & nis, app_state & app);
118
119// These returns the current roster, except they do not bother updating the
120// hashes in that roster -- the "shape" is correct, all files and dirs exist
121// and under the correct names -- but do not trust file content hashes.
122void get_base_and_current_roster_shape(roster_t & base_roster,
123 roster_t & current_roster,
124 node_id_source & nis,
125 app_state & app);
126
127// the "user log" is a file the user can edit as they program to record
128// changes they make to their source code. Upon commit the file is read
129// and passed to the edit_comment lua hook. If the commit is a success,
130// the user log is then blanked. If the commit does not succeed, no
131// change is made to the user log file.
132
133void get_user_log_path(bookkeeping_path & ul_path);
134
135void read_user_log(data & dat);
136
137void write_user_log(data const & dat);
138
139void blank_user_log();
140
141bool has_contents_user_log();
142
143// the "options map" is another administrative file, stored in
144// _MTN/options. it keeps a list of name/value pairs which are considered
145// "persistent options", associated with a particular the workspace and
146// implied unless overridden on the command line. the main ones are
147// --branch and --db, although some others may follow in the future.
148
149typedef std::map<std::string, utf8> options_map;
150
151void get_options_path(bookkeeping_path & o_path);
152
153void read_options_map(data const & dat, options_map & options);
154
155void write_options_map(data & dat,
156 options_map const & options);
157
158// the "local dump file' is a debugging file, stored in _MTN/debug. if we
159// crash, we save some debugging information here.
160
161void get_local_dump_path(bookkeeping_path & d_path);
162
163// the 'inodeprints file' contains inode fingerprints
164
165void get_inodeprints_path(bookkeeping_path & ip_path);
166
167bool in_inodeprints_mode();
168
169void read_inodeprints(data & dat);
170
171void write_inodeprints(data const & dat);
172
173void enable_inodeprints();
174
175bool get_attribute_from_roster(roster_t const & ros,
176 file_path const & path,
177 attr_key const & key,
178 attr_value & val);
179
180void update_any_attrs(app_state & app);
181
182struct file_content_source
183{
184 virtual void get_file_content(file_id const & fid,
185 file_data & dat) const = 0;
186 virtual ~file_content_source() {};
187};
188
189struct empty_file_content_source : public file_content_source
190{
191 virtual void get_file_content(file_id const & fid,
192 file_data & dat) const
193 {
194 I(false);
195 }
196};
197
198struct editable_working_tree : public editable_tree
199{
200 editable_working_tree(app_state & app, file_content_source const & source);
201
202 virtual node_id detach_node(split_path const & src);
203 virtual void drop_detached_node(node_id nid);
204
205 virtual node_id create_dir_node();
206 virtual node_id create_file_node(file_id const & content);
207 virtual void attach_node(node_id nid, split_path const & dst);
208
209 virtual void apply_delta(split_path const & pth,
210 file_id const & old_id,
211 file_id const & new_id);
212 virtual void clear_attr(split_path const & pth,
213 attr_key const & name);
214 virtual void set_attr(split_path const & pth,
215 attr_key const & name,
216 attr_value const & val);
217
218 virtual void commit();
219
220 virtual ~editable_working_tree();
221private:
222 app_state & app;
223 file_content_source const & source;
224 node_id next_nid;
225 std::map<bookkeeping_path, file_id> written_content;
226 std::map<bookkeeping_path, file_path> rename_add_drop_map;
227 bool root_dir_attached;
228};
229
230// Local Variables:
231// mode: C++
232// fill-column: 76
233// c-file-style: "gnu"
234// indent-tabs-mode: nil
235// End:
236// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
237
238#endif // __WORK_HH__

Archive Download this file

Branches

Tags

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