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
37 VCS(Buffer * b) : owner_(b) {}
40 /// register a file for version control
41 virtual void registrer(std::string const & msg) = 0;
42 /// check in the current revision, returns log
43 virtual std::string checkIn(std::string const & msg) = 0;
44 /// can this operation be processed in the current VCS?
45 virtual bool checkInEnabled() = 0;
46 /// should a log message provided for next checkin?
47 virtual bool isCheckInWithConfirmation() = 0;
48 /// check out for editing, returns log
49 virtual std::string checkOut() = 0;
50 /// can this operation be processed in the current VCS?
51 virtual bool checkOutEnabled() = 0;
52 /// synchronize with repository, returns log
53 virtual std::string repoUpdate() = 0;
54 /// can this operation be processed in the current VCS?
55 virtual bool repoUpdateEnabled() = 0;
56 /// toggle locking property of the file
57 virtual std::string lockingToggle() = 0;
58 /// can this operation be processed in the current VCS?
59 virtual bool lockingToggleEnabled() = 0;
60 /// revert current edits
61 virtual bool revert() = 0;
62 /// should a confirmation before revert requested?
63 virtual bool isRevertWithConfirmation() = 0;
65 * Merge the current with the previous version
66 * in a reverse patch kind of way, so that the
67 * result is to revert the last changes.
69 virtual void undoLast() = 0;
70 /// can this operation be processed in the current VCS?
71 virtual bool undoLastEnabled() = 0;
73 * getLog - read the revision log into the given file
74 * @param fname file name to read into
76 virtual void getLog(support::FileName const &) = 0;
77 /// return the current version description
78 virtual std::string const versionString() const = 0;
79 /// return the owning buffer
80 Buffer * owner() const { return owner_; }
81 /// return the lock status of this file
82 VCStatus status() const { return vcstatus; }
83 /// do we need special handling for read-only toggling?
84 /// (also used for check-out operation)
85 virtual bool toggleReadOnlyEnabled() = 0;
86 /// Return revision info specified by the argument.
87 virtual std::string revisionInfo(LyXVC::RevisionInfo const info) = 0;
88 /// can this operation be processed in the current VCS?
89 virtual bool prepareFileRevision(std::string const & rev, std::string & f) = 0;
90 /// can this operation be processed in the current VCS?
91 virtual bool prepareFileRevisionEnabled() = 0;
93 /// Check the directory of file and all parent directories
94 /// for the existence of the given pathname
95 static bool checkparentdirs(support::FileName const & file, std::string const & pathname);
98 /// parse information from the version file
99 virtual void scanMaster() = 0;
101 /// Prepare a version identifier suitable for RCS and CVS.
102 /// If needed converts last or relative number to the absolute revision.
103 bool makeRCSRevision(std::string const &version, std::string &revis) const;
105 /// GUI container for doVCCommandCall
106 int doVCCommand(std::string const & cmd, support::FileName const & path, bool reportError = true);
108 * doVCCommandCall - call out to the version control utility
109 * @param cmd the command to execute
110 * @param path the path from which to execute
111 * @return exit status
113 static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
116 * The master VC file. For RCS this is *,v or RCS/ *,v. master should
119 support::FileName master_;
121 /// The status of the VC controlled file.
124 /// The buffer using this VC
125 Buffer * const owner_;
130 class RCS : public VCS {
134 RCS(support::FileName const & m, Buffer * b);
136 /// return the revision file for the given file, if found
137 static support::FileName const findFile(support::FileName const & file);
139 static bool retrieve(support::FileName const & file);
141 virtual void registrer(std::string const & msg);
143 virtual std::string checkIn(std::string const & msg);
145 virtual bool checkInEnabled();
147 virtual bool isCheckInWithConfirmation();
149 virtual std::string checkOut();
151 virtual bool checkOutEnabled();
153 virtual std::string repoUpdate();
155 virtual bool repoUpdateEnabled();
157 virtual std::string lockingToggle();
159 virtual bool lockingToggleEnabled();
161 virtual bool revert();
163 virtual bool isRevertWithConfirmation();
165 virtual void undoLast();
167 virtual bool undoLastEnabled();
169 virtual void getLog(support::FileName const &);
171 virtual std::string const versionString() const {
172 return "RCS: " + version_;
175 virtual bool toggleReadOnlyEnabled();
177 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
179 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
181 virtual bool prepareFileRevisionEnabled();
184 virtual void scanMaster();
186 bool getRevisionInfo();
188 * The version of the VC file. I am not sure if this can be a
189 * string or if it must be a float/int.
191 std::string version_;
192 /// The user currently keeping the lock on the VC file (or "Unlocked").
194 /// Cache for revision info.
195 std::string rev_date_cache_;
197 std::string rev_time_cache_;
199 std::string rev_author_cache_;
204 class CVS : public VCS {
208 CVS(support::FileName const & m, Buffer * b);
210 /// return the revision file for the given file, if found
211 static support::FileName const findFile(support::FileName const & file);
213 static bool retrieve(support::FileName const & file);
215 virtual void registrer(std::string const & msg);
217 virtual std::string checkIn(std::string const & msg);
219 virtual bool checkInEnabled();
221 virtual bool isCheckInWithConfirmation();
223 virtual std::string checkOut();
225 virtual bool checkOutEnabled();
227 virtual std::string repoUpdate();
229 virtual bool repoUpdateEnabled();
231 virtual std::string lockingToggle();
233 virtual bool lockingToggleEnabled();
235 virtual bool isRevertWithConfirmation();
237 virtual bool revert();
239 virtual void undoLast();
241 virtual bool undoLastEnabled();
243 virtual void getLog(support::FileName const &);
245 /// Check for messages in cvs output.
246 /// Returns conflict line.
247 std::string scanLogFile(support::FileName const & f, std::string & status);
249 virtual std::string const versionString() const {
250 return "CVS: " + version_;
253 virtual bool toggleReadOnlyEnabled();
255 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
257 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
259 virtual bool prepareFileRevisionEnabled();
262 virtual void scanMaster();
263 /// the mode of operation for some VC commands
268 /// possible status values of file
280 // revision number from scanMaster
281 std::string version_;
284 * doVCCommandWithOutput
285 * - call out to the version control utility
286 * - it is able to collect output in a file
287 * @param cmd the command to execute
288 * @param path the path from which to execute
289 * @param output the path where to store output
290 * @param reportError display of low level error message dialog
291 * @return exit status
293 int doVCCommandWithOutput(std::string const & cmd,
294 support::FileName const & path,
295 support::FileName const & output,
296 bool reportError = true);
297 static int doVCCommandCallWithOutput(std::string const & cmd,
298 support::FileName const & path,
299 support::FileName const & output);
301 /// return the quoted pathname if Directory or filename if File
302 virtual std::string const getTarget(OperationMode opmode) const;
303 /// collect the diff of file or directory against repository
304 /// result is placed in temporary file
305 void getDiff(OperationMode opmode, support::FileName const & tmpf);
306 /// make the file ready for editing:
307 /// save a copy in CVS/Base and change file permissions to rw if needed
309 /// revert the edit operation
310 virtual int unedit();
311 /// retrieve repository changes into working copy
312 virtual int update(OperationMode opmode, support::FileName const & tmpf);
313 /// check readonly state for file
314 /// assume true when file is writable
315 virtual bool isLocked() const;
316 /// query and parse the cvs status of file
317 virtual CvsStatus getStatus();
318 /// convert enum to string
319 virtual docstring toString(CvsStatus status) const;
321 /// cache the info values of current file revision
322 /// author, date and time of commit
323 std::string rev_author_cache_;
324 std::string rev_date_cache_;
325 std::string rev_time_cache_;
326 /// fills the cache values, returns true if successfull.
327 void getRevisionInfo();
333 class SVN : public VCS {
337 SVN(support::FileName const & m, Buffer * b);
339 /// return the revision file for the given file, if found
340 static support::FileName const findFile(support::FileName const & file);
342 static bool retrieve(support::FileName const & file);
344 virtual void registrer(std::string const & msg);
346 virtual std::string checkIn(std::string const & msg);
348 virtual bool checkInEnabled();
350 virtual bool isCheckInWithConfirmation();
352 virtual std::string checkOut();
354 virtual bool checkOutEnabled();
356 virtual std::string repoUpdate();
358 virtual bool repoUpdateEnabled();
360 virtual std::string lockingToggle();
362 virtual bool lockingToggleEnabled();
364 virtual bool revert();
366 virtual bool isRevertWithConfirmation();
368 virtual void undoLast();
370 virtual bool undoLastEnabled();
372 virtual void getLog(support::FileName const &);
374 virtual std::string const versionString() const {
375 return "SVN: " + rev_file_cache_;
378 virtual bool toggleReadOnlyEnabled();
380 virtual std::string revisionInfo(LyXVC::RevisionInfo const info);
382 virtual bool prepareFileRevision(std::string const & rev, std::string & f);
384 virtual bool prepareFileRevisionEnabled();
387 virtual void scanMaster();
388 /// Check for messages in svn output. Returns error.
389 std::string scanLogFile(support::FileName const & f, std::string & status);
390 /// checks locking policy and setup locked_mode_
391 bool checkLockMode();
392 /// is the loaded file locked?
393 bool isLocked() const;
394 /// acquire/release write lock for the current file
395 void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
398 /// is the loaded file under locking policy?
401 * Real code for obtaining file revision info. Fills all file-related caches
402 * and returns true if successfull.
403 * "?" is stored in rev_file_cache_ as a signal if request for obtaining info
404 * was already unsuccessful.
406 bool getFileRevisionInfo();
407 /// cache for file revision number, "?" if already unsuccessful, isNumber==true
408 std::string rev_file_cache_;
409 /// cache for author of last commit
410 std::string rev_author_cache_;
411 /// cache for date of last commit
412 std::string rev_date_cache_;
413 /// cache for time of last commit
414 std::string rev_time_cache_;
415 /// fills rev_tree_cache_, returns true if successfull.
416 bool getTreeRevisionInfo();
417 /// cache for tree revision number, "?" if already unsuccessful
418 std::string rev_tree_cache_;
423 #endif // VCBACKEND_H