on master help sign in
Check that the last vertex of a linear graph should be the head vertex
commite7e65accb6cc3105491c99c41f04aa8cba8f4cbc authorSridhar Ratnakumar <srid@srid.ca> dateMon 25 Jun 2018, 13:03 (8 years ago) parent4728540
4 files changed+22−19
lib/command/src/Obelisk/Command/Upgrade.hs+13−12 lib/migration/src/Obelisk/Migration.hs+9−7 migration/59742705e53838ae13066a2239a72040-95955d1dd0981ebb538ee941cde1f963/obelisk-handoff migration/59742705e53838ae13066a2239a72040-95955d1dd0981ebb538ee941cde1f963/obelisk-upgrade
lib/command/src/Obelisk/Command/Upgrade.hs+13−12
@@ -189,24 +189,25 @@ verifyMigration obDir = do
189189 getMigrationGraph @Text obDir MigrationGraph_ObeliskUpgrade
190190 withSpinner "Checking graph integrity" $
191191 ensureGraphIntegrity upgradeGraph
192− withSpinner "Checking graph is linear" $
193− -- We don't support merge commits (i.e., diamonds in a graph) yet.
194− -- Until we do, ensure that the graph is a linear list.
195− try (ensureGraphLinearity upgradeGraph) >>= \case
196− Left (NonLinearGraph_MultipleAdjacents vertex) ->
197− failWith $ "Graph is not linear; branches at vertex: " <> tshow vertex
198− Left (NonLinearGraph_NotConnected isolatedVertices) ->
199− failWith $ "Graph is partly linear, but with isolated vertices: " <> tshow isolatedVertices
200− Right () ->
201− pure ()
202− liftIO (doesDirectoryExist $ obDir </> ".git") >>= \case
192+ headVertex <- liftIO (doesDirectoryExist $ obDir </> ".git") >>= \case
203193 True ->
204194 withSpinner "Checking existence of HEAD vertex" $
205− void $ getHeadVertex obDir
195+ getHeadVertex obDir
206196 False -> do
207197 hash <- computeVertexHash obDir
208198 unless (hasVertex hash upgradeGraph) $
209199 failWith $ "No vertex found for obelisk hash " <> hash
200+ pure hash
201+ withSpinner "Checking graph linearity" $
202+ -- NOTE: We don't support merge commits (i.e., diamonds in a graph) yet.
203+ -- Until we do, ensure that the graph is a fully connected linear list.
204+ try (ensureGraphLinearity upgradeGraph) >>= \case
205+ Left (NonLinearGraph_MultipleAdjacents vertex) ->
206+ failWith $ "Graph is not linear; branches at vertex: " <> tshow vertex
207+ Left (NonLinearGraph_NotConnected isolatedVertices) ->
208+ failWith $ "Graph is partly linear, with isolated vertices: " <> tshow isolatedVertices
209+ Right lastVertex -> unless (lastVertex == headVertex) $
210+ failWith $ "Graph is linear, but its last vertex (" <> lastVertex <> ") is different from head vertex (" <> headVertex <> ")"
210211
211212-- | Create an edge from HEAD vertex to the hash corresponding to the Git
212213-- working copy. The HEAD vertex must already exist.
lib/migration/src/Obelisk/Migration.hs+9−7
@@ -134,22 +134,24 @@ ensureGraphIntegrity m = do
134134 visitFrom mempty mempty firstVertex
135135
136136-- | Ensure that the graph is a fully connected linear list
137−ensureGraphLinearity :: MonadThrow m => Migration action -> m ()
137+--
138+-- Returns the last vertex in the linear list.
139+ensureGraphLinearity :: MonadThrow m => Migration action -> m Hash
138140ensureGraphLinearity m = do
139141 graph <- fmap adjacencyMap $ getDag $ _migration_graph m
140142 firstVertex <- getFirst $ _migration_graph m
141143 let
144+ allVertices = vertexSet $ _migration_graph m
142145 visitFrom start = case Map.lookup start graph of
143146 Nothing -> throwM $ GraphInternalError $ "Vertex not found: " <> start
144147 Just adjs -> case (Set.toList adjs) of
145− [] -> [start]
146− [adj] -> start : visitFrom adj
148+ [] -> pure (start, [start])
149+ [adj] -> fmap (start :) <$> visitFrom adj
147150 _ -> throwM $ NonLinearGraph_MultipleAdjacents start
148− visitedVertices = Set.fromList $ visitFrom firstVertex
149− allVertices = vertexSet $ _migration_graph m
150− unvisitedVertices = Set.difference allVertices visitedVertices
151+ (lastVertex, visitedVertices) <- visitFrom firstVertex
152+ let unvisitedVertices = Set.difference allVertices $ Set.fromList visitedVertices
151153 if Set.null unvisitedVertices
152− then pure ()
154+ then pure lastVertex
153155 else throwM $ NonLinearGraph_NotConnected unvisitedVertices
154156
155157-- | Find the concatenated actions between two vertices
migration/59742705e53838ae13066a2239a72040-95955d1dd0981ebb538ee941cde1f963/obelisk-handoffnew file

No changes to the content.

migration/59742705e53838ae13066a2239a72040-95955d1dd0981ebb538ee941cde1f963/obelisk-upgradenew file

No changes to the content.