]> git.lyx.org Git - features.git/blob - src/VCBackend.h
Lets start some cleanup of old version() VCS API
[features.git] / src / VCBackend.h
1 // -*- C++ -*-
2 /**
3  * \file VCBackend.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Pavel Sanda
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef VC_BACKEND_H
14 #define VC_BACKEND_H
15
16 #include "support/FileName.h"
17
18 #include <string>
19
20 #include "LyXVC.h"
21
22
23 namespace lyx {
24
25 class Buffer;
26
27 /// A simple version control system interface
28 class VCS {
29 public:
30         /// the status of the managed file
31         enum VCStatus {
32                 UNLOCKED,
33                 LOCKED,
34                 NOLOCKING
35         };
36
37         virtual ~VCS() {}
38
39         /// register a file for version control
40         virtual void registrer(std::string const & msg) = 0;
41         /// check in the current revision, returns log
42         virtual std::string checkIn(std::string const & msg) = 0;
43         // can be this operation processed in the current RCS?
44         virtual bool checkInEnabled() = 0;
45         /// check out for editing, returns log
46         virtual std::string checkOut() = 0;
47         // can be this operation processed in the current RCS?
48         virtual bool checkOutEnabled() = 0;
49         /// synchronize with repository, returns log
50         virtual std::string repoUpdate() = 0;
51         // can be this operation processed in the current RCS?
52         virtual bool repoUpdateEnabled() = 0;
53         // toggle locking property of the file
54         virtual std::string lockingToggle() = 0;
55         // can be this operation processed in the current RCS?
56         virtual bool lockingToggleEnabled() = 0;
57         /// revert current edits
58         virtual void revert() = 0;
59         /// FIXME
60         virtual void undoLast() = 0;
61         // can be this operation processed in the current RCS?
62         virtual bool undoLastEnabled() = 0;
63         /**
64          * getLog - read the revision log into the given file
65          * @param fname file name to read into
66          */
67         virtual void getLog(support::FileName const &) = 0;
68         /// return the current version description
69         virtual std::string const versionString() const = 0;
70         /// return the user who has locked the file
71         std::string const & locker() const { return locker_; }
72         /// set the owning buffer
73         void owner(Buffer * b) { owner_ = b; }
74         /// return the owning buffer
75         Buffer * owner() const { return owner_; }
76         /// return the lock status of this file
77         VCStatus status() const { return vcstatus; }
78         /// do we need special handling for read-only toggling?
79         /// (also used for check-out operation)
80         virtual bool toggleReadOnlyEnabled() = 0;
81         /// Return revision info specified by the argument.
82         virtual std::string revisionInfo(LyXVC::RevisionInfo const info) = 0;
83 protected:
84         /// parse information from the version file
85         virtual void scanMaster() = 0;
86
87         // GUI container for doVCCommandCall
88         int doVCCommand(std::string const & cmd, support::FileName const & path);
89         /**
90          * doVCCommandCall - call out to the version control utility
91          * @param cmd the command to execute
92          * @param path the path from which to execute
93          * @return exit status
94          */
95         static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
96
97         /**
98          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
99          * have full path.
100          */
101         support::FileName master_;
102
103         /// The status of the VC controlled file.
104         VCStatus vcstatus;
105
106         /// The user currently keeping the lock on the VC file.
107         std::string locker_;
108         /// The buffer using this VC
109         Buffer * owner_;
110 };
111
112
113 ///
114 class RCS : public VCS {
115 public:
116
117         explicit
118         RCS(support::FileName const & m);
119
120         /// return the revision file for the given file, if found
121         static support::FileName const findFile(support::FileName const & file);
122
123         static void retrieve(support::FileName const & file);
124
125         virtual void registrer(std::string const & msg);
126
127         virtual std::string checkIn(std::string const & msg);
128
129         virtual bool checkInEnabled();
130
131         virtual std::string checkOut();
132
133         virtual bool checkOutEnabled();
134
135         virtual std::string repoUpdate();
136
137         virtual bool repoUpdateEnabled();
138
139         virtual std::string lockingToggle();
140
141         virtual bool lockingToggleEnabled();
142
143         virtual void revert();
144
145         virtual void undoLast();
146
147         virtual bool undoLastEnabled();
148
149         virtual void getLog(support::FileName const &);
150
151         virtual std::string const versionString() const {
152                 return "RCS: " + version_;
153         }
154
155         virtual bool toggleReadOnlyEnabled();
156
157         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
158
159 protected:
160         virtual void scanMaster();
161 private:
162         /**
163          * The version of the VC file. I am not sure if this can be a
164          * string or if it must be a float/int.
165          */
166         std::string version_;
167 };
168
169
170 ///
171 class CVS : public VCS {
172 public:
173         ///
174         explicit
175         CVS(support::FileName const & m, support::FileName const & f);
176
177         /// return the revision file for the given file, if found
178         static support::FileName const findFile(support::FileName const & file);
179
180         virtual void registrer(std::string const & msg);
181
182         virtual std::string checkIn(std::string const & msg);
183
184         virtual bool checkInEnabled();
185
186         virtual std::string checkOut();
187
188         virtual bool checkOutEnabled();
189
190         virtual std::string repoUpdate();
191
192         virtual bool repoUpdateEnabled();
193
194         virtual std::string lockingToggle();
195
196         virtual bool lockingToggleEnabled();
197
198         virtual void revert();
199
200         virtual void undoLast();
201
202         virtual bool undoLastEnabled();
203
204         virtual void getLog(support::FileName const &);
205
206         virtual std::string const versionString() const {
207                 return "CVS: " + version_;
208         }
209
210         virtual bool toggleReadOnlyEnabled();
211
212         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
213
214 protected:
215         virtual void scanMaster();
216
217 private:
218         support::FileName file_;
219         // revision number from scanMaster
220         std::string version_;
221 };
222
223
224 ///
225 class SVN : public VCS {
226 public:
227         ///
228         explicit
229         SVN(support::FileName const & m, support::FileName const & f);
230
231         /// return the revision file for the given file, if found
232         static support::FileName const findFile(support::FileName const & file);
233
234         virtual void registrer(std::string const & msg);
235
236         virtual std::string checkIn(std::string const & msg);
237
238         virtual bool checkInEnabled();
239
240         virtual std::string checkOut();
241
242         virtual bool checkOutEnabled();
243
244         virtual std::string repoUpdate();
245
246         virtual bool repoUpdateEnabled();
247
248         virtual std::string lockingToggle();
249
250         virtual bool lockingToggleEnabled();
251
252         virtual void revert();
253
254         virtual void undoLast();
255
256         virtual bool undoLastEnabled();
257
258         virtual void getLog(support::FileName const &);
259
260         virtual std::string const versionString() const {
261                 return "SVN: " + rev_file_cache_;
262         }
263
264         virtual bool toggleReadOnlyEnabled();
265
266         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
267
268 protected:
269         virtual void scanMaster();
270         /// Check for messages in svn output. Returns error.
271         std::string scanLogFile(support::FileName const & f, std::string & status);
272         /// checks locking policy and setup locked_mode_
273         bool checkLockMode();
274         /// is the loaded file locked?
275         bool isLocked() const;
276         /// acquire/release write lock for the current file
277         void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
278
279 private:
280         support::FileName file_;
281         /// is the loaded file under locking policy?
282         bool locked_mode_;
283         /**
284          * Real code for obtaining file revision info. Fills all file-related caches
285          * and returns true if successfull.
286          * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
287          * was already unsuccessful.
288          */
289         bool getFileRevisionInfo();
290         /// cache for file revision number, "?" if already unsuccessful
291         std::string rev_file_cache_;
292         /// cache for author of last commit
293         std::string rev_author_cache_;
294         /// cache for date of last commit
295         std::string rev_date_cache_;
296         /// cache for time of last commit
297         std::string rev_time_cache_;
298         /// fills rev_tree_cache_, returns true if successfull.
299         bool getTreeRevisionInfo();
300         /// cache for tree revision number, "?" if already unsuccessful
301         std::string rev_tree_cache_;
302 };
303
304 } // namespace lyx
305
306 #endif // VCBACKEND_H