Skip to content

Commit 4c241d5

Browse files
author
Torgny Nyblom
committed
Merge commit 'refs/merge-requests/12' of git://gitorious.org/svn2git/svn2git into merge-requests/12
Conflicts: src/ruleparser.cpp
2 parents e8a16c9 + c630dd7 commit 4c241d5

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/ruleparser.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,48 @@ const QList<Rules::Match> Rules::matchRules() const
7777
return m_matchRules;
7878
}
7979

80+
Rules::Match::Substitution Rules::parseSubstitution(const QString &string)
81+
{
82+
if (string.at(0) != 's' || string.length() < 5)
83+
return Match::Substitution();
84+
85+
const QChar sep = string.at(1);
86+
87+
if (string.at(string.length() - 1) != sep)
88+
return Match::Substitution();
89+
90+
int i = 2, end = 0;
91+
Match::Substitution subst;
92+
93+
// Separator might have been escaped with a backslash
94+
while (i > end) {
95+
int backslashCount = 0;
96+
if ((end = string.indexOf(sep, i)) > -1) {
97+
for (i = end - 1; i >= 2; i--) {
98+
if (string.at(i) == '\\')
99+
backslashCount++;
100+
else
101+
break;
102+
}
103+
} else {
104+
return Match::Substitution(); // error
105+
}
106+
107+
if (backslashCount % 2 != 0) {
108+
// Separator was escaped. Search for another one
109+
i = end + 1;
110+
}
111+
}
112+
113+
// Found the end of the pattern
114+
subst.pattern = QRegExp(string.mid(2, end - 2));
115+
if (!subst.pattern.isValid())
116+
return Match::Substitution(); // error
117+
subst.replacement = string.mid(end + 1, string.length() - 1 - end - 1);
118+
119+
return subst;
120+
}
121+
80122
void Rules::load()
81123
{
82124
load(filename);
@@ -94,7 +136,9 @@ void Rules::load(const QString &filename)
94136
QRegExp matchActionLine("action\\s+(\\w+)", Qt::CaseInsensitive);
95137
QRegExp matchRepoLine("repository\\s+(\\S+)", Qt::CaseInsensitive);
96138
QRegExp matchDescLine("description\\s+(.+)$", Qt::CaseInsensitive);
139+
QRegExp matchRepoSubstLine("substitute repository\\s+(.+)$", Qt::CaseInsensitive);
97140
QRegExp matchBranchLine("branch\\s+(\\S+)", Qt::CaseInsensitive);
141+
QRegExp matchBranchSubstLine("substitute branch\\s+(.+)$", Qt::CaseInsensitive);
98142
QRegExp matchRevLine("(min|max) revision (\\d+)", Qt::CaseInsensitive);
99143
QRegExp matchAnnotateLine("annotated\\s+(\\S+)", Qt::CaseInsensitive);
100144
QRegExp matchPrefixLine("prefix\\s+(\\S+)", Qt::CaseInsensitive);
@@ -179,6 +223,22 @@ void Rules::load(const QString &filename)
179223
} else if (matchBranchLine.exactMatch(line)) {
180224
match.branch = matchBranchLine.cap(1);
181225
continue;
226+
} else if (matchRepoSubstLine.exactMatch(line)) {
227+
Match::Substitution subst = parseSubstitution(matchRepoSubstLine.cap(1));
228+
if (!subst.isValid()) {
229+
qFatal("Malformed substitution in rules file: line %d: %s",
230+
lineNumber, qPrintable(origLine));
231+
}
232+
match.repo_substs += subst;
233+
continue;
234+
} else if (matchBranchSubstLine.exactMatch(line)) {
235+
Match::Substitution subst = parseSubstitution(matchBranchSubstLine.cap(1));
236+
if (!subst.isValid()) {
237+
qFatal("Malformed substitution in rules file: line %d: %s",
238+
lineNumber, qPrintable(origLine));
239+
}
240+
match.branch_substs += subst;
241+
continue;
182242
} else if (matchRevLine.exactMatch(line)) {
183243
if (matchRevLine.cap(1) == "min")
184244
match.minRevision = matchRevLine.cap(2).toInt();

src/ruleparser.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,19 @@ class Rules
5858

5959
struct Match : Rule
6060
{
61+
struct Substitution {
62+
QRegExp pattern;
63+
QString replacement;
64+
65+
bool isValid() { return !pattern.isEmpty(); }
66+
QString& apply(QString &string) { return string.replace(pattern, replacement); }
67+
};
68+
6169
QRegExp rx;
6270
QString repository;
71+
QList<Substitution> repo_substs;
6372
QString branch;
73+
QList<Substitution> branch_substs;
6474
QString prefix;
6575
int minRevision;
6676
int maxRevision;
@@ -84,6 +94,7 @@ class Rules
8494

8595
const QList<Repository> repositories() const;
8696
const QList<Match> matchRules() const;
97+
Match::Substitution parseSubstitution(const QString &string);
8798
void load();
8899

89100
private:

src/svn.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,17 @@ static void splitPathName(const Rules::Match &rule, const QString &pathName, QSt
214214
if (repository_p) {
215215
*repository_p = svnprefix;
216216
repository_p->replace(rule.rx, rule.repository);
217+
foreach (Rules::Match::Substitution subst, rule.repo_substs) {
218+
subst.apply(*repository_p);
219+
}
217220
}
218221

219222
if (branch_p) {
220223
*branch_p = svnprefix;
221224
branch_p->replace(rule.rx, rule.branch);
225+
foreach (Rules::Match::Substitution subst, rule.branch_substs) {
226+
subst.apply(*branch_p);
227+
}
222228
}
223229

224230
if (path_p) {

0 commit comments

Comments
 (0)