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