7 #include "vc-backend.h"
10 #include "BufferView.h"
14 #include "support/FileInfo.h"
15 #include "support/LRegex.h"
16 #include "support/LSubstring.h"
17 #include "support/path.h"
18 #include "support/filetools.h"
19 #include "support/lstrings.h"
27 int VCS::doVCCommand(string const & cmd, string const & path)
29 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
32 int const ret = one.startscript(Systemcalls::System, cmd);
37 RCS::RCS(string const & m)
44 string const RCS::find_file(string const & file)
47 // Check if *,v exists.
50 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
52 if (f.newFile(tmp).readable()) {
53 lyxerr[Debug::LYXVC] << "Yes " << file
54 << " is under rcs." << endl;
57 // Check if RCS/*,v exists.
58 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
60 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
62 if (f.newFile(tmp).readable()) {
63 lyxerr[Debug::LYXVC] << "Yes " << file
64 << " it is under rcs."<< endl;
72 void RCS::retrive(string const & file)
74 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrive.\n\t" << file << endl;
75 VCS::doVCCommand("co -q -r \""
81 void RCS::scanMaster()
83 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
85 ifstream ifs(master_.c_str());
88 bool read_enough = false;
90 while (!read_enough && ifs >> token) {
92 << "LyXVC::scanMaster: current lex text: `"
93 << token << "'" << endl;
97 else if (token == "head") {
101 tmv = strip(tmv, ';');
103 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
105 } else if (contains(token, "access")
106 || contains(token, "symbols")
107 || contains(token, "strict")) {
109 } else if (contains(token, "locks")) {
111 if (contains(token, ";")) {
112 locker_ = "Unlocked";
121 s1 = strip(tmpt, ';');
122 // tmp is now in the format <user>:<version>
123 s1 = split(s1, s2, ':');
124 // s2 is user, and s1 is version
125 if (s1 == version_) {
130 } while (!contains(tmpt, ";"));
132 } else if (token == "comment") {
133 // we don't need to read any further than this.
138 << "LyXVC::scanMaster(): unexpected token"
145 void RCS::registrer(string const & msg)
147 string cmd = "ci -q -u -i -t-\"";
150 cmd += OnlyFilename(owner_->fileName());
152 doVCCommand(cmd, owner_->filepath);
153 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
157 void RCS::checkIn(string const & msg)
159 doVCCommand("ci -q -u -m\"" + msg + "\" \""
160 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
161 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
167 owner_->markLyxClean();
168 doVCCommand("co -q -l \""
169 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
170 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
176 doVCCommand("co -f -u" + version() + " \""
177 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
178 // We ignore changes and just reload!
179 owner_->markLyxClean();
180 owner_->getUser()->owner()
181 ->getLyXFunc()->dispatch("buffer-reload");
187 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
188 doVCCommand("rcs -o" + version() + " \""
189 + OnlyFilename(owner_->fileName()) + "\"",
194 void RCS::getLog(string const & tmpf)
196 doVCCommand("rlog \""
197 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
201 CVS::CVS(string const & m, string const & f)
209 string const CVS::find_file(string const & file)
211 // First we look for the CVS/Entries in the same dir
212 // where we have file.
213 string const dir = OnlyPath(file) + "/CVS/Entries";
214 string const tmpf = "/" + OnlyFilename(file) + "/";
215 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
216 << "' for `" << tmpf << "'" << endl;
217 FileInfo const f(dir);
219 // Ok we are at least in a CVS dir. Parse the CVS/Entries
220 // and see if we can find this file. We do a fast and
222 ifstream ifs(dir.c_str());
224 while (getline(ifs, line)) {
225 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
226 if (contains(line, tmpf)) return dir;
233 void CVS::scanMaster()
235 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
237 // Ok now we do the real scan...
238 ifstream ifs(master_.c_str());
239 string tmpf = "/" + OnlyFilename(file_) + "/";
240 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
242 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
243 while (getline(ifs, line)) {
244 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
245 if (contains(line, tmpf)) {
246 // Ok extract the fields.
247 LRegex::SubMatches const & sm = reg.exec(line);
248 //sm[0]; // whole matched string
250 version_ = LSubstring(line, sm[2].first,
252 string file_date = LSubstring(line, sm[3].first,
255 //sm[5]; // tag or tagdate
257 time_t mod = fi.getModificationTime();
258 string mod_date = strip(asctime(gmtime(&mod)), '\n');
260 << "Date in Entries: `" << file_date
261 << "'\nModification date of file: `"
262 << mod_date << "'" << endl;
263 if (file_date == mod_date) {
264 locker_ = "Unlocked";
267 // Here we should also to some more checking
268 // to see if there are conflicts or not.
278 void CVS::registrer(string const & msg)
280 doVCCommand("cvs -q add -m \"" + msg + "\" \""
281 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
282 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
286 void CVS::checkIn(string const & msg)
288 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
289 + OnlyFilename(owner_->fileName()) + "\"",
291 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
297 // cvs update or perhaps for cvs this should be a noop
298 lyxerr << "Sorry not implemented." << endl;
304 // Reverts to the version in CVS repository and
305 // gets the updated version from the repository.
306 string const fil = OnlyFilename(owner_->fileName());
308 doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
310 owner_->markLyxClean();
311 owner_->getUser()->owner()
312 ->getLyXFunc()->dispatch("buffer-reload");
318 // merge the current with the previous version
319 // in a reverse patch kind of way, so that the
320 // result is to revert the last changes.
321 lyxerr << "Sorry not implemented." << endl;
325 void CVS::getLog(string const & tmpf)
327 doVCCommand("cvs log \""
328 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf,