Pavel Sanda wrote:
> but to add support for svn (on the level of cvs) seems to be easy bussines of
> copy and paste from cvs code (nearly:) without beeing invasive to other parts
> of code.

as simple as this
pavel
diff --git a/src/LyXVC.cpp b/src/LyXVC.cpp
index e156396..63d2622 100644
--- a/src/LyXVC.cpp
+++ b/src/LyXVC.cpp
@@ -60,6 +60,13 @@ bool LyXVC::file_found_hook(FileName const & fn)
                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;
 }
@@ -72,6 +79,8 @@ bool LyXVC::file_not_found_hook(FileName const & fn)
                return true;
        if (!CVS::findFile(fn).empty())
                return true;
+       if (!SVN::findFile(fn).empty())
+               return true;
        return false;
 }
 
@@ -98,8 +107,14 @@ void LyXVC::registrer()
        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));
diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp
index f784305..6fba90b 100644
--- a/src/VCBackend.cpp
+++ b/src/VCBackend.cpp
@@ -380,4 +380,125 @@ void CVS::getLog(FileName const & tmpf)
 }
 
 
+/////////////////////////////////////////////////////////////////////
+//
+// 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
diff --git a/src/VCBackend.h b/src/VCBackend.h
index 43e1027..ad441c6 100644
--- a/src/VCBackend.h
+++ b/src/VCBackend.h
@@ -177,6 +177,46 @@ private:
        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

Reply via email to