New submission from Ben Franksen <[email protected]>:

I am not screening this one yet, please take a look and tell me if you think
this is a bad idea. With this patch I can successfully push and pull between
the two repos that lemming attached to the ticket (after reverting
unrecorded changes).

This patch breaks the test for issue1879 which is to be expected. Detecting
inconsistencies between repos (this includes malicious patch manipulation)
is a valid goal but I think we should aim for something more reliable. That
is, commute all (supposedly) common remote patches into the same context as
the version in our repo and then compare contents; which would not interfere
with the proposed mitigation for issue2738.

1 patch for repository https://darcs.net/screened:

patch 3bba990fe96e421f81bb2cf45ece9994d075ce35
Author: Ben Franksen <[email protected]>
Date:   Wed Jan 29 13:13:20 CET 2025
  * mitigate issue2738: make merging more robust in the face of V1/V2 commute 
bugs

  We add a new method robustMerge that is able to handle identical patches by
  returning "null patches" (represented as Nothing2 :: Maybe2), and base the
  generic instance Merge for FLs on that, instead of the plain merge. This
  allows us to keep common patches that cannot be commuted to the tail in the
  "uncommon" branches (in functions like findCommonFL) instead of calling
  error.

----------
files: 
mitigate-issue2738_-make-merging-more-robust-in-the-face-of-v1_v2-commute-bugs.dpatch,
 patch-preview.txt
messages: 24179
nosy: bfrk
status: needs-screening
title: mitigate issue2738: make merging more robust in the fa...

__________________________________
Darcs bug tracker <[email protected]>
<https://bugs.darcs.net/patch2455>
__________________________________
[mitigate issue2738: make merging more robust in the face of V1/V2 commute bugs
Ben Franksen <[email protected]>**20250129121320
 Ignore-this: 50f5b9ddc61c025d32f9b7bb4eccc937d7a6cfcb228456937e714240d0d77cb4e7aca3784e405a29
 
 We add a new method robustMerge that is able to handle identical patches by
 returning "null patches" (represented as Nothing2 :: Maybe2), and base the
 generic instance Merge for FLs on that, instead of the plain merge. This
 allows us to keep common patches that cannot be commuted to the tail in the
 "uncommon" branches (in functions like findCommonFL) instead of calling
 error.
] hunk ./src/Darcs/Patch/Ident.hs 38
+    , (+<+)
hunk ./src/Darcs/Patch/Ident.hs 49
-import Darcs.Util.Printer ( Doc, renderString, text, vcat, ($$) )
+import Darcs.Util.Printer ( Doc )
hunk ./src/Darcs/Patch/Ident.hs 256
-    cxs :> NilRL :> xs' -> cxs :> reverseRL xs'
-    _ :> remaining :> _ ->
-      error $ renderString
-        $ text "failed to commute common patches:"
-        $$ vcat (mapRL (showId ForDisplay . ident) remaining)
+    -- Theoretically, 'remaining' should be empty. But RepoPatchV1/V2 have
+    -- (unfixable) bugs that can result in common patches not being commutable
+    -- to the left. In order to mitigate these situations, instead of calling
+    -- error we keep common patches in the trailing branches. This relies on a
+    -- more robust implementation of merge for FLs that correctly handles
+    -- inputs with common patches.
+    cxs :> remaining :> xs' -> cxs :> remaining +>>+ reverseRL xs'
hunk ./src/Darcs/Patch/Ident.hs 276
-            NotEq -> error "common patches aren't equal"
+            NotEq ->
+              -- with buggy patch formats this can happen, too
+              case findCommonRL cxs cys of
+                Fork com xs'' ys'' ->
+                  Fork com (xs'' +<+ xs') (ys'' +<+ ys')
hunk ./src/Darcs/Patch/Ident.hs 288
-    cxs :> NilFL :> xs' -> reverseFL cxs :> xs'
-    _ :> remaining :> _ ->
-      error $ renderString
-        $ text "failed to commute common patches:"
-        $$ vcat (mapFL (showId ForDisplay . ident) remaining)
+    -- See remark in 'findCommonWithThemFL'.
+    cxs :> remaining :> xs' -> reverseFL cxs :> reverseFL remaining +<+ xs'
hunk ./src/Darcs/Patch/Merge.hs 35
+import Darcs.Patch.Witnesses.Maybe
hunk ./src/Darcs/Patch/Merge.hs 42
+    , mapFL_FL
hunk ./src/Darcs/Patch/Merge.hs 125
+    -- | Note: for named patches this is only defined if the patches aren't
+    -- nominally equal.
hunk ./src/Darcs/Patch/Merge.hs 128
+    -- | A more robust version that can also handle input patches with
+    -- the same identity.
+    robustMerge :: (p :\/: p) wX wY -> (Maybe2 p :/\: Maybe2 p) wX wY
+    -- The default implementation should only be changed for Named and
+    -- PatchInfoAnd to mitigate commutation bugs in V1/V2.
+    robustMerge pq | q' :/\: p' <- merge pq = Just2 q' :/\: Just2 p'
hunk ./src/Darcs/Patch/Merge.hs 140
-    merge = mergerFLFL merge
+  merge (ps :\/: qs) =
+    -- Wrapping the input patches with Maybe2 is done so that we can
+    -- (re-)use the existing merger* machinery below.
+    case mergerFLFL raiseMerge (mapFL_FL Just2 ps :\/: mapFL_FL Just2 qs) of
+      mqs' :/\: mps' -> catMaybesFL mqs' :/\: catMaybesFL mps'
+    where
+      raiseMerge (Nothing2 :\/: mq) = mq :/\: Nothing2
+      raiseMerge (mp :\/: Nothing2) = Nothing2 :/\: mp
+      raiseMerge (Just2 p :\/: Just2 q) = robustMerge (p :\/: q)
hunk ./src/Darcs/Patch/Named.hs 63
-import Darcs.Patch.Ident ( Ident(..), PatchId )
+import Darcs.Patch.Ident ( Ident(..), PatchId, (=\^/=) )
hunk ./src/Darcs/Patch/Named.hs 85
-import Darcs.Patch.Witnesses.Eq ( Eq2(..) )
+import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) )
+import Darcs.Patch.Witnesses.Maybe ( Maybe2(..) )
hunk ./src/Darcs/Patch/Named.hs 222
+    robustMerge (p :\/: q)
+      | IsEq <- p =\^/= q = Nothing2 :/\: Nothing2
+      | q' :/\: p' <- merge (p :\/: q) = Just2 q' :/\: Just2 p'
hunk ./src/Darcs/Patch/PatchInfoAnd.hs 51
-import Darcs.Patch.Ident ( Ident(..), PatchId )
+import Darcs.Patch.Ident ( Ident(..), PatchId, (=\^/=) )
hunk ./src/Darcs/Patch/PatchInfoAnd.hs 61
-import Darcs.Patch.Witnesses.Eq ( Eq2(..) )
+import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) )
+import Darcs.Patch.Witnesses.Maybe ( Maybe2(..) )
hunk ./src/Darcs/Patch/PatchInfoAnd.hs 281
+    robustMerge (x :\/: y)
+      | IsEq <- x =\^/= y = Nothing2 :/\: Nothing2
+      | y' :/\: x' <- merge (x :\/: y) = Just2 y' :/\: Just2 x'
hunk ./src/Darcs/Patch/Witnesses/Maybe.hs 3
+  , catMaybesFL
hunk ./src/Darcs/Patch/Witnesses/Maybe.hs 25
+
+-- | Throw out the 'Nothing2's, keep what's in the 'Just2's.
+catMaybesFL :: FL (Maybe2 p) wX wY -> FL p wX wY
+catMaybesFL NilFL = NilFL
+catMaybesFL (Nothing2 :>: ps) = catMaybesFL ps
+catMaybesFL (Just2 p :>: ps) = p :>: catMaybesFL ps
+

Attachment: mitigate-issue2738_-make-merging-more-robust-in-the-face-of-v1_v2-commute-bugs.dpatch
Description: application/darcs-patch

_______________________________________________
darcs-devel mailing list
[email protected]
https://lists.darcs.net/mailman/listinfo/darcs-devel

Reply via email to