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 // GUI container for doVCCommandCall
95 int doVCCommand(std::string const & cmd, support::FileName const & path, bool reportError = true);
97 * doVCCommandCall - call out to the version control utility
98 * @param cmd the command to execute
99 * @param path the path from which to execute
100 * @return exit status
102 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
105 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
108 support::FileName master_;
110 /// The status of the VC controlled file.
113 /// The buffer using this VC
119 class RCS : public VCS {
123 RCS(support::FileName const & m);
125 /// return the revision file for the given file, if found
126 static support::FileName const findFile(support::FileName const & file);
128 static void retrieve(support::FileName const & file);
130 virtual void registrer(std::string const & msg);
132 virtual std::string checkIn(std::string const & msg);
134 virtual bool checkInEnabled();
136 virtual bool isCheckInWithConfirmation();
138 virtual std::string checkOut();
140 virtual bool checkOutEnabled();
142 virtual std::string repoUpdate();
144 virtual bool repoUpdateEnabled();
146 virtual std::string lockingToggle();
148 virtual bool lockingToggleEnabled();
150 virtual bool revert();
152 virtual bool isRevertWithConfirmation();
154 virtual void undoLast();
156 virtual bool undoLastEnabled();
158 virtual void getLog(support::FileName const &);
160 virtual std::string const versionString() const {
161 return "RCS: " + version_;
164 virtual bool toggleReadOnlyEnabled();
166 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
168 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
170 virtual bool prepareFileRevisionEnabled();
173 virtual void scanMaster();
176 * The version of the VC file. I am not sure if this can be a
177 * string or if it must be a float/int.
179 std::string version_;
180 /// The user currently keeping the lock on the VC file (or "Unlocked").
186 class CVS : public VCS {
190 CVS(support::FileName const & m, support::FileName const & f);
192 /// return the revision file for the given file, if found
193 static support::FileName const findFile(support::FileName const & file);
195 virtual void registrer(std::string const & msg);
197 virtual std::string checkIn(std::string const & msg);
199 virtual bool checkInEnabled();
201 virtual bool isCheckInWithConfirmation();
203 virtual std::string checkOut();
205 virtual bool checkOutEnabled();
207 virtual std::string repoUpdate();
209 virtual bool repoUpdateEnabled();
211 virtual std::string lockingToggle();
213 virtual bool lockingToggleEnabled();
215 virtual bool isRevertWithConfirmation();
217 virtual bool revert();
219 virtual void undoLast();
221 virtual bool undoLastEnabled();
223 virtual void getLog(support::FileName const &);
225 /// Check for messages in cvs output.
226 /// Returns conflict line.
227 std::string scanLogFile(support::FileName const & f, std::string & status);
229 virtual std::string const versionString() const {
230 return "CVS: " + version_;
233 virtual bool toggleReadOnlyEnabled();
235 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
237 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
239 virtual bool prepareFileRevisionEnabled();
242 virtual void scanMaster();
243 /// the mode of operation for some VC commands
248 /// possible status values of file
260 support::FileName file_;
261 // revision number from scanMaster
262 std::string version_;
265 * doVCCommandWithOutput
266 * - call out to the version control utility
267 * - it is able to collect output in a file
268 * @param cmd the command to execute
269 * @param path the path from which to execute
270 * @param output the path where to store output
271 * @param reportError display of low level error message dialog
272 * @return exit status
274 int doVCCommandWithOutput(std::string const & cmd,
275 support::FileName const & path,
276 support::FileName const & output,
277 bool reportError = true);
278 static int doVCCommandCallWithOutput(std::string const & cmd,
279 support::FileName const & path,
280 support::FileName const & output);
282 /// return the quoted pathname if Directory or filename if File
283 virtual std::string const getTarget(OperationMode opmode) const;
284 /// collect the diff of file or directory against repository
285 /// result is placed in temporary file
286 void getDiff(OperationMode opmode, support::FileName const & tmpf);
287 /// make the file ready for editing:
288 /// save a copy in CVS/Base and change file permissions to rw if needed
290 /// revert the edit operation
291 virtual int unedit();
292 /// retrieve repository changes into working copy
293 virtual int update(OperationMode opmode, support::FileName const & tmpf);
294 /// check readonly state for file
295 /// assume true when file is writable
296 virtual bool isLocked() const;
297 /// query and parse the cvs status of file
298 virtual CvsStatus getStatus();
299 /// convert enum to string
300 virtual docstring toString(CvsStatus status) const;
302 /// cache the info values of current file revision
303 /// author, date and time of commit
304 std::string rev_author_cache_;
305 std::string rev_date_cache_;
306 std::string rev_time_cache_;
307 /// fills the cache values, returns true if successfull.
308 void getRevisionInfo();
314 class SVN : public VCS {
318 SVN(support::FileName const & m, support::FileName const & f);
320 /// return the revision file for the given file, if found
321 static support::FileName const findFile(support::FileName const & file);
323 virtual void registrer(std::string const & msg);
325 virtual std::string checkIn(std::string const & msg);
327 virtual bool checkInEnabled();
329 virtual bool isCheckInWithConfirmation();
331 virtual std::string checkOut();
333 virtual bool checkOutEnabled();
335 virtual std::string repoUpdate();
337 virtual bool repoUpdateEnabled();
339 virtual std::string lockingToggle();
341 virtual bool lockingToggleEnabled();
343 virtual bool revert();
345 virtual bool isRevertWithConfirmation();
347 virtual void undoLast();
349 virtual bool undoLastEnabled();
351 virtual void getLog(support::FileName const &);
353 virtual std::string const versionString() const {
354 return "SVN: " + rev_file_cache_;
357 virtual bool toggleReadOnlyEnabled();
359 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
361 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
363 virtual bool prepareFileRevisionEnabled();
366 virtual void scanMaster();
367 /// Check for messages in svn output. Returns error.
368 std::string scanLogFile(support::FileName const & f, std::string & status);
369 /// checks locking policy and setup locked_mode_
370 bool checkLockMode();
371 /// is the loaded file locked?
372 bool isLocked() const;
373 /// acquire/release write lock for the current file
374 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
377 support::FileName file_;
378 /// is the loaded file under locking policy?
381 * Real code for obtaining file revision info. Fills all file-related caches
382 * and returns true if successfull.
383 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
384 * was already unsuccessful.
386 bool getFileRevisionInfo();
387 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
388 std::string rev_file_cache_;
389 /// cache for author of last commit
390 std::string rev_author_cache_;
391 /// cache for date of last commit
392 std::string rev_date_cache_;
393 /// cache for time of last commit
394 std::string rev_time_cache_;
395 /// fills rev_tree_cache_, returns true if successfull.
396 bool getTreeRevisionInfo();
397 /// cache for tree revision number, "?" if already unsuccessful
398 std::string rev_tree_cache_;
403 #endif // VCBACKEND_H