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(std::string const & 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, bool reportError = true);
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(std::string const & 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 /// Check for messages in cvs output.
214 /// Returns conflict line.
215 std::string scanLogFile(support::FileName const & f, std::string & status);
217 virtual std::string const versionString() const {
218 return "CVS: " + version_;
221 virtual bool toggleReadOnlyEnabled();
223 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
225 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
227 virtual bool prepareFileRevisionEnabled();
230 virtual void scanMaster();
231 /// the mode of operation for some VC commands
236 /// possible status values of file
248 support::FileName file_;
249 // revision number from scanMaster
250 std::string version_;
252 /// return the quoted pathname if Directory or filename if File
253 virtual std::string const getTarget(OperationMode opmode) const;
254 /// collect the diff of file or directory against repository
255 /// result is placed in temporary file
256 void getDiff(OperationMode opmode, support::FileName const & tmpf);
257 /// make the file ready for editing:
258 /// save a copy in CVS/Base and change file permissions to rw if needed
260 /// revert the edit operation
261 virtual int unedit();
262 /// retrieve repository changes into working copy
263 virtual int update(OperationMode opmode, support::FileName const & tmpf);
264 /// check readonly state for file
265 /// assume true when file is writable
266 virtual bool isLocked() const;
267 /// query and parse the cvs status of file
268 virtual CvsStatus getStatus();
269 /// convert enum to string
270 virtual docstring toString(CvsStatus status) const;
275 class SVN : public VCS {
279 SVN(support::FileName const & m, support::FileName const & f);
281 /// return the revision file for the given file, if found
282 static support::FileName const findFile(support::FileName const & file);
284 virtual void registrer(std::string const & msg);
286 virtual std::string checkIn(std::string const & msg);
288 virtual bool checkInEnabled();
290 virtual std::string checkOut();
292 virtual bool checkOutEnabled();
294 virtual std::string repoUpdate();
296 virtual bool repoUpdateEnabled();
298 virtual std::string lockingToggle();
300 virtual bool lockingToggleEnabled();
302 virtual void revert();
304 virtual void undoLast();
306 virtual bool undoLastEnabled();
308 virtual void getLog(support::FileName const &);
310 virtual std::string const versionString() const {
311 return "SVN: " + rev_file_cache_;
314 virtual bool toggleReadOnlyEnabled();
316 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
318 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
320 virtual bool prepareFileRevisionEnabled();
323 virtual void scanMaster();
324 /// Check for messages in svn output. Returns error.
325 std::string scanLogFile(support::FileName const & f, std::string & status);
326 /// checks locking policy and setup locked_mode_
327 bool checkLockMode();
328 /// is the loaded file locked?
329 bool isLocked() const;
330 /// acquire/release write lock for the current file
331 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
334 support::FileName file_;
335 /// is the loaded file under locking policy?
338 * Real code for obtaining file revision info. Fills all file-related caches
339 * and returns true if successfull.
340 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
341 * was already unsuccessful.
343 bool getFileRevisionInfo();
344 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
345 std::string rev_file_cache_;
346 /// cache for author of last commit
347 std::string rev_author_cache_;
348 /// cache for date of last commit
349 std::string rev_date_cache_;
350 /// cache for time of last commit
351 std::string rev_time_cache_;
352 /// fills rev_tree_cache_, returns true if successfull.
353 bool getTreeRevisionInfo();
354 /// cache for tree revision number, "?" if already unsuccessful
355 std::string rev_tree_cache_;
360 #endif // VCBACKEND_H