monotone

monotone Mtn Source Tree

Root/cvs_client.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 <string>
7#include <vector>
8#include <set>
9#include <stdarg.h>
10#include <zlib.h>
11#include "ui.hh"
12#include "netxx_pipe.hh"
13#include <boost/shared_ptr.hpp>
14
15/* this class encapsulates all communication with a CVS server over a pipe
16 or network link */
17
18class cvs_client
19{public:
20 struct update
21 { std::string contents;
22 std::string checksum;
23 std::string patch;
24 std::string keyword_substitution;
25 std::string new_revision;
26 std::string file;
27 time_t mod_time;
28 bool removed;
29 update() : mod_time(-1),removed() {}
30 };
31 struct rlog_callbacks
32 { // virtual void file(const std::string &file,)=0;
33 virtual void file(const std::string &file,
34 const std::string &head_rev) const=0;
35 virtual void tag(const std::string &file,const std::string &tag,
36 const std::string &revision) const=0;
37 virtual void revision(const std::string &file,time_t checkin_date,
38 const std::string &rev,const std::string &author,
39 const std::string &state,const std::string &log) const=0;
40 // to silence gcc
41 virtual ~rlog_callbacks() {}
42 };
43
44 struct rlist_callbacks
45 { virtual void file(const std::string &name, time_t last_change,
46 const std::string &last_rev, bool dead) const=0;
47 // to silence gcc
48 virtual ~rlist_callbacks() {}
49 };
50
51 struct checkout
52 { time_t mod_time;
53 std::string contents;
54 std::string mode;
55 bool dead;
56 std::string keyword_substitution;
57 std::string committemplate;
58
59 checkout() : mod_time(-1), dead() {}
60 };
61 struct update_callbacks
62 { virtual void operator()(const update &) const=0;
63 // to silence gcc
64 virtual ~update_callbacks() {}
65 };
66 struct update_args
67 { std::string file, old_revision, new_revision, keyword_substitution;
68 update_args(const std::string &f, const std::string &o,
69 const std::string &n,const std::string &k)
70 : file(f), old_revision(o), new_revision(n), keyword_substitution(k) {}
71 update_args(const std::string &f, const std::string &o)
72 : file(f), old_revision(o) {}
73 };
74 struct commit_arg
75 { std::string file;
76 std::string old_revision; // newly_added => "0"
77 std::string keyword_substitution;
78 // actually these two form a tristate ;-)
79 bool removed;
80 std::string new_content;
81
82 commit_arg() : old_revision("0"), removed() {}
83 };
84
85private:
86 boost::shared_ptr<Netxx::StreamBase> stream;
87 std::auto_ptr<ticker> byte_in_ticker;
88 std::auto_ptr<ticker> byte_out_ticker;
89 typedef std::set<std::string> stringset_t;
90 stringset_t Valid_requests;
91 int gzip_level;
92 z_stream compress,decompress;
93 std::string inputbuffer;
94 std::map<std::string,std::string> server_dir; // local path -> rcs path
95 std::string user;
96 bool pserver;
97
98 void InitZipStream(int level);
99 void underflow(); // fetch new characters from stream
100 static bool begins_with(const std::string &s, const std::string &sub);
101 std::string rcs_file2path(std::string s) const;
102 void processLogOutput(const rlog_callbacks &cb);
103 void connect();
104 void primeModules();
105 void Log_internal(const rlog_callbacks &cb,const std::string &file,
106 std::vector<std::string> const &args);
107 void Log_internal(const rlog_callbacks &cb,const std::string &file,va_list ap);
108
109 void writestr(const std::string &s, bool flush=false);
110 std::string readline();
111 std::string read_n(unsigned size);
112
113 void SendCommand(const char *cmd,...);
114 void SendCommand(const char *cmd, va_list ap);
115 void SendCommand(std::string const& cmd, std::vector<std::string> const&args);
116 void SendArgument(const std::string &a);
117 // false if none available
118 bool fetch_result(std::string &result);
119 // semi internal helper to get one result line from a list
120 static std::string combine_result(const std::vector<std::pair<std::string,std::string> > &result);
121
122 // MT style
123 bool fetch_result(std::vector<std::pair<std::string,std::string> > &result);
124
125 static std::string pserver_password(const std::string &root);
126
127 std::string shorten_path(const std::string &p) const;
128 static void parse_entry(const std::string &line, std::string &new_revision,
129 std::string &keyword_substitution);
130 void Directory(const std::string &path);
131 std::vector<std::string> ExpandModules();
132
133 std::map<std::string,std::string> RequestServerDir();
134protected:
135 std::string root;
136 std::string module;
137 std::string branch;
138 std::string host; // for author certification
139
140 void reconnect();
141 static std::string localhost_name();
142public:
143 cvs_client(const std::string &repository, const std::string &module,
144 std::string const& branch=std::string(), bool connect=true);
145 ~cvs_client();
146
147 static bool begins_with(const std::string &s, const std::string &sub, unsigned &len);
148
149 void GzipStream(int level);
150
151 void RLog(const rlog_callbacks &cb,bool dummy,...);
152 void Log(const rlog_callbacks &cb,const char *file,...);
153 void Log(const rlog_callbacks &cb,const std::string &file,
154 std::vector<std::string> const &args);
155 void RList(const rlist_callbacks &cb,bool dummy,...);
156 struct checkout CheckOut(const std::string &file, const std::string &revision);
157 struct update Update(const std::string &file,
158 const std::string &old_revision, const std::string &new_revision,
159 const std::string &keyword_substitution);
160 // update can also check out files
161 struct update Update(const std::string &file, const std::string &new_revision);
162 void Update(const std::vector<update_args> &args, const update_callbacks &cb);
163 // returns <filename, <new_revision,keyword_substitution> ("" on remove)>
164 std::map<std::string,std::pair<std::string,std::string> >
165 Commit(const std::string &changelog, time_t when,
166 const std::vector<commit_arg> &commits);
167
168 bool CommandValid(const std::string &cmd) const
169 { return Valid_requests.find(cmd)!=Valid_requests.end(); }
170 void SetServerDir(const std::map<std::string,std::string> &m);
171 const std::map<std::string,std::string> &GetServerDir() const
172 { return server_dir; }
173
174 void drop_connection();
175 static std::string time_t2rfc822(time_t t);
176 static time_t Entries2time_t(const std::string &t);
177
178 void validate_path(const std::string &local, const std::string &server);
179};
180

Archive Download this file

Branches

Tags

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