From 7b227d6899df8951287102713368fc6b8907b708 Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Fri, 12 Feb 2010 01:43:59 +0000 Subject: [PATCH] VCS: Extended API for revision info git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33425 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXVC.cpp | 9 +++++++++ src/LyXVC.h | 15 +++++++++++++-- src/VCBackend.cpp | 33 ++++++++++++++++++++++++++++++++- src/VCBackend.h | 14 +++++++++++++- 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/LyXVC.cpp b/src/LyXVC.cpp index b35f6aef55..b33459a0da 100644 --- a/src/LyXVC.cpp +++ b/src/LyXVC.cpp @@ -287,6 +287,15 @@ string const LyXVC::getLogFile() const } +std::string const LyXVC::revisionInfo(RevisionInfo const info) +{ + if (!vcs) + return string(); + + return vcs->revisionInfo(info); +} + + bool LyXVC::checkOutEnabled() const { return vcs && vcs->checkOutEnabled(); diff --git a/src/LyXVC.h b/src/LyXVC.h index b81269f447..f3e591fa03 100644 --- a/src/LyXVC.h +++ b/src/LyXVC.h @@ -123,8 +123,7 @@ public: /// Is the document under administration by VCS? bool inUse() const; - /// FIXME resurrect version once we add version info - /// into SVN. RCS parser is already prepared. + /// FIXME Either rename or kill, we have revisionInfo now. /// Returns the version number. //std::string const & version() const; /// Returns the version number. @@ -144,6 +143,18 @@ public: */ std::string const & locker() const; + // type of the revision information + enum RevisionInfo { + File = 1 + }; + + /** + * Return revision info specified by the argument. + * Its safe to call it regardless VCS is in usage or this + * info is (un)available. Returns empty string in such a case. + */ + std::string const revisionInfo(RevisionInfo const info); + private: /// Buffer * owner_; diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp index bf439b85a3..e1df1e08f3 100644 --- a/src/VCBackend.cpp +++ b/src/VCBackend.cpp @@ -280,6 +280,12 @@ bool RCS::toggleReadOnlyEnabled() return false; } +// FIXME This could be implemented with cache from scanMaster +string const RCS::revisionInfo(LyXVC::RevisionInfo const) +{ + return string(); +} + ///////////////////////////////////////////////////////////////////// // @@ -475,6 +481,13 @@ bool CVS::toggleReadOnlyEnabled() return false; } + +string const CVS::revisionInfo(LyXVC::RevisionInfo const) +{ + return string(); +} + + ///////////////////////////////////////////////////////////////////// // // SVN @@ -844,7 +857,25 @@ bool SVN::undoLastEnabled() } -string SVN::getFileRevisionInfo(){ +string const SVN::revisionInfo(LyXVC::RevisionInfo const info) +{ + switch (info) { + case LyXVC::File: + if (_rev_file_cache.empty()) + _rev_file_cache = getFileRevisionInfo(); + if (_rev_file_cache.empty()) + _rev_file_cache = "?"; + if (_rev_file_cache == "?") + return string(); + + return _rev_file_cache; + } + return string(); +} + + +std::string SVN::getFileRevisionInfo() +{ FileName tmpf = FileName::tempName("lyxvcout"); doVCCommand("svn info --xml " + quoteName(onlyFilename(owner_->absFileName())) diff --git a/src/VCBackend.h b/src/VCBackend.h index 5f5f0f77d9..c14ba17754 100644 --- a/src/VCBackend.h +++ b/src/VCBackend.h @@ -16,6 +16,8 @@ #include +#include "LyXVC.h" + namespace lyx { @@ -77,6 +79,8 @@ public: /// do we need special handling for read-only toggling? /// (also used for check-out operation) virtual bool toggleReadOnlyEnabled() = 0; + /// Return revision info specified by the argument. + virtual std::string const revisionInfo(LyXVC::RevisionInfo const info) = 0; protected: /// parse information from the version file virtual void scanMaster() = 0; @@ -157,6 +161,8 @@ public: virtual bool toggleReadOnlyEnabled(); + virtual std::string const revisionInfo(LyXVC::RevisionInfo const info); + protected: virtual void scanMaster(); }; @@ -204,6 +210,8 @@ public: virtual bool toggleReadOnlyEnabled(); + virtual std::string const revisionInfo(LyXVC::RevisionInfo const info); + protected: virtual void scanMaster(); @@ -254,7 +262,7 @@ public: virtual bool toggleReadOnlyEnabled(); - std::string getFileRevisionInfo(); + virtual std::string const revisionInfo(LyXVC::RevisionInfo const info); protected: virtual void scanMaster(); @@ -271,6 +279,10 @@ private: support::FileName file_; /// is the loaded file under locking policy? bool locked_mode_; + /// real code for obtaining file revision info + std::string getFileRevisionInfo(); + /// cache for file revision number, "?" if already unsuccessful + std::string _rev_file_cache; }; } // namespace lyx