monotone

monotone Mtn Source Tree

Root/cvs_sync.hh

1// copyright (C) 2005 Christof Petig <christof@petig-baender.de>
2// all rights reserved.
3// licensed to the public under the terms of the GNU GPL (>= 2)
4// see the file COPYING for details
5
6#include <map>
7#include <list>
8#include <iostream>
9#include <stdexcept>
10#include "sanity.hh"
11#include "cvs_client.hh"
12#include "constants.hh"
13#include "app_state.hh"
14#include "packet.hh"
15
16namespace cvs_sync {
17struct cvs_revision_nr
18{ std::vector<int> parts;
19
20 cvs_revision_nr(const std::string &x);
21 void operator++();
22 std::string get_string() const;
23 bool is_branch() const;
24 bool is_parent_of(const cvs_revision_nr &child) const;
25 bool operator==(const cvs_revision_nr &b) const;
26 bool operator<(const cvs_revision_nr &b) const;
27};
28
29struct file_state
30{ time_t since_when;
31 std::string cvs_version; // cvs_revision_nr ?
32 unsigned size;
33 unsigned patchsize;
34 bool dead;
35 std::string md5sum;
36 hexenc<id> sha1sum; // make this a file_id
37 std::string log_msg;
38 std::string author;
39 std::string keyword_substitution;
40
41 file_state() : since_when(), size(), patchsize(), dead() {}
42 file_state(time_t sw,const std::string &rev,bool d=false)
43 : since_when(sw), cvs_version(rev), size(), patchsize(), dead(d) {}
44 bool operator==(const file_state &b) const
45 { return since_when==b.since_when && cvs_version==cvs_version; }
46 bool operator<(const file_state &b) const;
47};
48
49struct file_history
50{ std::set<file_state> known_states;
51};
52
53typedef std::set<file_state>::const_iterator cvs_file_state;
54
55// state of the files at a specific point in history, dead files do not occur here
56typedef std::map<std::string,cvs_file_state> cvs_manifest;
57
58struct cvs_edge // careful this name is also used in cvs_import
59{
60 std::string changelog;
61 bool changelog_valid;
62 std::string author;
63 time_t time;
64 mutable time_t time2;
65 mutable revision_id delta_base;
66 // delta encoded if !delta_base().empty()
67 mutable cvs_manifest xfiles; // manifest (or use cvs_manifest)
68 mutable unsigned cm_delta_depth; // we store a full manifest every N revisions
69 static const unsigned cm_max_delta_depth=50;
70 mutable hexenc<id> revision; // monotone revision
71 // make this a revision_id
72
73 // I do not want this to be 3 hours (how comes?)
74 static size_t const cvs_window = 5;
75
76 cvs_edge() : changelog_valid(), time(), time2(), cm_delta_depth() {}
77 cvs_edge(time_t when) : changelog_valid(), time(when), time2(when), cm_delta_depth() {}
78 cvs_edge(const std::string &log, time_t when, const std::string &auth)
79 : changelog(log), changelog_valid(true), author(auth), time(when), time2(when),
80 cm_delta_depth()
81 {}
82 cvs_edge(const revision_id &rid,app_state &app);
83
84 bool similar_enough(cvs_edge const & other) const;
85 inline bool operator==(cvs_edge const & other) const
86 {
87 return // branch == other.branch &&
88 changelog == other.changelog &&
89 author == other.author &&
90 time == other.time;
91 }
92 bool operator<(cvs_edge const & other) const;
93};
94
95bool operator<(const file_state &,const cvs_edge &);
96bool operator<=(const file_state &,const cvs_edge &);
97
98class cvs_repository : public cvs_client
99{
100public:
101 typedef cvs_manifest tree_state_t;
102 struct prime_log_cb;
103 struct get_all_files_log_cb;
104 struct get_all_files_list_cb;
105 struct update_cb;
106
107private:
108 std::set<cvs_edge> edges;
109 std::map<revision_id,std::set<cvs_edge>::iterator> revision_lookup;
110 std::map<std::string,file_history> files;
111 // tag,file,rev
112 std::map<std::string,std::map<std::string,std::string> > tags;
113
114 app_state &app;
115 std::auto_ptr<ticker> file_id_ticker;
116 std::auto_ptr<ticker> revision_ticker;
117 std::auto_ptr<ticker> cvs_edges_ticker;
118
119 // for delta encoding of files
120 std::set<file_state> remove_set; // remove_state lives here
121 cvs_file_state remove_state;
122
123 time_t sync_since;
124
125public:
126 std::string create_cvs_cert_header() const;
127 static void parse_cvs_cert_header(revision<cert> const& c,
128 std::string &repository, std::string& module, std::string& branch);
129 static std::string::size_type parse_cvs_cert_header(cert_value const& value,
130 std::string &repository, std::string& module, std::string& branch);
131
132private:
133 void check_split(const cvs_file_state &s, const cvs_file_state &end,
134 const std::set<cvs_edge>::iterator &e);
135 void get_all_files();
136 void update(std::set<file_state>::const_iterator s,
137 std::set<file_state>::iterator s2,const std::string &file,
138 std::string &contents);
139 void store_checkout(std::set<file_state>::iterator s2,
140 const cvs_client::checkout &file, std::string &file_contents);
141 void store_checkout(std::set<file_state>::iterator s2,
142 const cvs_client::update &file, std::string &file_contents);
143 void store_update(std::set<file_state>::const_iterator s,
144 std::set<file_state>::iterator s2,const cvs_client::update &u,
145 std::string &file_contents);
146 void fill_manifests(std::set<cvs_edge>::iterator e);
147 void commit_revisions(std::set<cvs_edge>::iterator e);
148
149// std::string is equivalent to data
150 void store_contents(const data &contents, hexenc<id> &sha1sum);
151// void apply_delta(std::string &contents, const std::string &patch);
152 void store_delta(const std::string &new_contents, const std::string &old_contents, const std::string &patch, const hexenc<id> &from, hexenc<id> &to);
153
154 void cert_cvs(const cvs_edge &e, packet_consumer & pc);
155 cvs_file_state remember(std::set<file_state> &s,const file_state &fs, std::string const& filename);
156 void join_edge_parts(std::set<cvs_edge>::iterator i);
157 std::set<cvs_edge>::iterator last_known_revision();
158 std::set<cvs_edge>::iterator commit(
159 std::set<cvs_edge>::iterator parent, const revision_id &rid, bool &fail);
160 const cvs_manifest &get_files(const cvs_edge &e);
161 // try harder (reconnect if something goes wrong)
162 struct checkout CheckOut2(const std::string &file, const std::string &revision);
163 void takeover_dir(const std::string &path);
164
165 void store_modules();
166 void retrieve_modules();
167 std::string gather_merge_information(revision_id const& id,int depth=5);
168
169public: // semi public interface for push/pull
170 void prime();
171 void update();
172 void commit();
173 void migrate();
174 void process_certs(const std::vector< revision<cert> > &certs);
175 bool empty() const { return edges.empty() && files.empty(); }
176
177 const cvs_manifest &get_files(const revision_id &e);
178
179 static time_t posix2time_t(std::string s);
180
181 void takeover();
182 std::string debug_file(std::string const& name);
183
184public:
185 cvs_repository(app_state &app, const std::string &repository,
186 const std::string &module, const std::string &branch=std::string(),
187 bool connect=true);
188
189 std::string debug() const;
190
191#if 0 // yet unimplemented and unneeded ~nice~ API ideas
192 std::list<std::string> get_modules();
193 void set_branch(const std::string &tag);
194 const tree_state_t &find(const std::string &date,const std::string &changelog);
195 const tree_state_t &next(const tree_state_t &m) const;
196#endif
197};
198
199void pull(const std::string &repository, const std::string &module,
200 std::string const& branch, app_state &app);
201void push(const std::string &repository, const std::string &module,
202 std::string const& branch, app_state &app);
203void debug(const std::string &command, const std::string &arg, app_state &app);
204void takeover(app_state &app, const std::string &module);
205void migrate(app_state &app);
206} // end namespace cvs_sync

Archive Download this file

Branches

Tags

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