]> andersk Git - svn-all-fast-export.git/commitdiff
Add support for resuming work
authorThiago Macieira <thiago@cassini.local.lan>
Mon, 24 Dec 2007 13:11:50 +0000 (11:11 -0200)
committerThiago Macieira <thiago@cassini.local.lan>
Mon, 24 Dec 2007 13:11:50 +0000 (11:11 -0200)
src/main.cpp
src/repository.cpp
src/repository.h

index a8f4069fb217f38a55d6519cf7140926398c8d30..2ce11c592e0c86c18d3de69f6578319328eab4f1 100644 (file)
@@ -36,10 +36,18 @@ int main(int argc, char **argv)
     Rules rules(options.ruleFile);
     rules.load();
 
+    int min_rev = options.options.value("resume-from").toInt();
+    if (min_rev < 1)
+        min_rev = 1;
+
     // create the repository list
     QHash<QString, Repository *> repositories;
-    foreach (Rules::Repository rule, rules.repositories())
-        repositories.insert(rule.name, new Repository(rule));
+    foreach (Rules::Repository rule, rules.repositories()) {
+        Repository *repo = new Repository(rule);
+        if (min_rev > 1)
+            repo->reloadBranches();
+        repositories.insert(rule.name, repo);
+    }
 
     Svn::initialize();
     Svn svn(options.pathToRepository);
@@ -47,7 +55,7 @@ int main(int argc, char **argv)
     svn.setRepositories(repositories);
 
     int max_rev = svn.youngestRevision();
-    for (int i = 1; i <= max_rev; ++i)
+    for (int i = min_rev; i <= max_rev; ++i)
         if (!svn.exportRevision(i))
             break;
 
index 8a5f4f0c91eccc3d200a96c9069fcf038dd36dcd..c3f52fb1e4e815a73a74708ffa82ceb1d808c6b5 100644 (file)
@@ -33,7 +33,7 @@ Repository::Repository(const Rules::Repository &rule)
     // create the default branch
     branches["master"].isCreated = true;
 
-    fastImport.setWorkingDirectory(rule.name);
+    fastImport.setWorkingDirectory(name);
     fastImport.setProcessChannelMode(QProcess::ForwardedChannels);
 }
 
@@ -45,6 +45,36 @@ Repository::~Repository()
     }
 }
 
+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");
+            it->isCreated = true;
+        }
+    }
+}
+
 Repository::Transaction *Repository::newTransaction(const QString &branch, const QString &svnprefix,
                                                     int revnum)
 {
@@ -61,6 +91,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
@@ -69,8 +105,6 @@ Repository::Transaction *Repository::newTransaction(const QString &branch, const
         fastImport.start("/bin/cat", QStringList());
 #endif
     }
-
-    return txn;
 }
 
 Repository::Transaction::~Transaction()
index 60c2aedda1815e3ee7ee73698cf7c78e5b4b8ba8..4160d3faf9a3ba48b255edde2c64a2e3a2bacf18 100644 (file)
@@ -62,6 +62,7 @@ public:
     Repository(const Rules::Repository &rule);
     ~Repository();
 
+    void reloadBranches();
     Transaction *newTransaction(const QString &branch, const QString &svnprefix, int revnum);
 
 private:
@@ -75,6 +76,8 @@ private:
     QString name;
     QProcess fastImport;
 
+    void startFastImport();
+
     Q_DISABLE_COPY(Repository)
 };
 
This page took 0.03631 seconds and 5 git commands to generate.