}
-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 log -n 1 --pretty=format:%H . > " + 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;
}