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"
20 int VCS::doVCCommand(string const & cmd)
22 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
24 Path p(owner_->filepath);
25 int ret = one.startscript(Systemcalls::System, cmd);
30 RCS::RCS(string const & m)
37 string RCS::find_file(string const & file)
40 // Check if *,v exists.
43 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
45 if (f.newFile(tmp).readable()) {
46 lyxerr[Debug::LYXVC] << "Yes " << file
47 << " is under rcs." << endl;
50 // Check if RCS/*,v exists.
51 tmp = AddName(AddPath(OnlyPath(file), "RCS"), file);
53 lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
55 if (f.newFile(tmp).readable()) {
56 lyxerr[Debug::LYXVC] << "Yes " << file
57 << " it is under rcs."<< endl;
65 void RCS::scanMaster()
67 lyxerr[Debug::LYXVC] << "LyXVC::RCS: scanMaster." << endl;
69 ifstream ifs(master_.c_str());
72 bool read_enough = false;
74 while (!read_enough && ifs >> token) {
76 << "LyXVC::scanMaster: current lex text: `"
77 << token << "'" << endl;
81 else if (token == "head") {
85 tmv = strip(tmv, ';');
87 lyxerr[Debug::LYXVC] << "LyXVC: version found to be "
89 } else if (contains(token, "access")
90 || contains(token, "symbols")
91 || contains(token, "strict")) {
93 } else if (contains(token, "locks")) {
95 if (contains(token, ";")) {
103 s1 = strip(tmpt, ';');
104 // tmp is now in the format <user>:<version>
105 s1 = split(s1, s2, ':');
106 // s2 is user, and s1 is version
107 if (s1 == version_) {
112 } while (!contains(tmpt, ";"));
114 } else if (token == "comment") {
115 // we don't need to read any further than this.
120 << "LyXVC::scanMaster(): unexpected token"
124 version_ = "RCS: " + version_;
128 void RCS::registrer(string const & msg)
130 string cmd = "ci -q -u -i -t-\"";
133 cmd += OnlyFilename(owner_->getFileName());
136 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
140 void RCS::checkIn(string const & msg)
142 doVCCommand("ci -q -u -m\"" + msg + "\" \""
143 + OnlyFilename(owner_->getFileName()) + "\"");
144 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
150 owner_->markLyxClean();
151 doVCCommand("co -q -l \""
152 + OnlyFilename(owner_->getFileName()) + "\"");
153 owner_->getUser()->owner()->getLyXFunc()->Dispatch("buffer-reload");
159 doVCCommand("co -f -u" + version() + " \""
160 + OnlyFilename(owner_->getFileName()) + "\"");
161 // We ignore changes and just reload!
162 owner_->markLyxClean();
163 owner_->getUser()->owner()
164 ->getLyXFunc()->Dispatch("buffer-reload");
170 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
171 doVCCommand("rcs -o" + version() + " \""
172 + OnlyFilename(owner_->getFileName()) + "\"");
176 void RCS::getLog(string const & tmpf)
178 doVCCommand("rlog \""
179 + OnlyFilename(owner_->getFileName()) + "\" > " + tmpf);
183 CVS::CVS(string const & m, string const & f)
191 string CVS::find_file(string const & file)
193 // First we look for the CVS/Entries in the same dir
194 // where we have file.
195 string dir = OnlyPath(file);
196 string tmpf = "/" + OnlyFilename(file) + "/";
197 dir += "/CVS/Entries";
198 lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
199 << "' for `" << tmpf << "'" << endl;
202 // Ok we are at least in a CVS dir. Parse the CVS/Entries
203 // and see if we can find this file. We do a fast and
205 ifstream ifs(dir.c_str());
207 while (getline(ifs, line)) {
208 lyxerr[Debug::LYXVC] << "\tEntries: " << line << endl;
209 if (contains(line, tmpf)) return dir;
216 void CVS::scanMaster()
218 lyxerr[Debug::LYXVC] << "LyXVC::CVS: scanMaster. \n Checking: "
220 // Ok now we do the real scan...
221 ifstream ifs(master_.c_str());
222 string tmpf = "/" + OnlyFilename(file_) + "/";
223 lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
225 while(getline(ifs, line)) {
226 lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
227 if (contains(line, tmpf)) {
228 // Ok extract the fields.
229 LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
230 LRegex::SubMatches const & sm = reg.exec(line);
231 //sm[0]; // whole matched string
234 version_ += LSubstring(line, sm[2].first,
236 string file_date = LSubstring(line, sm[3].first,
239 //sm[5]; // tag or tagdate
241 time_t mod = fi.getModificationTime();
242 string mod_date = strip(asctime(gmtime(&mod)), '\n');
244 << "Date in Entries: `" << file_date
245 << "'\nModification date of file: `"
246 << mod_date << "'" << endl;
247 if (file_date == mod_date) {
248 locker_ = "Unlocked";
251 // Here we should also to some more checking
252 // to see if there are conflicts or not.
257 for (LRegex::SubMatches::const_iterator cit = sm.begin();
258 cit != sm.end(); ++cit) {
259 if ((*cit).first != string::npos)
260 lyxerr << string(line, (*cit).first,
261 (*cit).second) << endl;
270 void CVS::registrer(string const & msg)
276 void CVS::checkIn(string const & msg)
290 // not sure how to do this...
298 // merge the current with the previous version
299 // in a reverse patch kind of way, so that the
300 // result is to revert the last changes.
304 void CVS::getLog(string const &)