7 #include "vc-backend.h"
10 #include "BufferView.h"
11 #include "frontends/LyXView.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()->getLyXFunc()->dispatch(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()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
177 doVCCommand("co -q -l \""
178 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
179 owner_->getUser()->owner()->getLyXFunc()->dispatch(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()
190 ->getLyXFunc()->dispatch(LFUN_MENURELOAD);
196 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
197 doVCCommand("rcs -o" + version() + " \""
198 + OnlyFilename(owner_->fileName()) + "\"",
203 void RCS::getLog(string const & tmpf)
205 doVCCommand("rlog \""
206 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filePath());
210 CVS::CVS(string const & m, string const & f)
218 string const CVS::find_file(string const & file)
220 // First we look for the CVS/Entries in the same dir
221 // where we have file.
222 string const dir = OnlyPath(file) + "/CVS/Entries";
223 string const tmpf = "/" + OnlyFilename(file) + "/";
224 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
225 << "' for `" << tmpf << "'" << endl;
226 FileInfo const f(dir);
228 // Ok we are at least in a CVS dir. Parse the CVS/Entries
229 // and see if we can find this file. We do a fast and
231 ifstream ifs(dir.c_str());
233 while (getline(ifs, line)) {
234 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
235 if (contains(line, tmpf)) return dir;
242 void CVS::scanMaster()
244 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
246 // Ok now we do the real scan...
247 ifstream ifs(master_.c_str());
248 string tmpf = "/" + OnlyFilename(file_) + "/";
249 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
251 regex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
252 while (getline(ifs, line)) {
253 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
254 if (contains(line, tmpf)) {
255 // Ok extract the fields.
257 regex_match(line, sm, reg);
259 //sm[0]; // whole matched string
262 string file_date = sm[3];
264 //sm[5]; // tag or tagdate
266 // FIXME: must double check file is stattable/existing
267 time_t mod = fi.getModificationTime();
268 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
270 << "Date in Entries: `" << file_date
271 << "'\nModification date of file: `"
272 << mod_date << "'" << endl;
273 if (file_date == mod_date) {
274 locker_ = "Unlocked";
277 // Here we should also to some more checking
278 // to see if there are conflicts or not.
288 void CVS::registrer(string const & msg)
290 doVCCommand("cvs -q add -m \"" + msg + "\" \""
291 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
292 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
296 void CVS::checkIn(string const & msg)
298 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
299 + OnlyFilename(owner_->fileName()) + "\"",
301 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
307 // cvs update or perhaps for cvs this should be a noop
308 lyxerr << "Sorry not implemented." << endl;
314 // Reverts to the version in CVS repository and
315 // gets the updated version from the repository.
316 string const fil = OnlyFilename(owner_->fileName());
318 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
321 owner_->getUser()->owner()
322 ->getLyXFunc()->dispatch(LFUN_MENURELOAD);
328 // merge the current with the previous version
329 // in a reverse patch kind of way, so that the
330 // result is to revert the last changes.
331 lyxerr << "Sorry not implemented." << endl;
335 void CVS::getLog(string const & tmpf)
337 doVCCommand("cvs log \""
338 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,