if (ret)
return LyXVC::ErrorCommand;
log = "RCS: Proceeded";
- return LyXVC::Success;
+ return LyXVC::VCSuccess;
}
if (unedit())
return LyXVC::ErrorCommand;
log = "CVS: Proceeded";
- return LyXVC::Success;
+ return LyXVC::VCSuccess;
case LocallyModified:
case LocallyAdded: {
int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
if (rc)
return LyXVC::ErrorCommand;
log = "CVS: Proceeded";
- return LyXVC::Success;
+ return LyXVC::VCSuccess;
}
case NeedsMerge:
case NeedsCheckout:
f.push_back(owner_->fileName());
f.push_back(newFile);
string log;
- if (checkIn(f, msg, log) != LyXVC::Success) {
+ if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
cmd = "svn revert -q " +
quoteName(onlyFileName(owner_->absFileName())) + ' ' +
quoteName(relFile);
return string();
vector<support::FileName> f(1, newFile);
string log;
- if (checkIn(f, msg, log) == LyXVC::Success)
+ if (checkIn(f, msg, log) == LyXVC::VCSuccess)
return log;
return string();
}
os << " > " << quoteName(tmpf.toFilesystemEncoding());
LyXVC::CommandResult ret =
doVCCommand(os.str(), FileName(owner_->filePath())) ?
- LyXVC::ErrorCommand : LyXVC::Success;
+ LyXVC::ErrorCommand : LyXVC::VCSuccess;
string res = scanLogFile(tmpf, log);
if (!res.empty()) {
tmpf.removeFile();
if (!log.empty())
log.insert(0, "SVN: ");
- if (ret == LyXVC::Success && log.empty())
+ if (ret == LyXVC::VCSuccess && log.empty())
log = "SVN: Proceeded";
return ret;
}
f.push_back(owner_->fileName());
f.push_back(newFile);
string log;
- if (checkIn(f, msg, log) != LyXVC::Success) {
+ if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
cmd = "git checkout -q " +
quoteName(onlyFileName(owner_->absFileName())) + ' ' +
quoteName(relFile);
os << " > " << quoteName(tmpf.toFilesystemEncoding());
LyXVC::CommandResult ret =
doVCCommand(os.str(), FileName(owner_->filePath())) ?
- LyXVC::ErrorCommand : LyXVC::Success;
+ LyXVC::ErrorCommand : LyXVC::VCSuccess;
string res = scanLogFile(tmpf, log);
if (!res.empty()) {
tmpf.removeFile();
if (!log.empty())
log.insert(0, "GIT: ");
- if (ret == LyXVC::Success && log.empty())
+ if (ret == LyXVC::VCSuccess && log.empty())
log = "GIT: Proceeded";
return ret;
}
}
-string GIT::revisionInfo(LyXVC::RevisionInfo const /*info*/)
+string GIT::revisionInfo(LyXVC::RevisionInfo const info)
{
+ if (info == LyXVC::Tree) {
+ if (rev_tree_cache_.empty())
+ if (!getTreeRevisionInfo())
+ rev_tree_cache_ = "?";
+ if (rev_tree_cache_ == "?")
+ return string();
+
+ return rev_tree_cache_;
+ }
+
+ // fill the rest of the attributes for a single file
+ if (rev_file_cache_.empty())
+ if (!getFileRevisionInfo())
+ rev_file_cache_ = "?";
+
+ switch (info) {
+ case LyXVC::File:
+ if (rev_file_cache_ == "?")
+ return string();
+ return rev_file_cache_;
+ case LyXVC::Author:
+ return rev_author_cache_;
+ case LyXVC::Date:
+ return rev_date_cache_;
+ case LyXVC::Time:
+ return rev_time_cache_;
+ default: ;
+
+ }
+
return string();
}
+bool GIT::getFileRevisionInfo()
+{
+ FileName tmpf = FileName::tempName("lyxvcout");
+ if (tmpf.empty()) {
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return false;
+ }
+
+ doVCCommand("git log -n 1 --pretty=format:%H%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),
+ FileName(owner_->filePath()));
+
+ if (tmpf.empty())
+ return false;
+
+ ifstream ifs(tmpf.toFilesystemEncoding().c_str());
+
+ if (ifs)
+ getline(ifs, rev_file_cache_);
+ if (ifs)
+ getline(ifs, rev_author_cache_);
+ if (ifs) {
+ string line;
+ getline(ifs, line);
+ rev_time_cache_ = split(line, rev_date_cache_, ' ');
+ }
+
+ ifs.close();
+ tmpf.removeFile();
+ return !rev_file_cache_.empty();
+}
+
+
+bool GIT::getTreeRevisionInfo()
+{
+ FileName tmpf = FileName::tempName("lyxvcout");
+ 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()));
+
+ if (tmpf.empty())
+ return false;
+
+ // only first line in case something bad happens.
+ ifstream ifs(tmpf.toFilesystemEncoding().c_str());
+ getline(ifs, rev_tree_cache_);
+ ifs.close();
+ tmpf.removeFile();
+
+ return !rev_tree_cache_.empty();
+}
+
+
void GIT::getLog(FileName const & tmpf)
{
doVCCommand("git log " + quoteName(onlyFileName(owner_->absFileName()))
}
-bool GIT::prepareFileRevision(string const & /*revis*/, string & /*f*/)
+//at this moment we don't accept revision SHA, but just number of revision steps back
+//GUI and infrastucture needs to be changed first
+bool GIT::prepareFileRevision(string const & revis, string & f)
{
- return false;
+ // anything positive means we got hash, not "0" or minus revision
+ int rev = 1;
+
+ // hash is rarely number and should be long
+ if (isStrInt(revis) && revis.length()<20)
+ rev = convert<int>(revis);
+
+ // revision and filename
+ string pointer;
+
+ // go back for "minus" revisions
+ if (rev <= 0)
+ pointer = "HEAD~" + convert<string>(-rev);
+ // normal hash
+ else
+ pointer = revis;
+
+ pointer += ":";
+
+ FileName tmpf = FileName::tempName("lyxvcrev_" + revis + "_");
+ if (tmpf.empty()) {
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return false;
+ }
+
+ doVCCommand("git show " + pointer + "./"
+ + quoteName(onlyFileName(owner_->absFileName()))
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),
+ FileName(owner_->filePath()));
+ if (tmpf.isFileEmpty())
+ return false;
+
+ f = tmpf.absFileName();
+ return true;
}
bool GIT::prepareFileRevisionEnabled()
{
- return false;
+ return true;
}