Revert "Try yet again try to fix bug #9158."

(Unintentionally committed.)

This reverts commit 7b29d4e7aa.
This commit is contained in:
Richard Kimberly Heck 2018-09-02 00:09:11 -04:00
parent 7b29d4e7aa
commit a3e87dad80
5 changed files with 77 additions and 63 deletions

View File

@ -279,7 +279,7 @@ public:
/// A cache for the bibfiles (including bibfiles of loaded child
/// documents), needed for appropriate update of natbib labels.
mutable docstring_list bibfiles_cache_;
mutable FileNamePairList bibfiles_cache_;
// FIXME The caching mechanism could be improved. At present, we have a
// cache for each Buffer, that caches all the bibliography info for that
@ -2394,7 +2394,7 @@ void Buffer::invalidateBibinfoCache() const
}
docstring_list const & Buffer::getBibfiles(UpdateScope scope) const
FileNamePairList const & Buffer::getBibfiles(UpdateScope scope) const
{
// FIXME This is probably unnecessary, given where we call this.
// If this is a child document, use the master instead.
@ -2420,7 +2420,7 @@ BiblioInfo const & Buffer::bibInfo() const
}
void Buffer::registerBibfiles(const docstring_list & bf) const
void Buffer::registerBibfiles(FileNamePairList const & bf) const
{
// We register the bib files in the master buffer,
// if there is one, but also in every single buffer,
@ -2430,7 +2430,7 @@ void Buffer::registerBibfiles(const docstring_list & bf) const
tmp->registerBibfiles(bf);
for (auto const & p : bf) {
docstring_list::const_iterator temp =
FileNamePairList::const_iterator temp =
find(d->bibfiles_cache_.begin(), d->bibfiles_cache_.end(), p);
if (temp == d->bibfiles_cache_.end())
d->bibfiles_cache_.push_back(p);
@ -2438,29 +2438,6 @@ void Buffer::registerBibfiles(const docstring_list & bf) const
}
static map<docstring, FileName> bibfileCache;
FileName Buffer::getBibfilePath(docstring const & bibid) const
{
map<docstring, FileName>::const_iterator it =
bibfileCache.find(bibid);
if (it != bibfileCache.end()) {
// i.e., bibfileCache[bibid]
return it->second;
}
string texfile = changeExtension(to_utf8(bibid), "bib");
// note that, if the filename can be found directly from the path,
// findtexfile will just return a FileName object for that path.
FileName file(findtexfile(texfile, "bib"));
if (file.empty())
file = FileName(makeAbsPath(texfile, filePath()));
bibfileCache[bibid] = file;
return bibfileCache[bibid];
}
void Buffer::checkIfBibInfoCacheIsValid() const
{
// use the master's cache
@ -2476,9 +2453,11 @@ void Buffer::checkIfBibInfoCacheIsValid() const
return;
// compare the cached timestamps with the actual ones.
docstring_list const & bibfiles_cache = getBibfiles();
for (auto const & bf : bibfiles_cache) {
FileName const fn = getBibfilePath(bf);
FileNamePairList const & bibfiles_cache = getBibfiles();
FileNamePairList::const_iterator ei = bibfiles_cache.begin();
FileNamePairList::const_iterator en = bibfiles_cache.end();
for (; ei != en; ++ ei) {
FileName const fn = ei->second;
time_t lastw = fn.lastModified();
time_t prevw = d->bibfile_status_[fn];
if (lastw != prevw) {
@ -2499,17 +2478,10 @@ void Buffer::reloadBibInfoCache(bool const force) const
return;
}
if (!force) {
checkIfBibInfoCacheIsValid();
if (d->bibinfo_cache_valid_)
return;
}
checkIfBibInfoCacheIsValid();
if (d->bibinfo_cache_valid_ && !force)
return;
// re-read file locations when this info changes
// FIXME Is this sufficient? Or should we also force that
// in some other cases? If so, then it is easy enough to
// add the following line in some other places.
bibfileCache.clear();
d->bibinfo_.clear();
FileNameList checkedFiles;
collectBibKeys(checkedFiles);
@ -3225,7 +3197,7 @@ string const Buffer::prepareFileNameForLaTeX(string const & name,
vector<docstring> const Buffer::prepareBibFilePaths(OutputParams const & runparams,
docstring_list const & bibfilelist,
FileNamePairList const bibfilelist,
bool const add_extension) const
{
// If we are processing the LaTeX file in a temp directory then
@ -3247,7 +3219,7 @@ vector<docstring> const Buffer::prepareBibFilePaths(OutputParams const & runpara
bool found_space = false;
for (auto const & bit : bibfilelist) {
string utf8input = to_utf8(bit);
string utf8input = to_utf8(bit.first);
string database =
prepareFileNameForLaTeX(utf8input, ".bib", runparams.nice);
FileName try_in_file =
@ -3256,7 +3228,7 @@ vector<docstring> const Buffer::prepareBibFilePaths(OutputParams const & runpara
// If the file has not been found, try with the real file name
// (it might come from a child in a sub-directory)
if (!not_from_texmf) {
try_in_file = getBibfilePath(bit);
try_in_file = bit.second;
if (try_in_file.isReadableFile()) {
// Check if the file is in texmf
FileName kpsefile(findtexfile(changeExtension(utf8input, "bib"), "bib", true));
@ -4798,7 +4770,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
Buffer const * const master = masterBuffer();
DocumentClass const & textclass = master->params().documentClass();
docstring_list old_bibfiles;
FileNamePairList old_bibfiles;
// Do this only if we are the top-level Buffer. We also need to account
// for the case of a previewed child with ignored parent here.
if (master == this && !d->ignore_parent) {
@ -4862,7 +4834,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
return;
// if the bibfiles changed, the cache of bibinfo is invalid
docstring_list new_bibfiles = d->bibfiles_cache_;
FileNamePairList new_bibfiles = d->bibfiles_cache_;
// this is a trick to determine whether the two vectors have
// the same elements.
sort(new_bibfiles.begin(), new_bibfiles.end());

View File

@ -70,6 +70,7 @@ class WorkAreaManager;
namespace support {
class DocFileName;
class FileName;
class FileNamePairList;
} // namespace support
namespace graphics {
@ -416,7 +417,7 @@ public:
* output in the respective BibTeX/Biblatex macro
*/
std::vector<docstring> const prepareBibFilePaths(OutputParams const &,
const docstring_list & bibfilelist,
support::FileNamePairList const bibfilelist,
bool const extension = true) const;
/** Returns the path where a local layout file lives.
@ -764,9 +765,7 @@ public:
bool areChangesPresent() const;
void updateChangesPresent() const;
///
void registerBibfiles(docstring_list const & bf) const;
///
support::FileName getBibfilePath(docstring const & bibid) const;
void registerBibfiles(support::FileNamePairList const & bf) const;
private:
friend class MarkAsExporting;
@ -785,7 +784,7 @@ private:
void checkIfBibInfoCacheIsValid() const;
/// Return the list with all bibfiles in use (including bibfiles
/// of loaded child documents).
docstring_list const &
support::FileNamePairList const &
getBibfiles(UpdateScope scope = UpdateMaster) const;
///
void collectChildren(ListOfBuffers & children, bool grand_children) const;

View File

@ -38,7 +38,6 @@
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/docstring_list.h"
#include "support/ExceptionMessage.h"
#include "support/FileNameList.h"
#include "support/filetools.h"
@ -152,7 +151,7 @@ void InsetBibtex::editDatabases() const
vector<docstring>::const_iterator it = bibfilelist.begin();
vector<docstring>::const_iterator en = bibfilelist.end();
for (; it != en; ++it) {
FileName const bibfile = buffer().getBibfilePath(*it);
FileName const bibfile = getBibTeXPath(*it, buffer());
theFormats().edit(buffer(), bibfile,
theFormats().getFormatFromFile(bibfile));
}
@ -383,9 +382,29 @@ void InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const
}
docstring_list InsetBibtex::getBibFiles() const
FileNamePairList InsetBibtex::getBibFiles() const
{
return getVectorFromString(getParam("bibfiles"));
FileName path(buffer().filePath());
PathChanger p(path);
// We need to store both the real FileName and the way it is entered
// (with full path, rel path or as a single file name).
// The latter is needed for biblatex's central bibfile macro.
FileNamePairList vec;
vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
vector<docstring>::const_iterator it = bibfilelist.begin();
vector<docstring>::const_iterator en = bibfilelist.end();
for (; it != en; ++it) {
FileName const file = getBibTeXPath(*it, buffer());
if (!file.empty())
vec.push_back(make_pair(*it, file));
else
LYXERR0("Couldn't find " + to_utf8(*it) + " in InsetBibtex::getBibFiles()!");
}
return vec;
}
namespace {
@ -656,13 +675,11 @@ void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
BiblioInfo keylist;
docstring_list const files = getBibFiles();
for (auto const & bf : files) {
FileName const bibfile = buffer().getBibfilePath(bf);
if (bibfile.empty()) {
LYXERR0("Unable to find path for " << bf << "!");
continue;
}
FileNamePairList const files = getBibFiles();
FileNamePairList::const_iterator it = files.begin();
FileNamePairList::const_iterator en = files.end();
for (; it != en; ++ it) {
FileName const bibfile = it->second;
if (find(checkedFiles.begin(), checkedFiles.end(), bibfile) != checkedFiles.end())
// already checked this one. Skip.
continue;
@ -680,6 +697,7 @@ void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
VarMap strings;
while (ifs) {
ifs.get(ch);
if (!ifs)
break;
@ -838,6 +856,18 @@ void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
}
FileName InsetBibtex::getBibTeXPath(docstring const & filename, Buffer const & buf)
{
string texfile = changeExtension(to_utf8(filename), "bib");
// note that, if the filename can be found directly from the path,
// findtexfile will just return a FileName object for that path.
FileName file(findtexfile(texfile, "bib"));
if (file.empty())
file = FileName(makeAbsPath(texfile, buf.filePath()));
return file;
}
bool InsetBibtex::addDatabase(docstring const & db)
{
docstring bibfiles = getParam("bibfiles");

View File

@ -17,10 +17,10 @@
namespace lyx {
class BiblioInfo;
class docstring_list;
namespace support {
class FileName;
class FileNamePairList;
} // namespace support
/** Used to insert BibTeX's information
@ -31,7 +31,7 @@ public:
InsetBibtex(Buffer *, InsetCommandParams const &);
///
docstring_list getBibFiles() const;
support::FileNamePairList getBibFiles() const;
///
bool addDatabase(docstring const &);
///
@ -78,6 +78,9 @@ public:
//@}
private:
/// look up the path to the file using TeX
static support::FileName
getBibTeXPath(docstring const & filename, Buffer const & buf);
///
void editDatabases() const;
///

View File

@ -28,6 +28,16 @@ class FileNameList: public std::vector<FileName>
{
};
/**
* List of filename with additional information. Used by the Bibfiles cache,
* which needs to store, next to the real filename, the way it was entered
* in the BibTeX inset (as abspath, relpath or texmf file)
*/
class FileNamePairList: public std::vector<std::pair<docstring, FileName>>
{
};
} // namespace support
} // namespace lyx