]> git.lyx.org Git - lyx.git/blob - src/VCBackend.h
Hebrew translation updates by Ran
[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
20 namespace lyx {
21
22 class Buffer;
23
24 /// A simple version control system interface
25 class VCS {
26 public:
27         /// the status of the managed file
28         enum VCStatus {
29                 UNLOCKED,
30                 LOCKED
31         };
32
33         virtual ~VCS() {}
34
35         /// register a file for version control
36         virtual void registrer(std::string const & msg) = 0;
37         /// check in the current revision
38         virtual void checkIn(std::string const & msg) = 0;
39         // can be this operation processed in the current RCS?
40         virtual bool checkInEnabled() = 0;
41         /// check out for editing
42         virtual void checkOut() = 0;
43         // can be this operation processed in the current RCS?
44         virtual bool checkOutEnabled() = 0;
45         /// revert current edits
46         virtual void revert() = 0;
47         /// FIXME
48         virtual void undoLast() = 0;
49         // can be this operation processed in the current RCS?
50         virtual bool undoLastEnabled() = 0;
51         /**
52          * getLog - read the revision log into the given file
53          * @param fname file name to read into
54          */
55         virtual void getLog(support::FileName const &) = 0;
56         /// return the current version description
57         virtual std::string const versionString() const = 0;
58         /// return the current version
59         std::string const & version() const { return version_; }
60         /// return the user who has locked the file
61         std::string const & locker() const { return locker_; }
62         /// set the owning buffer
63         void owner(Buffer * b) { owner_ = b; }
64         /// return the owning buffer
65         Buffer * owner() const { return owner_; }
66         /// return the lock status of this file
67         VCStatus status() const { return vcstatus; }
68         /// do we need special handling for read-only toggling?
69         /// (also used for check-out operation)
70         virtual bool toggleReadOnlyEnabled() = 0;
71 protected:
72         /// parse information from the version file
73         virtual void scanMaster() = 0;
74
75         /**
76          * doVCCommand - call out to the version control utility
77          * @param cmd the command to execute
78          * @param path the path from which to execute
79          * @return exit status
80          */
81         static int doVCCommand(std::string const & cmd, support::FileName const & path);
82
83         /**
84          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
85          * have full path.
86          */
87         support::FileName master_;
88
89         /// The status of the VC controlled file.
90         VCStatus vcstatus;
91
92         /**
93          * The version of the VC file. I am not sure if this can be a
94          * string or if it must be a float/int.
95          */
96         std::string version_;
97
98         /// The user currently keeping the lock on the VC file.
99         std::string locker_;
100         /// The buffer using this VC
101         Buffer * owner_;
102 };
103
104
105 ///
106 class RCS : public VCS {
107 public:
108
109         explicit
110         RCS(support::FileName const & m);
111
112         /// return the revision file for the given file, if found
113         static support::FileName const findFile(support::FileName const & file);
114
115         static void retrieve(support::FileName const & file);
116
117         virtual void registrer(std::string const & msg);
118
119         virtual void checkIn(std::string const & msg);
120
121         virtual bool checkInEnabled();
122
123         virtual void checkOut();
124
125         virtual bool checkOutEnabled();
126
127         virtual void revert();
128
129         virtual void undoLast();
130
131         virtual bool undoLastEnabled();
132
133         virtual void getLog(support::FileName const &);
134
135         virtual std::string const versionString() const {
136                 return "RCS: " + version_;
137         }
138
139         virtual bool toggleReadOnlyEnabled();
140
141 protected:
142         virtual void scanMaster();
143 };
144
145
146 ///
147 class CVS : public VCS {
148 public:
149         ///
150         explicit
151         CVS(support::FileName const & m, support::FileName const & f);
152
153         /// return the revision file for the given file, if found
154         static support::FileName const findFile(support::FileName const & file);
155
156         virtual void registrer(std::string const & msg);
157
158         virtual void checkIn(std::string const & msg);
159
160         virtual bool checkInEnabled();
161
162         virtual void checkOut();
163
164         virtual bool checkOutEnabled();
165
166         virtual void revert();
167
168         virtual void undoLast();
169
170         virtual bool undoLastEnabled();
171
172         virtual void getLog(support::FileName const &);
173
174         virtual std::string const versionString() const {
175                 return "CVS: " + version_;
176         }
177
178         virtual bool toggleReadOnlyEnabled();
179
180 protected:
181         virtual void scanMaster();
182
183 private:
184         support::FileName file_;
185 };
186
187
188 ///
189 class SVN : public VCS {
190 public:
191         ///
192         explicit
193         SVN(support::FileName const & m, support::FileName const & f);
194
195         /// return the revision file for the given file, if found
196         static support::FileName const findFile(support::FileName const & file);
197
198         virtual void registrer(std::string const & msg);
199
200         virtual void checkIn(std::string const & msg);
201
202         virtual bool checkInEnabled();
203
204         virtual void checkOut();
205
206         virtual bool checkOutEnabled();
207
208         virtual void revert();
209
210         virtual void undoLast();
211
212         virtual bool undoLastEnabled();
213
214         virtual void getLog(support::FileName const &);
215
216         virtual std::string const versionString() const {
217                 return "SVN: " + version_;
218         }
219
220         virtual bool toggleReadOnlyEnabled();
221
222 protected:
223         virtual void scanMaster();
224         /// Check for error messages in svn output.
225         std::string scanLogFile(support::FileName const & f);
226
227 private:
228         support::FileName file_;
229 };
230
231 } // namespace lyx
232
233 #endif // VCBACKEND_H