File: enumerator.hh

package info (click to toggle)
monotone 0.40-7
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 24,064 kB
  • ctags: 17,296
  • sloc: cpp: 98,733; ansic: 83,690; sh: 6,065; lisp: 957; makefile: 777; perl: 715; python: 312; sql: 104; sed: 16
file content (91 lines) | stat: -rw-r--r-- 2,795 bytes parent folder | download
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
#ifndef __ENUMERATOR_H__
#define __ENUMERATOR_H__

// Copyright (C) 2005 Graydon Hoare <graydon@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.

#include <deque>
#include <map>
#include <set>
#include "vector.hh"
#include "vocab.hh"

class database;
class project_t;

// The revision_enumerator struct acts as a cursor which emits files,
// deltas, revisions and certs in dependency-correct order. This is
// used for sending sections of the revision graph through netsync.

struct
enumerator_callbacks
{
  // Your callback will be asked whether you want the details of each rev
  // or cert, in order; you should return true for any rev or cert you want
  // to be notified about the contents of. The rev's children will be
  // traversed no matter what you return here.
  virtual bool process_this_rev(revision_id const & rev) = 0;
  virtual bool queue_this_cert(id const & c) = 0;
  virtual bool queue_this_file(id const & c) = 0;

  virtual void note_file_data(file_id const & f) = 0;
  virtual void note_file_delta(file_id const & src, file_id const & dst) = 0;
  virtual void note_rev(revision_id const & rev) = 0;
  virtual void note_cert(id const & c) = 0;
  virtual ~enumerator_callbacks() {}
};

struct
enumerator_item
{
  enum { fdata, fdelta, rev, cert } tag;
  id ident_a;
  id ident_b;
};

class
revision_enumerator
{
  project_t & project;
  enumerator_callbacks & cb;
  std::set<revision_id> terminal_nodes;
  std::set<revision_id> enumerated_nodes;
  std::deque<revision_id> revs;
  std::deque<enumerator_item> items;
  std::multimap<revision_id, revision_id> graph;
  std::multimap<revision_id, revision_id> inverse_graph;
  std::multimap<revision_id, id>          revision_certs;

  bool all_parents_enumerated(revision_id const & child);
  void files_for_revision(revision_id const & r,
                          std::set<file_id> & full_files,
                          std::set<std::pair<file_id,file_id> > & del_files);
  void get_revision_certs(revision_id const & rid,
			  std::vector<id> & certs);

public:
  revision_enumerator(project_t & project,
                      enumerator_callbacks & cb);
  void get_revision_parents(revision_id const & rid,
			    std::vector<revision_id> & parents);
  void note_cert(revision_id const & rid,
                 id const & cert_hash);
  void step();
  bool done();
};

// 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:

#endif // __ENUMERATOR_H__