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
10 * Full author contact details are available in file CREDITS.
16 #include "support/FileName.h"
27 /// A simple version control system interface
30 /// the status of the managed file
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;
60 virtual void undoLast() = 0;
61 // can be this operation processed in the current RCS?
62 virtual bool undoLastEnabled() = 0;
64 * getLog - read the revision log into the given file
65 * @param fname file name to read into
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;
82 virtual bool prepareFileRevision(int rev, std::string & f) = 0;
84 virtual bool prepareFileRevisionEnabled() = 0;
87 /// parse information from the version file
88 virtual void scanMaster() = 0;
90 // GUI container for doVCCommandCall
91 int doVCCommand(std::string const & cmd, support::FileName const & path);
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
98 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
101 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
104 support::FileName master_;
106 /// The status of the VC controlled file.
109 /// The buffer using this VC
115 class RCS : public VCS {
119 RCS(support::FileName const & m);
121 /// return the revision file for the given file, if found
122 static support::FileName const findFile(support::FileName const & file);
124 static void retrieve(support::FileName const & file);
126 virtual void registrer(std::string const & msg);
128 virtual std::string checkIn(std::string const & msg);
130 virtual bool checkInEnabled();
132 virtual std::string checkOut();
134 virtual bool checkOutEnabled();
136 virtual std::string repoUpdate();
138 virtual bool repoUpdateEnabled();
140 virtual std::string lockingToggle();
142 virtual bool lockingToggleEnabled();
144 virtual void revert();
146 virtual void undoLast();
148 virtual bool undoLastEnabled();
150 virtual void getLog(support::FileName const &);
152 virtual std::string const versionString() const {
153 return "RCS: " + version_;
156 virtual bool toggleReadOnlyEnabled();
158 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
160 virtual bool prepareFileRevision(int rev, std::string & f);
162 virtual bool prepareFileRevisionEnabled();
165 virtual void scanMaster();
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.
171 std::string version_;
172 /// The user currently keeping the lock on the VC file (or "Unlocked").
178 class CVS : public VCS {
182 CVS(support::FileName const & m, support::FileName const & f);
184 /// return the revision file for the given file, if found
185 static support::FileName const findFile(support::FileName const & file);
187 virtual void registrer(std::string const & msg);
189 virtual std::string checkIn(std::string const & msg);
191 virtual bool checkInEnabled();
193 virtual std::string checkOut();
195 virtual bool checkOutEnabled();
197 virtual std::string repoUpdate();
199 virtual bool repoUpdateEnabled();
201 virtual std::string lockingToggle();
203 virtual bool lockingToggleEnabled();
205 virtual void revert();
207 virtual void undoLast();
209 virtual bool undoLastEnabled();
211 virtual void getLog(support::FileName const &);
213 virtual std::string const versionString() const {
214 return "CVS: " + version_;
217 virtual bool toggleReadOnlyEnabled();
219 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
221 virtual bool prepareFileRevision(int rev, std::string & f);
223 virtual bool prepareFileRevisionEnabled();
226 virtual void scanMaster();
229 support::FileName file_;
230 // revision number from scanMaster
231 std::string version_;
232 /// The user currently keeping the lock on the VC file.
238 class SVN : public VCS {
242 SVN(support::FileName const & m, support::FileName const & f);
244 /// return the revision file for the given file, if found
245 static support::FileName const findFile(support::FileName const & file);
247 virtual void registrer(std::string const & msg);
249 virtual std::string checkIn(std::string const & msg);
251 virtual bool checkInEnabled();
253 virtual std::string checkOut();
255 virtual bool checkOutEnabled();
257 virtual std::string repoUpdate();
259 virtual bool repoUpdateEnabled();
261 virtual std::string lockingToggle();
263 virtual bool lockingToggleEnabled();
265 virtual void revert();
267 virtual void undoLast();
269 virtual bool undoLastEnabled();
271 virtual void getLog(support::FileName const &);
273 virtual std::string const versionString() const {
274 return "SVN: " + rev_file_cache_;
277 virtual bool toggleReadOnlyEnabled();
279 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
281 virtual bool prepareFileRevision(int rev, std::string & f);
283 virtual bool prepareFileRevisionEnabled();
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);
297 support::FileName file_;
298 /// is the loaded file under locking policy?
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.
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_;
323 #endif // VCBACKEND_H