vcs->owner(owner_);
return true;
}
+ // Check if file is under SVN
+ if (!(found_file = SVN::findFile(fn)).empty()) {
+ vcs.reset(new SVN(found_file, fn));
+ vcs->owner(owner_);
+ return true;
+ }
+
// file is not under any VCS.
return false;
}
return true;
if (!CVS::findFile(fn).empty())
return true;
+ if (!SVN::findFile(fn).empty())
+ return true;
return false;
}
if (!vcs) {
//check in the root directory of the document
FileName const cvs_entries(onlyPath(filename.absFilename()) + "/CVS/Entries");
+ FileName const svn_entries(onlyPath(filename.absFilename()) + "/.svn/entries");
+
+ if (svn_entries.isReadableFile()) {
+ LYXERR(Debug::LYXVC, "LyXVC: registering "
+ << to_utf8(filename.displayName()) << " with SVN");
+ vcs.reset(new SVN(cvs_entries, filename));
- if (cvs_entries.isReadableFile()) {
+ } else if (cvs_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with CVS");
vcs.reset(new CVS(cvs_entries, filename));
}
+/////////////////////////////////////////////////////////////////////
+//
+// SVN
+//
+/////////////////////////////////////////////////////////////////////
+
+SVN::SVN(FileName const & m, FileName const & f)
+{
+ master_ = m;
+ file_ = f;
+ scanMaster();
+}
+
+
+FileName const SVN::findFile(FileName const & file)
+{
+ // First we look for the CVS/Entries in the same dir
+ // where we have file.
+ FileName const entries(onlyPath(file.absFilename()) + "/.svn/entries");
+ string const tmpf = onlyFilename(file.absFilename());
+ LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
+ << "' for `" << tmpf << '\'');
+ if (entries.isReadableFile()) {
+ // Ok we are at least in a CVS dir. Parse the CVS/Entries
+ // and see if we can find this file. We do a fast and
+ // dirty parse here.
+ ifstream ifs(entries.toFilesystemEncoding().c_str());
+ string line, oldline;
+ while (getline(ifs, line)) {
+ if (line == "dir" || line == "file")
+ LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
+ if (oldline == tmpf && line == "file")
+ return entries;
+ oldline = line;
+ }
+ }
+ return FileName();
+}
+
+
+void SVN::scanMaster()
+{
+ // if we want some locking under svn
+ // we need different infrastructure around
+ locker_ = "Unlocked";
+ vcstatus = UNLOCKED;
+}
+
+
+void SVN::registrer(string const & msg)
+{
+ doVCCommand("svn -q add " + quoteName(onlyFilename(owner_->absFileName())),
+ FileName(owner_->filePath()));
+}
+
+
+void SVN::checkIn(string const & msg)
+{
+ doVCCommand("svn -q commit -m \"" + msg + "\" "
+ + quoteName(onlyFilename(owner_->absFileName())),
+ FileName(owner_->filePath()));
+}
+
+
+bool SVN::checkInEnabled()
+{
+ return true;
+}
+
+
+void SVN::checkOut()
+{
+ // svn update or perhaps for svn this should be a noop
+ // we need to detect conflict (eg "C" in output)
+ // before we can do this.
+ lyxerr << "Sorry not implemented." << endl;
+}
+
+
+bool SVN::checkOutEnabled()
+{
+ return false;
+}
+
+
+void SVN::revert()
+{
+ // Reverts to the version in CVS repository and
+ // gets the updated version from the repository.
+ string const fil = quoteName(onlyFilename(owner_->absFileName()));
+
+ doVCCommand("svn revert -q " + fil,
+ FileName(owner_->filePath()));
+ owner_->markClean();
+}
+
+
+void SVN::undoLast()
+{
+ // merge the current with the previous version
+ // in a reverse patch kind of way, so that the
+ // result is to revert the last changes.
+ lyxerr << "Sorry not implemented." << endl;
+}
+
+
+bool SVN::undoLastEnabled()
+{
+ return false;
+}
+
+
+void SVN::getLog(FileName const & tmpf)
+{
+ doVCCommand("svn log " + quoteName(onlyFilename(owner_->absFileName()))
+ + " > " + tmpf.toFilesystemEncoding(),
+ FileName(owner_->filePath()));
+}
+
+
+
} // namespace lyx
support::FileName file_;
};
+
+///
+class SVN : public VCS {
+public:
+ ///
+ explicit
+ SVN(support::FileName const & m, support::FileName const & f);
+
+ /// return the revision file for the given file, if found
+ static support::FileName const findFile(support::FileName const & file);
+
+ virtual void registrer(std::string const & msg);
+
+ virtual void checkIn(std::string const & msg);
+
+ virtual bool checkInEnabled();
+
+ virtual void checkOut();
+
+ virtual bool checkOutEnabled();
+
+ virtual void revert();
+
+ virtual void undoLast();
+
+ virtual bool undoLastEnabled();
+
+ virtual void getLog(support::FileName const &);
+
+ virtual std::string const versionString() const {
+ return "SVN: " + version_;
+ }
+
+protected:
+ virtual void scanMaster();
+
+private:
+ support::FileName file_;
+};
+
} // namespace lyx
#endif // VCBACKEND_H