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);
50 owner_->getUser()->reload();
51 /* Watch out ! We have deleted ourselves here
52 * via the ->reload() !
57 RCS::RCS(string const & m)
64 string const RCS::find_file(string const & file)
67 // Check if *,v exists.
70 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
72 if (f.newFile(tmp).readable()) {
73 lyxerr[Debug::LYXVC] << "Yes " << file
74 << " is under rcs." << endl;
77 // Check if RCS/*,v exists.
78 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
80 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
82 if (f.newFile(tmp).readable()) {
83 lyxerr[Debug::LYXVC] << "Yes " << file
84 << " it is under rcs."<< endl;
92 void RCS::retrieve(string const & file)
94 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
95 VCS::doVCCommand("co -q -r \""
101 void RCS::scanMaster()
103 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
105 ifstream ifs(master_.c_str());
108 bool read_enough = false;
110 while (!read_enough && ifs >> token) {
112 << "LyXVC::scanMaster: current lex text: `"
113 << token << '\'' << endl;
117 else if (token == "head") {
121 tmv = rtrim(tmv, ";");
123 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
125 } else if (contains(token, "access")
126 || contains(token, "symbols")
127 || contains(token, "strict")) {
129 } else if (contains(token, "locks")) {
131 if (contains(token, ";")) {
132 locker_ = "Unlocked";
141 s1 = rtrim(tmpt, ";");
142 // tmp is now in the format <user>:<version>
143 s1 = split(s1, s2, ':');
144 // s2 is user, and s1 is version
145 if (s1 == version_) {
150 } while (!contains(tmpt, ";"));
152 } else if (token == "comment") {
153 // we don't need to read any further than this.
158 << "LyXVC::scanMaster(): unexpected token"
165 void RCS::registrer(string const & msg)
167 string cmd = "ci -q -u -i -t-\"";
170 cmd += OnlyFilename(owner_->fileName());
172 doVCCommand(cmd, owner_->filePath());
177 void RCS::checkIn(string const & msg)
179 doVCCommand("ci -q -u -m\"" + msg + "\" \""
180 + OnlyFilename(owner_->fileName()) + '"',
189 doVCCommand("co -q -l \""
190 + OnlyFilename(owner_->fileName()) + '"',
198 doVCCommand("co -f -u" + version() + " \""
199 + OnlyFilename(owner_->fileName()) + '"',
201 // We ignore changes and just reload!
209 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
210 doVCCommand("rcs -o" + version() + " \""
211 + OnlyFilename(owner_->fileName()) + '"',
216 void RCS::getLog(string const & tmpf)
218 doVCCommand("rlog \""
219 + OnlyFilename(owner_->fileName()) + "\" > "
220 + tmpf, owner_->filePath());
224 CVS::CVS(string const & m, string const & f)
232 string const CVS::find_file(string const & file)
234 // First we look for the CVS/Entries in the same dir
235 // where we have file.
236 string const dir = OnlyPath(file) + "/CVS/Entries";
237 string const tmpf = "/" + OnlyFilename(file) + "/";
238 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
239 << "' for `" << tmpf << '\'' << endl;
240 FileInfo const f(dir);
242 // Ok we are at least in a CVS dir. Parse the CVS/Entries
243 // and see if we can find this file. We do a fast and
245 ifstream ifs(dir.c_str());
247 while (getline(ifs, line)) {
248 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
249 if (contains(line, tmpf)) return dir;
256 void CVS::scanMaster()
258 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
260 // Ok now we do the real scan...
261 ifstream ifs(master_.c_str());
262 string tmpf = "/" + OnlyFilename(file_) + "/";
263 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << '\'' << endl;
265 regex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
266 while (getline(ifs, line)) {
267 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
268 if (contains(line, tmpf)) {
269 // Ok extract the fields.
270 #ifndef USE_INCLUDED_STRING
275 regex_match(STRCONV(line), sm, reg);
277 //sm[0]; // whole matched string
279 version_ = STRCONV(sm.str(2));
280 string const file_date = STRCONV(sm.str(3));
283 //sm[5]; // tag or tagdate
285 // FIXME: must double check file is stattable/existing
286 time_t mod = fi.getModificationTime();
287 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
289 << "Date in Entries: `" << file_date
290 << "'\nModification date of file: `"
291 << mod_date << '\'' << endl;
292 if (file_date == mod_date) {
293 locker_ = "Unlocked";
296 // Here we should also to some more checking
297 // to see if there are conflicts or not.
307 void CVS::registrer(string const & msg)
309 doVCCommand("cvs -q add -m \"" + msg + "\" \""
310 + OnlyFilename(owner_->fileName()) + '"',
316 void CVS::checkIn(string const & msg)
318 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
319 + OnlyFilename(owner_->fileName()) + '"',
327 // cvs update or perhaps for cvs this should be a noop
328 lyxerr << "Sorry not implemented." << endl;
334 // Reverts to the version in CVS repository and
335 // gets the updated version from the repository.
336 string const fil = OnlyFilename(owner_->fileName());
338 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + '"',
347 // merge the current with the previous version
348 // in a reverse patch kind of way, so that the
349 // result is to revert the last changes.
350 lyxerr << "Sorry not implemented." << endl;
354 void CVS::getLog(string const & tmpf)
356 doVCCommand("cvs log \""
357 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,