]> git.lyx.org Git - lyx.git/blobdiff - src/VCBackend.cpp
More requires --> required, for C++2a.
[lyx.git] / src / VCBackend.cpp
index 06fa0dfcf153b20e9e95344408b3bb74deb8916c..42fd36be318c17358fb5cb8f7b87198cede63a93 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "VCBackend.h"
 #include "Buffer.h"
+#include "DispatchResult.h"
 #include "LyX.h"
 #include "FuncRequest.h"
 
@@ -30,6 +31,8 @@
 #include "support/TempFile.h"
 
 #include <fstream>
+#include <iomanip>
+#include <sstream>
 
 using namespace std;
 using namespace lyx::support;
@@ -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);
 }
 
 
@@ -168,6 +171,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 +287,7 @@ LyXVC::CommandResult RCS::checkIn(string const & msg, string & log)
 
 bool RCS::checkInEnabled()
 {
-       return owner_ && !owner_->isReadonly();
+       return owner_ && !owner_->hasReadonlyFlag();
 }
 
 
@@ -324,7 +329,7 @@ string RCS::checkOut()
 
 bool RCS::checkOutEnabled()
 {
-       return owner_ && owner_->isReadonly();
+       return owner_ && owner_->hasReadonlyFlag();
 }
 
 
@@ -387,7 +392,7 @@ void RCS::undoLast()
 
 bool RCS::undoLastEnabled()
 {
-       return true;
+       return owner_->hasReadonlyFlag();
 }
 
 
@@ -425,7 +430,8 @@ string RCS::revisionInfo(LyXVC::RevisionInfo const info)
                        return rev_date_cache_;
                case LyXVC::Time:
                        return rev_time_cache_;
-               default: ;
+               default:
+                       break;
        }
 
        return string();
@@ -494,6 +500,7 @@ bool RCS::prepareFileRevision(string const &revis, string & f)
                      + quoteName(onlyFileName(owner_->absFileName()))
                      + " > " + quoteName(tmpf.toFilesystemEncoding()),
                FileName(owner_->filePath()));
+       tmpf.refresh();
        if (tmpf.isFileEmpty())
                return false;
 
@@ -563,8 +570,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
@@ -725,12 +734,14 @@ void CVS::getRevisionInfo()
                LYXERR(Debug::LYXVC, line << '\n');
                if (prefixIs(line, "date:")) {
                        smatch sm;
-                       regex_match(line, sm, reg);
-                       //sm[0]; // whole matched string
-                       rev_date_cache_ = sm[1];
-                       rev_time_cache_ = sm[2];
-                       //sm[3]; // GMT offset
-                       rev_author_cache_ = sm[4];
+                       if (regex_match(line, sm, reg)) {
+                         //sm[0]; // whole matched string
+                         rev_date_cache_ = sm[1];
+                         rev_time_cache_ = sm[2];
+                         //sm[3]; // GMT offset
+                         rev_author_cache_ = sm[4];
+                       } else
+                         LYXERR(Debug::LYXVC, "\tCannot parse line. Skipping."); 
                        break;
                }
        }
@@ -1094,7 +1105,8 @@ string CVS::revisionInfo(LyXVC::RevisionInfo const info)
                        return rev_date_cache_;
                case LyXVC::Time:
                        return rev_time_cache_;
-               default: ;
+               default:
+                       break;
                }
        }
        return string();
@@ -1118,6 +1130,7 @@ bool CVS::prepareFileRevision(string const & revis, string & f)
        doVCCommandWithOutput("cvs update -p -r" + rev + ' '
                + getTarget(File),
                FileName(owner_->filePath()), tmpf);
+       tmpf.refresh();
        if (tmpf.isFileEmpty())
                return false;
 
@@ -1429,7 +1442,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) {
@@ -1657,8 +1670,8 @@ string SVN::revisionInfo(LyXVC::RevisionInfo const info)
                        return rev_date_cache_;
                case LyXVC::Time:
                        return rev_time_cache_;
-               default: ;
-
+               default:
+                       break;
        }
 
        return string();
@@ -1783,6 +1796,7 @@ bool SVN::prepareFileRevision(string const & revis, string & f)
                      + quoteName(onlyFileName(owner_->absFileName()))
                      + " > " + quoteName(tmpf.toFilesystemEncoding()),
                FileName(owner_->filePath()));
+       tmpf.refresh();
        if (tmpf.isFileEmpty())
                return false;
 
@@ -1842,6 +1856,7 @@ FileName const GIT::findFile(FileName const & file)
                        quoteName(fname) + " > " +
                        quoteName(tmpf.toFilesystemEncoding()),
                        file.onlyPath());
+       tmpf.refresh();
        bool found = !tmpf.isFileEmpty();
        LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
        return found ? file : FileName();
@@ -2110,22 +2125,28 @@ string GIT::revisionInfo(LyXVC::RevisionInfo const info)
 
        // fill the rest of the attributes for a single file
        if (rev_file_cache_.empty())
-               if (!getFileRevisionInfo())
+               if (!getFileRevisionInfo()) {
                        rev_file_cache_ = "?";
+                       rev_file_abbrev_cache_ = "?";
+    }
 
        switch (info) {
                case LyXVC::File:
                        if (rev_file_cache_ == "?")
                                return string();
                        return rev_file_cache_;
+               case LyXVC::FileAbbrev:
+                       if (rev_file_abbrev_cache_ == "?")
+                               return string();
+                       return rev_file_abbrev_cache_;
                case LyXVC::Author:
                        return rev_author_cache_;
                case LyXVC::Date:
                        return rev_date_cache_;
                case LyXVC::Time:
                        return rev_time_cache_;
-               default: ;
-
+               default:
+                       break;
        }
 
        return string();
@@ -2141,7 +2162,7 @@ bool GIT::getFileRevisionInfo()
                return false;
        }
 
-       doVCCommand("git log -n 1 --pretty=format:%H%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
+       doVCCommand("git log -n 1 --pretty=format:%H%n%h%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 
@@ -2152,6 +2173,8 @@ bool GIT::getFileRevisionInfo()
 
        if (ifs)
                getline(ifs, rev_file_cache_);
+       if (ifs)
+               getline(ifs, rev_file_abbrev_cache_);
        if (ifs)
                getline(ifs, rev_author_cache_);
        if (ifs) {
@@ -2175,7 +2198,8 @@ bool GIT::getTreeRevisionInfo()
        }
 
        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;
@@ -2232,6 +2256,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;
 
@@ -2248,7 +2273,7 @@ bool GIT::prepareFileRevisionEnabled()
 
 bool GIT::toggleReadOnlyEnabled()
 {
-       return false;
+       return true;
 }