Another minor change, but this should almost get us to the point that we
[lyx.git] / src / VCBackend.h
blobdbcd84ca8151016dd84db7f979f94a7ca5f8952e
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.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
12 #ifndef VC_BACKEND_H
13 #define VC_BACKEND_H
15 #include "support/FileName.h"
17 #include <string>
20 namespace lyx {
22 class Buffer;
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 NOLOCKING
34 virtual ~VCS() {}
36 /// register a file for version control
37 virtual void registrer(std::string const & msg) = 0;
38 /// check in the current revision, returns log
39 virtual std::string checkIn(std::string const & msg) = 0;
40 // can be this operation processed in the current RCS?
41 virtual bool checkInEnabled() = 0;
42 /// check out for editing, returns log
43 virtual std::string checkOut() = 0;
44 // can be this operation processed in the current RCS?
45 virtual bool checkOutEnabled() = 0;
46 /// synchronize with repository, returns log
47 virtual std::string repoUpdate() = 0;
48 // can be this operation processed in the current RCS?
49 virtual bool repoUpdateEnabled() = 0;
50 // toggle locking property of the file
51 virtual std::string lockingToggle() = 0;
52 // can be this operation processed in the current RCS?
53 virtual bool lockingToggleEnabled() = 0;
54 /// revert current edits
55 virtual void revert() = 0;
56 /// FIXME
57 virtual void undoLast() = 0;
58 // can be this operation processed in the current RCS?
59 virtual bool undoLastEnabled() = 0;
60 /**
61 * getLog - read the revision log into the given file
62 * @param fname file name to read into
64 virtual void getLog(support::FileName const &) = 0;
65 /// return the current version description
66 virtual std::string const versionString() const = 0;
67 /// return the current version
68 std::string const & version() const { return version_; }
69 /// return the user who has locked the file
70 std::string const & locker() const { return locker_; }
71 /// set the owning buffer
72 void owner(Buffer * b) { owner_ = b; }
73 /// return the owning buffer
74 Buffer * owner() const { return owner_; }
75 /// return the lock status of this file
76 VCStatus status() const { return vcstatus; }
77 /// do we need special handling for read-only toggling?
78 /// (also used for check-out operation)
79 virtual bool toggleReadOnlyEnabled() = 0;
80 protected:
81 /// parse information from the version file
82 virtual void scanMaster() = 0;
84 // GUI container for doVCCommandCall
85 int doVCCommand(std::string const & cmd, support::FileName const & path);
86 /**
87 * doVCCommandCall - call out to the version control utility
88 * @param cmd the command to execute
89 * @param path the path from which to execute
90 * @return exit status
92 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
94 /**
95 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
96 * have full path.
98 support::FileName master_;
100 /// The status of the VC controlled file.
101 VCStatus vcstatus;
104 * The version of the VC file. I am not sure if this can be a
105 * string or if it must be a float/int.
107 std::string version_;
109 /// The user currently keeping the lock on the VC file.
110 std::string locker_;
111 /// The buffer using this VC
112 Buffer * owner_;
117 class RCS : public VCS {
118 public:
120 explicit
121 RCS(support::FileName const & m);
123 /// return the revision file for the given file, if found
124 static support::FileName const findFile(support::FileName const & file);
126 static void retrieve(support::FileName const & file);
128 virtual void registrer(std::string const & msg);
130 virtual std::string checkIn(std::string const & msg);
132 virtual bool checkInEnabled();
134 virtual std::string checkOut();
136 virtual bool checkOutEnabled();
138 virtual std::string repoUpdate();
140 virtual bool repoUpdateEnabled();
142 virtual std::string lockingToggle();
144 virtual bool lockingToggleEnabled();
146 virtual void revert();
148 virtual void undoLast();
150 virtual bool undoLastEnabled();
152 virtual void getLog(support::FileName const &);
154 virtual std::string const versionString() const {
155 return "RCS: " + version_;
158 virtual bool toggleReadOnlyEnabled();
160 protected:
161 virtual void scanMaster();
166 class CVS : public VCS {
167 public:
169 explicit
170 CVS(support::FileName const & m, support::FileName const & f);
172 /// return the revision file for the given file, if found
173 static support::FileName const findFile(support::FileName const & file);
175 virtual void registrer(std::string const & msg);
177 virtual std::string checkIn(std::string const & msg);
179 virtual bool checkInEnabled();
181 virtual std::string checkOut();
183 virtual bool checkOutEnabled();
185 virtual std::string repoUpdate();
187 virtual bool repoUpdateEnabled();
189 virtual std::string lockingToggle();
191 virtual bool lockingToggleEnabled();
193 virtual void revert();
195 virtual void undoLast();
197 virtual bool undoLastEnabled();
199 virtual void getLog(support::FileName const &);
201 virtual std::string const versionString() const {
202 return "CVS: " + version_;
205 virtual bool toggleReadOnlyEnabled();
207 protected:
208 virtual void scanMaster();
210 private:
211 support::FileName file_;
216 class SVN : public VCS {
217 public:
219 explicit
220 SVN(support::FileName const & m, support::FileName const & f);
222 /// return the revision file for the given file, if found
223 static support::FileName const findFile(support::FileName const & file);
225 virtual void registrer(std::string const & msg);
227 virtual std::string checkIn(std::string const & msg);
229 virtual bool checkInEnabled();
231 virtual std::string checkOut();
233 virtual bool checkOutEnabled();
235 virtual std::string repoUpdate();
237 virtual bool repoUpdateEnabled();
239 virtual std::string lockingToggle();
241 virtual bool lockingToggleEnabled();
243 virtual void revert();
245 virtual void undoLast();
247 virtual bool undoLastEnabled();
249 virtual void getLog(support::FileName const &);
251 virtual std::string const versionString() const {
252 return "SVN: " + version_;
255 virtual bool toggleReadOnlyEnabled();
257 protected:
258 virtual void scanMaster();
259 /// Check for messages in svn output. Returns error.
260 std::string scanLogFile(support::FileName const & f, std::string & status);
261 /// checks locking policy and setup locked_mode_
262 bool checkLockMode();
263 /// is the loaded file locked?
264 bool isLocked() const;
265 /// acquire/release write lock for the current file
266 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
268 private:
269 support::FileName file_;
270 /// is the loaded file under locking policy?
271 bool locked_mode_;
274 } // namespace lyx
276 #endif // VCBACKEND_H