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
37 VCS(Buffer * b) : owner_(b) {}
40 /// register a file for version control
41 virtual void registrer(std::string const & msg) = 0;
42 /// check in the current revision, returns log
43 virtual std::string checkIn(std::string const & msg) = 0;
44 // can be this operation processed in the current RCS?
45 virtual bool checkInEnabled() = 0;
46 // should a log message provided for next checkin?
47 virtual bool isCheckInWithConfirmation() = 0;
48 /// check out for editing, returns log
49 virtual std::string checkOut() = 0;
50 // can be this operation processed in the current RCS?
51 virtual bool checkOutEnabled() = 0;
52 /// synchronize with repository, returns log
53 virtual std::string repoUpdate() = 0;
54 // can be this operation processed in the current RCS?
55 virtual bool repoUpdateEnabled() = 0;
56 // toggle locking property of the file
57 virtual std::string lockingToggle() = 0;
58 // can be this operation processed in the current RCS?
59 virtual bool lockingToggleEnabled() = 0;
60 /// revert current edits
61 virtual bool revert() = 0;
62 // should a confirmation before revert requested?
63 virtual bool isRevertWithConfirmation() = 0;
65 virtual void undoLast() = 0;
66 // can be this operation processed in the current RCS?
67 virtual bool undoLastEnabled() = 0;
69 * getLog - read the revision log into the given file
70 * @param fname file name to read into
72 virtual void getLog(support::FileName const &) = 0;
73 /// return the current version description
74 virtual std::string const versionString() const = 0;
75 /// return the owning buffer
76 Buffer * owner() const { return owner_; }
77 /// return the lock status of this file
78 VCStatus status() const { return vcstatus; }
79 /// do we need special handling for read-only toggling?
80 /// (also used for check-out operation)
81 virtual bool toggleReadOnlyEnabled() = 0;
82 /// Return revision info specified by the argument.
83 virtual std::string revisionInfo(LyXVC::RevisionInfo const info) = 0;
85 virtual bool prepareFileRevision(std::string const & rev, std::string & f) = 0;
87 virtual bool prepareFileRevisionEnabled() = 0;
89 /// Check the directory of file and all parent directories
90 // for the existence of the given pathname
91 static bool checkparentdirs(support::FileName const & file, std::string const & pathname);
94 /// parse information from the version file
95 virtual void scanMaster() = 0;
97 /// Prepare a version identifier suitable for RCS and CVS.
98 /// If needed converts last or relative number to the absolute revision.
99 bool makeRCSRevision(std::string const &version, std::string &revis) const;
101 // GUI container for doVCCommandCall
102 int doVCCommand(std::string const & cmd, support::FileName const & path, bool reportError = true);
104 * doVCCommandCall - call out to the version control utility
105 * @param cmd the command to execute
106 * @param path the path from which to execute
107 * @return exit status
109 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
112 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
115 support::FileName master_;
117 /// The status of the VC controlled file.
120 /// The buffer using this VC
121 Buffer * const owner_;
126 class RCS : public VCS {
130 RCS(support::FileName const & m, Buffer * b);
132 /// return the revision file for the given file, if found
133 static support::FileName const findFile(support::FileName const & file);
135 static void retrieve(support::FileName const & file);
137 virtual void registrer(std::string const & msg);
139 virtual std::string checkIn(std::string const & msg);
141 virtual bool checkInEnabled();
143 virtual bool isCheckInWithConfirmation();
145 virtual std::string checkOut();
147 virtual bool checkOutEnabled();
149 virtual std::string repoUpdate();
151 virtual bool repoUpdateEnabled();
153 virtual std::string lockingToggle();
155 virtual bool lockingToggleEnabled();
157 virtual bool revert();
159 virtual bool isRevertWithConfirmation();
161 virtual void undoLast();
163 virtual bool undoLastEnabled();
165 virtual void getLog(support::FileName const &);
167 virtual std::string const versionString() const {
168 return "RCS: " + version_;
171 virtual bool toggleReadOnlyEnabled();
173 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
175 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
177 virtual bool prepareFileRevisionEnabled();
180 virtual void scanMaster();
182 bool getRevisionInfo();
184 * The version of the VC file. I am not sure if this can be a
185 * string or if it must be a float/int.
187 std::string version_;
188 /// The user currently keeping the lock on the VC file (or "Unlocked").
190 /// Cache for revision info.
191 std::string rev_date_cache_;
193 std::string rev_time_cache_;
195 std::string rev_author_cache_;
200 class CVS : public VCS {
204 CVS(support::FileName const & m, Buffer * b);
206 /// return the revision file for the given file, if found
207 static support::FileName const findFile(support::FileName const & file);
209 virtual void registrer(std::string const & msg);
211 virtual std::string checkIn(std::string const & msg);
213 virtual bool checkInEnabled();
215 virtual bool isCheckInWithConfirmation();
217 virtual std::string checkOut();
219 virtual bool checkOutEnabled();
221 virtual std::string repoUpdate();
223 virtual bool repoUpdateEnabled();
225 virtual std::string lockingToggle();
227 virtual bool lockingToggleEnabled();
229 virtual bool isRevertWithConfirmation();
231 virtual bool revert();
233 virtual void undoLast();
235 virtual bool undoLastEnabled();
237 virtual void getLog(support::FileName const &);
239 /// Check for messages in cvs output.
240 /// Returns conflict line.
241 std::string scanLogFile(support::FileName const & f, std::string & status);
243 virtual std::string const versionString() const {
244 return "CVS: " + version_;
247 virtual bool toggleReadOnlyEnabled();
249 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
251 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
253 virtual bool prepareFileRevisionEnabled();
256 virtual void scanMaster();
257 /// the mode of operation for some VC commands
262 /// possible status values of file
274 // revision number from scanMaster
275 std::string version_;
278 * doVCCommandWithOutput
279 * - call out to the version control utility
280 * - it is able to collect output in a file
281 * @param cmd the command to execute
282 * @param path the path from which to execute
283 * @param output the path where to store output
284 * @param reportError display of low level error message dialog
285 * @return exit status
287 int doVCCommandWithOutput(std::string const & cmd,
288 support::FileName const & path,
289 support::FileName const & output,
290 bool reportError = true);
291 static int doVCCommandCallWithOutput(std::string const & cmd,
292 support::FileName const & path,
293 support::FileName const & output);
295 /// return the quoted pathname if Directory or filename if File
296 virtual std::string const getTarget(OperationMode opmode) const;
297 /// collect the diff of file or directory against repository
298 /// result is placed in temporary file
299 void getDiff(OperationMode opmode, support::FileName const & tmpf);
300 /// make the file ready for editing:
301 /// save a copy in CVS/Base and change file permissions to rw if needed
303 /// revert the edit operation
304 virtual int unedit();
305 /// retrieve repository changes into working copy
306 virtual int update(OperationMode opmode, support::FileName const & tmpf);
307 /// check readonly state for file
308 /// assume true when file is writable
309 virtual bool isLocked() const;
310 /// query and parse the cvs status of file
311 virtual CvsStatus getStatus();
312 /// convert enum to string
313 virtual docstring toString(CvsStatus status) const;
315 /// cache the info values of current file revision
316 /// author, date and time of commit
317 std::string rev_author_cache_;
318 std::string rev_date_cache_;
319 std::string rev_time_cache_;
320 /// fills the cache values, returns true if successfull.
321 void getRevisionInfo();
327 class SVN : public VCS {
331 SVN(support::FileName const & m, Buffer * b);
333 /// return the revision file for the given file, if found
334 static support::FileName const findFile(support::FileName const & file);
336 virtual void registrer(std::string const & msg);
338 virtual std::string checkIn(std::string const & msg);
340 virtual bool checkInEnabled();
342 virtual bool isCheckInWithConfirmation();
344 virtual std::string checkOut();
346 virtual bool checkOutEnabled();
348 virtual std::string repoUpdate();
350 virtual bool repoUpdateEnabled();
352 virtual std::string lockingToggle();
354 virtual bool lockingToggleEnabled();
356 virtual bool revert();
358 virtual bool isRevertWithConfirmation();
360 virtual void undoLast();
362 virtual bool undoLastEnabled();
364 virtual void getLog(support::FileName const &);
366 virtual std::string const versionString() const {
367 return "SVN: " + rev_file_cache_;
370 virtual bool toggleReadOnlyEnabled();
372 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
374 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
376 virtual bool prepareFileRevisionEnabled();
379 virtual void scanMaster();
380 /// Check for messages in svn output. Returns error.
381 std::string scanLogFile(support::FileName const & f, std::string & status);
382 /// checks locking policy and setup locked_mode_
383 bool checkLockMode();
384 /// is the loaded file locked?
385 bool isLocked() const;
386 /// acquire/release write lock for the current file
387 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
390 /// is the loaded file under locking policy?
393 * Real code for obtaining file revision info. Fills all file-related caches
394 * and returns true if successfull.
395 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
396 * was already unsuccessful.
398 bool getFileRevisionInfo();
399 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
400 std::string rev_file_cache_;
401 /// cache for author of last commit
402 std::string rev_author_cache_;
403 /// cache for date of last commit
404 std::string rev_date_cache_;
405 /// cache for time of last commit
406 std::string rev_time_cache_;
407 /// fills rev_tree_cache_, returns true if successfull.
408 bool getTreeRevisionInfo();
409 /// cache for tree revision number, "?" if already unsuccessful
410 std::string rev_tree_cache_;
415 #endif // VCBACKEND_H