7 #include "vc-backend.h"
10 #include "BufferView.h"
11 #include "frontends/LyXView.h"
12 #include "funcrequest.h"
14 #include "support/FileInfo.h"
15 #include "support/path.h"
16 #include "support/filetools.h"
17 #include "support/lstrings.h"
18 #include "support/systemcall.h"
20 #include <boost/regex.hpp>
24 #ifndef CXX_GLOBAL_CSTD
33 using boost::regex_match;
35 #ifndef USE_INCLUDED_STRING
42 int VCS::doVCCommand(string const & cmd, string const & path)
44 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
47 int const ret = one.startscript(Systemcall::Wait, cmd);
52 RCS::RCS(string const & m)
59 string const RCS::find_file(string const & file)
62 // Check if *,v exists.
65 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
67 if (f.newFile(tmp).readable()) {
68 lyxerr[Debug::LYXVC] << "Yes " << file
69 << " is under rcs." << endl;
72 // Check if RCS/*,v exists.
73 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
75 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
77 if (f.newFile(tmp).readable()) {
78 lyxerr[Debug::LYXVC] << "Yes " << file
79 << " it is under rcs."<< endl;
87 void RCS::retrieve(string const & file)
89 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
90 VCS::doVCCommand("co -q -r \""
96 void RCS::scanMaster()
98 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
100 ifstream ifs(master_.c_str());
103 bool read_enough = false;
105 while (!read_enough && ifs >> token) {
107 << "LyXVC::scanMaster: current lex text: `"
108 << token << "'" << endl;
112 else if (token == "head") {
116 tmv = rtrim(tmv, ";");
118 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
120 } else if (contains(token, "access")
121 || contains(token, "symbols")
122 || contains(token, "strict")) {
124 } else if (contains(token, "locks")) {
126 if (contains(token, ";")) {
127 locker_ = "Unlocked";
136 s1 = rtrim(tmpt, ";");
137 // tmp is now in the format <user>:<version>
138 s1 = split(s1, s2, ':');
139 // s2 is user, and s1 is version
140 if (s1 == version_) {
145 } while (!contains(tmpt, ";"));
147 } else if (token == "comment") {
148 // we don't need to read any further than this.
153 << "LyXVC::scanMaster(): unexpected token"
160 void RCS::registrer(string const & msg)
162 string cmd = "ci -q -u -i -t-\"";
165 cmd += OnlyFilename(owner_->fileName());
167 doVCCommand(cmd, owner_->filePath());
168 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
172 void RCS::checkIn(string const & msg)
174 doVCCommand("ci -q -u -m\"" + msg + "\" \""
175 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
176 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
183 doVCCommand("co -q -l \""
184 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
185 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
191 doVCCommand("co -f -u" + version() + " \""
192 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
193 // We ignore changes and just reload!
195 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
201 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
202 doVCCommand("rcs -o" + version() + " \""
203 + OnlyFilename(owner_->fileName()) + "\"",
208 void RCS::getLog(string const & tmpf)
210 doVCCommand("rlog \""
211 + OnlyFilename(owner_->fileName()) + "\" > " + 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()) + "\"", owner_->filePath());
302 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
306 void CVS::checkIn(string const & msg)
308 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
309 + OnlyFilename(owner_->fileName()) + "\"",
311 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
317 // cvs update or perhaps for cvs this should be a noop
318 lyxerr << "Sorry not implemented." << endl;
324 // Reverts to the version in CVS repository and
325 // gets the updated version from the repository.
326 string const fil = OnlyFilename(owner_->fileName());
328 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
331 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
337 // merge the current with the previous version
338 // in a reverse patch kind of way, so that the
339 // result is to revert the last changes.
340 lyxerr << "Sorry not implemented." << endl;
344 void CVS::getLog(string const & tmpf)
346 doVCCommand("cvs log \""
347 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,