]> git.lyx.org Git - lyx.git/blob - src/LyXVC.h
add short git hash to name of devel disk images to get different names for devel...
[lyx.git] / src / LyXVC.h
1 // -*- C++ -*-
2 /**
3  * \file LyXVC.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LYX_VC_H
13 #define LYX_VC_H
14
15 #include <boost/scoped_ptr.hpp>
16
17 #include <string>
18
19
20 namespace lyx {
21
22 namespace support { class FileName; }
23
24 class VCS;
25 class Buffer;
26
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.
33
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.
39 */
40 class LyXVC {
41 public:
42         /// Return status of a command
43         enum CommandResult {
44                 Cancelled,    ///< command was cancelled
45                 ErrorBefore,  ///< error before executing command
46                 ErrorCommand, ///< error while executing command
47                 VCSuccess     ///< command was executed successfully
48         };
49         ///
50         LyXVC();
51         ///
52         ~LyXVC();
53         /// Is \p fn under version control?
54         static bool fileInVC(support::FileName const & fn);
55         /** Not a good name perhaps. This function should be called whenever
56           LyX loads a file. This function then checks for a master VC file (for
57           RCS this is *,v or RCS/ *,v ; for CVS this is CVS/Entries and .svn/entries
58           for SVN) if this file or entry is found, the loaded file is assumed to be
59           under control by VC, and the appropiate actions is taken.
60           Returns true if the file is under control by a VCS.
61           */
62         bool file_found_hook(support::FileName const & fn);
63
64         /** Is \p fn under version control?
65           This function should be run when a file is requested for loading,
66           but it does not exist. This function will then check for a VC master
67           file with the same name (see above function). If this exists the
68           user should be asked if he/her wants to checkout a version for
69           viewing/editing. Returns true if the file is under control by a VCS
70           and the user wants to view/edit it.
71           */
72         static bool file_not_found_hook(support::FileName const & fn);
73
74         ///
75         void setBuffer(Buffer *);
76
77         /// Register the document as a VC file.
78         bool registrer();
79
80
81         // std::string used as a return value in functions below are
82         // workaround to defer messages to be displayed in UI. If message()
83         // is used directly, message string is immediately overwritten
84         // by the next multiple messages on the top of the processed dispatch
85         // machinery.
86
87         ///
88         std::string rename(support::FileName const &);
89         /// Does the current VC support this operation?
90         bool renameEnabled() const;
91         ///
92         std::string copy(support::FileName const &);
93         /// Does the current VC support this operation?
94         bool copyEnabled() const;
95
96         /// Unlock and commit changes.
97         /// \p log is non-empty on success and may be empty on failure.
98         CommandResult checkIn(std::string & log);
99         /// Does the current VC support this operation?
100         bool checkInEnabled() const;
101         /// Should a log message be provided for next checkin?
102         bool isCheckInWithConfirmation() const;
103
104         /// Lock/update and prepare to edit document. Returns log.
105         std::string checkOut();
106         /// Does the current VC support this operation?
107         bool checkOutEnabled() const;
108
109         /// Synchronize the whole archive with repository
110         std::string repoUpdate();
111         /// Does the current VC support this operation?
112         bool repoUpdateEnabled() const;
113
114         /**
115          * Toggle locking property of the edited file,
116          * i.e. whether the file uses locking mechanism.
117          */
118         std::string lockingToggle();
119         /// Does the current VC support this operation?
120         bool lockingToggleEnabled() const;
121
122         /// Revert to last version
123         bool revert();
124
125         /// Undo last check-in.
126         void undoLast();
127         /// Does the current VC support this operation?
128         bool undoLastEnabled() const;
129         /**
130          * Prepare revision rev of the file into newly created temporary file
131          * and save the filename into parameter f.
132          * Parameter rev can be either revision number or negative number
133          * which is interpreted as how many revision back from the current
134          * one do we want. rev=0 is reserved for the last (committed) revision.
135          * We need rev to be string, since in various VCS revision is not integer.
136          * If RCS addressed by a single number, it is automatically used
137          * as the last number in the whole revision specification (it applies
138          * for retrieving normal revisions (rev>0) or backtracking (rev<0).
139          */
140         bool prepareFileRevision(std::string const & rev, std::string & f);
141         /// Does the current VC support this operation?
142         bool prepareFileRevisionEnabled();
143
144         /**
145          * Generate a log file and return the filename.
146          * It is the caller's responsibility to remove the
147          * file after use.
148          */
149         const std::string getLogFile() const;
150
151         /**
152          * We do not support this generally. In RCS/SVN file read-only flag
153          * is often connected with locking state and one has to be careful to
154          * keep things in synchro once we would allow user to toggle
155          * read-only flags.
156          */
157         std::string toggleReadOnly();
158
159         /// Is the document under administration by VCS?
160         /// returns false for unregistered documents in a path managed by VCS
161         bool inUse() const;
162
163         /// Returns the RCS + version number for messages
164         std::string const versionString() const;
165
166         /**
167          * Returns whether we use locking for the given file.
168          */
169         bool locking() const;
170
171         // type of the revision information
172         enum RevisionInfo {
173                 Unknown = 0,
174                 File = 1,
175                 Tree = 2,
176                 Author = 3,
177                 Date = 4,
178                 Time = 5
179         };
180
181         /**
182          * Return revision info specified by the argument.
183          * Its safe to call it regardless VCS is in usage or this
184          * info is (un)available. Returns empty string in such a case.
185          */
186         std::string revisionInfo(RevisionInfo const info) const;
187
188 private:
189         ///
190         Buffer * owner_;
191
192         ///
193         boost::scoped_ptr<VCS> vcs;
194 };
195
196
197 } // namespace lyx
198
199 #endif