revis = rev;
return true;
}
-
+
+bool VCS::checkparentdirs(FileName const & file, std::string const & pathname)
+{
+ FileName dirname = file.onlyPath();
+ FileName tocheck = FileName(addName(dirname.absFileName(),pathname));
+ bool result = tocheck.exists();
+ while ( !result && !dirname.empty() ) {
+ dirname = dirname.parentPath();
+ tocheck = FileName(addName(dirname.absFileName(),pathname));
+ result = tocheck.exists();
+ }
+ return result;
+}
+
/////////////////////////////////////////////////////////////////////
//
return false;
}
+
string RCS::revisionInfo(LyXVC::RevisionInfo const info)
{
if (info == LyXVC::File)
return version_;
+ // fill the rest of the attributes for a single file
+ if (rev_date_cache_.empty())
+ if (!getRevisionInfo())
+ return string();
+
+ switch (info) {
+ 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 RCS::getRevisionInfo()
+{
+ FileName tmpf = FileName::tempName("lyxvcout");
+ if (tmpf.empty()) {
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return false;
+ }
+ doVCCommand("rlog -r " + quoteName(onlyFileName(owner_->absFileName()))
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),
+ FileName(owner_->filePath()));
+
+ if (tmpf.empty())
+ return false;
+
+ ifstream ifs(tmpf.toFilesystemEncoding().c_str());
+ string line;
+
+ // we reached to the entry, i.e. after initial log message
+ bool entry=false;
+ // line with critical info, e.g:
+ //"date: 2011/07/02 11:02:54; author: sanda; state: Exp; lines: +17 -2"
+ string result;
+
+ while (ifs) {
+ getline(ifs, line);
+ LYXERR(Debug::LYXVC, line);
+ if (entry && prefixIs(line, "date:")) {
+ result = line;
+ break;
+ }
+ if (prefixIs(line, "revision"))
+ entry = true;
+ }
+ if (result.empty())
+ return false;
+
+ rev_date_cache_ = token(result, ' ', 1);
+ rev_time_cache_ = rtrim(token(result, ' ', 2), ";");
+ rev_author_cache_ = trim(token(token(result, ';', 1), ':', 1));
+
+ return !rev_author_cache_.empty();
+}
+
bool RCS::prepareFileRevision(string const &revis, string & f)
{
string rev = revis;
FileName const SVN::findFile(FileName const & file)
{
- // First we look for the .svn/entries in the same dir
- // where we have file.
- FileName const entries(onlyPath(file.absFileName()) + "/.svn/entries");
- string const tmpf = onlyFileName(file.absFileName());
- LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
- << "' for `" << tmpf << '\'');
- if (entries.isReadableFile()) {
- // Ok we are at least in a SVN dir. Parse the .svn/entries
- // and see if we can find this file. We do a fast and
- // dirty parse here.
- ifstream ifs(entries.toFilesystemEncoding().c_str());
- string line, oldline;
- while (getline(ifs, line)) {
- if (line == "dir" || line == "file")
- LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
- if (oldline == tmpf && line == "file")
- return entries;
- oldline = line;
- }
+ // First we check the existence of repository meta data.
+ if (!VCS::checkparentdirs(file, ".svn")) {
+ LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
+ return FileName();
}
- return FileName();
+
+ // Now we check the status of the file.
+ FileName tmpf = FileName::tempName("lyxvcout");
+ if (tmpf.empty()) {
+ LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+ return FileName();
+ }
+
+ string const fname = onlyFileName(file.absFileName());
+ LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn control for `" << fname << '\'');
+ bool found = 0 == doVCCommandCall("svn info " + quoteName(fname)
+ + " > " + quoteName(tmpf.toFilesystemEncoding()),
+ file.onlyPath());
+ LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
+ return found ? file : FileName();
}
string line;
bool ret = false;
- while (ifs) {
+ while (ifs && !ret) {
getline(ifs, line);
LYXERR(Debug::LYXVC, line);
if (contains(line, "svn:needs-lock"))