From 4aa6db803febef30308f81e168a4d49146ebc8e4 Mon Sep 17 00:00:00 2001 From: Torgny Nyblom Date: Mon, 17 Jan 2011 10:30:21 +0100 Subject: Support ranges in the revisions file --- src/main.cpp | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 62a0612..6125171 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,27 +68,51 @@ QHash loadIdentityMapFile(const QString &fileName) return result; } -QSet loadRevisionsFile( const QString &fileName ) +QSet loadRevisionsFile( const QString &fileName, Svn &svn ) { + QRegExp revint("(\\d+)\\s*(?:-\\s*(\\d+|HEAD))?"); QSet revisions; if(fileName.isEmpty()) return revisions; QFile file(fileName); if( !file.open(QIODevice::ReadOnly)) { - fprintf(stderr, "Could not open file %s: %s", qPrintable(fileName), qPrintable(file.errorString())); + fprintf(stderr, "Could not open file %s: %s\n", qPrintable(fileName), qPrintable(file.errorString())); return revisions; } + bool ok; while(!file.atEnd()) { - QByteArray line = file.readLine(); - bool ok; - line = line.trimmed(); - int rev = line.toInt(&ok); - if(!ok) { - fprintf(stderr, "Unable to convert %s to int, skipping revision.", qPrintable(QString(line))); + QByteArray line = file.readLine().trimmed(); + revint.indexIn(line); + if( revint.cap(2).isEmpty() ) { + int rev = revint.cap(1).toInt(&ok); + if(ok) { + revisions.insert(rev); + } else { + fprintf(stderr, "Unable to convert %s to int, skipping revision.\n", qPrintable(QString(line))); + } + } else if( revint.captureCount() == 2 ) { + int rev = revint.cap(1).toInt(&ok); + if(!ok) { + fprintf(stderr, "Unable to convert %s (%s) to int, skipping revisions.\n", qPrintable(revint.cap(1)), qPrintable(QString(line))); + continue; + } + int lastrev = 0; + if(revint.cap(2) == "HEAD") { + lastrev = svn.youngestRevision(); + ok = true; + } else { + lastrev = revint.cap(2).toInt(&ok); + } + if(!ok) { + fprintf(stderr, "Unable to convert %s (%s) to int, skipping revisions.\n", qPrintable(revint.cap(2)), qPrintable(QString(line))); + continue; + } + for(; rev <= lastrev; ++rev ) + revisions.insert(rev); } else { - revisions.insert(rev); + fprintf(stderr, "Unable to convert %s to int, skipping revision.\n", qPrintable(QString(line))); } } file.close(); @@ -220,7 +244,7 @@ int main(int argc, char **argv) max_rev = svn.youngestRevision(); bool errors = false; - QSet revisions = loadRevisionsFile(args->optionArgument(QLatin1String("revisions-file"))); + QSet revisions = loadRevisionsFile(args->optionArgument(QLatin1String("revisions-file")), svn); const bool filerRevisions = !revisions.isEmpty(); for (int i = min_rev; i <= max_rev; ++i) { if(filerRevisions) { -- cgit v1.2.1