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.
43 /// \p log is non-empty on success and may be empty on failure.
44 virtual LyXVC::CommandResult
45 checkIn(std::string const & msg, std::string & log) = 0;
46 /// can this operation be processed in the current VCS?
47 virtual bool checkInEnabled() = 0;
48 /// should a log message provided for next checkin?
49 virtual bool isCheckInWithConfirmation() = 0;
50 /// check out for editing, returns log
51 virtual std::string checkOut() = 0;
52 /// can this operation be processed in the current VCS?
53 virtual bool checkOutEnabled() = 0;
54 /// synchronize with repository, returns log
55 virtual std::string repoUpdate() = 0;
56 /// can this operation be processed in the current VCS?
57 virtual bool repoUpdateEnabled() = 0;
58 /// toggle locking property of the file
59 virtual std::string lockingToggle() = 0;
60 /// can this operation be processed in the current VCS?
61 virtual bool lockingToggleEnabled() = 0;
62 /// revert current edits
63 virtual bool revert() = 0;
64 /// should a confirmation before revert requested?
65 virtual bool isRevertWithConfirmation() = 0;
67 * Merge the current with the previous version
68 * in a reverse patch kind of way, so that the
69 * result is to revert the last changes.
71 virtual void undoLast() = 0;
72 /// can this operation be processed in the current VCS?
73 virtual bool undoLastEnabled() = 0;
75 * getLog - read the revision log into the given file
76 * @param fname file name to read into
78 virtual void getLog(support::FileName const &) = 0;
79 /// return the current version description
80 virtual std::string const versionString() const = 0;
81 /// return the owning buffer
82 Buffer * owner() const { return owner_; }
83 /// return the lock status of this file
84 VCStatus status() const { return vcstatus; }
85 /// do we need special handling for read-only toggling?
86 /// (also used for check-out operation)
87 virtual bool toggleReadOnlyEnabled() = 0;
88 /// Return revision info specified by the argument.
89 virtual std::string revisionInfo(LyXVC::RevisionInfo const info) = 0;
90 /// can this operation be processed in the current VCS?
91 virtual bool prepareFileRevision(std::string const & rev, std::string & f) = 0;
92 /// can this operation be processed in the current VCS?
93 virtual bool prepareFileRevisionEnabled() = 0;
95 /// Check the directory of file and all parent directories
96 /// for the existence of the given pathname
97 static bool checkparentdirs(support::FileName const & file, std::string const & pathname);
100 /// parse information from the version file
101 virtual void scanMaster() = 0;
103 /// Prepare a version identifier suitable for RCS and CVS.
104 /// If needed converts last or relative number to the absolute revision.
105 bool makeRCSRevision(std::string const &version, std::string &revis) const;
107 /// GUI container for doVCCommandCall
108 int doVCCommand(std::string const & cmd, support::FileName const & path, bool reportError = true);
110 * doVCCommandCall - call out to the version control utility
111 * @param cmd the command to execute
112 * @param path the path from which to execute
113 * @return exit status
115 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
118 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
121 support::FileName master_;
123 /// The status of the VC controlled file.
126 /// The buffer using this VC
127 Buffer * const owner_;
132 class RCS : public VCS {
136 RCS(support::FileName const & m, Buffer * b);
138 /// return the revision file for the given file, if found
139 static support::FileName const findFile(support::FileName const & file);
141 static bool retrieve(support::FileName const & file);
143 virtual void registrer(std::string const & msg);
145 virtual LyXVC::CommandResult
146 checkIn(std::string const & msg, std::string & log);
148 virtual bool checkInEnabled();
150 virtual bool isCheckInWithConfirmation();
152 virtual std::string checkOut();
154 virtual bool checkOutEnabled();
156 virtual std::string repoUpdate();
158 virtual bool repoUpdateEnabled();
160 virtual std::string lockingToggle();
162 virtual bool lockingToggleEnabled();
164 virtual bool revert();
166 virtual bool isRevertWithConfirmation();
168 virtual void undoLast();
170 virtual bool undoLastEnabled();
172 virtual void getLog(support::FileName const &);
174 virtual std::string const versionString() const {
175 return "RCS: " + version_;
178 virtual bool toggleReadOnlyEnabled();
180 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
182 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
184 virtual bool prepareFileRevisionEnabled();
187 virtual void scanMaster();
189 bool getRevisionInfo();
191 * The version of the VC file. I am not sure if this can be a
192 * string or if it must be a float/int.
194 std::string version_;
195 /// The user currently keeping the lock on the VC file (or "Unlocked").
197 /// Cache for revision info.
198 std::string rev_date_cache_;
200 std::string rev_time_cache_;
202 std::string rev_author_cache_;
207 class CVS : public VCS {
211 CVS(support::FileName const & m, Buffer * b);
213 /// return the revision file for the given file, if found
214 static support::FileName const findFile(support::FileName const & file);
216 static bool retrieve(support::FileName const & file);
218 virtual void registrer(std::string const & msg);
220 virtual LyXVC::CommandResult
221 checkIn(std::string const & msg, std::string & log);
223 virtual bool checkInEnabled();
225 virtual bool isCheckInWithConfirmation();
227 virtual std::string checkOut();
229 virtual bool checkOutEnabled();
231 virtual std::string repoUpdate();
233 virtual bool repoUpdateEnabled();
235 virtual std::string lockingToggle();
237 virtual bool lockingToggleEnabled();
239 virtual bool isRevertWithConfirmation();
241 virtual bool revert();
243 virtual void undoLast();
245 virtual bool undoLastEnabled();
247 virtual void getLog(support::FileName const &);
249 /// Check for messages in cvs output.
250 /// Returns conflict line.
251 std::string scanLogFile(support::FileName const & f, std::string & status);
253 virtual std::string const versionString() const {
254 return "CVS: " + version_;
257 virtual bool toggleReadOnlyEnabled();
259 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
261 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
263 virtual bool prepareFileRevisionEnabled();
266 virtual void scanMaster();
267 /// the mode of operation for some VC commands
272 /// possible status values of file
284 // revision number from scanMaster
285 std::string version_;
288 * doVCCommandWithOutput
289 * - call out to the version control utility
290 * - it is able to collect output in a file
291 * @param cmd the command to execute
292 * @param path the path from which to execute
293 * @param output the path where to store output
294 * @param reportError display of low level error message dialog
295 * @return exit status
297 int doVCCommandWithOutput(std::string const & cmd,
298 support::FileName const & path,
299 support::FileName const & output,
300 bool reportError = true);
301 static int doVCCommandCallWithOutput(std::string const & cmd,
302 support::FileName const & path,
303 support::FileName const & output);
305 /// return the quoted pathname if Directory or filename if File
306 virtual std::string const getTarget(OperationMode opmode) const;
307 /// collect the diff of file or directory against repository
308 /// result is placed in temporary file
309 void getDiff(OperationMode opmode, support::FileName const & tmpf);
310 /// make the file ready for editing:
311 /// save a copy in CVS/Base and change file permissions to rw if needed
313 /// revert the edit operation
314 virtual int unedit();
315 /// retrieve repository changes into working copy
316 virtual int update(OperationMode opmode, support::FileName const & tmpf);
317 /// check readonly state for file
318 /// assume true when file is writable
319 virtual bool isLocked() const;
320 /// query and parse the cvs status of file
321 virtual CvsStatus getStatus();
322 /// convert enum to string
323 virtual docstring toString(CvsStatus status) const;
325 /// cache the info values of current file revision
326 /// author, date and time of commit
327 std::string rev_author_cache_;
328 std::string rev_date_cache_;
329 std::string rev_time_cache_;
330 /// fills the cache values, returns true if successfull.
331 void getRevisionInfo();
337 class SVN : public VCS {
341 SVN(support::FileName const & m, Buffer * b);
343 /// return the revision file for the given file, if found
344 static support::FileName const findFile(support::FileName const & file);
346 static bool retrieve(support::FileName const & file);
348 virtual void registrer(std::string const & msg);
350 virtual LyXVC::CommandResult
351 checkIn(std::string const & msg, std::string & log);
353 virtual bool checkInEnabled();
355 virtual bool isCheckInWithConfirmation();
357 virtual std::string checkOut();
359 virtual bool checkOutEnabled();
361 virtual std::string repoUpdate();
363 virtual bool repoUpdateEnabled();
365 virtual std::string lockingToggle();
367 virtual bool lockingToggleEnabled();
369 virtual bool revert();
371 virtual bool isRevertWithConfirmation();
373 virtual void undoLast();
375 virtual bool undoLastEnabled();
377 virtual void getLog(support::FileName const &);
379 virtual std::string const versionString() const {
380 return "SVN: " + rev_file_cache_;
383 virtual bool toggleReadOnlyEnabled();
385 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
387 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
389 virtual bool prepareFileRevisionEnabled();
392 virtual void scanMaster();
393 /// Check for messages in svn output. Returns error.
394 std::string scanLogFile(support::FileName const & f, std::string & status);
395 /// checks locking policy and setup locked_mode_
396 bool checkLockMode();
397 /// is the loaded file locked?
398 bool isLocked() const;
399 /// acquire/release write lock for the current file
400 bool fileLock(bool lock, support::FileName const & tmpf, std::string & status);
403 /// is the loaded file under locking policy?
406 * Real code for obtaining file revision info. Fills all file-related caches
407 * and returns true if successfull.
408 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
409 * was already unsuccessful.
411 bool getFileRevisionInfo();
412 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
413 std::string rev_file_cache_;
414 /// cache for author of last commit
415 std::string rev_author_cache_;
416 /// cache for date of last commit
417 std::string rev_date_cache_;
418 /// cache for time of last commit
419 std::string rev_time_cache_;
420 /// fills rev_tree_cache_, returns true if successfull.
421 bool getTreeRevisionInfo();
422 /// cache for tree revision number, "?" if already unsuccessful
423 std::string rev_tree_cache_;
428 #endif // VCBACKEND_H