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