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 // should a log message provided for next checkin?
46 virtual bool isCheckInWithConfirmation() = 0;
47 /// check out for editing, returns log
48 virtual std::string checkOut() = 0;
49 // can be this operation processed in the current RCS?
50 virtual bool checkOutEnabled() = 0;
51 /// synchronize with repository, returns log
52 virtual std::string repoUpdate() = 0;
53 // can be this operation processed in the current RCS?
54 virtual bool repoUpdateEnabled() = 0;
55 // toggle locking property of the file
56 virtual std::string lockingToggle() = 0;
57 // can be this operation processed in the current RCS?
58 virtual bool lockingToggleEnabled() = 0;
59 /// revert current edits
60 virtual bool revert() = 0;
61 // should a confirmation before revert requested?
62 virtual bool isRevertWithConfirmation() = 0;
64 virtual void undoLast() = 0;
65 // can be this operation processed in the current RCS?
66 virtual bool undoLastEnabled() = 0;
68 * getLog - read the revision log into the given file
69 * @param fname file name to read into
71 virtual void getLog(support::FileName const &) = 0;
72 /// return the current version description
73 virtual std::string const versionString() const = 0;
74 /// set the owning buffer
75 void owner(Buffer * b) { owner_ = b; }
76 /// return the owning buffer
77 Buffer * owner() const { return owner_; }
78 /// return the lock status of this file
79 VCStatus status() const { return vcstatus; }
80 /// do we need special handling for read-only toggling?
81 /// (also used for check-out operation)
82 virtual bool toggleReadOnlyEnabled() = 0;
83 /// Return revision info specified by the argument.
84 virtual std::string revisionInfo(LyXVC::RevisionInfo const info) = 0;
86 virtual bool prepareFileRevision(std::string const & rev, std::string & f) = 0;
88 virtual bool prepareFileRevisionEnabled() = 0;
91 /// parse information from the version file
92 virtual void scanMaster() = 0;
94 /// Prepare a version identifier suitable for RCS and CVS.
95 /// If needed converts last or relative number to the absolute revision.
96 bool makeRCSRevision(std::string const &version, std::string &revis) const;
98 // GUI container for doVCCommandCall
99 int doVCCommand(std::string const & cmd, support::FileName const & path, bool reportError = true);
101 * doVCCommandCall - call out to the version control utility
102 * @param cmd the command to execute
103 * @param path the path from which to execute
104 * @return exit status
106 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
109 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
112 support::FileName master_;
114 /// The status of the VC controlled file.
117 /// The buffer using this VC
123 class RCS : public VCS {
127 RCS(support::FileName const & m);
129 /// return the revision file for the given file, if found
130 static support::FileName const findFile(support::FileName const & file);
132 static void retrieve(support::FileName const & file);
134 virtual void registrer(std::string const & msg);
136 virtual std::string checkIn(std::string const & msg);
138 virtual bool checkInEnabled();
140 virtual bool isCheckInWithConfirmation();
142 virtual std::string checkOut();
144 virtual bool checkOutEnabled();
146 virtual std::string repoUpdate();
148 virtual bool repoUpdateEnabled();
150 virtual std::string lockingToggle();
152 virtual bool lockingToggleEnabled();
154 virtual bool revert();
156 virtual bool isRevertWithConfirmation();
158 virtual void undoLast();
160 virtual bool undoLastEnabled();
162 virtual void getLog(support::FileName const &);
164 virtual std::string const versionString() const {
165 return "RCS: " + version_;
168 virtual bool toggleReadOnlyEnabled();
170 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
172 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
174 virtual bool prepareFileRevisionEnabled();
177 virtual void scanMaster();
179 bool getRevisionInfo();
181 * The version of the VC file. I am not sure if this can be a
182 * string or if it must be a float/int.
184 std::string version_;
185 /// The user currently keeping the lock on the VC file (or "Unlocked").
187 /// Cache for revision info.
188 std::string rev_date_cache_;
190 std::string rev_time_cache_;
192 std::string rev_author_cache_;
197 class CVS : public VCS {
201 CVS(support::FileName const & m, support::FileName const & f);
203 /// return the revision file for the given file, if found
204 static support::FileName const findFile(support::FileName const & file);
206 virtual void registrer(std::string const & msg);
208 virtual std::string checkIn(std::string const & msg);
210 virtual bool checkInEnabled();
212 virtual bool isCheckInWithConfirmation();
214 virtual std::string checkOut();
216 virtual bool checkOutEnabled();
218 virtual std::string repoUpdate();
220 virtual bool repoUpdateEnabled();
222 virtual std::string lockingToggle();
224 virtual bool lockingToggleEnabled();
226 virtual bool isRevertWithConfirmation();
228 virtual bool revert();
230 virtual void undoLast();
232 virtual bool undoLastEnabled();
234 virtual void getLog(support::FileName const &);
236 /// Check for messages in cvs output.
237 /// Returns conflict line.
238 std::string scanLogFile(support::FileName const & f, std::string & status);
240 virtual std::string const versionString() const {
241 return "CVS: " + version_;
244 virtual bool toggleReadOnlyEnabled();
246 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
248 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
250 virtual bool prepareFileRevisionEnabled();
253 virtual void scanMaster();
254 /// the mode of operation for some VC commands
259 /// possible status values of file
271 support::FileName file_;
272 // revision number from scanMaster
273 std::string version_;
276 * doVCCommandWithOutput
277 * - call out to the version control utility
278 * - it is able to collect output in a file
279 * @param cmd the command to execute
280 * @param path the path from which to execute
281 * @param output the path where to store output
282 * @param reportError display of low level error message dialog
283 * @return exit status
285 int doVCCommandWithOutput(std::string const & cmd,
286 support::FileName const & path,
287 support::FileName const & output,
288 bool reportError = true);
289 static int doVCCommandCallWithOutput(std::string const & cmd,
290 support::FileName const & path,
291 support::FileName const & output);
293 /// return the quoted pathname if Directory or filename if File
294 virtual std::string const getTarget(OperationMode opmode) const;
295 /// collect the diff of file or directory against repository
296 /// result is placed in temporary file
297 void getDiff(OperationMode opmode, support::FileName const & tmpf);
298 /// make the file ready for editing:
299 /// save a copy in CVS/Base and change file permissions to rw if needed
301 /// revert the edit operation
302 virtual int unedit();
303 /// retrieve repository changes into working copy
304 virtual int update(OperationMode opmode, support::FileName const & tmpf);
305 /// check readonly state for file
306 /// assume true when file is writable
307 virtual bool isLocked() const;
308 /// query and parse the cvs status of file
309 virtual CvsStatus getStatus();
310 /// convert enum to string
311 virtual docstring toString(CvsStatus status) const;
313 /// cache the info values of current file revision
314 /// author, date and time of commit
315 std::string rev_author_cache_;
316 std::string rev_date_cache_;
317 std::string rev_time_cache_;
318 /// fills the cache values, returns true if successfull.
319 void getRevisionInfo();
325 class SVN : public VCS {
329 SVN(support::FileName const & m, support::FileName const & f);
331 /// return the revision file for the given file, if found
332 static support::FileName const findFile(support::FileName const & file);
334 virtual void registrer(std::string const & msg);
336 virtual std::string checkIn(std::string const & msg);
338 virtual bool checkInEnabled();
340 virtual bool isCheckInWithConfirmation();
342 virtual std::string checkOut();
344 virtual bool checkOutEnabled();
346 virtual std::string repoUpdate();
348 virtual bool repoUpdateEnabled();
350 virtual std::string lockingToggle();
352 virtual bool lockingToggleEnabled();
354 virtual bool revert();
356 virtual bool isRevertWithConfirmation();
358 virtual void undoLast();
360 virtual bool undoLastEnabled();
362 virtual void getLog(support::FileName const &);
364 virtual std::string const versionString() const {
365 return "SVN: " + rev_file_cache_;
368 virtual bool toggleReadOnlyEnabled();
370 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
372 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
374 virtual bool prepareFileRevisionEnabled();
377 virtual void scanMaster();
378 /// Check for messages in svn output. Returns error.
379 std::string scanLogFile(support::FileName const & f, std::string & status);
380 /// checks locking policy and setup locked_mode_
381 bool checkLockMode();
382 /// is the loaded file locked?
383 bool isLocked() const;
384 /// acquire/release write lock for the current file
385 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
388 support::FileName file_;
389 /// is the loaded file under locking policy?
392 * Real code for obtaining file revision info. Fills all file-related caches
393 * and returns true if successfull.
394 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
395 * was already unsuccessful.
397 bool getFileRevisionInfo();
398 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
399 std::string rev_file_cache_;
400 /// cache for author of last commit
401 std::string rev_author_cache_;
402 /// cache for date of last commit
403 std::string rev_date_cache_;
404 /// cache for time of last commit
405 std::string rev_time_cache_;
406 /// fills rev_tree_cache_, returns true if successfull.
407 bool getTreeRevisionInfo();
408 /// cache for tree revision number, "?" if already unsuccessful
409 std::string rev_tree_cache_;
414 #endif // VCBACKEND_H