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";
118 s1 = strip(tmpt, ';');
119 // tmp is now in the format <user>:<version>
120 s1 = split(s1, s2, ':');
121 // s2 is user, and s1 is version
122 if (s1 == version_) {
127 } while (!contains(tmpt, ";"));
129 } else if (token == "comment") {
130 // we don't need to read any further than this.
135 << "LyXVC::scanMaster(): unexpected token"
139 version_ = "RCS: " + version_;
143 void RCS::registrer(string const & msg)
145 string cmd = "ci -q -u -i -t-\"";
148 cmd += OnlyFilename(owner_->fileName());
150 doVCCommand(cmd, owner_->filepath);
151 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
155 void RCS::checkIn(string const & msg)
157 doVCCommand("ci -q -u -m\"" + msg + "\" \""
158 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
159 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
165 owner_->markLyxClean();
166 doVCCommand("co -q -l \""
167 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
168 owner_->getUser()->owner()->getLyXFunc()->dispatch("buffer-reload");
174 doVCCommand("co -f -u" + version() + " \""
175 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
176 // We ignore changes and just reload!
177 owner_->markLyxClean();
178 owner_->getUser()->owner()
179 ->getLyXFunc()->dispatch("buffer-reload");
185 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
186 doVCCommand("rcs -o" + version() + " \""
187 + OnlyFilename(owner_->fileName()) + "\"",
192 void RCS::getLog(string const & tmpf)
194 doVCCommand("rlog \""
195 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
199 CVS::CVS(string const & m, string const & f)
207 string const CVS::find_file(string const & file)
209 // First we look for the CVS/Entries in the same dir
210 // where we have file.
211 string const dir = OnlyPath(file) + "/CVS/Entries";
212 string const tmpf = "/" + OnlyFilename(file) + "/";
213 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
214 << "' for `" << tmpf << "'" << endl;
215 FileInfo const f(dir);
217 // Ok we are at least in a CVS dir. Parse the CVS/Entries
218 // and see if we can find this file. We do a fast and
220 ifstream ifs(dir.c_str());
222 while (getline(ifs, line)) {
223 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
224 if (contains(line, tmpf)) return dir;
231 void CVS::scanMaster()
233 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
235 // Ok now we do the real scan...
236 ifstream ifs(master_.c_str());
237 string tmpf = "/" + OnlyFilename(file_) + "/";
238 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
240 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
241 while(getline(ifs, line)) {
242 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
243 if (contains(line, tmpf)) {
244 // Ok extract the fields.
245 LRegex::SubMatches const & sm = reg.exec(line);
246 //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,