aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaja R Harinath <harinath@hurrynot.org>2010-06-20 19:15:39 +0530
committerRaja R Harinath <harinath@hurrynot.org>2010-06-20 20:13:01 +0530
commitc99f14df097f72394a6bb9c8ae9130cd8cb86cf1 (patch)
tree0eceba926ef4a5fbdfec7810cd0427f9eecb21a6
parent97657964b3c9ba5d5b45dced323a53c1e5d83b94 (diff)
downloadsvn2git-c99f14df097f72394a6bb9c8ae9130cd8cb86cf1.tar
svn2git-c99f14df097f72394a6bb9c8ae9130cd8cb86cf1.tar.gz
svn2git-c99f14df097f72394a6bb9c8ae9130cd8cb86cf1.tar.bz2
svn2git-c99f14df097f72394a6bb9c8ae9130cd8cb86cf1.tar.xz
svn2git-c99f14df097f72394a6bb9c8ae9130cd8cb86cf1.zip
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.
-rw-r--r--src/repository.cpp28
-rw-r--r--src/repository.h2
2 files changed, 17 insertions, 13 deletions
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<const int>::iterator it = qUpperBound(exportedCommits, branchRevNum);
- const int closestCommit = it == exportedCommits.begin() ? branchRevNum : *--it;
+ QVector<const int>::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<int> commits;
};
struct AnnotatedTag
{
@@ -86,7 +87,6 @@ private:
QHash<QString, Branch> branches;
QHash<QString, AnnotatedTag> annotatedTags;
QHash<int, int> commitMarks;
- QVector<int> exportedCommits;
QString name;
QProcess fastImport;
int commitCount;