Get rid of redundant CVS/SVN file_ member

It did always point to the buffer's file name, so it is not needed and it was
not used in most cases anyway. Instead, ensure that owner_ is always set and
cannot be changed later.
This commit is contained in:
Georg Baum 2012-11-13 21:44:36 +01:00
parent 2de7f0eeaf
commit 56e3d2153f
3 changed files with 24 additions and 33 deletions

View File

@ -50,20 +50,17 @@ bool LyXVC::file_found_hook(FileName const & fn)
FileName found_file; FileName found_file;
// Check if file is under RCS // Check if file is under RCS
if (!(found_file = RCS::findFile(fn)).empty()) { if (!(found_file = RCS::findFile(fn)).empty()) {
vcs.reset(new RCS(found_file)); vcs.reset(new RCS(found_file, owner_));
vcs->owner(owner_);
return true; return true;
} }
// Check if file is under CVS // Check if file is under CVS
if (!(found_file = CVS::findFile(fn)).empty()) { if (!(found_file = CVS::findFile(fn)).empty()) {
vcs.reset(new CVS(found_file, fn)); vcs.reset(new CVS(found_file, owner_));
vcs->owner(owner_);
return true; return true;
} }
// Check if file is under SVN // Check if file is under SVN
if (!(found_file = SVN::findFile(fn)).empty()) { if (!(found_file = SVN::findFile(fn)).empty()) {
vcs.reset(new SVN(found_file, fn)); vcs.reset(new SVN(found_file, owner_));
vcs->owner(owner_);
return true; return true;
} }
@ -127,20 +124,18 @@ bool LyXVC::registrer()
if (svn_entries.isReadableFile()) { if (svn_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering " LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with SVN"); << to_utf8(filename.displayName()) << " with SVN");
vcs.reset(new SVN(cvs_entries, filename)); vcs.reset(new SVN(cvs_entries, owner_));
} else if (cvs_entries.isReadableFile()) { } else if (cvs_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering " LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with CVS"); << to_utf8(filename.displayName()) << " with CVS");
vcs.reset(new CVS(cvs_entries, filename)); vcs.reset(new CVS(cvs_entries, owner_));
} else { } else {
LYXERR(Debug::LYXVC, "LyXVC: registering " LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with RCS"); << to_utf8(filename.displayName()) << " with RCS");
vcs.reset(new RCS(FileName())); vcs.reset(new RCS(FileName(), owner_));
} }
vcs->owner(owner_);
} }
LYXERR(Debug::LYXVC, "LyXVC: registrer"); LYXERR(Debug::LYXVC, "LyXVC: registrer");

View File

@ -122,7 +122,7 @@ bool VCS::checkparentdirs(FileName const & file, std::string const & pathname)
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
RCS::RCS(FileName const & m) RCS::RCS(FileName const & m, Buffer * b) : VCS(b)
{ {
master_ = m; master_ = m;
scanMaster(); scanMaster();
@ -472,10 +472,9 @@ bool RCS::prepareFileRevisionEnabled()
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
CVS::CVS(FileName const & m, FileName const & f) CVS::CVS(FileName const & m, Buffer * b) : VCS(b)
{ {
master_ = m; master_ = m;
file_ = f;
have_rev_info_ = false; have_rev_info_ = false;
scanMaster(); scanMaster();
} }
@ -510,7 +509,7 @@ void CVS::scanMaster()
LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_); LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n Checking: " << master_);
// Ok now we do the real scan... // Ok now we do the real scan...
ifstream ifs(master_.toFilesystemEncoding().c_str()); ifstream ifs(master_.toFilesystemEncoding().c_str());
string name = onlyFileName(file_.absFileName()); string name = onlyFileName(owner_->absFileName());
string tmpf = '/' + name + '/'; string tmpf = '/' + name + '/';
LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\''); LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
string line; string line;
@ -530,12 +529,13 @@ void CVS::scanMaster()
//sm[4]; // options //sm[4]; // options
//sm[5]; // tag or tagdate //sm[5]; // tag or tagdate
if (file_.isReadableFile()) { FileName file(owner_->absFileName());
time_t mod = file_.lastModified(); if (file.isReadableFile()) {
time_t mod = file.lastModified();
string mod_date = rtrim(asctime(gmtime(&mod)), "\n"); string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
<< "'\nModification date of file: `" << mod_date << '\''); << "'\nModification date of file: `" << mod_date << '\'');
if (file_.isReadOnly()) { if (file.isReadOnly()) {
// readonly checkout is unlocked // readonly checkout is unlocked
vcstatus = UNLOCKED; vcstatus = UNLOCKED;
} else { } else {
@ -1044,11 +1044,9 @@ bool CVS::prepareFileRevisionEnabled()
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
SVN::SVN(FileName const & m, FileName const & f) SVN::SVN(FileName const & m, Buffer * b) : VCS(b)
{ {
owner_ = 0;
master_ = m; master_ = m;
file_ = f;
locked_mode_ = 0; locked_mode_ = 0;
scanMaster(); scanMaster();
} }
@ -1103,9 +1101,9 @@ bool SVN::checkLockMode()
} }
LYXERR(Debug::LYXVC, "Detecting locking mode..."); LYXERR(Debug::LYXVC, "Detecting locking mode...");
if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName()) if (doVCCommandCall("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
+ " > " + quoteName(tmpf.toFilesystemEncoding()), + " > " + quoteName(tmpf.toFilesystemEncoding()),
file_.onlyPath())) FileName(owner_->filePath())))
return false; return false;
ifstream ifs(tmpf.toFilesystemEncoding().c_str()); ifstream ifs(tmpf.toFilesystemEncoding().c_str());
@ -1128,8 +1126,9 @@ bool SVN::checkLockMode()
bool SVN::isLocked() const bool SVN::isLocked() const
{ {
file_.refresh(); FileName file(owner_->absFileName());
return !file_.isReadOnly(); file.refresh();
return !file.isReadOnly();
} }

View File

@ -34,6 +34,7 @@ public:
NOLOCKING NOLOCKING
}; };
VCS(Buffer * b) : owner_(b) {}
virtual ~VCS() {} virtual ~VCS() {}
/// register a file for version control /// register a file for version control
@ -71,8 +72,6 @@ public:
virtual void getLog(support::FileName const &) = 0; virtual void getLog(support::FileName const &) = 0;
/// return the current version description /// return the current version description
virtual std::string const versionString() const = 0; virtual std::string const versionString() const = 0;
/// set the owning buffer
void owner(Buffer * b) { owner_ = b; }
/// return the owning buffer /// return the owning buffer
Buffer * owner() const { return owner_; } Buffer * owner() const { return owner_; }
/// return the lock status of this file /// return the lock status of this file
@ -119,7 +118,7 @@ protected:
VCStatus vcstatus; VCStatus vcstatus;
/// The buffer using this VC /// The buffer using this VC
Buffer * owner_; Buffer * const owner_;
}; };
@ -128,7 +127,7 @@ class RCS : public VCS {
public: public:
explicit explicit
RCS(support::FileName const & m); RCS(support::FileName const & m, Buffer * b);
/// return the revision file for the given file, if found /// return the revision file for the given file, if found
static support::FileName const findFile(support::FileName const & file); static support::FileName const findFile(support::FileName const & file);
@ -202,7 +201,7 @@ class CVS : public VCS {
public: public:
/// ///
explicit explicit
CVS(support::FileName const & m, support::FileName const & f); CVS(support::FileName const & m, Buffer * b);
/// return the revision file for the given file, if found /// return the revision file for the given file, if found
static support::FileName const findFile(support::FileName const & file); static support::FileName const findFile(support::FileName const & file);
@ -272,7 +271,6 @@ protected:
}; };
private: private:
support::FileName file_;
// revision number from scanMaster // revision number from scanMaster
std::string version_; std::string version_;
@ -330,7 +328,7 @@ class SVN : public VCS {
public: public:
/// ///
explicit explicit
SVN(support::FileName const & m, support::FileName const & f); SVN(support::FileName const & m, Buffer * b);
/// return the revision file for the given file, if found /// return the revision file for the given file, if found
static support::FileName const findFile(support::FileName const & file); static support::FileName const findFile(support::FileName const & file);
@ -389,7 +387,6 @@ protected:
void fileLock(bool lock, support::FileName const & tmpf, std::string & status); void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
private: private:
support::FileName file_;
/// is the loaded file under locking policy? /// is the loaded file under locking policy?
bool locked_mode_; bool locked_mode_;
/** /**