Fix return value of CVS::toString() + cosmetics

CVS::toString() returns a docstring, so rather be explicit than relying on a
cast that not everybody understands how it works at first sight.
This commit is contained in:
Georg Baum 2014-11-30 12:41:49 +01:00
parent e066dd6bd9
commit 06cfd26d5e

View File

@ -74,8 +74,8 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
// if positive use as the last number in the whole revision string // if positive use as the last number in the whole revision string
if (back > 0) { if (back > 0) {
string base; string base;
rsplit(version, base , '.' ); rsplit(version, base , '.');
rev = base + "." + rev; rev = base + '.' + rev;
} }
if (back == 0) if (back == 0)
rev = version; rev = version;
@ -83,14 +83,14 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
// in case of backward indexing // in case of backward indexing
if (back < 0) { if (back < 0) {
string cur, base; string cur, base;
cur = rsplit(version, base , '.' ); cur = rsplit(version, base , '.');
if (!isStrInt(cur)) if (!isStrInt(cur))
return false; return false;
int want = convert<int>(cur) + back; int want = convert<int>(cur) + back;
if (want <= 0) if (want <= 0)
return false; return false;
rev = base + "." + convert<string>(want); rev = base + '.' + convert<string>(want);
} }
} }
@ -359,7 +359,7 @@ bool RCS::lockingToggleEnabled()
bool RCS::revert() bool RCS::revert()
{ {
if (doVCCommand("co -f -u" + version_ + " " if (doVCCommand("co -f -u" + version_ + ' '
+ quoteName(onlyFileName(owner_->absFileName())), + quoteName(onlyFileName(owner_->absFileName())),
FileName(owner_->filePath()))) FileName(owner_->filePath())))
return false; return false;
@ -379,7 +379,7 @@ bool RCS::isRevertWithConfirmation()
void RCS::undoLast() void RCS::undoLast()
{ {
LYXERR(Debug::LYXVC, "LyXVC: undoLast"); LYXERR(Debug::LYXVC, "LyXVC: undoLast");
doVCCommand("rcs -o" + version_ + " " doVCCommand("rcs -o" + version_ + ' '
+ quoteName(onlyFileName(owner_->absFileName())), + quoteName(onlyFileName(owner_->absFileName())),
FileName(owner_->filePath())); FileName(owner_->filePath()));
} }
@ -482,7 +482,7 @@ bool RCS::prepareFileRevision(string const &revis, string & f)
if (!VCS::makeRCSRevision(version_, rev)) if (!VCS::makeRCSRevision(version_, rev))
return false; return false;
TempFile tempfile("lyxvcrev_" + rev + "_"); TempFile tempfile("lyxvcrev_" + rev + '_');
tempfile.setAutoRemove(false); tempfile.setAutoRemove(false);
FileName tmpf = tempfile.name(); FileName tmpf = tempfile.name();
if (tmpf.empty()) { if (tmpf.empty()) {
@ -490,7 +490,7 @@ bool RCS::prepareFileRevision(string const &revis, string & f)
return false; return false;
} }
doVCCommand("co -p" + rev + " " doVCCommand("co -p" + rev + ' '
+ quoteName(onlyFileName(owner_->absFileName())) + quoteName(onlyFileName(owner_->absFileName()))
+ " > " + quoteName(tmpf.toFilesystemEncoding()), + " > " + quoteName(tmpf.toFilesystemEncoding()),
FileName(owner_->filePath())); FileName(owner_->filePath()));
@ -638,7 +638,7 @@ docstring CVS::toString(CvsStatus status) const
case StatusError: case StatusError:
return _("Cannot retrieve CVS status"); return _("Cannot retrieve CVS status");
} }
return 0; return docstring();
} }
@ -679,7 +679,7 @@ CVS::CvsStatus CVS::getStatus()
while (ifs) { while (ifs) {
string line; string line;
getline(ifs, line); getline(ifs, line);
LYXERR(Debug::LYXVC, line << "\n"); LYXERR(Debug::LYXVC, line << '\n');
if (prefixIs(line, "File:")) { if (prefixIs(line, "File:")) {
if (contains(line, "Up-to-date")) if (contains(line, "Up-to-date"))
status = UpToDate; status = UpToDate;
@ -707,22 +707,22 @@ void CVS::getRevisionInfo()
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf); LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return; return;
} }
int rc = doVCCommandCallWithOutput("cvs log -r" + version_ int rc = doVCCommandCallWithOutput("cvs log -r" + version_
+ " " + getTarget(File), + ' ' + getTarget(File),
FileName(owner_->filePath()), tmpf); FileName(owner_->filePath()), tmpf);
if (rc) { if (rc) {
LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc); LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
return; return;
} }
ifstream ifs(tmpf.toFilesystemEncoding().c_str()); ifstream ifs(tmpf.toFilesystemEncoding().c_str());
static regex const reg("date: (.*) (.*) (.*); author: (.*); state: (.*);(.*)"); static regex const reg("date: (.*) (.*) (.*); author: (.*); state: (.*);(.*)");
while (ifs) { while (ifs) {
string line; string line;
getline(ifs, line); getline(ifs, line);
LYXERR(Debug::LYXVC, line << "\n"); LYXERR(Debug::LYXVC, line << '\n');
if (prefixIs(line, "date:")) { if (prefixIs(line, "date:")) {
smatch sm; smatch sm;
regex_match(line, sm, reg); regex_match(line, sm, reg);
@ -826,7 +826,7 @@ string CVS::scanLogFile(FileName const & f, string & status)
while (ifs) { while (ifs) {
string line; string line;
getline(ifs, line); getline(ifs, line);
LYXERR(Debug::LYXVC, line << "\n"); LYXERR(Debug::LYXVC, line << '\n');
if (!line.empty()) if (!line.empty())
status += line + "; "; status += line + "; ";
if (prefixIs(line, "C ")) { if (prefixIs(line, "C ")) {
@ -910,7 +910,7 @@ string CVS::checkOut()
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf); LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return string(); return string();
} }
int rc = update(File, tmpf); int rc = update(File, tmpf);
string log; string log;
string const res = scanLogFile(tmpf, log); string const res = scanLogFile(tmpf, log);
@ -922,7 +922,7 @@ string CVS::checkOut()
from_local8bit(res))); from_local8bit(res)));
rc = 0; rc = 0;
} }
return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log; return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
} }
@ -944,7 +944,7 @@ string CVS::repoUpdate()
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf); LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return string(); return string();
} }
getDiff(Directory, tmpf); getDiff(Directory, tmpf);
docstring res = tmpf.fileContents("UTF-8"); docstring res = tmpf.fileContents("UTF-8");
if (!res.empty()) { if (!res.empty()) {
@ -956,13 +956,13 @@ string CVS::repoUpdate()
"or you will need to revert back to the repository version."), file); "or you will need to revert back to the repository version."), file);
int ret = frontend::Alert::prompt(_("Changes detected"), int ret = frontend::Alert::prompt(_("Changes detected"),
text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ...")); text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
if (ret == 2 ) { if (ret == 2) {
dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName())); dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
ret = frontend::Alert::prompt(_("Changes detected"), ret = frontend::Alert::prompt(_("Changes detected"),
text, 0, 1, _("&Continue"), _("&Abort")); text, 0, 1, _("&Continue"), _("&Abort"));
hideDialogs("file", 0); hideDialogs("file", 0);
} }
if (ret == 1 ) if (ret == 1)
return string(); return string();
} }
@ -1107,7 +1107,7 @@ bool CVS::prepareFileRevision(string const & revis, string & f)
if (!VCS::makeRCSRevision(version_, rev)) if (!VCS::makeRCSRevision(version_, rev))
return false; return false;
TempFile tempfile("lyxvcrev_" + rev + "_"); TempFile tempfile("lyxvcrev_" + rev + '_');
tempfile.setAutoRemove(false); tempfile.setAutoRemove(false);
FileName tmpf = tempfile.name(); FileName tmpf = tempfile.name();
if (tmpf.empty()) { if (tmpf.empty()) {
@ -1115,7 +1115,7 @@ bool CVS::prepareFileRevision(string const & revis, string & f)
return false; return false;
} }
doVCCommandWithOutput("cvs update -p -r" + rev + " " doVCCommandWithOutput("cvs update -p -r" + rev + ' '
+ getTarget(File), + getTarget(File),
FileName(owner_->filePath()), tmpf); FileName(owner_->filePath()), tmpf);
if (tmpf.isFileEmpty()) if (tmpf.isFileEmpty())
@ -1401,8 +1401,8 @@ string SVN::scanLogFile(FileName const & f, string & status)
while (ifs) { while (ifs) {
getline(ifs, line); getline(ifs, line);
LYXERR(Debug::LYXVC, line << "\n"); LYXERR(Debug::LYXVC, line << '\n');
if (!line.empty()) if (!line.empty())
status += line + "; "; status += line + "; ";
if (prefixIs(line, "C ") || prefixIs(line, "CU ") if (prefixIs(line, "C ") || prefixIs(line, "CU ")
|| contains(line, "Commit failed")) { || contains(line, "Commit failed")) {
@ -1515,13 +1515,13 @@ string SVN::repoUpdate()
"\n\nContinue?"), file); "\n\nContinue?"), file);
int ret = frontend::Alert::prompt(_("Changes detected"), int ret = frontend::Alert::prompt(_("Changes detected"),
text, 0, 1, _("&Yes"), _("&No"), _("View &Log ...")); text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
if (ret == 2 ) { if (ret == 2) {
dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName())); dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
ret = frontend::Alert::prompt(_("Changes detected"), ret = frontend::Alert::prompt(_("Changes detected"),
text, 0, 1, _("&Yes"), _("&No")); text, 0, 1, _("&Yes"), _("&No"));
hideDialogs("file", 0); hideDialogs("file", 0);
} }
if (ret == 1 ) if (ret == 1)
return string(); return string();
} }
@ -1578,7 +1578,7 @@ string SVN::lockingToggle()
return string(); return string();
frontend::Alert::warning(_("SVN File Locking"), frontend::Alert::warning(_("SVN File Locking"),
(locking ? _("Locking property unset.") : _("Locking property set.")) + "\n" (locking ? _("Locking property unset.") : _("Locking property set.")) + '\n'
+ _("Do not forget to commit the locking property into the repository."), + _("Do not forget to commit the locking property into the repository."),
true); true);
@ -1771,7 +1771,7 @@ bool SVN::prepareFileRevision(string const & revis, string & f)
} }
string revname = convert<string>(rev); string revname = convert<string>(rev);
TempFile tempfile("lyxvcrev_" + revname + "_"); TempFile tempfile("lyxvcrev_" + revname + '_');
tempfile.setAutoRemove(false); tempfile.setAutoRemove(false);
FileName tmpf = tempfile.name(); FileName tmpf = tempfile.name();
if (tmpf.empty()) { if (tmpf.empty()) {
@ -1779,7 +1779,7 @@ bool SVN::prepareFileRevision(string const & revis, string & f)
return false; return false;
} }
doVCCommand("svn cat -r " + revname + " " doVCCommand("svn cat -r " + revname + ' '
+ quoteName(onlyFileName(owner_->absFileName())) + quoteName(onlyFileName(owner_->absFileName()))
+ " > " + quoteName(tmpf.toFilesystemEncoding()), + " > " + quoteName(tmpf.toFilesystemEncoding()),
FileName(owner_->filePath())); FileName(owner_->filePath()));
@ -2011,7 +2011,7 @@ string GIT::scanLogFile(FileName const & f, string & status)
while (ifs) { while (ifs) {
getline(ifs, line); getline(ifs, line);
LYXERR(Debug::LYXVC, line << "\n"); LYXERR(Debug::LYXVC, line << "\n");
if (!line.empty()) if (!line.empty())
status += line + "; "; status += line + "; ";
if (prefixIs(line, "C ") || prefixIs(line, "CU ") if (prefixIs(line, "C ") || prefixIs(line, "CU ")
|| contains(line, "Commit failed")) { || contains(line, "Commit failed")) {
@ -2218,9 +2218,9 @@ bool GIT::prepareFileRevision(string const & revis, string & f)
else else
pointer = revis; pointer = revis;
pointer += ":"; pointer += ':';
TempFile tempfile("lyxvcrev_" + revis + "_"); TempFile tempfile("lyxvcrev_" + revis + '_');
tempfile.setAutoRemove(false); tempfile.setAutoRemove(false);
FileName tmpf = tempfile.name(); FileName tmpf = tempfile.name();
if (tmpf.empty()) { if (tmpf.empty()) {