                     // Save the manager state.
                     self.serialQueue.sync {
                         do {
+                            // Update the serialized repositories map.
+                            //
+                            // We do this so we don't have to read the other
+                            // handles when saving the sate of this handle.
+                            self.serializedRepositories[repository.url] = handle.toJSON()
                             try self.persistence.saveState(self)
                         } catch {
                             // FIXME: Handle failure gracefully, somehow.

    // full specifier but then is capable of efficiently determining if two
    // repositories map to the same location.
    fileprivate var repositories: [String: RepositoryHandle] = [:]

    /// Queue to protect concurrent reads and mutations to repositories registery.
    private let serialQueue = DispatchQueue(label: "org.swift.swiftpm.repomanagerqueue-serial")

extension RepositoryManager: SimplePersistanceProtocol {

    public func restore(from json: JSON) throws {
        // Update the serialized repositories.
        //
        // We will use this to save the state so we don't have to read the other
        // handles when saving the sate of a handle.
        self.serializedRepositories = try json.get("repositories")
        self.repositories = try Dictionary(items: serializedRepositories.map({
            try ($0.0, RepositoryHandle(manager: self, json: $0.1))
        }))
    }

    public func toJSON() -> JSON {
        return JSON(["repositories": JSON(self.serializedRepositories)])
    }
}

