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).
This commit is contained in:
Georg Baum 2012-11-15 22:01:19 +01:00
parent 6c87c3626b
commit 9d99d3dbea
7 changed files with 66 additions and 19 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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())),

View File

@ -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);

View File

@ -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());

View File

@ -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)