The branch, master, has been updated. - Log -----------------------------------------------------------------
commit 9d99d3dbea13bde365273a6c36e087573f66a02b Author: Georg Baum <[email protected]> Date: Thu Nov 15 22:01:19 2012 +0100 Implement extractFromVC() for CVS and SVN. Both cvs and svn are able to retrieve non-existing files from repository, but this was only implemented for rcs. This is a prerequisite for the planned move and copy VCV operations. I also improved error schecking and used extractFromVC() also for files specified on the command line if they do not exist (in GUI mode, it was already the case in non-GUI mode). diff --git a/src/Buffer.h b/src/Buffer.h index 246e1ce..3ed3a95 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -246,8 +246,7 @@ private: /// \return \c true if file is not completely read. bool readDocument(Lexer &); /// Try to extract the file from a version control container - /// before reading if the file cannot be found. This is only - /// implemented for RCS. + /// before reading if the file cannot be found. /// \sa LyXVC::file_not_found_hook ReadStatus extractFromVC(); /// Reads the first tag of a LyX File and diff --git a/src/LyXVC.cpp b/src/LyXVC.cpp index 449e24d..192b70b 100644 --- a/src/LyXVC.cpp +++ b/src/LyXVC.cpp @@ -45,6 +45,18 @@ LyXVC::~LyXVC() {} +bool LyXVC::fileInVC(FileName const & fn) +{ + if (!RCS::findFile(fn).empty()) + return true; + if (!CVS::findFile(fn).empty()) + return true; + if (!SVN::findFile(fn).empty()) + return true; + return false; +} + + bool LyXVC::file_found_hook(FileName const & fn) { FileName found_file; @@ -75,9 +87,10 @@ bool LyXVC::file_not_found_hook(FileName const & fn) // Check if file is under RCS. // This happens if we are trying to load non existent // file on disk, but existent in ,v version. - // Seems there is no reasonable scenario for adding implementation - // of retrieve for cvs or svn. - if (!RCS::findFile(fn).empty()) { + bool foundRCS = !RCS::findFile(fn).empty(); + bool foundCVS = foundRCS ? false : !CVS::findFile(fn).empty(); + bool foundSVN = (foundRCS || foundCVS) ? false : !SVN::findFile(fn).empty(); + if (foundRCS || foundCVS || foundSVN) { docstring const file = makeDisplayPath(fn.absFileName(), 20); docstring const text = bformat(_("Do you want to retrieve the document" @@ -86,11 +99,17 @@ bool LyXVC::file_not_found_hook(FileName const & fn) text, 0, 1, _("&Retrieve"), _("&Cancel")); if (ret == 0) { - // How can we know _how_ to do the checkout? - // With the current VC support it has to be an RCS - // file since CVS and SVN do not have special ,v files. - RCS::retrieve(fn); - return true; + // Since the retrieve commands are implemented using + // more general update commands we need to ensure that + // we do not change an existing file by accident. + if (fn.exists()) + return false; + if (foundRCS) + return RCS::retrieve(fn); + else if (foundCVS) + return CVS::retrieve(fn); + else + return SVN::retrieve(fn); } } return false; diff --git a/src/LyXVC.h b/src/LyXVC.h index df6f273..a860bda 100644 --- a/src/LyXVC.h +++ b/src/LyXVC.h @@ -43,6 +43,8 @@ public: LyXVC(); /// ~LyXVC(); + /// Is \p fn under version control? + static bool fileInVC(support::FileName const & fn); /** Not a good name perhaps. This function should be called whenever LyX loads a file. This function then checks for a master VC file (for RCS this is *,v or RCS/ *,v ; for CVS this is CVS/Entries and .svn/entries @@ -52,7 +54,7 @@ public: */ bool file_found_hook(support::FileName const & fn); - /** Is \p fn in under version control? + /** Is \p fn under version control? This function should be run when a file is requested for loading, but it does not exist. This function will then check for a VC master file with the same name (see above function). If this exists the diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp index 31a8eb3..9841707 100644 --- a/src/VCBackend.cpp +++ b/src/VCBackend.cpp @@ -151,11 +151,12 @@ FileName const RCS::findFile(FileName const & file) } -void RCS::retrieve(FileName const & file) +bool RCS::retrieve(FileName const & file) { LYXERR(Debug::LYXVC, "LyXVC::RCS: retrieve.\n\t" << file); - doVCCommandCall("co -q -r " + quoteName(file.toFilesystemEncoding()), - FileName()); + // The caller ensures that file does not exists, so no need to check that. + return doVCCommandCall("co -q -r " + quoteName(file.toFilesystemEncoding()), + FileName()) == 0; } @@ -553,6 +554,15 @@ void CVS::scanMaster() } +bool CVS::retrieve(FileName const & file) +{ + LYXERR(Debug::LYXVC, "LyXVC::CVS: retrieve.\n\t" << file); + // The caller ensures that file does not exists, so no need to check that. + return doVCCommandCall("cvs -q update " + quoteName(file.toFilesystemEncoding()), + file.onlyPath()) == 0; +} + + string const CVS::getTarget(OperationMode opmode) const { switch(opmode) { @@ -1132,6 +1142,15 @@ bool SVN::isLocked() const } +bool SVN::retrieve(FileName const & file) +{ + LYXERR(Debug::LYXVC, "LyXVC::SVN: retrieve.\n\t" << file); + // The caller ensures that file does not exists, so no need to check that. + return doVCCommandCall("svn update -q --non-interactive " + quoteName(file.onlyFileName()), + file.onlyPath()) == 0; +} + + void SVN::registrer(string const & /*msg*/) { doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())), diff --git a/src/VCBackend.h b/src/VCBackend.h index 3b48f20..8f2ad41 100644 --- a/src/VCBackend.h +++ b/src/VCBackend.h @@ -136,7 +136,7 @@ public: /// return the revision file for the given file, if found static support::FileName const findFile(support::FileName const & file); - static void retrieve(support::FileName const & file); + static bool retrieve(support::FileName const & file); virtual void registrer(std::string const & msg); @@ -210,6 +210,8 @@ public: /// return the revision file for the given file, if found static support::FileName const findFile(support::FileName const & file); + static bool retrieve(support::FileName const & file); + virtual void registrer(std::string const & msg); virtual std::string checkIn(std::string const & msg); @@ -337,6 +339,8 @@ public: /// return the revision file for the given file, if found static support::FileName const findFile(support::FileName const & file); + static bool retrieve(support::FileName const & file); + virtual void registrer(std::string const & msg); virtual std::string checkIn(std::string const & msg); diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 073ddcb..85a22eb 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -26,6 +26,7 @@ #include "LaTeX.h" #include "Layout.h" #include "LyX.h" +#include "LyXVC.h" #include "TextClass.h" #include "Paragraph.h" #include "ParagraphList.h" @@ -81,8 +82,10 @@ Buffer * checkAndLoadLyXFile(FileName const & filename, bool const acceptDirty) return checkBuffer; } - if (filename.exists()) { - if (!filename.isReadableFile()) { + bool const exists = filename.exists(); + bool const tryVC = exists ? false : LyXVC::fileInVC(filename); + if (exists || tryVC) { + if (exists && !filename.isReadableFile()) { docstring text = bformat(_("The file %1$s exists but is not " "readable by the current user."), from_utf8(filename.absFileName())); @@ -178,7 +181,7 @@ Buffer * loadIfNeeded(FileName const & fname) { Buffer * buffer = theBufferList().getBuffer(fname); if (!buffer) { - if (!fname.exists()) + if (!fname.exists() && !LyXVC::fileInVC(fname)) return 0; buffer = theBufferList().newBuffer(fname.absFileName()); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 871a2d2..d06dee9 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1956,7 +1956,8 @@ void GuiView::openDocument(string const & fname) // if the file doesn't exist and isn't already open (bug 6645), // let the user create one - if (!fullname.exists() && !theBufferList().exists(fullname)) { + if (!fullname.exists() && !theBufferList().exists(fullname) && + !LyXVC::file_not_found_hook(fullname)) { // the user specifically chose this name. Believe him. Buffer * const b = newFile(filename, string(), true); if (b) ----------------------------------------------------------------------- Summary of changes: src/Buffer.h | 3 +-- src/LyXVC.cpp | 35 +++++++++++++++++++++++++++-------- src/LyXVC.h | 4 +++- src/VCBackend.cpp | 25 ++++++++++++++++++++++--- src/VCBackend.h | 6 +++++- src/buffer_funcs.cpp | 9 ++++++--- src/frontends/qt4/GuiView.cpp | 3 ++- 7 files changed, 66 insertions(+), 19 deletions(-) hooks/post-receive -- The LyX Source Repository
