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
9 * Full author contact details are available in file CREDITS.
15 #include "support/unique_ptr.h"
22 namespace support { class FileName; }
27 /** Version Control for LyX.
28 This is the class giving the version control features to LyX. It is
29 intended to support different kinds of version control.
30 The support in LyX is based loosely upon the version control in GNU Emacs,
31 but is not as extensive as that one. See Extended Manual for a simple
32 tutorial and manual for the use of the version control system in LyX.
34 LyXVC use this algorithm when it searches for VC files:
35 for RCS it searches for <filename>,v and RCS/<filename>,v similarly
36 CVS/Entries for cvs and .svn/entries. By doing this there doesn't need to be any
37 special support for VC in the lyx format, and this is especially good
38 when the lyx format will be a subset of LaTeX.
42 /// Return status of a command
44 Cancelled, ///< command was cancelled
45 ErrorBefore, ///< error before executing command
46 ErrorCommand, ///< error while executing command
47 VCSuccess ///< command was executed successfully
51 /// Is \p fn under version control?
52 static bool fileInVC(support::FileName const & fn);
53 /** Not a good name perhaps. This function should be called whenever
54 LyX loads a file. This function then checks for a master VC file (for
55 RCS this is *,v or RCS/ *,v ; for CVS this is CVS/Entries and .svn/entries
56 for SVN) if this file or entry is found, the loaded file is assumed to be
57 under control by VC, and the appropiate actions is taken.
58 Returns true if the file is under control by a VCS.
60 bool file_found_hook(support::FileName const & fn);
62 /** Is \p fn under version control?
63 This function should be run when a file is requested for loading,
64 but it does not exist. This function will then check for a VC master
65 file with the same name (see above function). If this exists the
66 user should be asked if he/her wants to checkout a version for
67 viewing/editing. Returns true if the file is under control by a VCS
68 and the user wants to view/edit it.
70 static bool file_not_found_hook(support::FileName const & fn);
73 void setBuffer(Buffer *);
75 /// Register the document as a VC file.
79 // std::string used as a return value in functions below are
80 // workaround to defer messages to be displayed in UI. If message()
81 // is used directly, message string is immediately overwritten
82 // by the next multiple messages on the top of the processed dispatch
86 std::string rename(support::FileName const &);
87 /// Does the current VC support this operation?
88 bool renameEnabled() const;
90 std::string copy(support::FileName const &);
91 /// Does the current VC support this operation?
92 bool copyEnabled() const;
94 /// Unlock and commit changes.
95 /// \p log is non-empty on success and may be empty on failure.
96 CommandResult checkIn(std::string & log);
97 /// Does the current VC support this operation?
98 bool checkInEnabled() const;
99 /// Should a log message be provided for next checkin?
100 bool isCheckInWithConfirmation() const;
102 /// Lock/update and prepare to edit document. Returns log.
103 std::string checkOut();
104 /// Does the current VC support this operation?
105 bool checkOutEnabled() const;
107 /// Synchronize the whole archive with repository
108 std::string repoUpdate();
109 /// Does the current VC support this operation?
110 bool repoUpdateEnabled() const;
113 * Toggle locking property of the edited file,
114 * i.e. whether the file uses locking mechanism.
116 std::string lockingToggle();
117 /// Does the current VC support this operation?
118 bool lockingToggleEnabled() const;
120 /// Revert to last version
123 /// Undo last check-in.
125 /// Does the current VC support this operation?
126 bool undoLastEnabled() const;
128 * Prepare revision rev of the file into newly created temporary file
129 * and save the filename into parameter f.
130 * Parameter rev can be either revision number or negative number
131 * which is interpreted as how many revision back from the current
132 * one do we want. rev=0 is reserved for the last (committed) revision.
133 * We need rev to be string, since in various VCS revision is not integer.
134 * If RCS addressed by a single number, it is automatically used
135 * as the last number in the whole revision specification (it applies
136 * for retrieving normal revisions (rev>0) or backtracking (rev<0).
138 bool prepareFileRevision(std::string const & rev, std::string & f);
139 /// Does the current VC support this operation?
140 bool prepareFileRevisionEnabled();
143 * Generate a log file and return the filename.
144 * It is the caller's responsibility to remove the
147 const std::string getLogFile() const;
150 * We do not support this generally. In RCS/SVN file read-only flag
151 * is often connected with locking state and one has to be careful to
152 * keep things in synchro once we would allow user to toggle
155 std::string toggleReadOnly();
157 /// Is the document under administration by VCS?
158 /// returns false for unregistered documents in a path managed by VCS
161 /// Returns the RCS + version number for messages
162 std::string const versionString() const;
165 * Returns whether we use locking for the given file.
167 bool locking() const;
169 // type of the revision information
180 * Return revision info specified by the argument.
181 * Its safe to call it regardless VCS is in usage or this
182 * info is (un)available. Returns empty string in such a case.
184 std::string revisionInfo(RevisionInfo const info) const;