#7855 subversion 1.7.x support: use svn info to check if a file is under version control; this works for 1.6.x too; to avoid excessive forks of child processes check for the existence of a .svn directory in current dir and parent directories

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40911 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stephan Witt 2012-03-11 11:12:12 +00:00
parent 281799d342
commit 8be18455fd
4 changed files with 54 additions and 22 deletions

View File

@ -98,6 +98,19 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
return true; return true;
} }
bool VCS::checkparentdirs(FileName const & file, std::string const & pathname)
{
FileName dirname = file.onlyPath();
FileName tocheck = FileName(addName(dirname.absFileName(),pathname));
bool result = tocheck.exists();
while ( !result && !dirname.empty() ) {
dirname = dirname.parentPath();
tocheck = FileName(addName(dirname.absFileName(),pathname));
result = tocheck.exists();
}
return result;
}
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// //
@ -1039,29 +1052,28 @@ SVN::SVN(FileName const & m, FileName const & f)
FileName const SVN::findFile(FileName const & file) FileName const SVN::findFile(FileName const & file)
{ {
// First we look for the .svn/entries in the same dir // First we check the existence of repository meta data.
// where we have file. if (!VCS::checkparentdirs(file, ".svn")) {
FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries"); LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
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 SVN dir. Parse the .svn/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(); return FileName();
} }
// Now we check the status of the file.
FileName tmpf = FileName::tempName("lyxvcout");
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return FileName();
}
string const fname = onlyFileName(file.absFileName());
LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn control for `" << fname << '\'');
bool found = 0 == doVCCommandCall("svn info " + quoteName(fname)
+ " > " + quoteName(tmpf.toFilesystemEncoding()),
file.onlyPath());
LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
return found ? file : FileName();
}
void SVN::scanMaster() void SVN::scanMaster()
{ {
@ -1096,7 +1108,7 @@ bool SVN::checkLockMode()
string line; string line;
bool ret = false; bool ret = false;
while (ifs) { while (ifs && !ret) {
getline(ifs, line); getline(ifs, line);
LYXERR(Debug::LYXVC, line); LYXERR(Debug::LYXVC, line);
if (contains(line, "svn:needs-lock")) if (contains(line, "svn:needs-lock"))

View File

@ -87,6 +87,10 @@ public:
virtual bool prepareFileRevisionEnabled() = 0; virtual bool prepareFileRevisionEnabled() = 0;
/// Check the directory of file and all parent directories
// for the existence of the given pathname
static bool checkparentdirs(support::FileName const & file, std::string const & pathname);
protected: protected:
/// parse information from the version file /// parse information from the version file
virtual void scanMaster() = 0; virtual void scanMaster() = 0;

View File

@ -367,6 +367,19 @@ FileName FileName::onlyPath() const
} }
FileName FileName::parentPath() const
{
FileName path;
// return empty path for parent of root dir
// parent of empty path is empty too
if (empty() || d->fi.isRoot())
return path;
path.d->fi.setFile(d->fi.path());
path.d->name = fromqstr(path.d->fi.absoluteFilePath());
return path;
}
bool FileName::isReadableFile() const bool FileName::isReadableFile() const
{ {
return !empty() && d->fi.isFile() && d->fi.isReadable(); return !empty() && d->fi.isFile() && d->fi.isReadable();

View File

@ -194,6 +194,9 @@ public:
bool hasExtension(const std::string & ext); bool hasExtension(const std::string & ext);
/// path without file name /// path without file name
FileName onlyPath() const; FileName onlyPath() const;
/// path of parent directory
/// returns empty path for root directory
FileName parentPath() const;
/// used for display in the Gui /// used for display in the Gui
docstring displayName(int threshold = 1000) const; docstring displayName(int threshold = 1000) const;