monotone

monotone Mtn Source Tree

Root/work.hh

1// -*- mode: C++; c-file-style: "gnu"; indent-tabs-mode: nil -*-
2#ifndef __WORK_HH__
3#define __WORK_HH__
4
5// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
6// all rights reserved.
7// licensed to the public under the terms of the GNU GPL (>= 2)
8// see the file COPYING for details
9
10#include <string>
11#include <set>
12#include <map>
13
14#include "change_set.hh"
15#include "manifest.hh"
16#include "vocab.hh"
17#include "paths.hh"
18
19//
20// this file defines structures to deal with the "working copy" of a tree
21//
22
23//
24// working copy book-keeping files are stored in a directory called MT, off
25// the root of the working copy source tree (analogous to the CVS or .svn
26// directories). there is no hierarchy of MT directories; only one exists,
27// and it is always at the root. it contains the following files:
28//
29// MT/revision -- contains the id of the checked out revision
30// MT/work -- (optional) a set of added, deleted or moved pathnames
31// this file is, syntactically, a path_rearrangement
32// MT/options -- the database, branch and key options currently in use
33// MT/log -- user edited log file
34// MT/inodeprints -- file fingerprint cache, presence turns on "reckless"
35// mode
36//
37// as work proceeds, the files in the working directory either change their
38// sha1 fingerprints from those listed in the revision's manifest, or else are
39// added or deleted or renamed (and the paths of those changes recorded in
40// 'MT/work').
41//
42// when it comes time to commit, the change_set is calculated by applying
43// the path_rearrangement to the manifest and then calculating the
44// delta_set between the modified manifest and the files in the working
45// copy.
46//
47// MT/inodes, if present, can be used to speed up this last step.
48
49typedef std::set<file_path> path_set;
50
51struct file_itemizer : public tree_walker
52{
53 app_state & app;
54 path_set & known;
55 path_set & unknown;
56 path_set & ignored;
57 file_itemizer(app_state & a, path_set & k, path_set & u, path_set & i)
58 : app(a), known(k), unknown(u), ignored(i) {}
59 virtual void file_itemizer::visit_file(file_path const & path);
60};
61
62void
63build_additions(std::vector<file_path> const & args,
64 manifest_map const & m_old,
65 app_state & app,
66 change_set::path_rearrangement & pr);
67
68void
69build_deletions(std::vector<file_path> const & args,
70 manifest_map const & m_old,
71 app_state & app,
72 change_set::path_rearrangement & pr);
73
74void
75build_rename(file_path const & src,
76 file_path const & dst,
77 manifest_map const & m_old,
78 app_state & app,
79 change_set::path_rearrangement & pr);
80
81
82// the "work" file contains the current path rearrangement representing
83// uncommitted add/drop/rename operations in the serialized change set format
84
85void get_path_rearrangement(change_set::path_rearrangement & w);
86void remove_path_rearrangement();
87void put_path_rearrangement(change_set::path_rearrangement & w);
88
89// the "revision" file contains the base revision id that the current working
90// copy was checked out from
91
92void get_revision_id(revision_id & c);
93void put_revision_id(revision_id const & rev);
94void get_base_revision(app_state & app,
95 revision_id & rid,
96 manifest_id & mid,
97 manifest_map & man);
98void get_base_manifest(app_state & app, manifest_map & man);
99
100// the "user log" is a file the user can edit as they program to record
101// changes they make to their source code. Upon commit the file is read
102// and passed to the edit_comment lua hook. If the commit is a success,
103// the user log is then blanked. If the commit does not succeed, no
104// change is made to the user log file.
105
106void get_user_log_path(bookkeeping_path & ul_path);
107
108void read_user_log(data & dat);
109
110void write_user_log(data const & dat);
111
112void blank_user_log();
113
114bool has_contents_user_log();
115
116// the "options map" is another administrative file, stored in
117// MT/options. it keeps a list of name/value pairs which are considered
118// "persistent options", associated with a particular the working copy and
119// implied unless overridden on the command line. the main ones are
120// --branch and --db, although some others may follow in the future.
121
122typedef std::map<std::string, utf8> options_map;
123
124void get_options_path(bookkeeping_path & o_path);
125
126void read_options_map(data const & dat, options_map & options);
127
128void write_options_map(data & dat,
129 options_map const & options);
130
131// the "local dump file' is a debugging file, stored in MT/debug. if we
132// crash, we save some debugging information here.
133
134void get_local_dump_path(bookkeeping_path & d_path);
135
136// the 'inodeprints file' contains inode fingerprints
137
138void get_inodeprints_path(bookkeeping_path & ip_path);
139
140bool in_inodeprints_mode();
141
142void read_inodeprints(data & dat);
143
144void write_inodeprints(data const & dat);
145
146void enable_inodeprints();
147
148// the "attribute map" is part of a working copy. it is *not* stored in MT,
149// because its contents are considered part of the "content" of a tree of
150// files. it is therefore stored in .mt-attrs, in the root of your
151// tree. you do not need a .mt-attrs file, it's just an extension
152// mechanism.
153//
154// the contents of the .mt-attrs file is a list of [file, name, value]
155// triples, each of which assigns a particular "extended attribute" to a
156// file in your manifest. example "extended attributes" are things like
157// "set the execute bit" or "this file is read-only" or whatnot. they are
158// intrinsic properties of the files, but not actually part of the file's
159// data stream. so they're kept here.
160
161typedef std::map<file_path, std::map<std::string, std::string> > attr_map;
162
163void get_attr_path(file_path & a_path);
164
165void read_attr_map(data const & dat, attr_map & attrs);
166
167void write_attr_map(data & dat,
168 attr_map const & options);
169
170extern std::string const encoding_attribute;
171extern std::string const manual_merge_attribute;
172
173void read_attr_map_from_db(manifest_map const & man,
174 attr_map & attr,
175 app_state & app);
176
177bool get_attribute_from_db(file_path const & file,
178 std::string const & attr_key,
179 manifest_map const & man,
180 std::string & attr_val,
181 app_state & app);
182
183bool get_attribute_from_working_copy(file_path const & file,
184 std::string const & attr_key,
185 std::string & attr_val);
186
187bool find_in_attr_map(attr_map const & attr,
188 file_path const & file,
189 std::string const & attr_key,
190 std::string & attr_val);
191
192void update_any_attrs(app_state & app);
193
194extern std::string const binary_encoding;
195extern std::string const default_encoding;
196
197#endif // __WORK_HH__

Archive Download this file

Branches

Tags

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