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"
16 #include "support/lstrings.h"
18 #include "BufferView.h"
26 int VCS::doVCCommand(string const & cmd, string const & path)
28 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
31 int const ret = one.startscript(Systemcalls::System, cmd);
36 RCS::RCS(string const & m)
43 string const RCS::find_file(string const & file)
46 // Check if *,v exists.
49 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
51 if (f.newFile(tmp).readable()) {
52 lyxerr[Debug::LYXVC] << "Yes " << file
53 << " is under rcs." << endl;
56 // Check if RCS/*,v exists.
57 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
59 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
61 if (f.newFile(tmp).readable()) {
62 lyxerr[Debug::LYXVC] << "Yes " << file
63 << " it is under rcs."<< endl;
71 void RCS::retrive(string const & file)
73 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrive.\n\t" << file << endl;
74 VCS::doVCCommand("co -q -r \""
80 void RCS::scanMaster()
82 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
84 ifstream ifs(master_.c_str());
87 bool read_enough = false;
89 while (!read_enough && ifs >> token) {
91 << "LyXVC::scanMaster: current lex text: `"
92 << token << "'" << endl;
96 else if (token == "head") {
100 tmv = strip(tmv, ';');
102 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
104 } else if (contains(token, "access")
105 || contains(token, "symbols")
106 || contains(token, "strict")) {
108 } else if (contains(token, "locks")) {
110 if (contains(token, ";")) {
111 locker_ = "Unlocked";
120 s1 = strip(tmpt, ';');
121 // tmp is now in the format <user>:<version>
122 s1 = split(s1, s2, ':');
123 // s2 is user, and s1 is version
124 if (s1 == version_) {
129 } while (!contains(tmpt, ";"));
131 } else if (token == "comment") {
132 // we don't need to read any further than this.
137 << "LyXVC::scanMaster(): unexpected token"
144 void RCS::registrer(string const & msg)
146 string cmd = "ci -q -u -i -t-\"";
149 cmd += OnlyFilename(owner_->fileName());
151 doVCCommand(cmd, owner_->filepath);
152 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
156 void RCS::checkIn(string const & msg)
158 doVCCommand("ci -q -u -m\"" + msg + "\" \""
159 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
160 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
166 owner_->markLyxClean();
167 doVCCommand("co -q -l \""
168 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
169 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
175 doVCCommand("co -f -u" + version() + " \""
176 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
177 // We ignore changes and just reload!
178 owner_->markLyxClean();
179 owner_->getUser()->owner()
180 ->getLyXFunc()->dispatch("buffer-reload");
186 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
187 doVCCommand("rcs -o" + version() + " \""
188 + OnlyFilename(owner_->fileName()) + "\"",
193 void RCS::getLog(string const & tmpf)
195 doVCCommand("rlog \""
196 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
200 CVS::CVS(string const & m, string const & f)
208 string const CVS::find_file(string const & file)
210 // First we look for the CVS/Entries in the same dir
211 // where we have file.
212 string const dir = OnlyPath(file) + "/CVS/Entries";
213 string const tmpf = "/" + OnlyFilename(file) + "/";
214 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
215 << "' for `" << tmpf << "'" << endl;
216 FileInfo const f(dir);
218 // Ok we are at least in a CVS dir. Parse the CVS/Entries
219 // and see if we can find this file. We do a fast and
221 ifstream ifs(dir.c_str());
223 while (getline(ifs, line)) {
224 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
225 if (contains(line, tmpf)) return dir;
232 void CVS::scanMaster()
234 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
236 // Ok now we do the real scan...
237 ifstream ifs(master_.c_str());
238 string tmpf = "/" + OnlyFilename(file_) + "/";
239 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
241 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
242 while(getline(ifs, line)) {
243 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
244 if (contains(line, tmpf)) {
245 // Ok extract the fields.
246 LRegex::SubMatches const & sm = reg.exec(line);
247 //sm[0]; // whole matched string
249 version_ = LSubstring(line, sm[2].first,
251 string file_date = LSubstring(line, sm[3].first,
254 //sm[5]; // tag or tagdate
256 time_t mod = fi.getModificationTime();
257 string mod_date = strip(asctime(gmtime(&mod)), '\n');
259 << "Date in Entries: `" << file_date
260 << "'\nModification date of file: `"
261 << mod_date << "'" << endl;
262 if (file_date == mod_date) {
263 locker_ = "Unlocked";
266 // Here we should also to some more checking
267 // to see if there are conflicts or not.
277 void CVS::registrer(string const & msg)
279 doVCCommand("cvs -q add -m \"" + msg + "\" \""
280 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
281 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
285 void CVS::checkIn(string const & msg)
287 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
288 + OnlyFilename(owner_->fileName()) + "\"",
290 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
296 // cvs update or perhaps for cvs this should be a noop
297 lyxerr << "Sorry not implemented." << endl;
303 // Reverts to the version in CVS repository and
304 // gets the updated version from the repository.
305 string const fil = OnlyFilename(owner_->fileName());
307 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
309 owner_->markLyxClean();
310 owner_->getUser()->owner()
311 ->getLyXFunc()->dispatch("buffer-reload");
317 // merge the current with the previous version
318 // in a reverse patch kind of way, so that the
319 // result is to revert the last changes.
320 lyxerr << "Sorry not implemented." << endl;
324 void CVS::getLog(string const & tmpf)
326 doVCCommand("cvs log \""
327 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,