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;
90 /// Check the directory of file and all parent directories
91 // for the existence of the given pathname
92 static bool checkparentdirs(support::FileName const & file, std::string const & pathname);
95 /// parse information from the version file
96 virtual void scanMaster() = 0;
98 /// Prepare a version identifier suitable for RCS and CVS.
99 /// If needed converts last or relative number to the absolute revision.
100 bool makeRCSRevision(std::string const &version, std::string &revis) const;
102 // GUI container for doVCCommandCall
103 int doVCCommand(std::string const & cmd, support::FileName const & path, bool reportError = true);
105 * doVCCommandCall - call out to the version control utility
106 * @param cmd the command to execute
107 * @param path the path from which to execute
108 * @return exit status
110 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
113 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
116 support::FileName master_;
118 /// The status of the VC controlled file.
121 /// The buffer using this VC
127 class RCS : public VCS {
131 RCS(support::FileName const & m);
133 /// return the revision file for the given file, if found
134 static support::FileName const findFile(support::FileName const & file);
136 static void retrieve(support::FileName const & file);
138 virtual void registrer(std::string const & msg);
140 virtual std::string checkIn(std::string const & msg);
142 virtual bool checkInEnabled();
144 virtual bool isCheckInWithConfirmation();
146 virtual std::string checkOut();
148 virtual bool checkOutEnabled();
150 virtual std::string repoUpdate();
152 virtual bool repoUpdateEnabled();
154 virtual std::string lockingToggle();
156 virtual bool lockingToggleEnabled();
158 virtual bool revert();
160 virtual bool isRevertWithConfirmation();
162 virtual void undoLast();
164 virtual bool undoLastEnabled();
166 virtual void getLog(support::FileName const &);
168 virtual std::string const versionString() const {
169 return "RCS: " + version_;
172 virtual bool toggleReadOnlyEnabled();
174 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
176 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
178 virtual bool prepareFileRevisionEnabled();
181 virtual void scanMaster();
183 bool getRevisionInfo();
185 * The version of the VC file. I am not sure if this can be a
186 * string or if it must be a float/int.
188 std::string version_;
189 /// The user currently keeping the lock on the VC file (or "Unlocked").
191 /// Cache for revision info.
192 std::string rev_date_cache_;
194 std::string rev_time_cache_;
196 std::string rev_author_cache_;
201 class CVS : public VCS {
205 CVS(support::FileName const & m, support::FileName const & f);
207 /// return the revision file for the given file, if found
208 static support::FileName const findFile(support::FileName const & file);
210 virtual void registrer(std::string const & msg);
212 virtual std::string checkIn(std::string const & msg);
214 virtual bool checkInEnabled();
216 virtual bool isCheckInWithConfirmation();
218 virtual std::string checkOut();
220 virtual bool checkOutEnabled();
222 virtual std::string repoUpdate();
224 virtual bool repoUpdateEnabled();
226 virtual std::string lockingToggle();
228 virtual bool lockingToggleEnabled();
230 virtual bool isRevertWithConfirmation();
232 virtual bool revert();
234 virtual void undoLast();
236 virtual bool undoLastEnabled();
238 virtual void getLog(support::FileName const &);
240 /// Check for messages in cvs output.
241 /// Returns conflict line.
242 std::string scanLogFile(support::FileName const & f, std::string & status);
244 virtual std::string const versionString() const {
245 return "CVS: " + version_;
248 virtual bool toggleReadOnlyEnabled();
250 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
252 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
254 virtual bool prepareFileRevisionEnabled();
257 virtual void scanMaster();
258 /// the mode of operation for some VC commands
263 /// possible status values of file
275 support::FileName file_;
276 // revision number from scanMaster
277 std::string version_;
280 * doVCCommandWithOutput
281 * - call out to the version control utility
282 * - it is able to collect output in a file
283 * @param cmd the command to execute
284 * @param path the path from which to execute
285 * @param output the path where to store output
286 * @param reportError display of low level error message dialog
287 * @return exit status
289 int doVCCommandWithOutput(std::string const & cmd,
290 support::FileName const & path,
291 support::FileName const & output,
292 bool reportError = true);
293 static int doVCCommandCallWithOutput(std::string const & cmd,
294 support::FileName const & path,
295 support::FileName const & output);
297 /// return the quoted pathname if Directory or filename if File
298 virtual std::string const getTarget(OperationMode opmode) const;
299 /// collect the diff of file or directory against repository
300 /// result is placed in temporary file
301 void getDiff(OperationMode opmode, support::FileName const & tmpf);
302 /// make the file ready for editing:
303 /// save a copy in CVS/Base and change file permissions to rw if needed
305 /// revert the edit operation
306 virtual int unedit();
307 /// retrieve repository changes into working copy
308 virtual int update(OperationMode opmode, support::FileName const & tmpf);
309 /// check readonly state for file
310 /// assume true when file is writable
311 virtual bool isLocked() const;
312 /// query and parse the cvs status of file
313 virtual CvsStatus getStatus();
314 /// convert enum to string
315 virtual docstring toString(CvsStatus status) const;
317 /// cache the info values of current file revision
318 /// author, date and time of commit
319 std::string rev_author_cache_;
320 std::string rev_date_cache_;
321 std::string rev_time_cache_;
322 /// fills the cache values, returns true if successfull.
323 void getRevisionInfo();
329 class SVN : public VCS {
333 SVN(support::FileName const & m, support::FileName const & f);
335 /// return the revision file for the given file, if found
336 static support::FileName const findFile(support::FileName const & file);
338 virtual void registrer(std::string const & msg);
340 virtual std::string checkIn(std::string const & msg);
342 virtual bool checkInEnabled();
344 virtual bool isCheckInWithConfirmation();
346 virtual std::string checkOut();
348 virtual bool checkOutEnabled();
350 virtual std::string repoUpdate();
352 virtual bool repoUpdateEnabled();
354 virtual std::string lockingToggle();
356 virtual bool lockingToggleEnabled();
358 virtual bool revert();
360 virtual bool isRevertWithConfirmation();
362 virtual void undoLast();
364 virtual bool undoLastEnabled();
366 virtual void getLog(support::FileName const &);
368 virtual std::string const versionString() const {
369 return "SVN: " + rev_file_cache_;
372 virtual bool toggleReadOnlyEnabled();
374 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
376 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
378 virtual bool prepareFileRevisionEnabled();
381 virtual void scanMaster();
382 /// Check for messages in svn output. Returns error.
383 std::string scanLogFile(support::FileName const & f, std::string & status);
384 /// checks locking policy and setup locked_mode_
385 bool checkLockMode();
386 /// is the loaded file locked?
387 bool isLocked() const;
388 /// acquire/release write lock for the current file
389 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
392 support::FileName file_;
393 /// is the loaded file under locking policy?
396 * Real code for obtaining file revision info. Fills all file-related caches
397 * and returns true if successfull.
398 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
399 * was already unsuccessful.
401 bool getFileRevisionInfo();
402 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
403 std::string rev_file_cache_;
404 /// cache for author of last commit
405 std::string rev_author_cache_;
406 /// cache for date of last commit
407 std::string rev_date_cache_;
408 /// cache for time of last commit
409 std::string rev_time_cache_;
410 /// fills rev_tree_cache_, returns true if successfull.
411 bool getTreeRevisionInfo();
412 /// cache for tree revision number, "?" if already unsuccessful
413 std::string rev_tree_cache_;
418 #endif // VCBACKEND_H