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

Archive Download this file

Branches

Tags

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