3 #include "vc-backend.h"
6 #include "BufferView.h"
7 #include "frontends/LyXView.h"
8 #include "funcrequest.h"
10 #include "support/FileInfo.h"
11 #include "support/path.h"
12 #include "support/filetools.h"
13 #include "support/lstrings.h"
14 #include "support/systemcall.h"
16 #include <boost/regex.hpp>
20 #ifndef CXX_GLOBAL_CSTD
29 using boost::regex_match;
31 #ifndef USE_INCLUDED_STRING
38 int VCS::doVCCommand(string const & cmd, string const & path)
40 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
43 int const ret = one.startscript(Systemcall::Wait, cmd);
48 RCS::RCS(string const & m)
55 string const RCS::find_file(string const & file)
58 // Check if *,v exists.
61 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
63 if (f.newFile(tmp).readable()) {
64 lyxerr[Debug::LYXVC] << "Yes " << file
65 << " is under rcs." << endl;
68 // Check if RCS/*,v exists.
69 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
71 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
73 if (f.newFile(tmp).readable()) {
74 lyxerr[Debug::LYXVC] << "Yes " << file
75 << " it is under rcs."<< endl;
83 void RCS::retrieve(string const & file)
85 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
86 VCS::doVCCommand("co -q -r \""
92 void RCS::scanMaster()
94 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
96 ifstream ifs(master_.c_str());
99 bool read_enough = false;
101 while (!read_enough && ifs >> token) {
103 << "LyXVC::scanMaster: current lex text: `"
104 << token << '\'' << endl;
108 else if (token == "head") {
112 tmv = rtrim(tmv, ";");
114 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
116 } else if (contains(token, "access")
117 || contains(token, "symbols")
118 || contains(token, "strict")) {
120 } else if (contains(token, "locks")) {
122 if (contains(token, ";")) {
123 locker_ = "Unlocked";
132 s1 = rtrim(tmpt, ";");
133 // tmp is now in the format <user>:<version>
134 s1 = split(s1, s2, ':');
135 // s2 is user, and s1 is version
136 if (s1 == version_) {
141 } while (!contains(tmpt, ";"));
143 } else if (token == "comment") {
144 // we don't need to read any further than this.
149 << "LyXVC::scanMaster(): unexpected token"
156 void RCS::registrer(string const & msg)
158 string cmd = "ci -q -u -i -t-\"";
161 cmd += OnlyFilename(owner_->fileName());
163 doVCCommand(cmd, owner_->filePath());
164 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
168 void RCS::checkIn(string const & msg)
170 doVCCommand("ci -q -u -m\"" + msg + "\" \""
171 + OnlyFilename(owner_->fileName()) + '"',
173 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
180 doVCCommand("co -q -l \""
181 + OnlyFilename(owner_->fileName()) + '"',
183 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
189 doVCCommand("co -f -u" + version() + " \""
190 + OnlyFilename(owner_->fileName()) + '"',
192 // We ignore changes and just reload!
194 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
200 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
201 doVCCommand("rcs -o" + version() + " \""
202 + OnlyFilename(owner_->fileName()) + '"',
207 void RCS::getLog(string const & tmpf)
209 doVCCommand("rlog \""
210 + OnlyFilename(owner_->fileName()) + "\" > "
211 + tmpf, owner_->filePath());
215 CVS::CVS(string const & m, string const & f)
223 string const CVS::find_file(string const & file)
225 // First we look for the CVS/Entries in the same dir
226 // where we have file.
227 string const dir = OnlyPath(file) + "/CVS/Entries";
228 string const tmpf = "/" + OnlyFilename(file) + "/";
229 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
230 << "' for `" << tmpf << '\'' << endl;
231 FileInfo const f(dir);
233 // Ok we are at least in a CVS dir. Parse the CVS/Entries
234 // and see if we can find this file. We do a fast and
236 ifstream ifs(dir.c_str());
238 while (getline(ifs, line)) {
239 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
240 if (contains(line, tmpf)) return dir;
247 void CVS::scanMaster()
249 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
251 // Ok now we do the real scan...
252 ifstream ifs(master_.c_str());
253 string tmpf = "/" + OnlyFilename(file_) + "/";
254 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << '\'' << endl;
256 regex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
257 while (getline(ifs, line)) {
258 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
259 if (contains(line, tmpf)) {
260 // Ok extract the fields.
261 #ifndef USE_INCLUDED_STRING
266 regex_match(STRCONV(line), sm, reg);
268 //sm[0]; // whole matched string
270 version_ = STRCONV(sm.str(2));
271 string const file_date = STRCONV(sm.str(3));
274 //sm[5]; // tag or tagdate
276 // FIXME: must double check file is stattable/existing
277 time_t mod = fi.getModificationTime();
278 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
280 << "Date in Entries: `" << file_date
281 << "'\nModification date of file: `"
282 << mod_date << '\'' << endl;
283 if (file_date == mod_date) {
284 locker_ = "Unlocked";
287 // Here we should also to some more checking
288 // to see if there are conflicts or not.
298 void CVS::registrer(string const & msg)
300 doVCCommand("cvs -q add -m \"" + msg + "\" \""
301 + OnlyFilename(owner_->fileName()) + '"',
303 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
307 void CVS::checkIn(string const & msg)
309 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
310 + OnlyFilename(owner_->fileName()) + '"',
312 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
318 // cvs update or perhaps for cvs this should be a noop
319 lyxerr << "Sorry not implemented." << endl;
325 // Reverts to the version in CVS repository and
326 // gets the updated version from the repository.
327 string const fil = OnlyFilename(owner_->fileName());
329 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + '"',
332 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
338 // merge the current with the previous version
339 // in a reverse patch kind of way, so that the
340 // result is to revert the last changes.
341 lyxerr << "Sorry not implemented." << endl;
345 void CVS::getLog(string const & tmpf)
347 doVCCommand("cvs log \""
348 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,