diff options
author | Torgny Nyblom <kde@nyblom.org> | 2010-09-10 12:30:12 +0200 |
---|---|---|
committer | Torgny Nyblom <kde@nyblom.org> | 2010-09-10 12:30:12 +0200 |
commit | 83b44874c5b380f3bf5e284ac1e46dddadda9594 (patch) | |
tree | 7e0c0733f8606d77e5e787e71fa22b7103422372 /src | |
parent | 984b474b891dba0113dd157e778bbd113cf6ecd8 (diff) | |
download | svn2git-83b44874c5b380f3bf5e284ac1e46dddadda9594.tar svn2git-83b44874c5b380f3bf5e284ac1e46dddadda9594.tar.gz svn2git-83b44874c5b380f3bf5e284ac1e46dddadda9594.tar.bz2 svn2git-83b44874c5b380f3bf5e284ac1e46dddadda9594.tar.xz svn2git-83b44874c5b380f3bf5e284ac1e46dddadda9594.zip |
Add posibility to use variables in rule files
"declare var=value"
now "${var}" in any line will be replaced by "value"
Diffstat (limited to 'src')
-rw-r--r-- | src/ruleparser.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp index 07269c1..10a22ac 100644 --- a/src/ruleparser.cpp +++ b/src/ruleparser.cpp @@ -82,6 +82,10 @@ void Rules::load() QRegExp matchRevLine("(min|max) revision (\\d+)", Qt::CaseInsensitive); QRegExp matchAnnotateLine("annotated\\s+(\\S+)", Qt::CaseInsensitive); QRegExp matchPrefixLine("prefix\\s+(\\S+)", Qt::CaseInsensitive); + QRegExp declareLine("declare\\s+(\\S+)\\s*=\\s*(\\S+)", Qt::CaseInsensitive); + QRegExp variableLine("\\$\\{(\\S+)\\}", Qt::CaseInsensitive); + + QMap<QString,QString> variables; enum { ReadingNone, ReadingRepository, ReadingMatch } state = ReadingNone; Repository repo; @@ -101,6 +105,12 @@ void Rules::load() if (line.isEmpty()) continue; + int index = variableLine.indexIn(line); + if ( index != -1 ) { + if (!variables.contains(variableLine.cap(1))) + qFatal("Undeclared variable: %s", qPrintable(variableLine.cap(1))); + line = line.replace(variableLine, variables[variableLine.cap(1)]); + } if (state == ReadingRepository) { if (matchBranchLine.exactMatch(line)) { Repository::Branch branch; @@ -169,6 +179,7 @@ void Rules::load() bool isRepositoryRule = repoLine.exactMatch(line); bool isMatchRule = matchLine.exactMatch(line); + bool isVariableRule = declareLine.exactMatch(line); if (isRepositoryRule) { // repository rule @@ -182,6 +193,10 @@ void Rules::load() match = Match(); match.rx = QRegExp(matchLine.cap(1), Qt::CaseSensitive, QRegExp::RegExp2); match.lineNumber = lineNumber; + } else if (isVariableRule) { + QString variable = declareLine.cap(1); + QString value = declareLine.cap(2); + variables.insert(variable, value); } else { qFatal("Malformed line in rules file: line %d: %s", lineNumber, qPrintable(origLine)); |