]> andersk Git - svn-all-fast-export.git/blobdiff - src/repository.cpp
add some more information to the output
[svn-all-fast-export.git] / src / repository.cpp
index bd229f0bccfbccacc240d3ac3c8aa6760df15a1c..1c7f8ba30605abad3cef1d37b4b4bb8ea1237e15 100644 (file)
 
 #include "repository.h"
 #include <QTextStream>
+#include <QDebug>
 
 Repository::Repository(const Rules::Repository &rule)
+    : name(rule.name)
 {
     foreach (Rules::Repository::Branch branchRule, rule.branches) {
         Branch branch;
         branch.branchFrom = branchRule.branchFrom;
+        if (!branch.branchFrom.startsWith("refs/heads/"))
+            branch.branchFrom.prepend("refs/heads/");
         branch.isCreated = false;
 
         branches.insert(branchRule.name, branch);
     }
 
-    fastImport.setWorkingDirectory(rule.name);
+    // create the default branch
+    branches["master"].isCreated = true;
+
+    fastImport.setWorkingDirectory(name);
     fastImport.setProcessChannelMode(QProcess::ForwardedChannels);
 }
 
 Repository::~Repository()
 {
-    if (fastImport.state() == QProcess::Running) {
+    if (fastImport.state() != QProcess::NotRunning) {
         fastImport.closeWriteChannel();
         fastImport.waitForFinished();
     }
 }
 
+void Repository::reloadBranches()
+{
+    QHash<QString, Branch>::Iterator it = branches.begin(),
+                                    end = branches.end();
+    for ( ; it != end; ++it) {
+        QString branchRef = it.key();
+        if (!branchRef.startsWith("refs/heads/"))
+            branchRef.prepend("refs/heads/");
+
+        bool branchExists;
+        // does this branch already exist?
+        QProcess revParse;
+        revParse.setWorkingDirectory(name);
+        revParse.start("git-rev-parse", QStringList() << "--verify" << branchRef);
+        revParse.waitForFinished();
+
+        if (revParse.exitCode() == 0)
+            branchExists = true;
+        else
+            branchExists = false;
+
+        if (branchExists) {
+            startFastImport();
+            fastImport.write("reset " + branchRef.toUtf8() +
+                             "\nfrom " + branchRef.toUtf8() + "^0\n\n");
+            it->isCreated = true;
+        }
+    }
+}
+
 Repository::Transaction *Repository::newTransaction(const QString &branch, const QString &svnprefix,
                                                     int revnum)
 {
-    if (!branches.contains(branch))
+    if (!branches.contains(branch)) {
+        qCritical() << branch << "is not a known branch in repository" << name;
         return 0;
+    }
 
     Transaction *txn = new Transaction;
     txn->repository = this;
@@ -54,6 +93,12 @@ Repository::Transaction *Repository::newTransaction(const QString &branch, const
     txn->revnum = revnum;
     txn->lastmark = revnum;
 
+    startFastImport();
+    return txn;
+}
+
+void Repository::startFastImport()
+{
     if (fastImport.state() == QProcess::NotRunning) {
         // start the process
 #ifndef DRY_RUN
@@ -62,8 +107,6 @@ Repository::Transaction *Repository::newTransaction(const QString &branch, const
         fastImport.start("/bin/cat", QStringList());
 #endif
     }
-
-    return txn;
 }
 
 Repository::Transaction::~Transaction()
@@ -115,7 +158,7 @@ void Repository::Transaction::commit()
     QByteArray message = log;
     if (!message.endsWith('\n'))
         message += '\n';
-    message += "\nsvn=" + svnprefix + "; revision=" + QByteArray::number(revnum) + "\n";
+    message += "\nsvn path=" + svnprefix + "; revision=" + QByteArray::number(revnum) + "\n";
 
     {
         QByteArray branchRef = branch;
@@ -125,7 +168,7 @@ void Repository::Transaction::commit()
         QTextStream s(&repository->fastImport);
         s << "commit " << branchRef << endl;
         s << "mark :" << revnum << endl;
-        s << "committer " << author << ' ' << datetime << "-0000" << endl;
+        s << "committer " << author << ' ' << datetime << " -0000" << endl;
 
         Branch &br = repository->branches[branch];
         if (!br.isCreated) {
This page took 1.375075 seconds and 4 git commands to generate.