aboutsummaryrefslogtreecommitdiffstats
path: root/src/repository.cpp
diff options
context:
space:
mode:
authorRaja R Harinath <harinath@hurrynot.org>2010-07-21 00:43:22 +0530
committerRaja R Harinath <harinath@hurrynot.org>2010-07-21 00:47:39 +0530
commita159decede356e9d72a74ea38d31ed251ce408e9 (patch)
treed3062335794f09d22f33f521d0bc871d7a22614d /src/repository.cpp
parent851fc6e50d0f30f9f42dcd2f9e3de8b23357b560 (diff)
downloadsvn2git-a159decede356e9d72a74ea38d31ed251ce408e9.tar
svn2git-a159decede356e9d72a74ea38d31ed251ce408e9.tar.gz
svn2git-a159decede356e9d72a74ea38d31ed251ce408e9.tar.bz2
svn2git-a159decede356e9d72a74ea38d31ed251ce408e9.tar.xz
svn2git-a159decede356e9d72a74ea38d31ed251ce408e9.zip
Carve out Repository::markFrom from createBranch(), and noteCopyFromBranch()
Put the slightly tricky qUpperBound logic in only one place.
Diffstat (limited to 'src/repository.cpp')
-rw-r--r--src/repository.cpp84
1 files changed, 41 insertions, 43 deletions
diff --git a/src/repository.cpp b/src/repository.cpp
index d70119b..48358e7 100644
--- a/src/repository.cpp
+++ b/src/repository.cpp
@@ -270,8 +270,32 @@ void Repository::reloadBranches()
}
}
+int Repository::markFrom(const QString &branchFrom, int branchRevNum, QByteArray &branchFromDesc)
+{
+ Branch &brFrom = branches[branchFrom];
+ if (!brFrom.created)
+ return -1;
+
+ if (branchRevNum == brFrom.commits.last())
+ return brFrom.marks.last();
+
+ QVector<int>::const_iterator it = qUpperBound(brFrom.commits, branchRevNum);
+ if (it == brFrom.commits.begin())
+ return 0;
+
+ int closestCommit = *--it;
+
+ if (!branchFromDesc.isEmpty()) {
+ branchFromDesc += " at r" + QByteArray::number(branchRevNum);
+ if (closestCommit != branchRevNum)
+ branchFromDesc += " => r" + QByteArray::number(closestCommit);
+ }
+
+ return brFrom.marks[it - brFrom.commits.begin()];
+}
+
int Repository::createBranch(const QString &branch, int revnum,
- const QString &branchFrom, int branchRevNum)
+ const QString &branchFrom, int branchRevNum)
{
startFastImport();
if (!branches.contains(branch)) {
@@ -279,29 +303,16 @@ int Repository::createBranch(const QString &branch, int revnum,
<< "Going to create it automatically";
}
- Branch &brFrom = branches[branchFrom];
- if (!brFrom.created) {
+ QByteArray branchFromDesc = "from branch " + branchFrom.toUtf8();
+ int mark = markFrom(branchFrom, branchRevNum, branchFromDesc);
+
+ if (mark == -1) {
qCritical() << branch << "in repository" << name
<< "is branching from branch" << branchFrom
<< "but the latter doesn't exist. Can't continue.";
return EXIT_FAILURE;
}
- int mark = 0;
- QByteArray branchFromDesc = "from branch " + branchFrom.toUtf8();
- if (branchRevNum == brFrom.commits.last()) {
- mark = brFrom.marks.last();
- } else {
- QVector<int>::const_iterator it = qUpperBound(brFrom.commits, branchRevNum);
- if (it != brFrom.commits.begin()) {
- int closestCommit = *--it;
- mark = brFrom.marks[it - brFrom.commits.begin()];
- branchFromDesc += " at r" + QByteArray::number(branchRevNum);
- if (closestCommit != branchRevNum)
- branchFromDesc += " => r" + QByteArray::number(closestCommit);
- }
- }
-
QByteArray branchFromRef = ":" + QByteArray::number(mark);
if (!mark) {
qWarning() << branch << "in repository" << name << "is branching but no exported commits exist in repository"
@@ -489,37 +500,24 @@ void Repository::Transaction::setLog(const QByteArray &l)
log = l;
}
-void Repository::Transaction::noteCopyFromBranch (const QString &branchFrom, int branchRevNum)
+void Repository::Transaction::noteCopyFromBranch(const QString &branchFrom, int branchRevNum)
{
- Branch &brFrom = repository->branches[branchFrom];
- if (!brFrom.created) {
+ static QByteArray dummy;
+ int mark = repository->markFrom(branchFrom, branchRevNum, dummy);
+ Q_ASSERT(dummy.isEmpty());
+
+ if (mark == -1) {
qWarning() << branch << "is copying from branch" << branchFrom
<< "but the latter doesn't exist. Continuing, assuming the files exist.";
- return;
- }
-
- int mark = 0;
-
- if (branchRevNum == brFrom.commits.last()) {
- mark = brFrom.marks.last();
- } else {
- QVector<int>::const_iterator it = qUpperBound(brFrom.commits, branchRevNum);
- if (it != brFrom.commits.begin()) {
- --it;
- mark = brFrom.marks[it - brFrom.commits.begin()];
- }
- }
-
- if (!mark) {
+ } else if (mark == 0) {
qWarning() << "Unknown revision r" << QByteArray::number(branchRevNum)
<< ". Continuing, assuming the files exist.";
- return;
- }
-
- qWarning() << "repository " + repository->name + " branch " + branch + " has some files copied from " + branchFrom + "@" + QByteArray::number(branchRevNum);
+ } else {
+ qWarning() << "repository " + repository->name + " branch " + branch + " has some files copied from " + branchFrom + "@" + QByteArray::number(branchRevNum);
- if (!merges.contains(mark))
- merges.append(mark);
+ if (!merges.contains(mark))
+ merges.append(mark);
+ }
}
void Repository::Transaction::deleteFile(const QString &path)