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();
180 * The version of the VC file. I am not sure if this can be a
181 * string or if it must be a float/int.
183 std::string version_;
184 /// The user currently keeping the lock on the VC file (or "Unlocked").
190 class CVS : public VCS {
194 CVS(support::FileName const & m, support::FileName const & f);
196 /// return the revision file for the given file, if found
197 static support::FileName const findFile(support::FileName const & file);
199 virtual void registrer(std::string const & msg);
201 virtual std::string checkIn(std::string const & msg);
203 virtual bool checkInEnabled();
205 virtual bool isCheckInWithConfirmation();
207 virtual std::string checkOut();
209 virtual bool checkOutEnabled();
211 virtual std::string repoUpdate();
213 virtual bool repoUpdateEnabled();
215 virtual std::string lockingToggle();
217 virtual bool lockingToggleEnabled();
219 virtual bool isRevertWithConfirmation();
221 virtual bool revert();
223 virtual void undoLast();
225 virtual bool undoLastEnabled();
227 virtual void getLog(support::FileName const &);
229 /// Check for messages in cvs output.
230 /// Returns conflict line.
231 std::string scanLogFile(support::FileName const & f, std::string & status);
233 virtual std::string const versionString() const {
234 return "CVS: " + version_;
237 virtual bool toggleReadOnlyEnabled();
239 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
241 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
243 virtual bool prepareFileRevisionEnabled();
246 virtual void scanMaster();
247 /// the mode of operation for some VC commands
252 /// possible status values of file
264 support::FileName file_;
265 // revision number from scanMaster
266 std::string version_;
269 * doVCCommandWithOutput
270 * - call out to the version control utility
271 * - it is able to collect output in a file
272 * @param cmd the command to execute
273 * @param path the path from which to execute
274 * @param output the path where to store output
275 * @param reportError display of low level error message dialog
276 * @return exit status
278 int doVCCommandWithOutput(std::string const & cmd,
279 support::FileName const & path,
280 support::FileName const & output,
281 bool reportError = true);
282 static int doVCCommandCallWithOutput(std::string const & cmd,
283 support::FileName const & path,
284 support::FileName const & output);
286 /// return the quoted pathname if Directory or filename if File
287 virtual std::string const getTarget(OperationMode opmode) const;
288 /// collect the diff of file or directory against repository
289 /// result is placed in temporary file
290 void getDiff(OperationMode opmode, support::FileName const & tmpf);
291 /// make the file ready for editing:
292 /// save a copy in CVS/Base and change file permissions to rw if needed
294 /// revert the edit operation
295 virtual int unedit();
296 /// retrieve repository changes into working copy
297 virtual int update(OperationMode opmode, support::FileName const & tmpf);
298 /// check readonly state for file
299 /// assume true when file is writable
300 virtual bool isLocked() const;
301 /// query and parse the cvs status of file
302 virtual CvsStatus getStatus();
303 /// convert enum to string
304 virtual docstring toString(CvsStatus status) const;
306 /// cache the info values of current file revision
307 /// author, date and time of commit
308 std::string rev_author_cache_;
309 std::string rev_date_cache_;
310 std::string rev_time_cache_;
311 /// fills the cache values, returns true if successfull.
312 void getRevisionInfo();
318 class SVN : public VCS {
322 SVN(support::FileName const & m, support::FileName const & f);
324 /// return the revision file for the given file, if found
325 static support::FileName const findFile(support::FileName const & file);
327 virtual void registrer(std::string const & msg);
329 virtual std::string checkIn(std::string const & msg);
331 virtual bool checkInEnabled();
333 virtual bool isCheckInWithConfirmation();
335 virtual std::string checkOut();
337 virtual bool checkOutEnabled();
339 virtual std::string repoUpdate();
341 virtual bool repoUpdateEnabled();
343 virtual std::string lockingToggle();
345 virtual bool lockingToggleEnabled();
347 virtual bool revert();
349 virtual bool isRevertWithConfirmation();
351 virtual void undoLast();
353 virtual bool undoLastEnabled();
355 virtual void getLog(support::FileName const &);
357 virtual std::string const versionString() const {
358 return "SVN: " + rev_file_cache_;
361 virtual bool toggleReadOnlyEnabled();
363 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
365 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
367 virtual bool prepareFileRevisionEnabled();
370 virtual void scanMaster();
371 /// Check for messages in svn output. Returns error.
372 std::string scanLogFile(support::FileName const & f, std::string & status);
373 /// checks locking policy and setup locked_mode_
374 bool checkLockMode();
375 /// is the loaded file locked?
376 bool isLocked() const;
377 /// acquire/release write lock for the current file
378 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
381 support::FileName file_;
382 /// is the loaded file under locking policy?
385 * Real code for obtaining file revision info. Fills all file-related caches
386 * and returns true if successfull.
387 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
388 * was already unsuccessful.
390 bool getFileRevisionInfo();
391 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
392 std::string rev_file_cache_;
393 /// cache for author of last commit
394 std::string rev_author_cache_;
395 /// cache for date of last commit
396 std::string rev_date_cache_;
397 /// cache for time of last commit
398 std::string rev_time_cache_;
399 /// fills rev_tree_cache_, returns true if successfull.
400 bool getTreeRevisionInfo();
401 /// cache for tree revision number, "?" if already unsuccessful
402 std::string rev_tree_cache_;
407 #endif // VCBACKEND_H