about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libstore/store.cc12
-rw-r--r--src/libstore/store.hh4
-rw-r--r--src/nix-store/main.cc8
3 files changed, 13 insertions, 11 deletions
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index 74f182468a5d..9c5d0bab8aae 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -302,19 +302,16 @@ static void writeSubstitutes(const Transaction & txn,
 }
 
 
-void registerSubstitute(const Path & srcPath,
-    const Substitute & sub)
+void registerSubstitute(const Transaction & txn,
+    const Path & srcPath, const Substitute & sub)
 {
     assertStorePath(srcPath);
     assertStorePath(sub.storeExpr);
     
-    Transaction txn(nixDB);
-
     Substitutes subs = readSubstitutes(txn, srcPath);
 
     if (find(subs.begin(), subs.end(), sub) != subs.end()) {
         /* Nothing to do if the substitute is already known. */
-        txn.abort();
         return;
     }
     subs.push_front(sub); /* new substitutes take precedence */
@@ -325,10 +322,9 @@ void registerSubstitute(const Path & srcPath,
     nixDB.queryStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
     if (find(revs.begin(), revs.end(), srcPath) == revs.end())
         revs.push_back(srcPath);
-    
-    nixDB.setStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
 
-    txn.commit();
+    // !!! O(n^2) complexity in building this
+    //    nixDB.setStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
 }
 
 
diff --git a/src/libstore/store.hh b/src/libstore/store.hh
index e09a4a94b70d..40d1859e533d 100644
--- a/src/libstore/store.hh
+++ b/src/libstore/store.hh
@@ -63,8 +63,8 @@ bool querySuccessor(const Path & srcPath, Path & sucPath);
 Paths queryPredecessors(const Path & sucPath);
 
 /* Register a substitute. */
-void registerSubstitute(const Path & srcPath,
-    const Substitute & sub);
+void registerSubstitute(const Transaction & txn,
+    const Path & srcPath, const Substitute & sub);
 
 /* Return the substitutes expression for the given path. */
 Substitutes querySubstitutes(const Path & srcPath);
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index 79d65c4be5d5..4df736911cae 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -170,6 +170,9 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
     if (!opArgs.empty())
         throw UsageError("no arguments expected");
 
+    Transaction txn;
+    createStoreTransaction(txn);
+
     while (1) {
         Path srcPath;
         Substitute sub;
@@ -188,8 +191,11 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
             sub.args.push_back(s);
         }
         if (!cin || cin.eof()) throw Error("missing input");
-        registerSubstitute(srcPath, sub);
+        cerr << ".";
+        registerSubstitute(txn, srcPath, sub);
     }
+
+    txn.commit();
 }