git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25785 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Pavel Sanda 2008-07-22 08:59:15 +00:00
parent 879c6001d6
commit bb14dc3a00
3 changed files with 177 additions and 1 deletions

View 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 (cvs_entries.isReadableFile()) {
if (svn_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with SVN");
vcs.reset(new SVN(cvs_entries, filename));
} else if (cvs_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with CVS");
vcs.reset(new CVS(cvs_entries, filename));

View 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

View 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