From c99f14df097f72394a6bb9c8ae9130cd8cb86cf1 Mon Sep 17 00:00:00 2001 From: Raja R Harinath Date: Sun, 20 Jun 2010 19:15:39 +0530 Subject: Track commits per-branch Previously, all the SVN commits were tracked in a linear array, and we searched for nearest commits in that array. However, SVN history is not linear, and the 'next smallest commit' search was picking the wrong commit. I've moved the commit array into the 'Branch' structure. As a minor subtlety, the branch creation revision is also noted in the 'commitMarks' structure, by copying the commit mark of the branch point. We need this to ensure that the commits array is strictly non-decreasing. --- src/repository.cpp | 28 ++++++++++++++++------------ src/repository.h | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/repository.cpp b/src/repository.cpp index 06ac2f6..c786a71 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -140,7 +140,6 @@ void Repository::createBranch(const QString &branch, int revnum, if (!branchRef.startsWith("refs/")) branchRef.prepend("refs/heads/"); - Branch &br = branches[branch]; if (br.created && br.created != revnum) { QByteArray backupBranch = branchRef + '_' + QByteArray::number(revnum); @@ -149,15 +148,27 @@ void Repository::createBranch(const QString &branch, int revnum, fastImport.write("reset " + backupBranch + "\nfrom " + branchRef + "\n\n"); } + Branch &brFrom = branches[branchFrom]; + if (!brFrom.created) { + qCritical() << branch << "in repository" << name + << "is branching from branch" << branchFrom + << "but the latter doesn't exist. Can't continue."; + exit(1); + } + // now create the branch br.created = revnum; + br.commits.append(revnum); + QByteArray branchFromRef, branchFromDesc; - QVector::iterator it = qUpperBound(exportedCommits, branchRevNum); - const int closestCommit = it == exportedCommits.begin() ? branchRevNum : *--it; + QVector::iterator it = qUpperBound(brFrom.commits, branchRevNum); + const int closestCommit = it == brFrom.commits.begin() ? branchRevNum : *--it; if(commitMarks.contains(closestCommit)) { - branchFromRef = ":" + QByteArray::number(commitMarks.value(closestCommit)); + int mark = commitMarks[closestCommit]; + branchFromRef = ":" + QByteArray::number(mark); branchFromDesc = branchFromRef + " (r" + QByteArray::number(closestCommit) + ")"; + commitMarks[revnum] = mark; } else { qWarning() << branch << "in repository" << name << "is branching but no exported commits exist in repository" << "creating an empty branch."; @@ -167,13 +178,6 @@ void Repository::createBranch(const QString &branch, int revnum, branchFromDesc = branchFromRef; } - if (!branches.contains(branchFrom) || !branches.value(branchFrom).created) { - qCritical() << branch << "in repository" << name - << "is branching from branch" << branchFrom - << "but the latter doesn't exist. Can't continue."; - exit(1); - } - fastImport.write("reset " + branchRef + "\nfrom " + branchFromRef + "\n\n" "progress Branch " + branchRef + " created from " + branchFromDesc + " r" + QByteArray::number(branchRevNum) + "\n\n"); @@ -369,7 +373,6 @@ void Repository::Transaction::commit() s << "commit " << branchRef << endl; s << "mark :" << QByteArray::number(++repository->lastmark) << endl; repository->commitMarks.insert(revnum, repository->lastmark); - repository->exportedCommits.append(revnum); s << "committer " << QString::fromUtf8(author) << ' ' << datetime << " -0000" << endl; Branch &br = repository->branches[branch]; @@ -378,6 +381,7 @@ void Repository::Transaction::commit() << revnum << "-- did you resume from the wrong revision?"; br.created = revnum; } + br.commits.append(revnum); s << "data " << message.length() << endl; } diff --git a/src/repository.h b/src/repository.h index 629616b..3df9d9a 100644 --- a/src/repository.h +++ b/src/repository.h @@ -72,6 +72,7 @@ private: struct Branch { int created; + QVector commits; }; struct AnnotatedTag { @@ -86,7 +87,6 @@ private: QHash branches; QHash annotatedTags; QHash commitMarks; - QVector exportedCommits; QString name; QProcess fastImport; int commitCount; -- cgit v1.2.1