]> git.lyx.org Git - lyx.git/blobdiff - src/VCBackend.cpp
Natbib authoryear uses (Ref1; Ref2) by default.
[lyx.git] / src / VCBackend.cpp
index 753bd63890cb119e7545f1c66f5fc922b82221b3..96b71d81ea32480fcd5c727a051264d1f22bc5ea 100644 (file)
@@ -34,7 +34,6 @@ using namespace std;
 using namespace lyx::support;
 
 
-
 namespace lyx {
 
 
@@ -68,7 +67,7 @@ int VCS::doVCCommand(string const & cmd, FileName const & path, bool reportError
 bool VCS::makeRCSRevision(string const &version, string &revis) const
 {
        string rev = revis;
-       
+
        if (isStrInt(rev)) {
                int back = convert<int>(rev);
                // if positive use as the last number in the whole revision string
@@ -99,23 +98,21 @@ 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();
-       FileName tocheck = FileName(addName(dirname.absFileName(),pathname));
-       LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
-       bool result = tocheck.exists();
-       while ( !result && !dirname.empty() ) {
+       do {
+               FileName tocheck = FileName(addName(dirname.absFileName(), vcsdir));
+               LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
+               if (tocheck.exists())
+                       return true;
                //this construct because of #8295
                dirname = FileName(dirname.absFileName()).parentPath();
-               LYXERR(Debug::LYXVC, "check directory: " << dirname.absFileName());
-               tocheck = FileName(addName(dirname.absFileName(),pathname));
-               result = tocheck.exists();
-       }
-       return result;
+       } while (!dirname.empty());
+       return false;
 }
 
-       
+
 /////////////////////////////////////////////////////////////////////
 //
 // RCS
@@ -124,6 +121,8 @@ bool VCS::checkparentdirs(FileName const & file, std::string const & pathname)
 
 RCS::RCS(FileName const & m, Buffer * b) : VCS(b)
 {
+       // Here we know that the buffer file is either already in RCS or
+       // about to be registered
        master_ = m;
        scanMaster();
 }
@@ -404,7 +403,7 @@ bool RCS::toggleReadOnlyEnabled()
        // This got broken somewhere along lfuns dispatch reorganization.
        // reloadBuffer would be needed after this, but thats problematic
        // since we are inside Buffer::dispatch.
-       // return return status() != UNVERSIONED;
+       // return true;
        return false;
 }
 
@@ -513,6 +512,8 @@ bool RCS::prepareFileRevisionEnabled()
 
 CVS::CVS(FileName const & m, Buffer * b) : VCS(b)
 {
+       // Here we know that the buffer file is either already in CVS or
+       // about to be registered
        master_ = m;
        have_rev_info_ = false;
        scanMaster();
@@ -553,7 +554,6 @@ void CVS::scanMaster()
        LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
        string line;
        static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
-       vcstatus = UNVERSIONED;
        while (getline(ifs, line)) {
                LYXERR(Debug::LYXVC, "\t  line: " << line);
                if (contains(line, tmpf)) {
@@ -1139,6 +1139,8 @@ bool CVS::prepareFileRevisionEnabled()
 
 SVN::SVN(FileName const & m, Buffer * b) : VCS(b)
 {
+       // Here we know that the buffer file is either already in SVN or
+       // about to be registered
        master_ = m;
        locked_mode_ = 0;
        scanMaster();
@@ -1173,19 +1175,14 @@ FileName const SVN::findFile(FileName const & file)
 
 void SVN::scanMaster()
 {
-       // vcstatus code other than UNVERSIONED is somewhat superflous,
+       // vcstatus code is somewhat superflous,
        // until we want to implement read-only toggle for svn.
-       FileName f = findFile(owner_->fileName());
-       if (f.empty()) {
-               vcstatus = UNVERSIONED;
-       } else {
-               vcstatus = NOLOCKING;
-               if (checkLockMode()) {
-                       if (isLocked())
-                               vcstatus = LOCKED;
-                       else
-                               vcstatus = UNLOCKED;
-               }
+       vcstatus = NOLOCKING;
+       if (checkLockMode()) {
+               if (isLocked())
+                       vcstatus = LOCKED;
+               else
+                       vcstatus = UNLOCKED;
        }
 }
 
@@ -1813,6 +1810,8 @@ bool SVN::toggleReadOnlyEnabled()
 
 GIT::GIT(FileName const & m, Buffer * b) : VCS(b)
 {
+       // Here we know that the buffer file is either already in GIT or
+       // about to be registered
        master_ = m;
        scanMaster();
 }
@@ -1833,27 +1832,14 @@ FileName const GIT::findFile(FileName const & file)
                return FileName();
        }
 
-       // --porcelain selects a format that is supposed to be stable across
-       // git versions
        string const fname = onlyFileName(file.absFileName());
        LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under git control for `"
                        << fname << '\'');
-       bool found = 0 == doVCCommandCall("git status --porcelain " +
-                               quoteName(fname) + " > " +
-                               quoteName(tmpf.toFilesystemEncoding()),
+       doVCCommandCall("git ls-files " +
+                       quoteName(fname) + " > " +
+                       quoteName(tmpf.toFilesystemEncoding()),
                        file.onlyPath());
-       if (found)
-       {
-               // The output contains a line starting with "??" for unknown
-               // files, no line for known unmodified files and a line
-               // starting with "M" or something else for modified/deleted
-               // etc. files.
-               ifstream ifs(tmpf.toFilesystemEncoding().c_str());
-               string test;
-               if ((ifs >> test))
-                       found = (test != "??");
-               // else is no error
-       }
+       bool found = !tmpf.isFileEmpty();
        tmpf.removeFile();
        LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
        return found ? file : FileName();
@@ -1862,13 +1848,9 @@ FileName const GIT::findFile(FileName const & file)
 
 void GIT::scanMaster()
 {
-       // vcstatus code other than UNVERSIONED is somewhat superflous,
+       // vcstatus code is somewhat superflous,
        // until we want to implement read-only toggle for git.
-       FileName f = findFile(owner_->fileName());
-       if (f.empty())
-               vcstatus = UNVERSIONED;
-       else
-               vcstatus = NOLOCKING;
+       vcstatus = NOLOCKING;
 }