]> andersk Git - svn-all-fast-export.git/blobdiff - src/repository.cpp
Add support for branch creation on-the-fly
[svn-all-fast-export.git] / src / repository.cpp
index 05f01e15b0e745e559cd1d93c27f9edd72352573..08a5306fa6a10722c0fcefd357b94fb9dd5abfad 100644 (file)
@@ -76,6 +76,36 @@ void Repository::reloadBranches()
     }
 }
 
+void Repository::createBranch(const QString &branch, int revnum,
+                              const QString &branchFrom, int)
+{
+    if (!branches.contains(branch)) {
+        qCritical() << branch << "is not a known branch in repository" << name;
+        exit(1);
+    }
+
+    startFastImport();
+    QByteArray branchRef = branch.toUtf8();
+    if (!branchRef.startsWith("refs/"))
+        branchRef.prepend("refs/heads/");
+
+    Branch &br = branches[branch];
+    if (br.isCreated) {
+        QByteArray backupBranch = branchRef + '_' + QByteArray::number(revnum);
+        qWarning() << branch << "already exists; backing up to" << backupBranch;
+
+        fastImport.write("reset " + backupBranch + "\nfrom " + branchRef + "\n\n");
+    }
+
+    // now create the branch
+    br.isCreated = true;
+    QByteArray branchFromRef = branchFrom.toUtf8();
+    if (!branchFromRef.startsWith("refs/"))
+        branchFromRef.prepend("refs/heads/");
+
+    fastImport.write("reset " + branchRef + "\nfrom " + branchFromRef + "\n\n");
+}
+
 Repository::Transaction *Repository::newTransaction(const QString &branch, const QString &svnprefix,
                                                     int revnum)
 {
This page took 0.043183 seconds and 4 git commands to generate.