]> git.lyx.org Git - lyx.git/blobdiff - src/VCBackend.cpp
Provide proper fallback if a bibliography processor is not found
[lyx.git] / src / VCBackend.cpp
index cec36fce065d83028f47363e77fa8204baba1b20..963064c93a3ac77d71e562cf4b473e8a5f40a89a 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "VCBackend.h"
 #include "Buffer.h"
+#include "DispatchResult.h"
 #include "LyX.h"
 #include "FuncRequest.h"
 
 #include "support/PathChanger.h"
 #include "support/Systemcall.h"
 #include "support/regex.h"
+#include "support/TempFile.h"
 
 #include <fstream>
+#include <iomanip>
+#include <sstream>
 
 using namespace std;
 using namespace lyx::support;
 
 
-
 namespace lyx {
 
 
@@ -43,7 +46,7 @@ int VCS::doVCCommandCall(string const & cmd, FileName const & path)
        LYXERR(Debug::LYXVC, "doVCCommandCall: " << cmd);
        Systemcall one;
        support::PathChanger p(path);
-       return one.startscript(Systemcall::Wait, cmd, string(), false);
+       return one.startscript(Systemcall::Wait, cmd, string(), string(), false);
 }
 
 
@@ -56,11 +59,15 @@ int VCS::doVCCommand(string const & cmd, FileName const & path, bool reportError
 
        if (owner_)
                owner_->setBusy(false);
-       if (ret && reportError)
+       if (ret && reportError) {
+               docstring rcsmsg;
+               if (prefixIs(cmd, "ci "))
+                       rcsmsg = "\n" + _("Perhaps the RCS package is not installed on your system?");
                frontend::Alert::error(_("Revision control error."),
-                       bformat(_("Some problem occured while running the command:\n"
-                                 "'%1$s'."),
+                       bformat(_("Some problem occurred while running the command:\n"
+                                 "'%1$s'.") + rcsmsg,
                        from_utf8(cmd)));
+       }
        return ret;
 }
 
@@ -74,8 +81,8 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
                // if positive use as the last number in the whole revision string
                if (back > 0) {
                        string base;
-                       rsplit(version, base , '.' );
-                       rev = base + "." + rev;
+                       rsplit(version, base , '.');
+                       rev = base + '.' + rev;
                }
                if (back == 0)
                        rev = version;
@@ -83,14 +90,14 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
                // in case of backward indexing
                if (back < 0) {
                        string cur, base;
-                       cur = rsplit(version, base , '.' );
+                       cur = rsplit(version, base , '.');
                        if (!isStrInt(cur))
                                return false;
                        int want = convert<int>(cur) + back;
                        if (want <= 0)
                                return false;
-                       
-                       rev = base + "." + convert<string>(want);
+
+                       rev = base + '.' + convert<string>(want);
                }
        }
 
@@ -99,11 +106,11 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
 }
 
 
-bool VCS::checkparentdirs(FileName const & file, std::string const & pathname)
+bool VCS::checkparentdirs(FileName const & file, std::string const & vcsdir)
 {
        FileName dirname = file.onlyPath();
        do {
-               FileName tocheck = FileName(addName(dirname.absFileName(), pathname));
+               FileName tocheck = FileName(addName(dirname.absFileName(), vcsdir));
                LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
                if (tocheck.exists())
                        return true;
@@ -168,6 +175,8 @@ void RCS::scanMaster()
        LYXERR(Debug::LYXVC, "LyXVC::RCS: scanMaster: " << master_);
 
        ifstream ifs(master_.toFilesystemEncoding().c_str());
+       // limit the size of strings we read to avoid memory problems
+       ifs >> setw(65636);
 
        string token;
        bool read_enough = false;
@@ -282,7 +291,7 @@ LyXVC::CommandResult RCS::checkIn(string const & msg, string & log)
 
 bool RCS::checkInEnabled()
 {
-       return owner_ && !owner_->isReadonly();
+       return owner_ && !owner_->hasReadonlyFlag();
 }
 
 
@@ -293,7 +302,8 @@ bool RCS::isCheckInWithConfirmation()
        // if (getDiff(file, diff) && diff.empty())
        //      return false;
 
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return true;
@@ -304,7 +314,6 @@ bool RCS::isCheckInWithConfirmation()
                FileName(owner_->filePath()));
 
        docstring diff = tmpf.fileContents("UTF-8");
-       tmpf.removeFile();
 
        if (diff.empty())
                return false;
@@ -324,7 +333,7 @@ string RCS::checkOut()
 
 bool RCS::checkOutEnabled()
 {
-       return owner_ && owner_->isReadonly();
+       return owner_ && owner_->hasReadonlyFlag();
 }
 
 
@@ -359,7 +368,7 @@ bool RCS::lockingToggleEnabled()
 
 bool RCS::revert()
 {
-       if (doVCCommand("co -f -u" + version_ + " "
+       if (doVCCommand("co -f -u" + version_ + ' '
                    + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath())))
                return false;
@@ -379,7 +388,7 @@ bool RCS::isRevertWithConfirmation()
 void RCS::undoLast()
 {
        LYXERR(Debug::LYXVC, "LyXVC: undoLast");
-       doVCCommand("rcs -o" + version_ + " "
+       doVCCommand("rcs -o" + version_ + ' '
                    + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
 }
@@ -387,7 +396,7 @@ void RCS::undoLast()
 
 bool RCS::undoLastEnabled()
 {
-       return true;
+       return owner_->hasReadonlyFlag();
 }
 
 
@@ -425,7 +434,8 @@ string RCS::revisionInfo(LyXVC::RevisionInfo const info)
                        return rev_date_cache_;
                case LyXVC::Time:
                        return rev_time_cache_;
-               default: ;
+               default:
+                       break;
        }
 
        return string();
@@ -434,7 +444,8 @@ string RCS::revisionInfo(LyXVC::RevisionInfo const info)
 
 bool RCS::getRevisionInfo()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
@@ -481,16 +492,19 @@ bool RCS::prepareFileRevision(string const &revis, string & f)
        if (!VCS::makeRCSRevision(version_, rev))
                return false;
 
-       FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
+       TempFile tempfile("lyxvcrev_" + rev + '_');
+       tempfile.setAutoRemove(false);
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
        }
 
-       doVCCommand("co -p" + rev + " "
+       doVCCommand("co -p" + rev + ' '
                      + quoteName(onlyFileName(owner_->absFileName()))
                      + " > " + quoteName(tmpf.toFilesystemEncoding()),
                FileName(owner_->filePath()));
+       tmpf.refresh();
        if (tmpf.isFileEmpty())
                return false;
 
@@ -560,8 +574,10 @@ void CVS::scanMaster()
                if (contains(line, tmpf)) {
                        // Ok extract the fields.
                        smatch sm;
-
-                       regex_match(line, sm, reg);
+                       if (!regex_match(line, sm, reg)) {
+                               LYXERR(Debug::LYXVC, "\t  Cannot parse line. Skipping.");
+                               continue;
+                       }
 
                        //sm[0]; // whole matched string
                        //sm[1]; // filename
@@ -635,7 +651,7 @@ docstring CVS::toString(CvsStatus status) const
        case StatusError:
                return _("Cannot retrieve CVS status");
        }
-       return 0;
+       return docstring();
 }
 
 
@@ -658,7 +674,8 @@ int CVS::doVCCommandCallWithOutput(std::string const & cmd,
 
 CVS::CvsStatus CVS::getStatus()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return StatusError;
@@ -666,7 +683,6 @@ CVS::CvsStatus CVS::getStatus()
 
        if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
                FileName(owner_->filePath()), tmpf)) {
-               tmpf.removeFile();
                return StatusError;
        }
 
@@ -676,7 +692,7 @@ CVS::CvsStatus CVS::getStatus()
        while (ifs) {
                string line;
                getline(ifs, line);
-               LYXERR(Debug::LYXVC, line << "\n");
+               LYXERR(Debug::LYXVC, line << '\n');
                if (prefixIs(line, "File:")) {
                        if (contains(line, "Up-to-date"))
                                status = UpToDate;
@@ -690,7 +706,6 @@ CVS::CvsStatus CVS::getStatus()
                                status = NeedsCheckout;
                }
        }
-       tmpf.removeFile();
        return status;
 }
 
@@ -699,28 +714,28 @@ void CVS::getRevisionInfo()
        if (have_rev_info_)
                return;
        have_rev_info_ = true;
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return;
        }
-       
-       int rc = doVCCommandCallWithOutput("cvs log -r" + version_ 
-               + " " + getTarget(File),
+
+       int rc = doVCCommandCallWithOutput("cvs log -r" + version_
+               + ' ' + getTarget(File),
                FileName(owner_->filePath()), tmpf);
        if (rc) {
-               tmpf.removeFile();
                LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
                return;
        }
-       
+
        ifstream ifs(tmpf.toFilesystemEncoding().c_str());
        static regex const reg("date: (.*) (.*) (.*);  author: (.*);  state: (.*);(.*)");
 
        while (ifs) {
                string line;
                getline(ifs, line);
-               LYXERR(Debug::LYXVC, line << "\n");
+               LYXERR(Debug::LYXVC, line << '\n');
                if (prefixIs(line, "date:")) {
                        smatch sm;
                        regex_match(line, sm, reg);
@@ -732,7 +747,6 @@ void CVS::getRevisionInfo()
                        break;
                }
        }
-       tmpf.removeFile();
        if (rev_author_cache_.empty())
                LYXERR(Debug::LYXVC,
                   "Could not retrieve revision info for " << version_ <<
@@ -825,7 +839,7 @@ string CVS::scanLogFile(FileName const & f, string & status)
        while (ifs) {
                string line;
                getline(ifs, line);
-               LYXERR(Debug::LYXVC, line << "\n");
+               LYXERR(Debug::LYXVC, line << '\n');
                if (!line.empty())
                        status += line + "; ";
                if (prefixIs(line, "C ")) {
@@ -903,12 +917,13 @@ string CVS::checkOut()
 {
        if (vcstatus != NOLOCKING && edit())
                return string();
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return string();
        }
-       
+
        int rc = update(File, tmpf);
        string log;
        string const res = scanLogFile(tmpf, log);
@@ -920,8 +935,7 @@ string CVS::checkOut()
                                from_local8bit(res)));
                rc = 0;
        }
-       
-       tmpf.removeFile();
+
        return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
 }
 
@@ -937,12 +951,13 @@ bool CVS::checkOutEnabled()
 
 string CVS::repoUpdate()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return string();
        }
-       
+
        getDiff(Directory, tmpf);
        docstring res = tmpf.fileContents("UTF-8");
        if (!res.empty()) {
@@ -954,16 +969,14 @@ string CVS::repoUpdate()
                                "or you will need to revert back to the repository version."), file);
                int ret = frontend::Alert::prompt(_("Changes detected"),
                                text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
-               if (ret == 2 ) {
+               if (ret == 2) {
                        dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
                        ret = frontend::Alert::prompt(_("Changes detected"),
                                text, 0, 1, _("&Continue"), _("&Abort"));
                        hideDialogs("file", 0);
                }
-               if (ret == 1 ) {
-                       tmpf.removeFile();
+               if (ret == 1)
                        return string();
-               }
        }
 
        int rc = update(Directory, tmpf);
@@ -981,8 +994,6 @@ string CVS::repoUpdate()
                                file, from_local8bit(sres)));
                rc = 0;
        }
-       
-       tmpf.removeFile();
 
        return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
 }
@@ -1096,7 +1107,8 @@ string CVS::revisionInfo(LyXVC::RevisionInfo const info)
                        return rev_date_cache_;
                case LyXVC::Time:
                        return rev_time_cache_;
-               default: ;
+               default:
+                       break;
                }
        }
        return string();
@@ -1109,15 +1121,18 @@ bool CVS::prepareFileRevision(string const & revis, string & f)
        if (!VCS::makeRCSRevision(version_, rev))
                return false;
 
-       FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
+       TempFile tempfile("lyxvcrev_" + rev + '_');
+       tempfile.setAutoRemove(false);
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
        }
 
-       doVCCommandWithOutput("cvs update -p -r" + rev + " "
+       doVCCommandWithOutput("cvs update -p -r" + rev + ' '
                + getTarget(File),
                FileName(owner_->filePath()), tmpf);
+       tmpf.refresh();
        if (tmpf.isFileEmpty())
                return false;
 
@@ -1157,7 +1172,8 @@ FileName const SVN::findFile(FileName const & file)
        }
 
        // Now we check the status of the file.
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return FileName();
@@ -1168,7 +1184,6 @@ FileName const SVN::findFile(FileName const & file)
        bool found = 0 == doVCCommandCall("svn info " + quoteName(fname)
                                                + " > " + quoteName(tmpf.toFilesystemEncoding()),
                                                file.onlyPath());
-       tmpf.removeFile();
        LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
        return found ? file : FileName();
 }
@@ -1190,7 +1205,8 @@ void SVN::scanMaster()
 
 bool SVN::checkLockMode()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()){
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
@@ -1320,7 +1336,8 @@ LyXVC::CommandResult SVN::checkIn(string const & msg, string & log)
 LyXVC::CommandResult
 SVN::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()){
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                log = N_("Error: Could not generate logfile.");
@@ -1348,7 +1365,6 @@ SVN::checkIn(vector<support::FileName> const & f, string const & msg, string & l
                if (!fileLock(false, tmpf, log))
                        ret = LyXVC::ErrorCommand;
 
-       tmpf.removeFile();
        if (!log.empty())
                log.insert(0, "SVN: ");
        if (ret == LyXVC::VCSuccess && log.empty())
@@ -1370,7 +1386,8 @@ bool SVN::isCheckInWithConfirmation()
 {
        // FIXME one day common getDiff and perhaps OpMode for all backends
 
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return true;
@@ -1381,7 +1398,6 @@ bool SVN::isCheckInWithConfirmation()
                FileName(owner_->filePath()));
 
        docstring diff = tmpf.fileContents("UTF-8");
-       tmpf.removeFile();
 
        if (diff.empty())
                return false;
@@ -1400,8 +1416,8 @@ string SVN::scanLogFile(FileName const & f, string & status)
 
        while (ifs) {
                getline(ifs, line);
-               LYXERR(Debug::LYXVC, line << "\n");
-               if (!line.empty()) 
+               LYXERR(Debug::LYXVC, line << '\n');
+               if (!line.empty())
                        status += line + "; ";
                if (prefixIs(line, "C ") || prefixIs(line, "CU ")
                                         || contains(line, "Commit failed")) {
@@ -1428,7 +1444,7 @@ bool SVN::fileLock(bool lock, FileName const & tmpf, string &status)
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 
-       // Lock error messages go unfortunately on stderr and are unreachible this way.
+       // Lock error messages go unfortunately on stderr and are unreachable this way.
        ifstream ifs(tmpf.toFilesystemEncoding().c_str());
        string line;
        while (ifs) {
@@ -1456,7 +1472,8 @@ bool SVN::fileLock(bool lock, FileName const & tmpf, string &status)
 
 string SVN::checkOut()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return N_("Error: Could not generate logfile.");
@@ -1477,7 +1494,6 @@ string SVN::checkOut()
 
        fileLock(true, tmpf, log);
 
-       tmpf.removeFile();
        return log.empty() ? string() : "SVN: " + log;
 }
 
@@ -1493,7 +1509,8 @@ bool SVN::checkOutEnabled()
 
 string SVN::repoUpdate()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return N_("Error: Could not generate logfile.");
@@ -1513,16 +1530,14 @@ string SVN::repoUpdate()
                                "\n\nContinue?"), file);
                int ret = frontend::Alert::prompt(_("Changes detected"),
                                text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
-               if (ret == 2 ) {
+               if (ret == 2) {
                        dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
                        ret = frontend::Alert::prompt(_("Changes detected"),
                                text, 0, 1, _("&Yes"), _("&No"));
                        hideDialogs("file", 0);
                }
-               if (ret == 1 ) {
-                       tmpf.removeFile();
+               if (ret == 1)
                        return string();
-               }
        }
 
        // Reverting looks too harsh, see bug #6255.
@@ -1536,7 +1551,6 @@ string SVN::repoUpdate()
        res += "Update log:\n" + tmpf.fileContents("UTF-8");
 
        LYXERR(Debug::LYXVC, res);
-       tmpf.removeFile();
        return to_utf8(res);
 }
 
@@ -1549,7 +1563,8 @@ bool SVN::repoUpdateEnabled()
 
 string SVN::lockingToggle()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return N_("Error: Could not generate logfile.");
@@ -1577,9 +1592,8 @@ string SVN::lockingToggle()
        if (ret)
                return string();
 
-       tmpf.removeFile();
        frontend::Alert::warning(_("SVN File Locking"),
-               (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
+               (locking ? _("Locking property unset.") : _("Locking property set.")) + '\n'
                + _("Do not forget to commit the locking property into the repository."),
                true);
 
@@ -1658,8 +1672,8 @@ string SVN::revisionInfo(LyXVC::RevisionInfo const info)
                        return rev_date_cache_;
                case LyXVC::Time:
                        return rev_time_cache_;
-               default: ;
-
+               default:
+                       break;
        }
 
        return string();
@@ -1668,7 +1682,8 @@ string SVN::revisionInfo(LyXVC::RevisionInfo const info)
 
 bool SVN::getFileRevisionInfo()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
@@ -1714,14 +1729,14 @@ bool SVN::getFileRevisionInfo()
        }
 
        ifs.close();
-       tmpf.removeFile();
        return !rev.empty();
 }
 
 
 bool SVN::getTreeRevisionInfo()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
@@ -1738,7 +1753,6 @@ bool SVN::getTreeRevisionInfo()
        string line;
        getline(ifs, line);
        ifs.close();
-       tmpf.removeFile();
 
        rev_tree_cache_ = line;
        return !line.empty();
@@ -1772,16 +1786,19 @@ bool SVN::prepareFileRevision(string const & revis, string & f)
        }
 
        string revname = convert<string>(rev);
-       FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
+       TempFile tempfile("lyxvcrev_" + revname + '_');
+       tempfile.setAutoRemove(false);
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
        }
 
-       doVCCommand("svn cat -r " + revname + " "
+       doVCCommand("svn cat -r " + revname + ' '
                      + quoteName(onlyFileName(owner_->absFileName()))
                      + " > " + quoteName(tmpf.toFilesystemEncoding()),
                FileName(owner_->filePath()));
+       tmpf.refresh();
        if (tmpf.isFileEmpty())
                return false;
 
@@ -1827,7 +1844,8 @@ FileName const GIT::findFile(FileName const & file)
        }
 
        // Now we check the status of the file.
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return FileName();
@@ -1840,8 +1858,8 @@ FileName const GIT::findFile(FileName const & file)
                        quoteName(fname) + " > " +
                        quoteName(tmpf.toFilesystemEncoding()),
                        file.onlyPath());
+       tmpf.refresh();
        bool found = !tmpf.isFileEmpty();
-       tmpf.removeFile();
        LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
        return found ? file : FileName();
 }
@@ -1935,7 +1953,8 @@ LyXVC::CommandResult GIT::checkIn(string const & msg, string & log)
 LyXVC::CommandResult
 GIT::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()){
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                log = N_("Error: Could not generate logfile.");
@@ -1960,7 +1979,6 @@ GIT::checkIn(vector<support::FileName> const & f, string const & msg, string & l
                ret = LyXVC::ErrorCommand;
        }
 
-       tmpf.removeFile();
        if (!log.empty())
                log.insert(0, "GIT: ");
        if (ret == LyXVC::VCSuccess && log.empty())
@@ -1979,7 +1997,8 @@ bool GIT::isCheckInWithConfirmation()
 {
        // FIXME one day common getDiff and perhaps OpMode for all backends
 
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return true;
@@ -1990,7 +2009,6 @@ bool GIT::isCheckInWithConfirmation()
                FileName(owner_->filePath()));
 
        docstring diff = tmpf.fileContents("UTF-8");
-       tmpf.removeFile();
 
        if (diff.empty())
                return false;
@@ -2010,7 +2028,7 @@ string GIT::scanLogFile(FileName const & f, string & status)
        while (ifs) {
                getline(ifs, line);
                LYXERR(Debug::LYXVC, line << "\n");
-               if (!line.empty()) 
+               if (!line.empty())
                        status += line + "; ";
                if (prefixIs(line, "C ") || prefixIs(line, "CU ")
                                         || contains(line, "Commit failed")) {
@@ -2123,8 +2141,8 @@ string GIT::revisionInfo(LyXVC::RevisionInfo const info)
                        return rev_date_cache_;
                case LyXVC::Time:
                        return rev_time_cache_;
-               default: ;
-
+               default:
+                       break;
        }
 
        return string();
@@ -2133,7 +2151,8 @@ string GIT::revisionInfo(LyXVC::RevisionInfo const info)
 
 bool GIT::getFileRevisionInfo()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
@@ -2159,21 +2178,22 @@ bool GIT::getFileRevisionInfo()
        }
 
        ifs.close();
-       tmpf.removeFile();
        return !rev_file_cache_.empty();
 }
 
 
 bool GIT::getTreeRevisionInfo()
 {
-       FileName tmpf = FileName::tempName("lyxvcout");
+       TempFile tempfile("lyxvcout");
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
        }
 
        doVCCommand("git describe --abbrev --dirty --long > " + quoteName(tmpf.toFilesystemEncoding()),
-                   FileName(owner_->filePath()));
+                   FileName(owner_->filePath()),
+                   false); //git describe returns $?=128 when no tag found (but git repo still exists)
 
        if (tmpf.empty())
                return false;
@@ -2182,7 +2202,6 @@ bool GIT::getTreeRevisionInfo()
        ifstream ifs(tmpf.toFilesystemEncoding().c_str());
        getline(ifs, rev_tree_cache_);
        ifs.close();
-       tmpf.removeFile();
 
        return !rev_tree_cache_.empty();
 }
@@ -2217,9 +2236,11 @@ bool GIT::prepareFileRevision(string const & revis, string & f)
        else
                pointer = revis;
 
-       pointer += ":";
+       pointer += ':';
 
-       FileName tmpf = FileName::tempName("lyxvcrev_" + revis + "_");
+       TempFile tempfile("lyxvcrev_" + revis + '_');
+       tempfile.setAutoRemove(false);
+       FileName tmpf = tempfile.name();
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return false;
@@ -2229,6 +2250,7 @@ bool GIT::prepareFileRevision(string const & revis, string & f)
                      + quoteName(onlyFileName(owner_->absFileName()))
                      + " > " + quoteName(tmpf.toFilesystemEncoding()),
                FileName(owner_->filePath()));
+       tmpf.refresh();
        if (tmpf.isFileEmpty())
                return false;
 
@@ -2245,7 +2267,7 @@ bool GIT::prepareFileRevisionEnabled()
 
 bool GIT::toggleReadOnlyEnabled()
 {
-       return false;
+       return true;
 }