]> git.lyx.org Git - lyx.git/blob - src/VCBackend.h
Kill locker() API in VCS
[lyx.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         /// set the owning buffer
71         void owner(Buffer * b) { owner_ = b; }
72         /// return the owning buffer
73         Buffer * owner() const { return owner_; }
74         /// return the lock status of this file
75         VCStatus status() const { return vcstatus; }
76         /// do we need special handling for read-only toggling?
77         /// (also used for check-out operation)
78         virtual bool toggleReadOnlyEnabled() = 0;
79         /// Return revision info specified by the argument.
80         virtual std::string revisionInfo(LyXVC::RevisionInfo const info) = 0;
81 protected:
82         /// parse information from the version file
83         virtual void scanMaster() = 0;
84
85         // GUI container for doVCCommandCall
86         int doVCCommand(std::string const & cmd, support::FileName const & path);
87         /**
88          * doVCCommandCall - call out to the version control utility
89          * @param cmd the command to execute
90          * @param path the path from which to execute
91          * @return exit status
92          */
93         static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
94
95         /**
96          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
97          * have full path.
98          */
99         support::FileName master_;
100
101         /// The status of the VC controlled file.
102         VCStatus vcstatus;
103
104         /// The buffer using this VC
105         Buffer * owner_;
106 };
107
108
109 ///
110 class RCS : public VCS {
111 public:
112
113         explicit
114         RCS(support::FileName const & m);
115
116         /// return the revision file for the given file, if found
117         static support::FileName const findFile(support::FileName const & file);
118
119         static void retrieve(support::FileName const & file);
120
121         virtual void registrer(std::string const & msg);
122
123         virtual std::string checkIn(std::string const & msg);
124
125         virtual bool checkInEnabled();
126
127         virtual std::string checkOut();
128
129         virtual bool checkOutEnabled();
130
131         virtual std::string repoUpdate();
132
133         virtual bool repoUpdateEnabled();
134
135         virtual std::string lockingToggle();
136
137         virtual bool lockingToggleEnabled();
138
139         virtual void revert();
140
141         virtual void undoLast();
142
143         virtual bool undoLastEnabled();
144
145         virtual void getLog(support::FileName const &);
146
147         virtual std::string const versionString() const {
148                 return "RCS: " + version_;
149         }
150
151         virtual bool toggleReadOnlyEnabled();
152
153         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
154
155 protected:
156         virtual void scanMaster();
157 private:
158         /**
159          * The version of the VC file. I am not sure if this can be a
160          * string or if it must be a float/int.
161          */
162         std::string version_;
163         /// The user currently keeping the lock on the VC file (or "Unlocked").
164         std::string locker_;
165 };
166
167
168 ///
169 class CVS : public VCS {
170 public:
171         ///
172         explicit
173         CVS(support::FileName const & m, support::FileName const & f);
174
175         /// return the revision file for the given file, if found
176         static support::FileName const findFile(support::FileName const & file);
177
178         virtual void registrer(std::string const & msg);
179
180         virtual std::string checkIn(std::string const & msg);
181
182         virtual bool checkInEnabled();
183
184         virtual std::string checkOut();
185
186         virtual bool checkOutEnabled();
187
188         virtual std::string repoUpdate();
189
190         virtual bool repoUpdateEnabled();
191
192         virtual std::string lockingToggle();
193
194         virtual bool lockingToggleEnabled();
195
196         virtual void revert();
197
198         virtual void undoLast();
199
200         virtual bool undoLastEnabled();
201
202         virtual void getLog(support::FileName const &);
203
204         virtual std::string const versionString() const {
205                 return "CVS: " + version_;
206         }
207
208         virtual bool toggleReadOnlyEnabled();
209
210         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
211
212 protected:
213         virtual void scanMaster();
214
215 private:
216         support::FileName file_;
217         // revision number from scanMaster
218         std::string version_;
219         /// The user currently keeping the lock on the VC file.
220         std::string locker_;
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