mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
#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:
parent
281799d342
commit
8be18455fd
@ -98,6 +98,19 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
|
||||
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)
|
||||
{
|
||||
// First we look for the .svn/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 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;
|
||||
}
|
||||
}
|
||||
// First we check the existence of repository meta data.
|
||||
if (!VCS::checkparentdirs(file, ".svn")) {
|
||||
LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
|
||||
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()
|
||||
{
|
||||
@ -1096,7 +1108,7 @@ bool SVN::checkLockMode()
|
||||
string line;
|
||||
bool ret = false;
|
||||
|
||||
while (ifs) {
|
||||
while (ifs && !ret) {
|
||||
getline(ifs, line);
|
||||
LYXERR(Debug::LYXVC, line);
|
||||
if (contains(line, "svn:needs-lock"))
|
||||
|
@ -87,6 +87,10 @@ public:
|
||||
|
||||
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:
|
||||
/// parse information from the version file
|
||||
virtual void scanMaster() = 0;
|
||||
|
@ -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
|
||||
{
|
||||
return !empty() && d->fi.isFile() && d->fi.isReadable();
|
||||
|
@ -194,6 +194,9 @@ public:
|
||||
bool hasExtension(const std::string & ext);
|
||||
/// path without file name
|
||||
FileName onlyPath() const;
|
||||
/// path of parent directory
|
||||
/// returns empty path for root directory
|
||||
FileName parentPath() const;
|
||||
/// used for display in the Gui
|
||||
docstring displayName(int threshold = 1000) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user