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"
28 int VCS::doVCCommand(string const & cmd, string const & path)
30 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
33 int const ret = one.startscript(Systemcall::Wait, cmd);
38 RCS::RCS(string const & m)
45 string const RCS::find_file(string const & file)
48 // Check if *,v exists.
51 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
53 if (f.newFile(tmp).readable()) {
54 lyxerr[Debug::LYXVC] << "Yes " << file
55 << " is under rcs." << endl;
58 // Check if RCS/*,v exists.
59 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
61 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
63 if (f.newFile(tmp).readable()) {
64 lyxerr[Debug::LYXVC] << "Yes " << file
65 << " it is under rcs."<< endl;
73 void RCS::retrieve(string const & file)
75 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrieve.\n\t" << file << endl;
76 VCS::doVCCommand("co -q -r \""
82 void RCS::scanMaster()
84 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
86 ifstream ifs(master_.c_str());
89 bool read_enough = false;
91 while (!read_enough && ifs >> token) {
93 << "LyXVC::scanMaster: current lex text: `"
94 << token << "'" << endl;
98 else if (token == "head") {
102 tmv = strip(tmv, ';');
104 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
106 } else if (contains(token, "access")
107 || contains(token, "symbols")
108 || contains(token, "strict")) {
110 } else if (contains(token, "locks")) {
112 if (contains(token, ";")) {
113 locker_ = "Unlocked";
122 s1 = strip(tmpt, ';');
123 // tmp is now in the format <user>:<version>
124 s1 = split(s1, s2, ':');
125 // s2 is user, and s1 is version
126 if (s1 == version_) {
131 } while (!contains(tmpt, ";"));
133 } else if (token == "comment") {
134 // we don't need to read any further than this.
139 << "LyXVC::scanMaster(): unexpected token"
146 void RCS::registrer(string const & msg)
148 string cmd = "ci -q -u -i -t-\"";
151 cmd += OnlyFilename(owner_->fileName());
153 doVCCommand(cmd, owner_->filePath());
154 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
158 void RCS::checkIn(string const & msg)
160 doVCCommand("ci -q -u -m\"" + msg + "\" \""
161 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
162 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
168 owner_->markLyxClean();
169 doVCCommand("co -q -l \""
170 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
171 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
177 doVCCommand("co -f -u" + version() + " \""
178 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
179 // We ignore changes and just reload!
180 owner_->markLyxClean();
181 owner_->getUser()->owner()
182 ->getLyXFunc()->dispatch(LFUN_MENURELOAD);
188 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
189 doVCCommand("rcs -o" + version() + " \""
190 + OnlyFilename(owner_->fileName()) + "\"",
195 void RCS::getLog(string const & tmpf)
197 doVCCommand("rlog \""
198 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filePath());
202 CVS::CVS(string const & m, string const & f)
210 string const CVS::find_file(string const & file)
212 // First we look for the CVS/Entries in the same dir
213 // where we have file.
214 string const dir = OnlyPath(file) + "/CVS/Entries";
215 string const tmpf = "/" + OnlyFilename(file) + "/";
216 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
217 << "' for `" << tmpf << "'" << endl;
218 FileInfo const f(dir);
220 // Ok we are at least in a CVS dir. Parse the CVS/Entries
221 // and see if we can find this file. We do a fast and
223 ifstream ifs(dir.c_str());
225 while (getline(ifs, line)) {
226 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
227 if (contains(line, tmpf)) return dir;
234 void CVS::scanMaster()
236 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
238 // Ok now we do the real scan...
239 ifstream ifs(master_.c_str());
240 string tmpf = "/" + OnlyFilename(file_) + "/";
241 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
243 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
244 while (getline(ifs, line)) {
245 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
246 if (contains(line, tmpf)) {
247 // Ok extract the fields.
248 LRegex::SubMatches const & sm = reg.exec(line);
249 //sm[0]; // whole matched string
251 version_ = LSubstring(line, sm[2].first,
253 string file_date = LSubstring(line, sm[3].first,
256 //sm[5]; // tag or tagdate
258 // FIXME: must double check file is stattable/existing
259 time_t mod = fi.getModificationTime();
260 string mod_date = strip(asctime(gmtime(&mod)), '\n');
262 << "Date in Entries: `" << file_date
263 << "'\nModification date of file: `"
264 << mod_date << "'" << endl;
265 if (file_date == mod_date) {
266 locker_ = "Unlocked";
269 // Here we should also to some more checking
270 // to see if there are conflicts or not.
280 void CVS::registrer(string const & msg)
282 doVCCommand("cvs -q add -m \"" + msg + "\" \""
283 + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
284 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
288 void CVS::checkIn(string const & msg)
290 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
291 + OnlyFilename(owner_->fileName()) + "\"",
293 owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
299 // cvs update or perhaps for cvs this should be a noop
300 lyxerr << "Sorry not implemented." << endl;
306 // Reverts to the version in CVS repository and
307 // gets the updated version from the repository.
308 string const fil = OnlyFilename(owner_->fileName());
310 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
312 owner_->markLyxClean();
313 owner_->getUser()->owner()
314 ->getLyXFunc()->dispatch(LFUN_MENURELOAD);
320 // merge the current with the previous version
321 // in a reverse patch kind of way, so that the
322 // result is to revert the last changes.
323 lyxerr << "Sorry not implemented." << endl;
327 void CVS::getLog(string const & tmpf)
329 doVCCommand("cvs log \""
330 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,