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>
28 using boost::regex_match;
31 int VCS::doVCCommand(string const & cmd, string const & path)
33 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
36 int const ret = one.startscript(Systemcall::Wait, cmd);
41 RCS::RCS(string const & m)
48 string const RCS::find_file(string const & file)
51 // Check if *,v exists.
54 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
56 if (f.newFile(tmp).readable()) {
57 lyxerr[Debug::LYXVC] << "Yes " << file
58 << " is under rcs." << endl;
61 // Check if RCS/*,v exists.
62 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
64 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
66 if (f.newFile(tmp).readable()) {
67 lyxerr[Debug::LYXVC] << "Yes " << file
68 << " it is under rcs."<< endl;
76 void RCS::retrieve(string const & file)
78 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
79 VCS::doVCCommand("co -q -r \""
85 void RCS::scanMaster()
87 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
89 ifstream ifs(master_.c_str());
92 bool read_enough = false;
94 while (!read_enough && ifs >> token) {
96 << "LyXVC::scanMaster: current lex text: `"
97 << token << "'" << endl;
101 else if (token == "head") {
105 tmv = strip(tmv, ';');
107 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
109 } else if (contains(token, "access")
110 || contains(token, "symbols")
111 || contains(token, "strict")) {
113 } else if (contains(token, "locks")) {
115 if (contains(token, ";")) {
116 locker_ = "Unlocked";
125 s1 = strip(tmpt, ';');
126 // tmp is now in the format <user>:<version>
127 s1 = split(s1, s2, ':');
128 // s2 is user, and s1 is version
129 if (s1 == version_) {
134 } while (!contains(tmpt, ";"));
136 } else if (token == "comment") {
137 // we don't need to read any further than this.
142 << "LyXVC::scanMaster(): unexpected token"
149 void RCS::registrer(string const & msg)
151 string cmd = "ci -q -u -i -t-\"";
154 cmd += OnlyFilename(owner_->fileName());
156 doVCCommand(cmd, owner_->filePath());
157 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
161 void RCS::checkIn(string const & msg)
163 doVCCommand("ci -q -u -m\"" + msg + "\" \""
164 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
165 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
171 owner_->markLyxClean();
172 doVCCommand("co -q -l \""
173 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
174 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
180 doVCCommand("co -f -u" + version() + " \""
181 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
182 // We ignore changes and just reload!
183 owner_->markLyxClean();
184 owner_->getUser()->owner()
185 ->getLyXFunc()->dispatch(LFUN_MENURELOAD);
191 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
192 doVCCommand("rcs -o" + version() + " \""
193 + OnlyFilename(owner_->fileName()) + "\"",
198 void RCS::getLog(string const & tmpf)
200 doVCCommand("rlog \""
201 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filePath());
205 CVS::CVS(string const & m, string const & f)
213 string const CVS::find_file(string const & file)
215 // First we look for the CVS/Entries in the same dir
216 // where we have file.
217 string const dir = OnlyPath(file) + "/CVS/Entries";
218 string const tmpf = "/" + OnlyFilename(file) + "/";
219 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
220 << "' for `" << tmpf << "'" << endl;
221 FileInfo const f(dir);
223 // Ok we are at least in a CVS dir. Parse the CVS/Entries
224 // and see if we can find this file. We do a fast and
226 ifstream ifs(dir.c_str());
228 while (getline(ifs, line)) {
229 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
230 if (contains(line, tmpf)) return dir;
237 void CVS::scanMaster()
239 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
241 // Ok now we do the real scan...
242 ifstream ifs(master_.c_str());
243 string tmpf = "/" + OnlyFilename(file_) + "/";
244 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
246 regex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
247 while (getline(ifs, line)) {
248 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
249 if (contains(line, tmpf)) {
250 // Ok extract the fields.
252 regex_match(line, sm, reg);
254 //sm[0]; // whole matched string
257 string file_date = sm[3];
259 //sm[5]; // tag or tagdate
261 // FIXME: must double check file is stattable/existing
262 time_t mod = fi.getModificationTime();
263 string mod_date = strip(asctime(gmtime(&mod)), '\n');
265 << "Date in Entries: `" << file_date
266 << "'\nModification date of file: `"
267 << mod_date << "'" << endl;
268 if (file_date == mod_date) {
269 locker_ = "Unlocked";
272 // Here we should also to some more checking
273 // to see if there are conflicts or not.
283 void CVS::registrer(string const & msg)
285 doVCCommand("cvs -q add -m \"" + msg + "\" \""
286 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
287 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
291 void CVS::checkIn(string const & msg)
293 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
294 + OnlyFilename(owner_->fileName()) + "\"",
296 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
302 // cvs update or perhaps for cvs this should be a noop
303 lyxerr << "Sorry not implemented." << endl;
309 // Reverts to the version in CVS repository and
310 // gets the updated version from the repository.
311 string const fil = OnlyFilename(owner_->fileName());
313 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
315 owner_->markLyxClean();
316 owner_->getUser()->owner()
317 ->getLyXFunc()->dispatch(LFUN_MENURELOAD);
323 // merge the current with the previous version
324 // in a reverse patch kind of way, so that the
325 // result is to revert the last changes.
326 lyxerr << "Sorry not implemented." << endl;
330 void CVS::getLog(string const & tmpf)
332 doVCCommand("cvs log \""
333 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,