Fix bug with registering files for VC when they are in repo subdirs.

This commit is contained in:
Richard Kimberly Heck 2020-12-18 15:48:51 -05:00
parent 2405788d84
commit fdbbddecb7
5 changed files with 63 additions and 31 deletions

View File

@ -153,30 +153,36 @@ bool LyXVC::registrer()
// it is very likely here that the vcs is not created yet...
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");
FileName const git_index(onlyPath(filename.absFileName()) + "/.git/index");
FileName found = VCS::checkParentDirs(filename, ".git/index");
if (git_index.isReadableFile()) {
if (!found.empty()) {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with GIT");
vcs_.reset(new GIT(git_index, owner_));
} else if (svn_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with SVN");
vcs_.reset(new SVN(svn_entries, owner_));
} else if (cvs_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with CVS");
vcs_.reset(new CVS(cvs_entries, owner_));
vcs_.reset(new GIT(found, owner_));
} else {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with RCS");
vcs_.reset(new RCS(FileName(), owner_));
found = VCS::checkParentDirs(filename, ".svn/entries");
if (!found.empty()) {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with SVN");
vcs_.reset(new SVN(found, owner_));
} else {
// We only need to check the current directory, since CVS meta-data
// is in every sub-directory.
FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries");
if (cvs_entries.isReadableFile()) {
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with CVS");
vcs_.reset(new CVS(cvs_entries, owner_));
} else {
// If all else fails, use RCS
LYXERR(Debug::LYXVC, "LyXVC: registering "
<< to_utf8(filename.displayName()) << " with RCS");
vcs_.reset(new RCS(FileName(), owner_));
}
}
}
}
@ -191,6 +197,8 @@ bool LyXVC::registrer()
}
if (response.empty())
response = _("(no initial description)");
// FIXME This will fail with svn if the current directory has not
// itself been added.
vcs_->registrer(to_utf8(response));
return true;
}

View File

@ -105,18 +105,19 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
}
bool VCS::checkParentDirs(FileName const & file, std::string const & vcsdir)
FileName VCS::checkParentDirs(FileName const & start, std::string const & file)
{
FileName dirname = file.onlyPath();
static FileName empty;
FileName dirname = start.onlyPath();
do {
FileName tocheck = FileName(addName(dirname.absFileName(), vcsdir));
FileName tocheck = FileName(addPathName(dirname.absFileName(), file));
LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
if (tocheck.exists())
return true;
//this construct because of #8295
return tocheck;
// this construct because of #8295
dirname = FileName(dirname.absFileName()).parentPath();
} while (!dirname.empty());
return false;
return empty;
}
@ -1169,7 +1170,7 @@ SVN::SVN(FileName const & m, Buffer * b) : VCS(b)
FileName const SVN::findFile(FileName const & file)
{
// First we check the existence of repository meta data.
if (!VCS::checkParentDirs(file, ".svn")) {
if (VCS::checkParentDirs(file, ".svn").empty()) {
LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
return FileName();
}
@ -1833,7 +1834,7 @@ GIT::GIT(FileName const & m, Buffer * b) : VCS(b)
FileName const GIT::findFile(FileName const & file)
{
// First we check the existence of repository meta data.
if (!VCS::checkParentDirs(file, ".git")) {
if (VCS::checkParentDirs(file, ".git").empty()) {
LYXERR(Debug::LYXVC, "Cannot find GIT meta data for " << file);
return FileName();
}

View File

@ -103,9 +103,15 @@ public:
/// can this operation be processed in the current VCS?
virtual bool prepareFileRevisionEnabled() = 0;
/// Check the directory of file and all parent directories
/// for the existence of repository-info like .git or .svn
static bool checkParentDirs(support::FileName const & file, std::string const & vcsdir);
/// Check the directory given in start and all parent directories
/// for the existence of some other file
/// \param start : where we start looking (we will strip the filename if given
/// and just use the directory
/// \param file : the directory or file for which to look
/// Note that this can be e.g. ".git/index", so we will look for the .git
/// directory and also for an index file in it.
/// Returns a FileName object for the found file or else an empty FileName
static support::FileName checkParentDirs(support::FileName const & start, std::string const & file);
protected:
/// parse information from the version file

View File

@ -654,6 +654,19 @@ string const addName(string const & path, string const & fname)
}
string const addPathName(std::string const & path, std::string const & fname)
{
string const pathpart = onlyPath(fname);
string const namepart = onlyFileName(fname);
string newpath = path;
if (!pathpart.empty())
newpath = addPath(newpath, pathpart);
if (!namepart.empty())
newpath = addName(newpath, namepart);
return newpath;
}
// Strips path from filename
string const onlyFileName(string const & fname)
{

View File

@ -210,7 +210,11 @@ std::string const quoteName(std::string const & file, quote_style style = quote_
/// Add a filename to a path. Any path from filename is stripped first.
std::string const addName(std::string const & path, std::string const & fname);
/// Append sub-directory(ies) to path in an intelligent way
/// Add a relative path to a path. Does not strip the pathname
std::string const addPathName(std::string const & path, std::string const & fname);
/// Append sub-directory(ies) to path in an intelligent way. Will append the
/// trailing directory separator if that is not provided.
std::string const addPath(std::string const & path, std::string const & path2);
/** Change extension of oldname to extension.