mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 10:18:50 +00:00
SVN info - add author, date, time
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33435 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
773d4a8253
commit
c0f9fb76a8
@ -415,7 +415,8 @@ void LyXAction::init()
|
||||
textclass: name of textclass (e.g. article) \n
|
||||
menu: name of lfun used in menu \n
|
||||
icon: name of lfun used in toolbar \n
|
||||
buffer: "name"|"path"|"class"|"vcs-revision"|"vcs-tree-revision"
|
||||
buffer: "name"|"path"|"class"|"vcs-tree-revision"|
|
||||
"vcs-revision"|"vcs-author"|"vcs-date"|"vcs-time"
|
||||
* \li Sample: command-sequence info-insert buffer path; info-insert buffer name
|
||||
* \li Origin: bpeng, 7 Oct 2007
|
||||
* \endvar
|
||||
|
@ -146,7 +146,10 @@ public:
|
||||
// type of the revision information
|
||||
enum RevisionInfo {
|
||||
File = 1,
|
||||
Tree = 2
|
||||
Tree = 2,
|
||||
Author = 3,
|
||||
Date = 4,
|
||||
Time = 5
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -860,32 +860,41 @@ bool SVN::undoLastEnabled()
|
||||
|
||||
string SVN::revisionInfo(LyXVC::RevisionInfo const info)
|
||||
{
|
||||
switch (info) {
|
||||
case LyXVC::File:
|
||||
if (rev_file_cache_.empty())
|
||||
rev_file_cache_ = getFileRevisionInfo();
|
||||
if (rev_file_cache_.empty())
|
||||
rev_file_cache_ = "?";
|
||||
if (rev_file_cache_ == "?")
|
||||
return string();
|
||||
|
||||
return rev_file_cache_;
|
||||
|
||||
case LyXVC::Tree:
|
||||
if (rev_tree_cache_.empty())
|
||||
rev_tree_cache_ = getTreeRevisionInfo();
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
std::string SVN::getFileRevisionInfo()
|
||||
bool SVN::getFileRevisionInfo()
|
||||
{
|
||||
FileName tmpf = FileName::tempName("lyxvcout");
|
||||
|
||||
@ -894,7 +903,7 @@ std::string SVN::getFileRevisionInfo()
|
||||
FileName(owner_->filePath()));
|
||||
|
||||
if (tmpf.empty())
|
||||
return string();
|
||||
return false;
|
||||
|
||||
ifstream ifs(tmpf.toFilesystemEncoding().c_str());
|
||||
string line;
|
||||
@ -911,16 +920,30 @@ std::string SVN::getFileRevisionInfo()
|
||||
string l1 = subst(line, "revision=\"", "");
|
||||
string l2 = trim(subst(l1, "\">", ""));
|
||||
if (isStrInt(l2))
|
||||
rev = l2;
|
||||
rev_file_cache_ = rev = l2;
|
||||
}
|
||||
if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
|
||||
string l1 = subst(line, "<author>", "");
|
||||
string l2 = subst(l1, "</author>", "");
|
||||
rev_author_cache_ = l2;
|
||||
}
|
||||
if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
|
||||
string l1 = subst(line, "<date>", "");
|
||||
string l2 = subst(l1, "</date>", "");
|
||||
l2 = split(l2, l1, 'T');
|
||||
rev_date_cache_ = l1;
|
||||
l2 = split(l2, l1, '.');
|
||||
rev_time_cache_ = l1;
|
||||
}
|
||||
}
|
||||
|
||||
ifs.close();
|
||||
tmpf.erase();
|
||||
return rev;
|
||||
return !rev.empty();
|
||||
}
|
||||
|
||||
|
||||
std::string SVN::getTreeRevisionInfo()
|
||||
bool SVN::getTreeRevisionInfo()
|
||||
{
|
||||
FileName tmpf = FileName::tempName("lyxvcout");
|
||||
|
||||
@ -928,7 +951,7 @@ std::string SVN::getTreeRevisionInfo()
|
||||
FileName(owner_->filePath()));
|
||||
|
||||
if (tmpf.empty())
|
||||
return string();
|
||||
return false;
|
||||
|
||||
// only first line in case something bad happens.
|
||||
ifstream ifs(tmpf.toFilesystemEncoding().c_str());
|
||||
@ -936,7 +959,9 @@ std::string SVN::getTreeRevisionInfo()
|
||||
getline(ifs, line);
|
||||
ifs.close();
|
||||
tmpf.erase();
|
||||
return line;
|
||||
|
||||
rev_tree_cache_ = line;
|
||||
return !line.empty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -279,12 +279,23 @@ private:
|
||||
support::FileName file_;
|
||||
/// is the loaded file under locking policy?
|
||||
bool locked_mode_;
|
||||
/// real code for obtaining file revision info
|
||||
std::string getFileRevisionInfo();
|
||||
/**
|
||||
* Real code for obtaining file revision info. Fills all file-related caches
|
||||
* and returns true if successfull.
|
||||
* "?" is stored in rev_file_cache_ as a signal if request for obtaining info
|
||||
* was already unsuccessful.
|
||||
*/
|
||||
bool getFileRevisionInfo();
|
||||
/// cache for file revision number, "?" if already unsuccessful
|
||||
std::string rev_file_cache_;
|
||||
/// real code for obtaining file revision info
|
||||
std::string getTreeRevisionInfo();
|
||||
/// cache for author of last commit
|
||||
std::string rev_author_cache_;
|
||||
/// cache for date of last commit
|
||||
std::string rev_date_cache_;
|
||||
/// cache for time of last commit
|
||||
std::string rev_time_cache_;
|
||||
/// fills rev_tree_cache_, returns true if successfull.
|
||||
bool getTreeRevisionInfo();
|
||||
/// cache for tree revision number, "?" if already unsuccessful
|
||||
std::string rev_tree_cache_;
|
||||
};
|
||||
|
@ -175,7 +175,8 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
|
||||
return true;
|
||||
case BUFFER_INFO:
|
||||
return name == "name" || name == "path" || name == "class" ||
|
||||
name == "vcs-revision" || name == "vcs-tree-revision";
|
||||
name == "vcs-revision" || name == "vcs-tree-revision" ||
|
||||
name == "vcs-author" || name == "vcs-date" || name == "vcs-time";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -379,6 +380,15 @@ void InsetInfo::updateInfo()
|
||||
else if (name_ == "vcs-tree-revision" && buffer().lyxvc().inUse() &&
|
||||
!buffer().lyxvc().revisionInfo(LyXVC::Tree).empty())
|
||||
setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::Tree)));
|
||||
else if (name_ == "vcs-author" && buffer().lyxvc().inUse() &&
|
||||
!buffer().lyxvc().revisionInfo(LyXVC::Author).empty())
|
||||
setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::Author)));
|
||||
else if (name_ == "vcs-time" && buffer().lyxvc().inUse() &&
|
||||
!buffer().lyxvc().revisionInfo(LyXVC::Time).empty())
|
||||
setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::Time)));
|
||||
else if (name_ == "vcs-date" && buffer().lyxvc().inUse() &&
|
||||
!buffer().lyxvc().revisionInfo(LyXVC::Date).empty())
|
||||
setText(from_utf8(buffer().lyxvc().revisionInfo(LyXVC::Date)));
|
||||
else
|
||||
setText(_("Unknown buffer info"));
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user