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"
28 /// A simple version control system interface
31 /// the status of the managed file
36 /// This file is not in version control, but it could be aded
37 /// (because the path is under version control)
41 VCS(Buffer * b) : owner_(b) {}
44 /// register a file for version control
45 virtual void registrer(std::string const & msg) = 0;
46 /// can this operation be processed in the current VCS?
47 virtual bool renameEnabled() = 0;
48 /// rename a file. Return non-empty log on success, empty log on failure.
49 virtual std::string rename(support::FileName const &, std::string const &) = 0;
50 /// copy a file. Return non-empty log on success, empty log on failure.
51 virtual std::string copy(support::FileName const &, std::string const &) = 0;
52 /// check in the current revision.
53 /// \p log is non-empty on success and may be empty on failure.
54 virtual LyXVC::CommandResult
55 checkIn(std::string const & msg, std::string & log) = 0;
56 /// can this operation be processed in the current VCS?
57 virtual bool checkInEnabled() = 0;
58 /// should a log message provided for next checkin?
59 virtual bool isCheckInWithConfirmation() = 0;
60 /// check out for editing, returns log
61 virtual std::string checkOut() = 0;
62 /// can this operation be processed in the current VCS?
63 virtual bool checkOutEnabled() = 0;
64 /// synchronize with repository, returns log
65 virtual std::string repoUpdate() = 0;
66 /// can this operation be processed in the current VCS?
67 virtual bool repoUpdateEnabled() = 0;
68 /// toggle locking property of the file
69 virtual std::string lockingToggle() = 0;
70 /// can this operation be processed in the current VCS?
71 virtual bool lockingToggleEnabled() = 0;
72 /// revert current edits
73 virtual bool revert() = 0;
74 /// should a confirmation before revert requested?
75 virtual bool isRevertWithConfirmation() = 0;
77 * Merge the current with the previous version
78 * in a reverse patch kind of way, so that the
79 * result is to revert the last changes.
81 virtual void undoLast() = 0;
82 /// can this operation be processed in the current VCS?
83 virtual bool undoLastEnabled() = 0;
85 * getLog - read the revision log into the given file
86 * @param fname file name to read into
88 virtual void getLog(support::FileName const &) = 0;
89 /// return the current version description
90 virtual std::string const versionString() const = 0;
91 /// return the owning buffer
92 Buffer * owner() const { return owner_; }
93 /// return the lock status of this file
94 VCStatus status() const { return vcstatus; }
95 /// do we need special handling for read-only toggling?
96 /// (also used for check-out operation)
97 virtual bool toggleReadOnlyEnabled() = 0;
98 /// Return revision info specified by the argument.
99 virtual std::string revisionInfo(LyXVC::RevisionInfo const info) = 0;
100 /// can this operation be processed in the current VCS?
101 virtual bool prepareFileRevision(std::string const & rev, std::string & f) = 0;
102 /// can this operation be processed in the current VCS?
103 virtual bool prepareFileRevisionEnabled() = 0;
105 /// Check the directory of file and all parent directories
106 /// for the existence of the given pathname
107 static bool checkparentdirs(support::FileName const & file, std::string const & pathname);
110 /// parse information from the version file
111 virtual void scanMaster() = 0;
113 /// Prepare a version identifier suitable for RCS and CVS.
114 /// If needed converts last or relative number to the absolute revision.
115 bool makeRCSRevision(std::string const &version, std::string &revis) const;
117 /// GUI container for doVCCommandCall
118 int doVCCommand(std::string const & cmd, support::FileName const & path, bool reportError = true);
120 * doVCCommandCall - call out to the version control utility
121 * @param cmd the command to execute
122 * @param path the path from which to execute
123 * @return exit status
125 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
128 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
131 support::FileName master_;
133 /// The status of the VC controlled file.
136 /// The buffer using this VC
137 Buffer * const owner_;
142 class RCS : public VCS {
146 RCS(support::FileName const & m, Buffer * b);
148 /// return the revision file for the given file, if found
149 static support::FileName const findFile(support::FileName const & file);
151 static bool retrieve(support::FileName const & file);
153 virtual void registrer(std::string const & msg);
155 virtual bool renameEnabled();
157 virtual std::string rename(support::FileName const &, std::string const &);
159 virtual std::string copy(support::FileName const &, std::string const &);
161 virtual LyXVC::CommandResult
162 checkIn(std::string const & msg, std::string & log);
164 virtual bool checkInEnabled();
166 virtual bool isCheckInWithConfirmation();
168 virtual std::string checkOut();
170 virtual bool checkOutEnabled();
172 virtual std::string repoUpdate();
174 virtual bool repoUpdateEnabled();
176 virtual std::string lockingToggle();
178 virtual bool lockingToggleEnabled();
180 virtual bool revert();
182 virtual bool isRevertWithConfirmation();
184 virtual void undoLast();
186 virtual bool undoLastEnabled();
188 virtual void getLog(support::FileName const &);
190 virtual std::string const versionString() const {
191 return "RCS: " + version_;
194 virtual bool toggleReadOnlyEnabled();
196 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
198 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
200 virtual bool prepareFileRevisionEnabled();
203 virtual void scanMaster();
205 bool getRevisionInfo();
207 * The version of the VC file. I am not sure if this can be a
208 * string or if it must be a float/int.
210 std::string version_;
211 /// The user currently keeping the lock on the VC file (or "Unlocked").
213 /// Cache for revision info.
214 std::string rev_date_cache_;
216 std::string rev_time_cache_;
218 std::string rev_author_cache_;
223 class CVS : public VCS {
227 CVS(support::FileName const & m, Buffer * b);
229 /// return the revision file for the given file, if found
230 static support::FileName const findFile(support::FileName const & file);
232 static bool retrieve(support::FileName const & file);
234 virtual void registrer(std::string const & msg);
236 virtual bool renameEnabled();
238 virtual std::string rename(support::FileName const &, std::string const &);
240 virtual std::string copy(support::FileName const &, std::string const &);
242 virtual LyXVC::CommandResult
243 checkIn(std::string const & msg, std::string & log);
245 virtual bool checkInEnabled();
247 virtual bool isCheckInWithConfirmation();
249 virtual std::string checkOut();
251 virtual bool checkOutEnabled();
253 virtual std::string repoUpdate();
255 virtual bool repoUpdateEnabled();
257 virtual std::string lockingToggle();
259 virtual bool lockingToggleEnabled();
261 virtual bool isRevertWithConfirmation();
263 virtual bool revert();
265 virtual void undoLast();
267 virtual bool undoLastEnabled();
269 virtual void getLog(support::FileName const &);
271 /// Check for messages in cvs output.
272 /// Returns conflict line.
273 std::string scanLogFile(support::FileName const & f, std::string & status);
275 virtual std::string const versionString() const {
276 return "CVS: " + version_;
279 virtual bool toggleReadOnlyEnabled();
281 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
283 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
285 virtual bool prepareFileRevisionEnabled();
288 virtual void scanMaster();
289 /// the mode of operation for some VC commands
294 /// possible status values of file
306 // revision number from scanMaster
307 std::string version_;
310 * doVCCommandWithOutput
311 * - call out to the version control utility
312 * - it is able to collect output in a file
313 * @param cmd the command to execute
314 * @param path the path from which to execute
315 * @param output the path where to store output
316 * @param reportError display of low level error message dialog
317 * @return exit status
319 int doVCCommandWithOutput(std::string const & cmd,
320 support::FileName const & path,
321 support::FileName const & output,
322 bool reportError = true);
323 static int doVCCommandCallWithOutput(std::string const & cmd,
324 support::FileName const & path,
325 support::FileName const & output);
327 /// return the quoted pathname if Directory or filename if File
328 virtual std::string const getTarget(OperationMode opmode) const;
329 /// collect the diff of file or directory against repository
330 /// result is placed in temporary file
331 void getDiff(OperationMode opmode, support::FileName const & tmpf);
332 /// make the file ready for editing:
333 /// save a copy in CVS/Base and change file permissions to rw if needed
335 /// revert the edit operation
336 virtual int unedit();
337 /// retrieve repository changes into working copy
338 virtual int update(OperationMode opmode, support::FileName const & tmpf);
339 /// check readonly state for file
340 /// assume true when file is writable
341 virtual bool isLocked() const;
342 /// query and parse the cvs status of file
343 virtual CvsStatus getStatus();
344 /// convert enum to string
345 virtual docstring toString(CvsStatus status) const;
347 /// cache the info values of current file revision
348 /// author, date and time of commit
349 std::string rev_author_cache_;
350 std::string rev_date_cache_;
351 std::string rev_time_cache_;
352 /// fills the cache values, returns true if successfull.
353 void getRevisionInfo();
359 class SVN : public VCS {
363 SVN(support::FileName const & m, Buffer * b);
365 /// return the revision file for the given file, if found
366 static support::FileName const findFile(support::FileName const & file);
368 static bool retrieve(support::FileName const & file);
370 virtual void registrer(std::string const & msg);
372 virtual bool renameEnabled();
374 virtual std::string rename(support::FileName const &, std::string const &);
376 virtual std::string copy(support::FileName const &, std::string const &);
378 virtual LyXVC::CommandResult
379 checkIn(std::string const & msg, std::string & log);
381 virtual bool checkInEnabled();
383 virtual bool isCheckInWithConfirmation();
385 virtual std::string checkOut();
387 virtual bool checkOutEnabled();
389 virtual std::string repoUpdate();
391 virtual bool repoUpdateEnabled();
393 virtual std::string lockingToggle();
395 virtual bool lockingToggleEnabled();
397 virtual bool revert();
399 virtual bool isRevertWithConfirmation();
401 virtual void undoLast();
403 virtual bool undoLastEnabled();
405 virtual void getLog(support::FileName const &);
407 virtual std::string const versionString() const {
408 return "SVN: " + rev_file_cache_;
411 virtual bool toggleReadOnlyEnabled();
413 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
415 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
417 virtual bool prepareFileRevisionEnabled();
420 virtual void scanMaster();
421 /// Check for messages in svn output. Returns error.
422 std::string scanLogFile(support::FileName const & f, std::string & status);
423 /// checks locking policy and setup locked_mode_
424 bool checkLockMode();
425 /// is the loaded file locked?
426 bool isLocked() const;
427 /// acquire/release write lock for the current file
428 bool fileLock(bool lock, support::FileName const & tmpf, std::string & status);
429 /// Check in files \p f with log \p msg
430 LyXVC::CommandResult checkIn(std::vector<support::FileName> const & f,
431 std::string const & msg, std::string & log);
434 /// is the loaded file under locking policy?
437 * Real code for obtaining file revision info. Fills all file-related caches
438 * and returns true if successfull.
439 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
440 * was already unsuccessful.
442 bool getFileRevisionInfo();
443 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
444 std::string rev_file_cache_;
445 /// cache for author of last commit
446 std::string rev_author_cache_;
447 /// cache for date of last commit
448 std::string rev_date_cache_;
449 /// cache for time of last commit
450 std::string rev_time_cache_;
451 /// fills rev_tree_cache_, returns true if successfull.
452 bool getTreeRevisionInfo();
453 /// cache for tree revision number, "?" if already unsuccessful
454 std::string rev_tree_cache_;
459 #endif // VCBACKEND_H