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"
24 int VCS::doVCCommand(string const & cmd, string const & path)
26 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
29 int const ret = one.startscript(Systemcalls::System, cmd);
34 RCS::RCS(string const & m)
41 string const RCS::find_file(string const & file)
44 // Check if *,v exists.
47 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
49 if (f.newFile(tmp).readable()) {
50 lyxerr[Debug::LYXVC] << "Yes " << file
51 << " is under rcs." << endl;
54 // Check if RCS/*,v exists.
55 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
57 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
59 if (f.newFile(tmp).readable()) {
60 lyxerr[Debug::LYXVC] << "Yes " << file
61 << " it is under rcs."<< endl;
69 void RCS::retrive(string const & file)
71 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrive.\n\t" << file << endl;
72 VCS::doVCCommand("co -q -r \""
78 void RCS::scanMaster()
80 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
82 ifstream ifs(master_.c_str());
85 bool read_enough = false;
87 while (!read_enough && ifs >> token) {
89 << "LyXVC::scanMaster: current lex text: `"
90 << token << "'" << endl;
94 else if (token == "head") {
98 tmv = strip(tmv, ';');
100 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
102 } else if (contains(token, "access")
103 || contains(token, "symbols")
104 || contains(token, "strict")) {
106 } else if (contains(token, "locks")) {
108 if (contains(token, ";")) {
109 locker_ = "Unlocked";
116 s1 = strip(tmpt, ';');
117 // tmp is now in the format <user>:<version>
118 s1 = split(s1, s2, ':');
119 // s2 is user, and s1 is version
120 if (s1 == version_) {
125 } while (!contains(tmpt, ";"));
127 } else if (token == "comment") {
128 // we don't need to read any further than this.
133 << "LyXVC::scanMaster(): unexpected token"
137 version_ = "RCS: " + version_;
141 void RCS::registrer(string const & msg)
143 string cmd = "ci -q -u -i -t-\"";
146 cmd += OnlyFilename(owner_->fileName());
148 doVCCommand(cmd, owner_->filepath);
149 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
153 void RCS::checkIn(string const & msg)
155 doVCCommand("ci -q -u -m\"" + msg + "\" \""
156 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
157 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
163 owner_->markLyxClean();
164 doVCCommand("co -q -l \""
165 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
166 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
172 doVCCommand("co -f -u" + version() + " \""
173 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
174 // We ignore changes and just reload!
175 owner_->markLyxClean();
176 owner_->getUser()->owner()
177 ->getLyXFunc()->Dispatch("buffer-reload");
183 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
184 doVCCommand("rcs -o" + version() + " \""
185 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
189 void RCS::getLog(string const & tmpf)
191 doVCCommand("rlog \""
192 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
196 CVS::CVS(string const & m, string const & f)
204 string const CVS::find_file(string const & file)
206 // First we look for the CVS/Entries in the same dir
207 // where we have file.
208 string const dir = OnlyPath(file) + "/CVS/Entries";
209 string const tmpf = "/" + OnlyFilename(file) + "/";
210 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
211 << "' for `" << tmpf << "'" << endl;
212 FileInfo const f(dir);
214 // Ok we are at least in a CVS dir. Parse the CVS/Entries
215 // and see if we can find this file. We do a fast and
217 ifstream ifs(dir.c_str());
219 while (getline(ifs, line)) {
220 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
221 if (contains(line, tmpf)) return dir;
228 void CVS::scanMaster()
230 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
232 // Ok now we do the real scan...
233 ifstream ifs(master_.c_str());
234 string tmpf = "/" + OnlyFilename(file_) + "/";
235 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
237 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
238 while(getline(ifs, line)) {
239 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
240 if (contains(line, tmpf)) {
241 // Ok extract the fields.
242 LRegex::SubMatches const & sm = reg.exec(line);
243 //sm[0]; // whole matched string
246 version_ += LSubstring(line, sm[2].first,
248 string file_date = LSubstring(line, sm[3].first,
251 //sm[5]; // tag or tagdate
253 time_t mod = fi.getModificationTime();
254 string mod_date = strip(asctime(gmtime(&mod)), '\n');
256 << "Date in Entries: `" << file_date
257 << "'\nModification date of file: `"
258 << mod_date << "'" << endl;
259 if (file_date == mod_date) {
260 locker_ = "Unlocked";
263 // Here we should also to some more checking
264 // to see if there are conflicts or not.
274 void CVS::registrer(string const & msg)
276 doVCCommand("cvs -q add -m \"" + msg + "\" \""
277 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
278 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
282 void CVS::checkIn(string const & msg)
284 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
285 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
286 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
292 // cvs update or perhaps for cvs this should be a noop
293 lyxerr << "Sorry not implemented." << endl;
299 // not sure how to do this...
302 lyxerr << "Sorry not implemented." << endl;
308 // merge the current with the previous version
309 // in a reverse patch kind of way, so that the
310 // result is to revert the last changes.
311 lyxerr << "Sorry not implemented." << endl;
315 void CVS::getLog(string const &)
317 lyxerr << "Sorry not implemented." << endl;