3 #include "vc-backend.h"
6 #include "frontends/LyXView.h"
7 #include "funcrequest.h"
9 #include "support/FileInfo.h"
10 #include "support/path.h"
11 #include "support/filetools.h"
12 #include "support/lstrings.h"
13 #include "support/systemcall.h"
15 #include <boost/regex.hpp>
19 using namespace lyx::support;
21 #ifndef CXX_GLOBAL_CSTD
30 using boost::regex_match;
32 #ifndef USE_INCLUDED_STRING
39 int VCS::doVCCommand(string const & cmd, string const & path)
41 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
44 int const ret = one.startscript(Systemcall::Wait, cmd);
49 RCS::RCS(string const & m)
56 string const RCS::find_file(string const & file)
59 // Check if *,v exists.
62 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
64 if (f.newFile(tmp).readable()) {
65 lyxerr[Debug::LYXVC] << "Yes " << file
66 << " is under rcs." << endl;
69 // Check if RCS/*,v exists.
70 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
72 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
74 if (f.newFile(tmp).readable()) {
75 lyxerr[Debug::LYXVC] << "Yes " << file
76 << " it is under rcs."<< endl;
84 void RCS::retrieve(string const & file)
86 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
87 VCS::doVCCommand("co -q -r \""
93 void RCS::scanMaster()
95 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
97 ifstream ifs(master_.c_str());
100 bool read_enough = false;
102 while (!read_enough && ifs >> token) {
104 << "LyXVC::scanMaster: current lex text: `"
105 << token << '\'' << endl;
109 else if (token == "head") {
113 tmv = rtrim(tmv, ";");
115 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
117 } else if (contains(token, "access")
118 || contains(token, "symbols")
119 || contains(token, "strict")) {
121 } else if (contains(token, "locks")) {
123 if (contains(token, ";")) {
124 locker_ = "Unlocked";
133 s1 = rtrim(tmpt, ";");
134 // tmp is now in the format <user>:<version>
135 s1 = split(s1, s2, ':');
136 // s2 is user, and s1 is version
137 if (s1 == version_) {
142 } while (!contains(tmpt, ";"));
144 } else if (token == "comment") {
145 // we don't need to read any further than this.
150 << "LyXVC::scanMaster(): unexpected token"
157 void RCS::registrer(string const & msg)
159 string cmd = "ci -q -u -i -t-\"";
162 cmd += OnlyFilename(owner_->fileName());
164 doVCCommand(cmd, owner_->filePath());
168 void RCS::checkIn(string const & msg)
170 doVCCommand("ci -q -u -m\"" + msg + "\" \""
171 + OnlyFilename(owner_->fileName()) + '"',
179 doVCCommand("co -q -l \""
180 + OnlyFilename(owner_->fileName()) + '"',
187 doVCCommand("co -f -u" + version() + " \""
188 + OnlyFilename(owner_->fileName()) + '"',
190 // We ignore changes and just reload!
197 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
198 doVCCommand("rcs -o" + version() + " \""
199 + OnlyFilename(owner_->fileName()) + '"',
204 void RCS::getLog(string const & tmpf)
206 doVCCommand("rlog \""
207 + OnlyFilename(owner_->fileName()) + "\" > "
208 + tmpf, owner_->filePath());
212 CVS::CVS(string const & m, string const & f)
220 string const CVS::find_file(string const & file)
222 // First we look for the CVS/Entries in the same dir
223 // where we have file.
224 string const dir = OnlyPath(file) + "/CVS/Entries";
225 string const tmpf = "/" + OnlyFilename(file) + "/";
226 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
227 << "' for `" << tmpf << '\'' << endl;
228 FileInfo const f(dir);
230 // Ok we are at least in a CVS dir. Parse the CVS/Entries
231 // and see if we can find this file. We do a fast and
233 ifstream ifs(dir.c_str());
235 while (getline(ifs, line)) {
236 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
237 if (contains(line, tmpf)) return dir;
244 void CVS::scanMaster()
246 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
248 // Ok now we do the real scan...
249 ifstream ifs(master_.c_str());
250 string tmpf = "/" + OnlyFilename(file_) + "/";
251 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << '\'' << endl;
253 regex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
254 while (getline(ifs, line)) {
255 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
256 if (contains(line, tmpf)) {
257 // Ok extract the fields.
258 #ifndef USE_INCLUDED_STRING
263 regex_match(STRCONV(line), sm, reg);
265 //sm[0]; // whole matched string
267 version_ = STRCONV(sm.str(2));
268 string const file_date = STRCONV(sm.str(3));
271 //sm[5]; // tag or tagdate
273 // FIXME: must double check file is stattable/existing
274 time_t mod = fi.getModificationTime();
275 string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
277 << "Date in Entries: `" << file_date
278 << "'\nModification date of file: `"
279 << mod_date << '\'' << endl;
280 if (file_date == mod_date) {
281 locker_ = "Unlocked";
284 // Here we should also to some more checking
285 // to see if there are conflicts or not.
295 void CVS::registrer(string const & msg)
297 doVCCommand("cvs -q add -m \"" + msg + "\" \""
298 + OnlyFilename(owner_->fileName()) + '"',
303 void CVS::checkIn(string const & msg)
305 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
306 + OnlyFilename(owner_->fileName()) + '"',
313 // cvs update or perhaps for cvs this should be a noop
314 lyxerr << "Sorry not implemented." << endl;
320 // Reverts to the version in CVS repository and
321 // gets the updated version from the repository.
322 string const fil = OnlyFilename(owner_->fileName());
324 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + '"',
332 // merge the current with the previous version
333 // in a reverse patch kind of way, so that the
334 // result is to revert the last changes.
335 lyxerr << "Sorry not implemented." << endl;
339 void CVS::getLog(string const & tmpf)
341 doVCCommand("cvs log \""
342 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,