monotone

monotone Mtn Source Tree

Root/cset.hh

1#ifndef __CSET_HH__
2#define __CSET_HH__
3
4// Copyright (C) 2005 Nathaniel Smith <njs@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 <map>
14#include <set>
15#include "vector.hh"
16
17#include "numeric_vocab.hh"
18#include "paths.hh"
19#include "vocab.hh"
20#include "sanity.hh"
21
22typedef std::map<attr_key, attr_value> attr_map_t;
23
24// Virtual interface to a tree-of-files which you can edit
25// destructively; this may be the filesystem or an in-memory
26// representation (a roster / mfest).
27
28typedef u32 node_id;
29
30struct editable_tree
31{
32 // Detaching existing nodes (for renaming or deleting)
33 virtual node_id detach_node(file_path const & src) = 0;
34 virtual void drop_detached_node(node_id nid) = 0;
35
36 // Attaching new nodes (via creation or as the tail end of renaming)
37 virtual node_id create_dir_node() = 0;
38 virtual node_id create_file_node(file_id const & content) = 0;
39 virtual void attach_node(node_id nid, file_path const & dst) = 0;
40
41 // Modifying elements in-place
42 virtual void apply_delta(file_path const & pth,
43 file_id const & old_id,
44 file_id const & new_id) = 0;
45 virtual void clear_attr(file_path const & pth,
46 attr_key const & name) = 0;
47 virtual void set_attr(file_path const & pth,
48 attr_key const & name,
49 attr_value const & val) = 0;
50
51 virtual void commit() = 0;
52
53 virtual ~editable_tree() {}
54};
55
56
57// In-memory representation of a change set.
58
59struct cset
60{
61 // Deletions.
62 std::set<file_path> nodes_deleted;
63
64 // Additions.
65 std::set<file_path> dirs_added;
66 std::map<file_path, file_id> files_added;
67
68 // Pure renames.
69 std::map<file_path, file_path> nodes_renamed;
70
71 // Pure deltas.
72 std::map<file_path, std::pair<file_id, file_id> > deltas_applied;
73
74 // Attribute changes.
75 std::set<std::pair<file_path, attr_key> > attrs_cleared;
76 std::map<std::pair<file_path, attr_key>, attr_value> attrs_set;
77
78 bool operator==(cset const & other) const
79 {
80 return nodes_deleted == other.nodes_deleted
81 && dirs_added == other.dirs_added
82 && files_added == other.files_added
83 && nodes_renamed == other.nodes_renamed
84 && deltas_applied == other.deltas_applied
85 && attrs_cleared == other.attrs_cleared
86 && attrs_set == other.attrs_set
87 ;
88 }
89
90 void apply_to(editable_tree & t) const;
91 bool empty() const;
92 void clear();
93};
94
95inline file_path const &
96delta_entry_path(std::map<file_path, std::pair<file_id, file_id> >::const_iterator i)
97{
98 return i->first;
99}
100
101inline file_id const &
102delta_entry_src(std::map<file_path, std::pair<file_id, file_id> >::const_iterator i)
103{
104 return i->second.first;
105}
106
107inline file_id const &
108delta_entry_dst(std::map<file_path, std::pair<file_id, file_id> >::const_iterator i)
109{
110 return i->second.second;
111}
112
113
114namespace basic_io { struct printer; struct parser; }
115
116void
117print_cset(basic_io::printer & printer,
118 cset const & cs);
119
120void
121write_cset(cset const & cs, data & dat);
122
123void
124parse_cset(basic_io::parser & parser,
125 cset & cs);
126
127void
128read_cset(data const & dat, cset & cs);
129
130template <> void
131dump(cset const & cs, std::string & out);
132
133// Local Variables:
134// mode: C++
135// fill-column: 76
136// c-file-style: "gnu"
137// indent-tabs-mode: nil
138// End:
139// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
140
141#endif // __CSET_HH__

Archive Download this file

Branches

Tags

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