]> git.lyx.org Git - features.git/commitdiff
VCS svn support, partly fixes http://bugzilla.lyx.org/show_bug.cgi?id=2574.
authorPavel Sanda <sanda@lyx.org>
Tue, 22 Jul 2008 08:59:15 +0000 (08:59 +0000)
committerPavel Sanda <sanda@lyx.org>
Tue, 22 Jul 2008 08:59:15 +0000 (08:59 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25785 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXVC.cpp
src/VCBackend.cpp
src/VCBackend.h

index e156396fe2cba1c1cf7c86082dfe7e5fd5bee941..63d26227a638f5b93242a5464b2aaf6aabd6e143 100644 (file)
@@ -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));
index d7e42a284c136a371c99e033093360cd93127e5c..b8e4e4b0a8095b5018489dd9eee59797802a4e81 100644 (file)
@@ -382,4 +382,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
index 43e1027a9fef4d40cb0b4dacf6fbe5a3bed36de8..ad441c60816edade7d1436d12bb43f7b471ce6ca 100644 (file)
@@ -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