10 #include "vc-backend.h"
12 #include "support/FileInfo.h"
13 #include "support/LRegex.h"
14 #include "support/LSubstring.h"
15 #include "support/path.h"
21 int VCS::doVCCommand(string const & cmd, string const & path)
23 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
26 int ret = one.startscript(Systemcalls::System, cmd);
31 RCS::RCS(string const & m)
38 string RCS::find_file(string const & file)
41 // Check if *,v exists.
44 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
46 if (f.newFile(tmp).readable()) {
47 lyxerr[Debug::LYXVC] << "Yes " << file
48 << " is under rcs." << endl;
51 // Check if RCS/*,v exists.
52 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
54 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
56 if (f.newFile(tmp).readable()) {
57 lyxerr[Debug::LYXVC] << "Yes " << file
58 << " it is under rcs."<< endl;
66 void RCS::retrive(string const & file)
68 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrive.\n\t" << file << endl;
69 VCS::doVCCommand("co -q -r \""
75 void RCS::scanMaster()
77 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
79 ifstream ifs(master_.c_str());
82 bool read_enough = false;
84 while (!read_enough && ifs >> token) {
86 << "LyXVC::scanMaster: current lex text: `"
87 << token << "'" << endl;
91 else if (token == "head") {
95 tmv = strip(tmv, ';');
97 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
99 } else if (contains(token, "access")
100 || contains(token, "symbols")
101 || contains(token, "strict")) {
103 } else if (contains(token, "locks")) {
105 if (contains(token, ";")) {
106 locker_ = "Unlocked";
113 s1 = strip(tmpt, ';');
114 // tmp is now in the format <user>:<version>
115 s1 = split(s1, s2, ':');
116 // s2 is user, and s1 is version
117 if (s1 == version_) {
122 } while (!contains(tmpt, ";"));
124 } else if (token == "comment") {
125 // we don't need to read any further than this.
130 << "LyXVC::scanMaster(): unexpected token"
134 version_ = "RCS: " + version_;
138 void RCS::registrer(string const & msg)
140 string cmd = "ci -q -u -i -t-\"";
143 cmd += OnlyFilename(owner_->fileName());
145 doVCCommand(cmd, owner_->filepath);
146 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
150 void RCS::checkIn(string const & msg)
152 doVCCommand("ci -q -u -m\"" + msg + "\" \""
153 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
154 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
160 owner_->markLyxClean();
161 doVCCommand("co -q -l \""
162 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
163 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
169 doVCCommand("co -f -u" + version() + " \""
170 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
171 // We ignore changes and just reload!
172 owner_->markLyxClean();
173 owner_->getUser()->owner()
174 ->getLyXFunc()->Dispatch("buffer-reload");
180 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
181 doVCCommand("rcs -o" + version() + " \""
182 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
186 void RCS::getLog(string const & tmpf)
188 doVCCommand("rlog \""
189 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
193 CVS::CVS(string const & m, string const & f)
201 string CVS::find_file(string const & file)
203 // First we look for the CVS/Entries in the same dir
204 // where we have file.
205 string dir = OnlyPath(file);
206 string tmpf = "/" + OnlyFilename(file) + "/";
207 dir += "/CVS/Entries";
208 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
209 << "' for `" << tmpf << "'" << endl;
212 // Ok we are at least in a CVS dir. Parse the CVS/Entries
213 // and see if we can find this file. We do a fast and
215 ifstream ifs(dir.c_str());
217 while (getline(ifs, line)) {
218 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
219 if (contains(line, tmpf)) return dir;
226 void CVS::scanMaster()
228 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
230 // Ok now we do the real scan...
231 ifstream ifs(master_.c_str());
232 string tmpf = "/" + OnlyFilename(file_) + "/";
233 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
235 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
236 while(getline(ifs, line)) {
237 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
238 if (contains(line, tmpf)) {
239 // Ok extract the fields.
240 LRegex::SubMatches const & sm = reg.exec(line);
241 //sm[0]; // whole matched string
244 version_ += LSubstring(line, sm[2].first,
246 string file_date = LSubstring(line, sm[3].first,
249 //sm[5]; // tag or tagdate
251 time_t mod = fi.getModificationTime();
252 string mod_date = strip(asctime(gmtime(&mod)), '\n');
254 << "Date in Entries: `" << file_date
255 << "'\nModification date of file: `"
256 << mod_date << "'" << endl;
257 if (file_date == mod_date) {
258 locker_ = "Unlocked";
261 // Here we should also to some more checking
262 // to see if there are conflicts or not.
272 void CVS::registrer(string const & msg)
274 doVCCommand("cvs -q add -m \"" + msg + "\" \""
275 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
276 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
280 void CVS::checkIn(string const & msg)
282 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
283 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
284 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
290 // cvs update or perhaps for cvs this should be a noop
291 lyxerr << "Sorry not implemented." << endl;
297 // not sure how to do this...
300 lyxerr << "Sorry not implemented." << endl;
306 // merge the current with the previous version
307 // in a reverse patch kind of way, so that the
308 // result is to revert the last changes.
309 lyxerr << "Sorry not implemented." << endl;
313 void CVS::getLog(string const &)
315 lyxerr << "Sorry not implemented." << endl;