on master help sign in
implement fast-forward commits when possible in ProjectM36.Client.autoMergeToHead

resolves #176 fix mistaken last commit

commitc02702c421bdf43bcfb2a087669bd07310f4445e authorAgentM <agentm@themactionfaction.com> dateTue 9 Jan 2018, 15:33 (9 years ago) parentc269ae7
2 files changed+16−16
src/lib/ProjectM36/Client.hs+16−8 test.c−8
src/lib/ProjectM36/Client.hs+16−8
@@ -582,7 +582,7 @@ executeDatabaseContextExpr sessionId (InProcessConnection conf) expr = excEither
582582 pure (Right ())
583583executeDatabaseContextExpr sessionId conn@(RemoteProcessConnection _) dbExpr = remoteCall conn (ExecuteDatabaseContextExpr sessionId dbExpr)
584584
585−-- | Similar to a git rebase, 'autoMergeToHead' atomically creates a temporary branch and merges it to the latest commit of the branch referred to by the 'HeadName' and commits the merge. This is useful to reduce incidents of 'TransactionIsNotAHeadError's but at the risk of merge errors (thus making it similar to rebasing).
585+-- | Similar to a git rebase, 'autoMergeToHead' atomically creates a temporary branch and merges it to the latest commit of the branch referred to by the 'HeadName' and commits the merge. This is useful to reduce incidents of 'TransactionIsNotAHeadError's but at the risk of merge errors (thus making it similar to rebasing). Alternatively, as an optimization, if a simple commit is possible (meaning that the head has not changed), then a fast-forward commit takes place instead.
586586autoMergeToHead :: SessionId -> Connection -> MergeStrategy -> HeadName -> IO (Either RelationalError ())
587587autoMergeToHead sessionId (InProcessConnection conf) strat headName' = do
588588 let sessions = ipSessions conf
@@ -594,13 +594,21 @@ autoMergeToHead sessionId (InProcessConnection conf) strat headName' = do
594594 eSession <- sessionForSessionId sessionId sessions
595595 case eSession of
596596 Left err -> pure (Left err)
597− Right session ->
598− --attempt fast-forward commit, if possible
599−
600− case Graph.autoMergeToHead stamp (id1, id2, id3) (Sess.disconnectedTransaction session) headName' strat graph of
601− Left err -> pure (Left err)
602− Right (discon', graph') ->
603− pure (Right (discon', graph', [id1, id2, id3]))
597+ Right session -> do
598+ case Graph.transactionForHead headName' graph of
599+ Nothing -> pure (Left (NoSuchHeadNameError headName'))
600+ Just headTrans -> do
601+ --attempt fast-forward commit, if possible
602+ let graphInfo = if Sess.parentId session == transactionId headTrans then do
603+ ret <- Graph.evalGraphOp stamp id1 (Sess.disconnectedTransaction session) graph Commit
604+ pure (ret, [id1])
605+ else do
606+ ret <- Graph.autoMergeToHead stamp (id1, id2, id3) (Sess.disconnectedTransaction session) headName' strat graph
607+ pure (ret, [id1,id2,id3])
608+ case graphInfo of
609+ Left err -> pure (Left err)
610+ Right ((discon', graph'), transactionIdsAdded) ->
611+ pure (Right (discon', graph', transactionIdsAdded))
604612autoMergeToHead sessionId conn@(RemoteProcessConnection _) strat headName' = remoteCall conn (ExecuteAutoMergeToHead sessionId strat headName')
605613
606614-- | Execute a database context IO-monad-based expression for the given session and connection. `DatabaseContextIOExpr`s modify the DatabaseContext but cannot be purely implemented.
test.cdeleted−8
@@ -1,8 +0,0 @@
1−#include <sys/statfs.h>
2−#include <stdio.h>
3−
4−int main ()
5−
6−{
7− printf("%d\n", sizeof(struct statfs));
8−}