]> git.lyx.org Git - lyx.git/blob - src/VCBackend.h
Pass the encoding to the japanese pLaTeX processor (#4697).
[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         // should a log message provided for next checkin?
46         virtual bool isCheckInWithConfirmation() = 0;
47         /// check out for editing, returns log
48         virtual std::string checkOut() = 0;
49         // can be this operation processed in the current RCS?
50         virtual bool checkOutEnabled() = 0;
51         /// synchronize with repository, returns log
52         virtual std::string repoUpdate() = 0;
53         // can be this operation processed in the current RCS?
54         virtual bool repoUpdateEnabled() = 0;
55         // toggle locking property of the file
56         virtual std::string lockingToggle() = 0;
57         // can be this operation processed in the current RCS?
58         virtual bool lockingToggleEnabled() = 0;
59         /// revert current edits
60         virtual bool revert() = 0;
61         // should a confirmation before revert requested?
62         virtual bool isRevertWithConfirmation() = 0;
63         /// FIXME
64         virtual void undoLast() = 0;
65         // can be this operation processed in the current RCS?
66         virtual bool undoLastEnabled() = 0;
67         /**
68          * getLog - read the revision log into the given file
69          * @param fname file name to read into
70          */
71         virtual void getLog(support::FileName const &) = 0;
72         /// return the current version description
73         virtual std::string const versionString() const = 0;
74         /// set the owning buffer
75         void owner(Buffer * b) { owner_ = b; }
76         /// return the owning buffer
77         Buffer * owner() const { return owner_; }
78         /// return the lock status of this file
79         VCStatus status() const { return vcstatus; }
80         /// do we need special handling for read-only toggling?
81         /// (also used for check-out operation)
82         virtual bool toggleReadOnlyEnabled() = 0;
83         /// Return revision info specified by the argument.
84         virtual std::string revisionInfo(LyXVC::RevisionInfo const info) = 0;
85
86         virtual bool prepareFileRevision(std::string const & rev, std::string & f) = 0;
87
88         virtual bool prepareFileRevisionEnabled() = 0;
89
90 protected:
91         /// parse information from the version file
92         virtual void scanMaster() = 0;
93
94         /// Prepare a version identifier suitable for RCS and CVS.
95         /// If needed converts last or relative number to the absolute revision.
96         bool makeRCSRevision(std::string const &version, std::string &revis) const;
97         
98         // GUI container for doVCCommandCall
99         int doVCCommand(std::string const & cmd, support::FileName const & path, bool reportError = true);
100         /**
101          * doVCCommandCall - call out to the version control utility
102          * @param cmd the command to execute
103          * @param path the path from which to execute
104          * @return exit status
105          */
106         static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
107
108         /**
109          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
110          * have full path.
111          */
112         support::FileName master_;
113
114         /// The status of the VC controlled file.
115         VCStatus vcstatus;
116
117         /// The buffer using this VC
118         Buffer * owner_;
119 };
120
121
122 ///
123 class RCS : public VCS {
124 public:
125
126         explicit
127         RCS(support::FileName const & m);
128
129         /// return the revision file for the given file, if found
130         static support::FileName const findFile(support::FileName const & file);
131
132         static void retrieve(support::FileName const & file);
133
134         virtual void registrer(std::string const & msg);
135
136         virtual std::string checkIn(std::string const & msg);
137
138         virtual bool checkInEnabled();
139
140         virtual bool isCheckInWithConfirmation();
141
142         virtual std::string checkOut();
143
144         virtual bool checkOutEnabled();
145
146         virtual std::string repoUpdate();
147
148         virtual bool repoUpdateEnabled();
149
150         virtual std::string lockingToggle();
151
152         virtual bool lockingToggleEnabled();
153
154         virtual bool revert();
155
156         virtual bool isRevertWithConfirmation();
157
158         virtual void undoLast();
159
160         virtual bool undoLastEnabled();
161
162         virtual void getLog(support::FileName const &);
163
164         virtual std::string const versionString() const {
165                 return "RCS: " + version_;
166         }
167
168         virtual bool toggleReadOnlyEnabled();
169
170         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
171
172         virtual bool prepareFileRevision(std::string const & rev, std::string & f);
173
174         virtual bool prepareFileRevisionEnabled();
175
176 protected:
177         virtual void scanMaster();
178 private:
179         bool getRevisionInfo();
180         /**
181          * The version of the VC file. I am not sure if this can be a
182          * string or if it must be a float/int.
183          */
184         std::string version_;
185         /// The user currently keeping the lock on the VC file (or "Unlocked").
186         std::string locker_;
187         /// Cache for revision info.
188         std::string rev_date_cache_;
189         ///
190         std::string rev_time_cache_;
191         ///
192         std::string rev_author_cache_;
193 };
194
195
196 ///
197 class CVS : public VCS {
198 public:
199         ///
200         explicit
201         CVS(support::FileName const & m, support::FileName const & f);
202
203         /// return the revision file for the given file, if found
204         static support::FileName const findFile(support::FileName const & file);
205
206         virtual void registrer(std::string const & msg);
207
208         virtual std::string checkIn(std::string const & msg);
209
210         virtual bool checkInEnabled();
211
212         virtual bool isCheckInWithConfirmation();
213
214         virtual std::string checkOut();
215
216         virtual bool checkOutEnabled();
217
218         virtual std::string repoUpdate();
219
220         virtual bool repoUpdateEnabled();
221
222         virtual std::string lockingToggle();
223
224         virtual bool lockingToggleEnabled();
225
226         virtual bool isRevertWithConfirmation();
227
228         virtual bool revert();
229
230         virtual void undoLast();
231
232         virtual bool undoLastEnabled();
233
234         virtual void getLog(support::FileName const &);
235
236         /// Check for messages in cvs output. 
237         /// Returns conflict line.
238         std::string scanLogFile(support::FileName const & f, std::string & status);
239
240         virtual std::string const versionString() const {
241                 return "CVS: " + version_;
242         }
243
244         virtual bool toggleReadOnlyEnabled();
245
246         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
247
248         virtual bool prepareFileRevision(std::string const & rev, std::string & f);
249
250         virtual bool prepareFileRevisionEnabled();
251
252 protected:
253         virtual void scanMaster();
254         /// the mode of operation for some VC commands
255         enum OperationMode {
256                 Directory = 0,
257                 File = 1
258         };
259         /// possible status values of file
260         enum CvsStatus {
261                 UpToDate = 0,
262                 LocallyModified = 1,
263                 LocallyAdded = 2,
264                 NeedsMerge = 3,
265                 NeedsCheckout = 4,
266                 NoCvsFile = 5,
267                 StatusError = 6
268         };
269
270 private:
271         support::FileName file_;
272         // revision number from scanMaster
273         std::string version_;
274
275         /**
276          * doVCCommandWithOutput
277          * - call out to the version control utility
278          * - it is able to collect output in a file
279          * @param cmd the command to execute
280          * @param path the path from which to execute
281          * @param output the path where to store output
282          * @param reportError display of low level error message dialog
283          * @return exit status
284          */
285         int doVCCommandWithOutput(std::string const & cmd,
286                         support::FileName const & path,
287                         support::FileName const & output,
288                         bool reportError = true);
289         static int doVCCommandCallWithOutput(std::string const & cmd,
290                         support::FileName const & path,
291                         support::FileName const & output);
292                                                 
293         /// return the quoted pathname if Directory or filename if File
294         virtual std::string const getTarget(OperationMode opmode) const;
295         /// collect the diff of file or directory against repository
296         /// result is placed in temporary file
297         void getDiff(OperationMode opmode, support::FileName const & tmpf);
298         /// make the file ready for editing:
299         /// save a copy in CVS/Base and change file permissions to rw if needed
300         virtual int edit();
301         /// revert the edit operation
302         virtual int unedit();
303         /// retrieve repository changes into working copy
304         virtual int update(OperationMode opmode, support::FileName const & tmpf);
305         /// check readonly state for file
306         /// assume true when file is writable
307         virtual bool isLocked() const;
308         /// query and parse the cvs status of file
309         virtual CvsStatus getStatus();
310         /// convert enum to string
311         virtual docstring toString(CvsStatus status) const;
312
313         /// cache the info values of current file revision
314         /// author, date and time of commit
315         std::string rev_author_cache_;
316         std::string rev_date_cache_;
317         std::string rev_time_cache_;
318         /// fills the cache values, returns true if successfull.
319         void getRevisionInfo();
320         bool have_rev_info_;
321 };
322
323
324 ///
325 class SVN : public VCS {
326 public:
327         ///
328         explicit
329         SVN(support::FileName const & m, support::FileName const & f);
330
331         /// return the revision file for the given file, if found
332         static support::FileName const findFile(support::FileName const & file);
333
334         virtual void registrer(std::string const & msg);
335
336         virtual std::string checkIn(std::string const & msg);
337
338         virtual bool checkInEnabled();
339
340         virtual bool isCheckInWithConfirmation();
341
342         virtual std::string checkOut();
343
344         virtual bool checkOutEnabled();
345
346         virtual std::string repoUpdate();
347
348         virtual bool repoUpdateEnabled();
349
350         virtual std::string lockingToggle();
351
352         virtual bool lockingToggleEnabled();
353
354         virtual bool revert();
355
356         virtual bool isRevertWithConfirmation();
357
358         virtual void undoLast();
359
360         virtual bool undoLastEnabled();
361
362         virtual void getLog(support::FileName const &);
363
364         virtual std::string const versionString() const {
365                 return "SVN: " + rev_file_cache_;
366         }
367
368         virtual bool toggleReadOnlyEnabled();
369
370         virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
371
372         virtual bool prepareFileRevision(std::string const & rev, std::string & f);
373
374         virtual bool prepareFileRevisionEnabled();
375
376 protected:
377         virtual void scanMaster();
378         /// Check for messages in svn output. Returns error.
379         std::string scanLogFile(support::FileName const & f, std::string & status);
380         /// checks locking policy and setup locked_mode_
381         bool checkLockMode();
382         /// is the loaded file locked?
383         bool isLocked() const;
384         /// acquire/release write lock for the current file
385         void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
386
387 private:
388         support::FileName file_;
389         /// is the loaded file under locking policy?
390         bool locked_mode_;
391         /**
392          * Real code for obtaining file revision info. Fills all file-related caches
393          * and returns true if successfull.
394          * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
395          * was already unsuccessful.
396          */
397         bool getFileRevisionInfo();
398         /// cache for file revision number, "?" if already unsuccessful, isNumber==true
399         std::string rev_file_cache_;
400         /// cache for author of last commit
401         std::string rev_author_cache_;
402         /// cache for date of last commit
403         std::string rev_date_cache_;
404         /// cache for time of last commit
405         std::string rev_time_cache_;
406         /// fills rev_tree_cache_, returns true if successfull.
407         bool getTreeRevisionInfo();
408         /// cache for tree revision number, "?" if already unsuccessful
409         std::string rev_tree_cache_;
410 };
411
412 } // namespace lyx
413
414 #endif // VCBACKEND_H