on master help sign in
Check that the last vertex of a linear graph should be the head vertex
e7e65acSridhar Ratnakumar
lib/command/src/Obelisk/Command/Upgrade.hs+13−12
@@ -189,24 +189,25 @@ verifyMigration obDir = do
189 getMigrationGraph @Text obDir MigrationGraph_ObeliskUpgrade
189 getMigrationGraph @Text obDir MigrationGraph_ObeliskUpgrade
190 withSpinner "Checking graph integrity" $
190 withSpinner "Checking graph integrity" $
191 ensureGraphIntegrity upgradeGraph
191 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
203 True ->
193 True ->
204 withSpinner "Checking existence of HEAD vertex" $
194 withSpinner "Checking existence of HEAD vertex" $
205− void $ getHeadVertex obDir
195+ getHeadVertex obDir
206 False -> do
196 False -> do
207 hash <- computeVertexHash obDir
197 hash <- computeVertexHash obDir
208 unless (hasVertex hash upgradeGraph) $
198 unless (hasVertex hash upgradeGraph) $
209 failWith $ "No vertex found for obelisk hash " <> hash
199 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 <> ")"
210
211
211-- | Create an edge from HEAD vertex to the hash corresponding to the Git
212-- | Create an edge from HEAD vertex to the hash corresponding to the Git
212-- working copy. The HEAD vertex must already exist.
213-- working copy. The HEAD vertex must already exist.
lib/migration/src/Obelisk/Migration.hs+9−7
@@ -134,22 +134,24 @@ ensureGraphIntegrity m = do
134 visitFrom mempty mempty firstVertex
134 visitFrom mempty mempty firstVertex
135
135
136-- | Ensure that the graph is a fully connected linear list
136-- | Ensure that the graph is a fully connected linear list
137+--
138+-- Returns the last vertex in the linear list.
137−ensureGraphLinearity :: MonadThrow m => Migration action -> m ()
139+ensureGraphLinearity :: MonadThrow m => Migration action -> m Hash
138ensureGraphLinearity m = do
140ensureGraphLinearity m = do
139 graph <- fmap adjacencyMap $ getDag $ _migration_graph m
141 graph <- fmap adjacencyMap $ getDag $ _migration_graph m
140 firstVertex <- getFirst $ _migration_graph m
142 firstVertex <- getFirst $ _migration_graph m
141 let
143 let
144+ allVertices = vertexSet $ _migration_graph m
142 visitFrom start = case Map.lookup start graph of
145 visitFrom start = case Map.lookup start graph of
143 Nothing -> throwM $ GraphInternalError $ "Vertex not found: " <> start
146 Nothing -> throwM $ GraphInternalError $ "Vertex not found: " <> start
144 Just adjs -> case (Set.toList adjs) of
147 Just adjs -> case (Set.toList adjs) of
145− [] -> [start]
148+ [] -> pure (start, [start])
146− [adj] -> start : visitFrom adj
149+ [adj] -> fmap (start :) <$> visitFrom adj
147 _ -> throwM $ NonLinearGraph_MultipleAdjacents start
150 _ -> throwM $ NonLinearGraph_MultipleAdjacents start
148− visitedVertices = Set.fromList $ visitFrom firstVertex
151+ (lastVertex, visitedVertices) <- visitFrom firstVertex
149− allVertices = vertexSet $ _migration_graph m
150− unvisitedVertices = Set.difference allVertices visitedVertices
152+ let unvisitedVertices = Set.difference allVertices $ Set.fromList visitedVertices
151 if Set.null unvisitedVertices
153 if Set.null unvisitedVertices
152− then pure ()
154+ then pure lastVertex
153 else throwM $ NonLinearGraph_NotConnected unvisitedVertices
155 else throwM $ NonLinearGraph_NotConnected unvisitedVertices
154
156
155-- | Find the concatenated actions between two vertices
157-- | 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.