]> git.lyx.org Git - lyx.git/blob - src/VCBackend.h
cosmetics
[lyx.git] / src / VCBackend.h
1 // -*- C++ -*-
2 /**
3  * \file VCBackend.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 VC_BACKEND_H
13 #define VC_BACKEND_H
14
15 #include "support/FileName.h"
16
17 #include <string>
18
19
20 namespace lyx {
21
22 class Buffer;
23
24 /// A simple version control system interface
25 class VCS {
26 public:
27         /// the status of the managed file
28         enum VCStatus {
29                 UNLOCKED,
30                 LOCKED
31         };
32
33         virtual ~VCS() {}
34
35         /// register a file for version control
36         virtual void registrer(std::string const & msg) = 0;
37         /// check in the current revision
38         virtual void checkIn(std::string const & msg) = 0;
39         /// check out for editing
40         virtual void checkOut() = 0;
41         /// revert current edits
42         virtual void revert() = 0;
43         /// FIXME
44         virtual void undoLast() = 0;
45         /**
46          * getLog - read the revision log into the given file
47          * @param fname file name to read into
48          */
49         virtual void getLog(support::FileName const &) = 0;
50         /// return the current version description
51         virtual std::string const versionString() const = 0;
52         /// return the current version
53         std::string const & version() const {
54                 return version_;
55         }
56         /// return the user who has locked the file
57         std::string const & locker() const { return locker_; }
58         /// set the owning buffer
59         void owner(Buffer * b) { owner_ = b; }
60         /// return the owning buffer
61         Buffer * owner() const { return owner_; }
62         /// return the lock status of this file
63         VCStatus status() const { return vcstatus; }
64 protected:
65         /// parse information from the version file
66         virtual void scanMaster() = 0;
67
68         /**
69          * doVCCommand - call out to the version control utility
70          * @param cmd the command to execute
71          * @param path the path from which to execute
72          * @return exit status
73          */
74         static int doVCCommand(std::string const & cmd, support::FileName const & path);
75
76         /**
77          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
78          * have full path.
79          */
80         support::FileName master_;
81
82         /// The status of the VC controlled file.
83         VCStatus vcstatus;
84
85         /**
86          * The version of the VC file. I am not sure if this can be a
87          * string or if it must be a float/int.
88          */
89         std::string version_;
90
91         /// The user currently keeping the lock on the VC file.
92         std::string locker_;
93         /// The buffer using this VC
94         Buffer * owner_;
95 };
96
97
98 ///
99 class RCS : public VCS {
100 public:
101
102         explicit
103         RCS(support::FileName const & m);
104
105         /// return the revision file for the given file, if found
106         static support::FileName const find_file(support::FileName const & file);
107
108         static void retrieve(support::FileName const & file);
109
110         virtual void registrer(std::string const & msg);
111
112         virtual void checkIn(std::string const & msg);
113
114         virtual void checkOut();
115
116         virtual void revert();
117
118         virtual void undoLast();
119
120         virtual void getLog(support::FileName const &);
121
122         virtual std::string const versionString() const {
123                 return "RCS: " + version_;
124         }
125
126 protected:
127         virtual void scanMaster();
128 };
129
130
131 ///
132 class CVS : public VCS {
133 public:
134         ///
135         explicit
136         CVS(support::FileName const & m, support::FileName const & f);
137
138         /// return the revision file for the given file, if found
139         static support::FileName const find_file(support::FileName const & file);
140
141         virtual void registrer(std::string const & msg);
142
143         virtual void checkIn(std::string const & msg);
144
145         virtual void checkOut();
146
147         virtual void revert();
148
149         virtual void undoLast();
150
151         virtual void getLog(support::FileName const &);
152
153         virtual std::string const versionString() const {
154                 return "CVS: " + version_;
155         }
156
157 protected:
158         virtual void scanMaster();
159
160 private:
161         support::FileName file_;
162 };
163
164 } // namespace lyx
165
166 #endif // VCBACKEND_H