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)
23 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
25 Path p(owner_->filepath);
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::scanMaster()
68 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
70 ifstream ifs(master_.c_str());
73 bool read_enough = false;
75 while (!read_enough && ifs >> token) {
77 << "LyXVC::scanMaster: current lex text: `"
78 << token << "'" << endl;
82 else if (token == "head") {
86 tmv = strip(tmv, ';');
88 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
90 } else if (contains(token, "access")
91 || contains(token, "symbols")
92 || contains(token, "strict")) {
94 } else if (contains(token, "locks")) {
96 if (contains(token, ";")) {
104 s1 = strip(tmpt, ';');
105 // tmp is now in the format <user>:<version>
106 s1 = split(s1, s2, ':');
107 // s2 is user, and s1 is version
108 if (s1 == version_) {
113 } while (!contains(tmpt, ";"));
115 } else if (token == "comment") {
116 // we don't need to read any further than this.
121 << "LyXVC::scanMaster(): unexpected token"
125 version_ = "RCS: " + version_;
129 void RCS::registrer(string const & msg)
131 string cmd = "ci -q -u -i -t-\"";
134 cmd += OnlyFilename(owner_->fileName());
137 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
141 void RCS::checkIn(string const & msg)
143 doVCCommand("ci -q -u -m\"" + msg + "\" \""
144 + OnlyFilename(owner_->fileName()) + "\"");
145 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
151 owner_->markLyxClean();
152 doVCCommand("co -q -l \""
153 + OnlyFilename(owner_->fileName()) + "\"");
154 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
160 doVCCommand("co -f -u" + version() + " \""
161 + OnlyFilename(owner_->fileName()) + "\"");
162 // We ignore changes and just reload!
163 owner_->markLyxClean();
164 owner_->getUser()->owner()
165 ->getLyXFunc()->Dispatch("buffer-reload");
171 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
172 doVCCommand("rcs -o" + version() + " \""
173 + OnlyFilename(owner_->fileName()) + "\"");
177 void RCS::getLog(string const & tmpf)
179 doVCCommand("rlog \""
180 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf);
184 CVS::CVS(string const & m, string const & f)
192 string CVS::find_file(string const & file)
194 // First we look for the CVS/Entries in the same dir
195 // where we have file.
196 string dir = OnlyPath(file);
197 string tmpf = "/" + OnlyFilename(file) + "/";
198 dir += "/CVS/Entries";
199 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
200 << "' for `" << tmpf << "'" << endl;
203 // Ok we are at least in a CVS dir. Parse the CVS/Entries
204 // and see if we can find this file. We do a fast and
206 ifstream ifs(dir.c_str());
208 while (getline(ifs, line)) {
209 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
210 if (contains(line, tmpf)) return dir;
217 void CVS::scanMaster()
219 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
221 // Ok now we do the real scan...
222 ifstream ifs(master_.c_str());
223 string tmpf = "/" + OnlyFilename(file_) + "/";
224 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
226 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
227 while(getline(ifs, line)) {
228 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
229 if (contains(line, tmpf)) {
230 // Ok extract the fields.
231 LRegex::SubMatches const & sm = reg.exec(line);
232 //sm[0]; // whole matched string
235 version_ += LSubstring(line, sm[2].first,
237 string file_date = LSubstring(line, sm[3].first,
240 //sm[5]; // tag or tagdate
242 time_t mod = fi.getModificationTime();
243 string mod_date = strip(asctime(gmtime(&mod)), '\n');
245 << "Date in Entries: `" << file_date
246 << "'\nModification date of file: `"
247 << mod_date << "'" << endl;
248 if (file_date == mod_date) {
249 locker_ = "Unlocked";
252 // Here we should also to some more checking
253 // to see if there are conflicts or not.
263 void CVS::registrer(string const & msg)
265 doVCCommand("cvs -q add -m \"" + msg + "\" \""
266 + OnlyFilename(owner_->fileName()) + "\"");
267 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
271 void CVS::checkIn(string const & msg)
273 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
274 + OnlyFilename(owner_->fileName()) + "\"");
275 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
281 // cvs update or perhaps for cvs this should be a noop
282 lyxerr << "Sorry not implemented." << endl;
288 // not sure how to do this...
291 lyxerr << "Sorry not implemented." << endl;
297 // merge the current with the previous version
298 // in a reverse patch kind of way, so that the
299 // result is to revert the last changes.
300 lyxerr << "Sorry not implemented." << endl;
304 void CVS::getLog(string const &)
306 lyxerr << "Sorry not implemented." << endl;