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