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 using namespace lyx::support;
22 #ifndef CXX_GLOBAL_CSTD
31 using boost::regex_match;
33 #ifndef USE_INCLUDED_STRING
40 int VCS::doVCCommand(string const & cmd, string const & path)
42 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
45 int const ret = one.startscript(Systemcall::Wait, cmd);
52 owner_->getUser()->reload();
53 /* Watch out ! We have deleted ourselves here
54 * via the ->reload() !
59 RCS::RCS(string const & m)
66 string const RCS::find_file(string const & file)
69 // Check if *,v exists.
72 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
74 if (f.newFile(tmp).readable()) {
75 lyxerr[Debug::LYXVC] << "Yes " << file
76 << " is under rcs." << endl;
79 // Check if RCS/*,v exists.
80 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
82 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
84 if (f.newFile(tmp).readable()) {
85 lyxerr[Debug::LYXVC] << "Yes " << file
86 << " it is under rcs."<< endl;
94 void RCS::retrieve(string const & file)
96 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
97 VCS::doVCCommand("co -q -r \""
103 void RCS::scanMaster()
105 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
107 ifstream ifs(master_.c_str());
110 bool read_enough = false;
112 while (!read_enough && ifs >> token) {
114 << "LyXVC::scanMaster: current lex text: `"
115 << token << '\'' << endl;
119 else if (token == "head") {
123 tmv = rtrim(tmv, ";");
125 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
127 } else if (contains(token, "access")
128 || contains(token, "symbols")
129 || contains(token, "strict")) {
131 } else if (contains(token, "locks")) {
133 if (contains(token, ";")) {
134 locker_ = "Unlocked";
143 s1 = rtrim(tmpt, ";");
144 // tmp is now in the format <user>:<version>
145 s1 = split(s1, s2, ':');
146 // s2 is user, and s1 is version
147 if (s1 == version_) {
152 } while (!contains(tmpt, ";"));
154 } else if (token == "comment") {
155 // we don't need to read any further than this.
160 << "LyXVC::scanMaster(): unexpected token"
167 void RCS::registrer(string const & msg)
169 string cmd = "ci -q -u -i -t-\"";
172 cmd += OnlyFilename(owner_->fileName());
174 doVCCommand(cmd, owner_->filePath());
179 void RCS::checkIn(string const & msg)
181 doVCCommand("ci -q -u -m\"" + msg + "\" \""
182 + OnlyFilename(owner_->fileName()) + '"',
191 doVCCommand("co -q -l \""
192 + OnlyFilename(owner_->fileName()) + '"',
200 doVCCommand("co -f -u" + version() + " \""
201 + OnlyFilename(owner_->fileName()) + '"',
203 // We ignore changes and just reload!
211 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
212 doVCCommand("rcs -o" + version() + " \""
213 + OnlyFilename(owner_->fileName()) + '"',
218 void RCS::getLog(string const & tmpf)
220 doVCCommand("rlog \""
221 + OnlyFilename(owner_->fileName()) + "\" > "
222 + tmpf, owner_->filePath());
226 CVS::CVS(string const & m, string const & f)
234 string const CVS::find_file(string const & file)
236 // First we look for the CVS/Entries in the same dir
237 // where we have file.
238 string const dir = OnlyPath(file) + "/CVS/Entries";
239 string const tmpf = "/" + OnlyFilename(file) + "/";
240 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
241 << "' for `" << tmpf << '\'' << endl;
242 FileInfo const f(dir);
244 // Ok we are at least in a CVS dir. Parse the CVS/Entries
245 // and see if we can find this file. We do a fast and
247 ifstream ifs(dir.c_str());
249 while (getline(ifs, line)) {
250 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
251 if (contains(line, tmpf)) return dir;
258 void CVS::scanMaster()
260 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
262 // Ok now we do the real scan...
263 ifstream ifs(master_.c_str());
264 string tmpf = "/" + OnlyFilename(file_) + "/";
265 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << '\'' << endl;
267 regex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
268 while (getline(ifs, line)) {
269 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
270 if (contains(line, tmpf)) {
271 // Ok extract the fields.
272 #ifndef USE_INCLUDED_STRING
277 regex_match(STRCONV(line), sm, reg);
279 //sm[0]; // whole matched string
281 version_ = STRCONV(sm.str(2));
282 string const file_date = STRCONV(sm.str(3));
285 //sm[5]; // tag or tagdate
287 // FIXME: must double check file is stattable/existing
288 time_t mod = fi.getModificationTime();
289 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
291 << "Date in Entries: `" << file_date
292 << "'\nModification date of file: `"
293 << mod_date << '\'' << endl;
294 if (file_date == mod_date) {
295 locker_ = "Unlocked";
298 // Here we should also to some more checking
299 // to see if there are conflicts or not.
309 void CVS::registrer(string const & msg)
311 doVCCommand("cvs -q add -m \"" + msg + "\" \""
312 + OnlyFilename(owner_->fileName()) + '"',
318 void CVS::checkIn(string const & msg)
320 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
321 + OnlyFilename(owner_->fileName()) + '"',
329 // cvs update or perhaps for cvs this should be a noop
330 lyxerr << "Sorry not implemented." << endl;
336 // Reverts to the version in CVS repository and
337 // gets the updated version from the repository.
338 string const fil = OnlyFilename(owner_->fileName());
340 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + '"',
349 // merge the current with the previous version
350 // in a reverse patch kind of way, so that the
351 // result is to revert the last changes.
352 lyxerr << "Sorry not implemented." << endl;
356 void CVS::getLog(string const & tmpf)
358 doVCCommand("cvs log \""
359 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,