]> andersk Git - svn-all-fast-export.git/blobdiff - src/repository.cpp
s,/,_, in the output filenames in dry-run mode
[svn-all-fast-export.git] / src / repository.cpp
index 05f01e15b0e745e559cd1d93c27f9edd72352573..cd2b4140f7538f755e3e08b0055748cefeab52f0 100644 (file)
@@ -24,9 +24,6 @@ Repository::Repository(const Rules::Repository &rule)
 {
     foreach (Rules::Repository::Branch branchRule, rule.branches) {
         Branch branch;
-        branch.branchFrom = branchRule.branchFrom;
-        if (!branch.branchFrom.startsWith("refs/"))
-            branch.branchFrom.prepend("refs/heads/");
         branch.isCreated = false;
 
         branches.insert(branchRule.name, branch);
@@ -76,6 +73,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)
 {
@@ -104,7 +131,9 @@ void Repository::startFastImport()
         fastImport.setProcessChannelMode(QProcess::ForwardedChannels);
         fastImport.start("git-fast-import", QStringList());
 #else
-        fastImport.setStandardOutputFile(name);
+        QString outputFile = name;
+        outputFile.replace('/', '_');
+        fastImport.setStandardOutputFile(outputFile);
         fastImport.start("/bin/cat", QStringList());
 #endif
     }
@@ -174,7 +203,6 @@ void Repository::Transaction::commit()
         Branch &br = repository->branches[branch];
         if (!br.isCreated) {
             br.isCreated = true;
-            s << "from " << br.branchFrom << endl;
         }
 
         s << "data " << message.length() << endl;
This page took 0.044313 seconds and 4 git commands to generate.