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;
36 int VCS::doVCCommand(string const & cmd, string const & path)
38 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
41 int const ret = one.startscript(Systemcall::Wait, cmd);
46 RCS::RCS(string const & m)
53 string const RCS::find_file(string const & file)
56 // Check if *,v exists.
59 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
61 if (f.newFile(tmp).readable()) {
62 lyxerr[Debug::LYXVC] << "Yes " << file
63 << " is under rcs." << endl;
66 // Check if RCS/*,v exists.
67 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
69 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
71 if (f.newFile(tmp).readable()) {
72 lyxerr[Debug::LYXVC] << "Yes " << file
73 << " it is under rcs."<< endl;
81 void RCS::retrieve(string const & file)
83 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
84 VCS::doVCCommand("co -q -r \""
90 void RCS::scanMaster()
92 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
94 ifstream ifs(master_.c_str());
97 bool read_enough = false;
99 while (!read_enough && ifs >> token) {
101 << "LyXVC::scanMaster: current lex text: `"
102 << token << "'" << endl;
106 else if (token == "head") {
110 tmv = rtrim(tmv, ";");
112 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
114 } else if (contains(token, "access")
115 || contains(token, "symbols")
116 || contains(token, "strict")) {
118 } else if (contains(token, "locks")) {
120 if (contains(token, ";")) {
121 locker_ = "Unlocked";
130 s1 = rtrim(tmpt, ";");
131 // tmp is now in the format <user>:<version>
132 s1 = split(s1, s2, ':');
133 // s2 is user, and s1 is version
134 if (s1 == version_) {
139 } while (!contains(tmpt, ";"));
141 } else if (token == "comment") {
142 // we don't need to read any further than this.
147 << "LyXVC::scanMaster(): unexpected token"
154 void RCS::registrer(string const & msg)
156 string cmd = "ci -q -u -i -t-\"";
159 cmd += OnlyFilename(owner_->fileName());
161 doVCCommand(cmd, owner_->filePath());
162 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
166 void RCS::checkIn(string const & msg)
168 doVCCommand("ci -q -u -m\"" + msg + "\" \""
169 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
170 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
177 doVCCommand("co -q -l \""
178 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
179 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
185 doVCCommand("co -f -u" + version() + " \""
186 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
187 // We ignore changes and just reload!
189 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
195 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
196 doVCCommand("rcs -o" + version() + " \""
197 + OnlyFilename(owner_->fileName()) + "\"",
202 void RCS::getLog(string const & tmpf)
204 doVCCommand("rlog \""
205 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filePath());
209 CVS::CVS(string const & m, string const & f)
217 string const CVS::find_file(string const & file)
219 // First we look for the CVS/Entries in the same dir
220 // where we have file.
221 string const dir = OnlyPath(file) + "/CVS/Entries";
222 string const tmpf = "/" + OnlyFilename(file) + "/";
223 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
224 << "' for `" << tmpf << "'" << endl;
225 FileInfo const f(dir);
227 // Ok we are at least in a CVS dir. Parse the CVS/Entries
228 // and see if we can find this file. We do a fast and
230 ifstream ifs(dir.c_str());
232 while (getline(ifs, line)) {
233 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
234 if (contains(line, tmpf)) return dir;
241 void CVS::scanMaster()
243 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
245 // Ok now we do the real scan...
246 ifstream ifs(master_.c_str());
247 string tmpf = "/" + OnlyFilename(file_) + "/";
248 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
250 regex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
251 while (getline(ifs, line)) {
252 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
253 if (contains(line, tmpf)) {
254 // Ok extract the fields.
256 regex_match(line, sm, reg);
258 //sm[0]; // whole matched string
261 string file_date = sm[3];
263 //sm[5]; // tag or tagdate
265 // FIXME: must double check file is stattable/existing
266 time_t mod = fi.getModificationTime();
267 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
269 << "Date in Entries: `" << file_date
270 << "'\nModification date of file: `"
271 << mod_date << "'" << endl;
272 if (file_date == mod_date) {
273 locker_ = "Unlocked";
276 // Here we should also to some more checking
277 // to see if there are conflicts or not.
287 void CVS::registrer(string const & msg)
289 doVCCommand("cvs -q add -m \"" + msg + "\" \""
290 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
291 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
295 void CVS::checkIn(string const & msg)
297 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
298 + OnlyFilename(owner_->fileName()) + "\"",
300 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
306 // cvs update or perhaps for cvs this should be a noop
307 lyxerr << "Sorry not implemented." << endl;
313 // Reverts to the version in CVS repository and
314 // gets the updated version from the repository.
315 string const fil = OnlyFilename(owner_->fileName());
317 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
320 owner_->getUser()->owner()->dispatch(FuncRequest(LFUN_MENURELOAD));
326 // merge the current with the previous version
327 // in a reverse patch kind of way, so that the
328 // result is to revert the last changes.
329 lyxerr << "Sorry not implemented." << endl;
333 void CVS::getLog(string const & tmpf)
335 doVCCommand("cvs log \""
336 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,