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 /// parse information from the version file
83 virtual void scanMaster() = 0;
85 // GUI container for doVCCommandCall
86 int doVCCommand(std::string const & cmd, support::FileName const & path);
88 * doVCCommandCall - call out to the version control utility
89 * @param cmd the command to execute
90 * @param path the path from which to execute
93 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
96 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
99 support::FileName master_;
101 /// The status of the VC controlled file.
104 /// The buffer using this VC
110 class RCS : public VCS {
114 RCS(support::FileName const & m);
116 /// return the revision file for the given file, if found
117 static support::FileName const findFile(support::FileName const & file);
119 static void retrieve(support::FileName const & file);
121 virtual void registrer(std::string const & msg);
123 virtual std::string checkIn(std::string const & msg);
125 virtual bool checkInEnabled();
127 virtual std::string checkOut();
129 virtual bool checkOutEnabled();
131 virtual std::string repoUpdate();
133 virtual bool repoUpdateEnabled();
135 virtual std::string lockingToggle();
137 virtual bool lockingToggleEnabled();
139 virtual void revert();
141 virtual void undoLast();
143 virtual bool undoLastEnabled();
145 virtual void getLog(support::FileName const &);
147 virtual std::string const versionString() const {
148 return "RCS: " + version_;
151 virtual bool toggleReadOnlyEnabled();
153 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
156 virtual void scanMaster();
159 * The version of the VC file. I am not sure if this can be a
160 * string or if it must be a float/int.
162 std::string version_;
163 /// The user currently keeping the lock on the VC file (or "Unlocked").
169 class CVS : public VCS {
173 CVS(support::FileName const & m, support::FileName const & f);
175 /// return the revision file for the given file, if found
176 static support::FileName const findFile(support::FileName const & file);
178 virtual void registrer(std::string const & msg);
180 virtual std::string checkIn(std::string const & msg);
182 virtual bool checkInEnabled();
184 virtual std::string checkOut();
186 virtual bool checkOutEnabled();
188 virtual std::string repoUpdate();
190 virtual bool repoUpdateEnabled();
192 virtual std::string lockingToggle();
194 virtual bool lockingToggleEnabled();
196 virtual void revert();
198 virtual void undoLast();
200 virtual bool undoLastEnabled();
202 virtual void getLog(support::FileName const &);
204 virtual std::string const versionString() const {
205 return "CVS: " + version_;
208 virtual bool toggleReadOnlyEnabled();
210 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
213 virtual void scanMaster();
216 support::FileName file_;
217 // revision number from scanMaster
218 std::string version_;
219 /// The user currently keeping the lock on the VC file.
225 class SVN : public VCS {
229 SVN(support::FileName const & m, support::FileName const & f);
231 /// return the revision file for the given file, if found
232 static support::FileName const findFile(support::FileName const & file);
234 virtual void registrer(std::string const & msg);
236 virtual std::string checkIn(std::string const & msg);
238 virtual bool checkInEnabled();
240 virtual std::string checkOut();
242 virtual bool checkOutEnabled();
244 virtual std::string repoUpdate();
246 virtual bool repoUpdateEnabled();
248 virtual std::string lockingToggle();
250 virtual bool lockingToggleEnabled();
252 virtual void revert();
254 virtual void undoLast();
256 virtual bool undoLastEnabled();
258 virtual void getLog(support::FileName const &);
260 virtual std::string const versionString() const {
261 return "SVN: " + rev_file_cache_;
264 virtual bool toggleReadOnlyEnabled();
266 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
269 virtual void scanMaster();
270 /// Check for messages in svn output. Returns error.
271 std::string scanLogFile(support::FileName const & f, std::string & status);
272 /// checks locking policy and setup locked_mode_
273 bool checkLockMode();
274 /// is the loaded file locked?
275 bool isLocked() const;
276 /// acquire/release write lock for the current file
277 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
280 support::FileName file_;
281 /// is the loaded file under locking policy?
284 * Real code for obtaining file revision info. Fills all file-related caches
285 * and returns true if successfull.
286 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
287 * was already unsuccessful.
289 bool getFileRevisionInfo();
290 /// cache for file revision number, "?" if already unsuccessful
291 std::string rev_file_cache_;
292 /// cache for author of last commit
293 std::string rev_author_cache_;
294 /// cache for date of last commit
295 std::string rev_date_cache_;
296 /// cache for time of last commit
297 std::string rev_time_cache_;
298 /// fills rev_tree_cache_, returns true if successfull.
299 bool getTreeRevisionInfo();
300 /// cache for tree revision number, "?" if already unsuccessful
301 std::string rev_tree_cache_;
306 #endif // VCBACKEND_H