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

Archive Download this file

Branches

Tags

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