aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolás Alvarez <nicolas.alvarez@gmail.com>2011-04-11 18:43:40 -0300
committerNicolás Alvarez <nicolas.alvarez@gmail.com>2011-04-11 18:43:40 -0300
commit1a41c9661e837e2463c492693d4526df8cc0538c (patch)
tree7add71d4abb318028e1513e578d3e34d7895dfee
parent7f27c60c636ff4ea63de11229bb5fe842e4e3ca7 (diff)
downloadsvn2git-1a41c9661e837e2463c492693d4526df8cc0538c.tar
svn2git-1a41c9661e837e2463c492693d4526df8cc0538c.tar.gz
svn2git-1a41c9661e837e2463c492693d4526df8cc0538c.tar.bz2
svn2git-1a41c9661e837e2463c492693d4526df8cc0538c.tar.xz
svn2git-1a41c9661e837e2463c492693d4526df8cc0538c.zip
Add support for default values in variable substitutions.
If there is no variable 'foo' set, ${foo} exits with a fatal error. With this patch, you can use ${foo|sometext}, which will substitute to 'sometext' if the variable 'foo' isn't set. The default text may be empty.
-rw-r--r--src/ruleparser.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp
index f4c7387..eb309bf 100644
--- a/src/ruleparser.cpp
+++ b/src/ruleparser.cpp
@@ -98,7 +98,7 @@ void Rules::load(const QString &filename)
QRegExp matchAnnotateLine("annotated\\s+(\\S+)", Qt::CaseInsensitive);
QRegExp matchPrefixLine("prefix\\s+(\\S+)", Qt::CaseInsensitive);
QRegExp declareLine("declare\\s+("+varRegex+")\\s*=\\s*(\\S+)", Qt::CaseInsensitive);
- QRegExp variableLine("\\$\\{("+varRegex+")\\}", Qt::CaseInsensitive);
+ QRegExp variableLine("\\$\\{("+varRegex+")(\\|[^}$]*)?\\}", Qt::CaseInsensitive);
QRegExp includeLine("include\\s+(.*)", Qt::CaseInsensitive);
enum { ReadingNone, ReadingRepository, ReadingMatch } state = ReadingNone;
@@ -133,9 +133,17 @@ void Rules::load(const QString &filename)
load(includeFile);
} else {
while( variableLine.indexIn(line) != -1 ) {
- if (!m_variables.contains(variableLine.cap(1)))
- qFatal("Undeclared variable: %s", qPrintable(variableLine.cap(1)));
- line = line.replace(variableLine, m_variables[variableLine.cap(1)]);
+ QString replacement;
+ if (m_variables.contains(variableLine.cap(1))) {
+ replacement = m_variables[variableLine.cap(1)];
+ } else {
+ if (variableLine.cap(2).startsWith('|')) {
+ replacement = variableLine.cap(2).mid(1);
+ } else {
+ qFatal("Undeclared variable: %s", qPrintable(variableLine.cap(1)));
+ }
+ }
+ line = line.replace(variableLine, replacement);
}
if (state == ReadingRepository) {
if (matchBranchLine.exactMatch(line)) {