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"
22 int VCS::doVCCommand(string const & cmd, string const & path)
24 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
27 int ret = one.startscript(Systemcalls::System, cmd);
32 RCS::RCS(string const & m)
39 string RCS::find_file(string const & file)
42 // Check if *,v exists.
45 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
47 if (f.newFile(tmp).readable()) {
48 lyxerr[Debug::LYXVC] << "Yes " << file
49 << " is under rcs." << endl;
52 // Check if RCS/*,v exists.
53 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
55 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
57 if (f.newFile(tmp).readable()) {
58 lyxerr[Debug::LYXVC] << "Yes " << file
59 << " it is under rcs."<< endl;
67 void RCS::retrive(string const & file)
69 lyxerr[Debug::LYXVC] << "LyXVC::RCS: retrive.\n\t" << file << endl;
70 VCS::doVCCommand("co -q -r \""
76 void RCS::scanMaster()
78 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
80 ifstream ifs(master_.c_str());
83 bool read_enough = false;
85 while (!read_enough && ifs >> token) {
87 << "LyXVC::scanMaster: current lex text: `"
88 << token << "'" << endl;
92 else if (token == "head") {
96 tmv = strip(tmv, ';');
98 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
100 } else if (contains(token, "access")
101 || contains(token, "symbols")
102 || contains(token, "strict")) {
104 } else if (contains(token, "locks")) {
106 if (contains(token, ";")) {
107 locker_ = "Unlocked";
114 s1 = strip(tmpt, ';');
115 // tmp is now in the format <user>:<version>
116 s1 = split(s1, s2, ':');
117 // s2 is user, and s1 is version
118 if (s1 == version_) {
123 } while (!contains(tmpt, ";"));
125 } else if (token == "comment") {
126 // we don't need to read any further than this.
131 << "LyXVC::scanMaster(): unexpected token"
135 version_ = "RCS: " + version_;
139 void RCS::registrer(string const & msg)
141 string cmd = "ci -q -u -i -t-\"";
144 cmd += OnlyFilename(owner_->fileName());
146 doVCCommand(cmd, owner_->filepath);
147 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
151 void RCS::checkIn(string const & msg)
153 doVCCommand("ci -q -u -m\"" + msg + "\" \""
154 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
155 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
161 owner_->markLyxClean();
162 doVCCommand("co -q -l \""
163 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
164 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
170 doVCCommand("co -f -u" + version() + " \""
171 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
172 // We ignore changes and just reload!
173 owner_->markLyxClean();
174 owner_->getUser()->owner()
175 ->getLyXFunc()->Dispatch("buffer-reload");
181 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
182 doVCCommand("rcs -o" + version() + " \""
183 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
187 void RCS::getLog(string const & tmpf)
189 doVCCommand("rlog \""
190 + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
194 CVS::CVS(string const & m, string const & f)
202 string CVS::find_file(string const & file)
204 // First we look for the CVS/Entries in the same dir
205 // where we have file.
206 string dir = OnlyPath(file);
207 string tmpf = "/" + OnlyFilename(file) + "/";
208 dir += "/CVS/Entries";
209 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
210 << "' for `" << tmpf << "'" << endl;
213 // Ok we are at least in a CVS dir. Parse the CVS/Entries
214 // and see if we can find this file. We do a fast and
216 ifstream ifs(dir.c_str());
218 while (getline(ifs, line)) {
219 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
220 if (contains(line, tmpf)) return dir;
227 void CVS::scanMaster()
229 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
231 // Ok now we do the real scan...
232 ifstream ifs(master_.c_str());
233 string tmpf = "/" + OnlyFilename(file_) + "/";
234 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
236 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
237 while(getline(ifs, line)) {
238 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
239 if (contains(line, tmpf)) {
240 // Ok extract the fields.
241 LRegex::SubMatches const & sm = reg.exec(line);
242 //sm[0]; // whole matched string
245 version_ += LSubstring(line, sm[2].first,
247 string file_date = LSubstring(line, sm[3].first,
250 //sm[5]; // tag or tagdate
252 time_t mod = fi.getModificationTime();
253 string mod_date = strip(asctime(gmtime(&mod)), '\n');
255 << "Date in Entries: `" << file_date
256 << "'\nModification date of file: `"
257 << mod_date << "'" << endl;
258 if (file_date == mod_date) {
259 locker_ = "Unlocked";
262 // Here we should also to some more checking
263 // to see if there are conflicts or not.
273 void CVS::registrer(string const & msg)
275 doVCCommand("cvs -q add -m \"" + msg + "\" \""
276 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
277 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
281 void CVS::checkIn(string const & msg)
283 doVCCommand("cvs -q commit -m \"" + msg + "\" \""
284 + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
285 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
291 // cvs update or perhaps for cvs this should be a noop
292 lyxerr << "Sorry not implemented." << endl;
298 // not sure how to do this...
301 lyxerr << "Sorry not implemented." << endl;
307 // merge the current with the previous version
308 // in a reverse patch kind of way, so that the
309 // result is to revert the last changes.
310 lyxerr << "Sorry not implemented." << endl;
314 void CVS::getLog(string const &)
316 lyxerr << "Sorry not implemented." << endl;