9 #include "vc-backend.h"
11 #include "support/FileInfo.h"
12 #include "support/LRegex.h"
13 #include "support/LSubstring.h"
14 #include "support/path.h"
15 #include "support/filetools.h"
17 #include "BufferView.h"
25 int VCS::doVCCommand(string const & cmd, string const & path)
27 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
30 int const ret = one.startscript(Systemcalls::System, cmd);
35 RCS::RCS(string const & m)
42 string const RCS::find_file(string const & file)
45 // Check if *,v exists.
48 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
50 if (f.newFile(tmp).readable()) {
51 lyxerr[Debug::LYXVC] << "Yes " << file
52 << " is under rcs." << endl;
55 // Check if RCS/*,v exists.
56 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
58 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
60 if (f.newFile(tmp).readable()) {
61 lyxerr[Debug::LYXVC] << "Yes " << file
62 << " it is under rcs."<< endl;
70 void RCS::retrive(string const & file)
72 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrive.\n\t" << file << endl;
73 VCS::doVCCommand("co -q -r \""
79 void RCS::scanMaster()
81 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
83 ifstream ifs(master_.c_str());
86 bool read_enough = false;
88 while (!read_enough && ifs >> token) {
90 << "LyXVC::scanMaster: current lex text: `"
91 << token << "'" << endl;
95 else if (token == "head") {
99 tmv = strip(tmv, ';');
101 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
103 } else if (contains(token, "access")
104 || contains(token, "symbols")
105 || contains(token, "strict")) {
107 } else if (contains(token, "locks")) {
109 if (contains(token, ";")) {
110 locker_ = "Unlocked";
117 s1 = strip(tmpt, ';');
118 // tmp is now in the format <user>:<version>
119 s1 = split(s1, s2, ':');
120 // s2 is user, and s1 is version
121 if (s1 == version_) {
126 } while (!contains(tmpt, ";"));
128 } else if (token == "comment") {
129 // we don't need to read any further than this.
134 << "LyXVC::scanMaster(): unexpected token"
138 version_ = "RCS: " + version_;
142 void RCS::registrer(string const & msg)
144 string cmd = "ci -q -u -i -t-\"";
147 cmd += OnlyFilename(owner_->fileName());
149 doVCCommand(cmd, owner_->filepath);
150 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
154 void RCS::checkIn(string const & msg)
156 doVCCommand("ci -q -u -m\"" + msg + "\" \""
157 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
158 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
164 owner_->markLyxClean();
165 doVCCommand("co -q -l \""
166 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
167 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
173 doVCCommand("co -f -u" + version() + " \""
174 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
175 // We ignore changes and just reload!
176 owner_->markLyxClean();
177 owner_->getUser()->owner()
178 ->getLyXFunc()->Dispatch("buffer-reload");
184 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
185 doVCCommand("rcs -o" + version() + " \""
186 + OnlyFilename(owner_->fileName()) + "\"",
191 void RCS::getLog(string const & tmpf)
193 doVCCommand("rlog \""
194 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
198 CVS::CVS(string const & m, string const & f)
206 string const CVS::find_file(string const & file)
208 // First we look for the CVS/Entries in the same dir
209 // where we have file.
210 string const dir = OnlyPath(file) + "/CVS/Entries";
211 string const tmpf = "/" + OnlyFilename(file) + "/";
212 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
213 << "' for `" << tmpf << "'" << endl;
214 FileInfo const f(dir);
216 // Ok we are at least in a CVS dir. Parse the CVS/Entries
217 // and see if we can find this file. We do a fast and
219 ifstream ifs(dir.c_str());
221 while (getline(ifs, line)) {
222 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
223 if (contains(line, tmpf)) return dir;
230 void CVS::scanMaster()
232 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
234 // Ok now we do the real scan...
235 ifstream ifs(master_.c_str());
236 string tmpf = "/" + OnlyFilename(file_) + "/";
237 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
239 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
240 while(getline(ifs, line)) {
241 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
242 if (contains(line, tmpf)) {
243 // Ok extract the fields.
244 LRegex::SubMatches const & sm = reg.exec(line);
245 //sm[0]; // whole matched string
248 version_ += LSubstring(line, sm[2].first,
250 string file_date = LSubstring(line, sm[3].first,
253 //sm[5]; // tag or tagdate
255 time_t mod = fi.getModificationTime();
256 string mod_date = strip(asctime(gmtime(&mod)), '\n');
258 << "Date in Entries: `" << file_date
259 << "'\nModification date of file: `"
260 << mod_date << "'" << endl;
261 if (file_date == mod_date) {
262 locker_ = "Unlocked";
265 // Here we should also to some more checking
266 // to see if there are conflicts or not.
276 void CVS::registrer(string const & msg)
278 doVCCommand("cvs -q add -m \"" + msg + "\" \""
279 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
280 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
284 void CVS::checkIn(string const & msg)
286 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
287 + OnlyFilename(owner_->fileName()) + "\"",
289 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
295 // cvs update or perhaps for cvs this should be a noop
296 lyxerr << "Sorry not implemented." << endl;
302 // Reverts to the version in CVS repository and
303 // gets the updated version from the repository.
304 string const fil = OnlyFilename(owner_->fileName());
306 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
308 owner_->markLyxClean();
309 owner_->getUser()->owner()
310 ->getLyXFunc()->Dispatch("buffer-reload");
316 // merge the current with the previous version
317 // in a reverse patch kind of way, so that the
318 // result is to revert the last changes.
319 lyxerr << "Sorry not implemented." << endl;
323 void CVS::getLog(string const & tmpf)
325 doVCCommand("cvs log \""
326 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,