]> git.lyx.org Git - lyx.git/blob - src/VCBackend.h
Fix bug #6649 - fix texrow structure generated by InsetIndex
[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
82         virtual bool prepareFileRevision(std::string const & rev, std::string & f) = 0;
83
84         virtual bool prepareFileRevisionEnabled() = 0;
85
86 protected:
87         /// parse information from the version file
88         virtual void scanMaster() = 0;
89
90         // GUI container for doVCCommandCall
91         int doVCCommand(std::string const & cmd, support::FileName const & path);
92         /**
93          * doVCCommandCall - call out to the version control utility
94          * @param cmd the command to execute
95          * @param path the path from which to execute
96          * @return exit status
97          */
98         static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
99
100         /**
101          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
102          * have full path.
103          */
104         support::FileName master_;
105
106         /// The status of the VC controlled file.
107         VCStatus vcstatus;
108
109         /// The buffer using this VC
110         Buffer * owner_;
111 };
112
113
114 ///
115 class RCS : public VCS {
116 public:
117
118         explicit
119         RCS(support::FileName const & m);
120
121         /// return the revision file for the given file, if found
122         static support::FileName const findFile(support::FileName const & file);
123
124         static void retrieve(support::FileName const & file);
125
126         virtual void registrer(std::string const & msg);
127
128         virtual std::string checkIn(std::string const & msg);
129
130         virtual bool checkInEnabled();
131
132         virtual std::string checkOut();
133
134         virtual bool checkOutEnabled();
135
136         virtual std::string repoUpdate();
137
138         virtual bool repoUpdateEnabled();
139
140         virtual std::string lockingToggle();
141
142         virtual bool lockingToggleEnabled();
143
144         virtual void revert();
145
146         virtual void undoLast();
147
148         virtual bool undoLastEnabled();
149
150         virtual void getLog(support::FileName const &);
151
152         virtual std::string const versionString() const {
153                 return "RCS: " + version_;
154         }
155
156         virtual bool toggleReadOnlyEnabled();
157
158         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
159
160         virtual bool prepareFileRevision(std::string const & rev, std::string & f);
161
162         virtual bool prepareFileRevisionEnabled();
163
164 protected:
165         virtual void scanMaster();
166 private:
167         /**
168          * The version of the VC file. I am not sure if this can be a
169          * string or if it must be a float/int.
170          */
171         std::string version_;
172         /// The user currently keeping the lock on the VC file (or "Unlocked").
173         std::string locker_;
174 };
175
176
177 ///
178 class CVS : public VCS {
179 public:
180         ///
181         explicit
182         CVS(support::FileName const & m, support::FileName const & f);
183
184         /// return the revision file for the given file, if found
185         static support::FileName const findFile(support::FileName const & file);
186
187         virtual void registrer(std::string const & msg);
188
189         virtual std::string checkIn(std::string const & msg);
190
191         virtual bool checkInEnabled();
192
193         virtual std::string checkOut();
194
195         virtual bool checkOutEnabled();
196
197         virtual std::string repoUpdate();
198
199         virtual bool repoUpdateEnabled();
200
201         virtual std::string lockingToggle();
202
203         virtual bool lockingToggleEnabled();
204
205         virtual void revert();
206
207         virtual void undoLast();
208
209         virtual bool undoLastEnabled();
210
211         virtual void getLog(support::FileName const &);
212
213         virtual std::string const versionString() const {
214                 return "CVS: " + version_;
215         }
216
217         virtual bool toggleReadOnlyEnabled();
218
219         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
220
221         virtual bool prepareFileRevision(std::string const & rev, std::string & f);
222
223         virtual bool prepareFileRevisionEnabled();
224
225 protected:
226         virtual void scanMaster();
227
228 private:
229         support::FileName file_;
230         // revision number from scanMaster
231         std::string version_;
232         /// The user currently keeping the lock on the VC file.
233         std::string locker_;
234 };
235
236
237 ///
238 class SVN : public VCS {
239 public:
240         ///
241         explicit
242         SVN(support::FileName const & m, support::FileName const & f);
243
244         /// return the revision file for the given file, if found
245         static support::FileName const findFile(support::FileName const & file);
246
247         virtual void registrer(std::string const & msg);
248
249         virtual std::string checkIn(std::string const & msg);
250
251         virtual bool checkInEnabled();
252
253         virtual std::string checkOut();
254
255         virtual bool checkOutEnabled();
256
257         virtual std::string repoUpdate();
258
259         virtual bool repoUpdateEnabled();
260
261         virtual std::string lockingToggle();
262
263         virtual bool lockingToggleEnabled();
264
265         virtual void revert();
266
267         virtual void undoLast();
268
269         virtual bool undoLastEnabled();
270
271         virtual void getLog(support::FileName const &);
272
273         virtual std::string const versionString() const {
274                 return "SVN: " + rev_file_cache_;
275         }
276
277         virtual bool toggleReadOnlyEnabled();
278
279         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
280
281         virtual bool prepareFileRevision(std::string const & rev, std::string & f);
282
283         virtual bool prepareFileRevisionEnabled();
284
285 protected:
286         virtual void scanMaster();
287         /// Check for messages in svn output. Returns error.
288         std::string scanLogFile(support::FileName const & f, std::string & status);
289         /// checks locking policy and setup locked_mode_
290         bool checkLockMode();
291         /// is the loaded file locked?
292         bool isLocked() const;
293         /// acquire/release write lock for the current file
294         void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
295
296 private:
297         support::FileName file_;
298         /// is the loaded file under locking policy?
299         bool locked_mode_;
300         /**
301          * Real code for obtaining file revision info. Fills all file-related caches
302          * and returns true if successfull.
303          * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
304          * was already unsuccessful.
305          */
306         bool getFileRevisionInfo();
307         /// cache for file revision number, "?" if already unsuccessful, isNumber==true
308         std::string rev_file_cache_;
309         /// cache for author of last commit
310         std::string rev_author_cache_;
311         /// cache for date of last commit
312         std::string rev_date_cache_;
313         /// cache for time of last commit
314         std::string rev_time_cache_;
315         /// fills rev_tree_cache_, returns true if successfull.
316         bool getTreeRevisionInfo();
317         /// cache for tree revision number, "?" if already unsuccessful
318         std::string rev_tree_cache_;
319 };
320
321 } // namespace lyx
322
323 #endif // VCBACKEND_H