monotone

monotone Mtn Source Tree

Root/src/cset.hh

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

Archive Download this file

Branches

Tags

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