File: cset.hh

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (129 lines) | stat: -rw-r--r-- 3,421 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (C) 2005 Nathaniel Smith <njs@pobox.com>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.

#ifndef __CSET_HH__
#define __CSET_HH__

#include <set>
#include "paths.hh"
#include "rev_types.hh"

// Virtual interface to a tree-of-files which you can edit
// destructively; this may be the filesystem or an in-memory
// representation (a roster / mfest).

struct editable_tree
{
  // Detaching existing nodes (for renaming or deleting)
  virtual node_id detach_node(file_path const & src) = 0;
  virtual void drop_detached_node(node_id nid) = 0;

  // Attaching new nodes (via creation or as the tail end of renaming)
  virtual node_id create_dir_node() = 0;
  virtual node_id create_file_node(file_id const & content) = 0;
  virtual void attach_node(node_id nid, file_path const & dst) = 0;

  // Modifying elements in-place
  virtual void apply_delta(file_path const & pth,
                           file_id const & old_id,
                           file_id const & new_id) = 0;
  virtual void clear_attr(file_path const & path,
                          attr_key const & key) = 0;
  virtual void set_attr(file_path const & path,
                        attr_key const & key,
                        attr_value const & val) = 0;

  virtual void commit() = 0;

  virtual ~editable_tree() {}
};


// In-memory representation of a change set.

struct cset
{
  // Deletions.
  std::set<file_path> nodes_deleted;

  // Additions.
  std::set<file_path> dirs_added;
  std::map<file_path, file_id> files_added;

  // Pure renames.
  std::map<file_path, file_path> nodes_renamed;

  // Pure deltas.
  std::map<file_path, std::pair<file_id, file_id> > deltas_applied;

  // Attribute changes.
  std::set<std::pair<file_path, attr_key> > attrs_cleared;
  std::map<std::pair<file_path, attr_key>, attr_value> attrs_set;

  bool operator==(cset const & other) const
  {
    return nodes_deleted == other.nodes_deleted
      && dirs_added == other.dirs_added
      && files_added == other.files_added
      && nodes_renamed == other.nodes_renamed
      && deltas_applied == other.deltas_applied
      && attrs_cleared == other.attrs_cleared
      && attrs_set == other.attrs_set
      ;
  }

  void apply_to(editable_tree & t) const;
  bool empty() const;
  void clear();
};

inline file_path const &
delta_entry_path(std::map<file_path, std::pair<file_id, file_id> >::const_iterator i)
{
  return i->first;
}

inline file_id const &
delta_entry_src(std::map<file_path, std::pair<file_id, file_id> >::const_iterator i)
{
  return i->second.first;
}

inline file_id const &
delta_entry_dst(std::map<file_path, std::pair<file_id, file_id> >::const_iterator i)
{
  return i->second.second;
}

void
print_cset(basic_io::printer & printer,
           cset const & cs);

void
write_cset(cset const & cs, data & dat);

void
parse_cset(basic_io::parser & parser,
           cset & cs);

void
read_cset(data const & dat, cset & cs);

template <> void
dump(cset const & cs, std::string & out);

#endif // __CSET_HH__

// Local Variables:
// mode: C++
// fill-column: 76
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: