monotone

monotone Mtn Source Tree

Root/enumerator.hh

1#ifndef __ENUMERATOR_H__
2#define __ENUMERATOR_H__
3
4// Copyright (C) 2005 Graydon Hoare <graydon@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 <deque>
14#include <map>
15#include <set>
16#include "vector.hh"
17
18#include "vocab.hh"
19class app_state;
20
21// The revision_enumerator struct acts as a cursor which emits files,
22// deltas, revisions and certs in dependency-correct order. This is
23// used for sending sections of the revision graph through netsync.
24
25struct
26enumerator_callbacks
27{
28 // Your callback will be asked whether you want the details of each rev
29 // or cert, in order; you should return true for any rev or cert you want
30 // to be notified about the contents of. The rev's children will be
31 // traversed no matter what you return here.
32 virtual bool process_this_rev(revision_id const & rev) = 0;
33 virtual bool queue_this_cert(hexenc<id> const & c) = 0;
34 virtual bool queue_this_file(hexenc<id> const & c) = 0;
35
36 virtual void note_file_data(file_id const & f) = 0;
37 virtual void note_file_delta(file_id const & src, file_id const & dst) = 0;
38 virtual void note_rev(revision_id const & rev) = 0;
39 virtual void note_cert(hexenc<id> const & c) = 0;
40 virtual ~enumerator_callbacks() {}
41};
42
43struct
44enumerator_item
45{
46 enum { fdata, fdelta, rev, cert } tag;
47 hexenc<id> ident_a;
48 hexenc<id> ident_b;
49};
50
51struct
52revision_enumerator
53{
54 enumerator_callbacks & cb;
55 app_state & app;
56 std::set<revision_id> terminal_nodes;
57 std::set<revision_id> enumerated_nodes;
58 std::deque<revision_id> revs;
59 std::deque<enumerator_item> items;
60 std::multimap<revision_id, revision_id> graph;
61 std::multimap<revision_id, revision_id> inverse_graph;
62 std::multimap<revision_id, hexenc<id> > revision_certs;
63
64 void note_cert(revision_id const & rid,
65 hexenc<id> const & cert_hash);
66 void get_revision_certs(revision_id const & rid,
67 std::vector<hexenc<id> > & certs);
68 void get_revision_parents(revision_id const & rid,
69 std::vector<revision_id> & parents);
70
71 revision_enumerator(enumerator_callbacks & cb,
72 app_state & app,
73 std::set<revision_id> const & initial,
74 std::set<revision_id> const & terminal);
75 revision_enumerator(enumerator_callbacks & cb,
76 app_state & app);
77 void load_graphs();
78 bool all_parents_enumerated(revision_id const & child);
79 void files_for_revision(revision_id const & r,
80 std::set<file_id> & full_files,
81 std::set<std::pair<file_id,file_id> > & del_files);
82 void step();
83 bool done();
84};
85
86// Local Variables:
87// mode: C++
88// fill-column: 76
89// c-file-style: "gnu"
90// indent-tabs-mode: nil
91// End:
92// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
93
94#endif // __ENUMERATOR_H__

Archive Download this file

Branches

Tags

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