7 #include "vc-backend.h"
10 #include "BufferView.h"
14 #include "support/FileInfo.h"
15 #include "support/LRegex.h"
16 #include "support/LSubstring.h"
17 #include "support/path.h"
18 #include "support/filetools.h"
19 #include "support/lstrings.h"
20 #include "support/systemcall.h"
24 #ifndef CXX_GLOBAL_CSTD
33 int VCS::doVCCommand(string const & cmd, string const & path)
35 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
38 int const ret = one.startscript(Systemcall::Wait, cmd);
43 RCS::RCS(string const & m)
50 string const RCS::find_file(string const & file)
53 // Check if *,v exists.
56 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
58 if (f.newFile(tmp).readable()) {
59 lyxerr[Debug::LYXVC] << "Yes " << file
60 << " is under rcs." << endl;
63 // Check if RCS/*,v exists.
64 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
66 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
68 if (f.newFile(tmp).readable()) {
69 lyxerr[Debug::LYXVC] << "Yes " << file
70 << " it is under rcs."<< endl;
78 void RCS::retrieve(string const & file)
80 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
81 VCS::doVCCommand("co -q -r \""
87 void RCS::scanMaster()
89 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
91 ifstream ifs(master_.c_str());
94 bool read_enough = false;
96 while (!read_enough && ifs >> token) {
98 << "LyXVC::scanMaster: current lex text: `"
99 << token << "'" << endl;
103 else if (token == "head") {
107 tmv = strip(tmv, ';');
109 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
111 } else if (contains(token, "access")
112 || contains(token, "symbols")
113 || contains(token, "strict")) {
115 } else if (contains(token, "locks")) {
117 if (contains(token, ";")) {
118 locker_ = "Unlocked";
127 s1 = strip(tmpt, ';');
128 // tmp is now in the format <user>:<version>
129 s1 = split(s1, s2, ':');
130 // s2 is user, and s1 is version
131 if (s1 == version_) {
136 } while (!contains(tmpt, ";"));
138 } else if (token == "comment") {
139 // we don't need to read any further than this.
144 << "LyXVC::scanMaster(): unexpected token"
151 void RCS::registrer(string const & msg)
153 string cmd = "ci -q -u -i -t-\"";
156 cmd += OnlyFilename(owner_->fileName());
158 doVCCommand(cmd, owner_->filePath());
159 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
163 void RCS::checkIn(string const & msg)
165 doVCCommand("ci -q -u -m\"" + msg + "\" \""
166 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
167 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
173 owner_->markLyxClean();
174 doVCCommand("co -q -l \""
175 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
176 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
182 doVCCommand("co -f -u" + version() + " \""
183 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
184 // We ignore changes and just reload!
185 owner_->markLyxClean();
186 owner_->getUser()->owner()
187 ->getLyXFunc()->dispatch(LFUN_MENURELOAD);
193 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
194 doVCCommand("rcs -o" + version() + " \""
195 + OnlyFilename(owner_->fileName()) + "\"",
200 void RCS::getLog(string const & tmpf)
202 doVCCommand("rlog \""
203 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filePath());
207 CVS::CVS(string const & m, string const & f)
215 string const CVS::find_file(string const & file)
217 // First we look for the CVS/Entries in the same dir
218 // where we have file.
219 string const dir = OnlyPath(file) + "/CVS/Entries";
220 string const tmpf = "/" + OnlyFilename(file) + "/";
221 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
222 << "' for `" << tmpf << "'" << endl;
223 FileInfo const f(dir);
225 // Ok we are at least in a CVS dir. Parse the CVS/Entries
226 // and see if we can find this file. We do a fast and
228 ifstream ifs(dir.c_str());
230 while (getline(ifs, line)) {
231 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
232 if (contains(line, tmpf)) return dir;
239 void CVS::scanMaster()
241 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
243 // Ok now we do the real scan...
244 ifstream ifs(master_.c_str());
245 string tmpf = "/" + OnlyFilename(file_) + "/";
246 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
248 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
249 while (getline(ifs, line)) {
250 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
251 if (contains(line, tmpf)) {
252 // Ok extract the fields.
253 LRegex::SubMatches const & sm = reg.exec(line);
254 //sm[0]; // whole matched string
256 version_ = LSubstring(line, sm[2].first,
258 string file_date = LSubstring(line, sm[3].first,
261 //sm[5]; // tag or tagdate
263 // FIXME: must double check file is stattable/existing
264 time_t mod = fi.getModificationTime();
265 string mod_date = strip(asctime(gmtime(&mod)), '\n');
267 << "Date in Entries: `" << file_date
268 << "'\nModification date of file: `"
269 << mod_date << "'" << endl;
270 if (file_date == mod_date) {
271 locker_ = "Unlocked";
274 // Here we should also to some more checking
275 // to see if there are conflicts or not.
285 void CVS::registrer(string const & msg)
287 doVCCommand("cvs -q add -m \"" + msg + "\" \""
288 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
289 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
293 void CVS::checkIn(string const & msg)
295 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
296 + OnlyFilename(owner_->fileName()) + "\"",
298 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
304 // cvs update or perhaps for cvs this should be a noop
305 lyxerr << "Sorry not implemented." << endl;
311 // Reverts to the version in CVS repository and
312 // gets the updated version from the repository.
313 string const fil = OnlyFilename(owner_->fileName());
315 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
317 owner_->markLyxClean();
318 owner_->getUser()->owner()
319 ->getLyXFunc()->dispatch(LFUN_MENURELOAD);
325 // merge the current with the previous version
326 // in a reverse patch kind of way, so that the
327 // result is to revert the last changes.
328 lyxerr << "Sorry not implemented." << endl;
332 void CVS::getLog(string const & tmpf)
334 doVCCommand("cvs log \""
335 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,