]> 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 { return version_; }
54         /// return the user who has locked the file
55         std::string const & locker() const { return locker_; }
56         /// set the owning buffer
57         void owner(Buffer * b) { owner_ = b; }
58         /// return the owning buffer
59         Buffer * owner() const { return owner_; }
60         /// return the lock status of this file
61         VCStatus status() const { return vcstatus; }
62 protected:
63         /// parse information from the version file
64         virtual void scanMaster() = 0;
65
66         /**
67          * doVCCommand - call out to the version control utility
68          * @param cmd the command to execute
69          * @param path the path from which to execute
70          * @return exit status
71          */
72         static int doVCCommand(std::string const & cmd, support::FileName const & path);
73
74         /**
75          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
76          * have full path.
77          */
78         support::FileName master_;
79
80         /// The status of the VC controlled file.
81         VCStatus vcstatus;
82
83         /**
84          * The version of the VC file. I am not sure if this can be a
85          * string or if it must be a float/int.
86          */
87         std::string version_;
88
89         /// The user currently keeping the lock on the VC file.
90         std::string locker_;
91         /// The buffer using this VC
92         Buffer * owner_;
93 };
94
95
96 ///
97 class RCS : public VCS {
98 public:
99
100         explicit
101         RCS(support::FileName const & m);
102
103         /// return the revision file for the given file, if found
104         static support::FileName const findFile(support::FileName const & file);
105
106         static void retrieve(support::FileName const & file);
107
108         virtual void registrer(std::string const & msg);
109
110         virtual void checkIn(std::string const & msg);
111
112         virtual void checkOut();
113
114         virtual void revert();
115
116         virtual void undoLast();
117
118         virtual void getLog(support::FileName const &);
119
120         virtual std::string const versionString() const {
121                 return "RCS: " + version_;
122         }
123
124 protected:
125         virtual void scanMaster();
126 };
127
128
129 ///
130 class CVS : public VCS {
131 public:
132         ///
133         explicit
134         CVS(support::FileName const & m, support::FileName const & f);
135
136         /// return the revision file for the given file, if found
137         static support::FileName const findFile(support::FileName const & file);
138
139         virtual void registrer(std::string const & msg);
140
141         virtual void checkIn(std::string const & msg);
142
143         virtual void checkOut();
144
145         virtual void revert();
146
147         virtual void undoLast();
148
149         virtual void getLog(support::FileName const &);
150
151         virtual std::string const versionString() const {
152                 return "CVS: " + version_;
153         }
154
155 protected:
156         virtual void scanMaster();
157
158 private:
159         support::FileName file_;
160 };
161
162 } // namespace lyx
163
164 #endif // VCBACKEND_H