Ben Franksen <[email protected]> added the comment:

Following up on your comment.

2 patches for repository https://darcs.net/screened:

patch 3e3d4a4c81e2a9ce99766cfc766509e3ef9aa1b9
Author: Ben Franksen <[email protected]>
Date:   Sat Jun 22 09:37:33 CEST 2024
  * resolve issue2288: add --covering PATTERN option to show tags command

patch 2a38a9de33638564b821d95a69acfcfbc3837149
Author: Ben Franksen <[email protected]>
Date:   Sat Nov 30 14:11:59 CET 2024
  * improve help text for --covering option

__________________________________
Darcs bug tracker <[email protected]>
<https://bugs.darcs.net/patch2418>
__________________________________
[resolve issue2288: add --covering PATTERN option to show tags command
Ben Franksen <[email protected]>**20240622073733
 Ignore-this: b95a7a678b4871fb6dbbaff90e19d781cca1beeae80d12cd8bcb49e0d94403567bcbfa714418f638
] hunk ./src/Darcs/Patch/Set.hs 34
+    , tagsCovering
hunk ./src/Darcs/Patch/Set.hs 43
-import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info )
+import Darcs.Patch.Named ( getdeps )
+import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, hopefully, info )
hunk ./src/Darcs/Patch/Set.hs 144
+-- Find all tags that cover the latest patch matching the given matcher.
+--
+-- The algorithm: Go back until a matching patch is found. On the way, collect
+-- information about tags. For each tag remember name and explicit
+-- dependencies. Then go forward, and add every tag to the result that covers
+-- the patch or covers one of the tags found so far. As a special optimization,
+-- known clean tags always depend everything before them, so we don't have to
+-- check their explicit dependencies.
+tagsCovering
+  :: forall p wO wX
+   . (forall wA wB. PatchInfoAnd p wA wB -> Bool)
+  -> PatchSet p wO wX
+  -> Maybe [String]
+tagsCovering matcher = fmap (catMaybes . fmap piTag) . go []
+  where
+    go :: [(PatchInfo, Maybe[PatchInfo])] -> PatchSet p wO wY -> Maybe [PatchInfo]
+    go _ (PatchSet NilRL NilRL) = Nothing
+    go tags (PatchSet (ts :<: Tagged ps t _) NilRL)
+      | matcher t = Just $ checkCovered (info t) tags
+      | otherwise = go ((info t, Nothing) : tags) (PatchSet ts ps)
+    go tags (PatchSet ts (ps :<: p))
+      | matcher p = Just $ checkCovered (info p) tags
+      | Just _ <- piTag (info p) =
+        go ((info p, Just (getdeps (hopefully p))) : tags) (PatchSet ts ps)
+      | otherwise = go tags (PatchSet ts ps)
+
+    checkCovered i ((t,Nothing):ts) = t : checkCovered i ts
+    checkCovered i ((t,Just is):ts)
+      | i `elem` is = t : checkCovered i ts
+      | otherwise = checkCovered i ts
+    checkCovered _ [] = []
+
hunk ./src/Darcs/UI/Commands/ShowTags.hs 25
-import Data.Maybe ( fromMaybe )
+import Data.Maybe ( fromMaybe, maybeToList )
hunk ./src/Darcs/UI/Commands/ShowTags.hs 28
-import Darcs.Patch.Set ( PatchSet, patchSetTags )
+import Darcs.Patch.Match
+    ( MatchFlag(OnePattern)
+    , MatchableRP
+    , checkMatchSyntax
+    , matchAPatch
+    )
+import Darcs.Patch.Set ( PatchSet(..), patchSetTags, tagsCovering )
hunk ./src/Darcs/UI/Commands/ShowTags.hs 39
-import Darcs.UI.Options ( oid, (?) )
+import Darcs.UI.Options ( oid, (?), (^) )
hunk ./src/Darcs/UI/Commands/ShowTags.hs 71
-    showTagsBasicOpts = O.possiblyRemoteRepo
+    showTagsBasicOpts = O.possiblyRemoteRepo ^ O.covering
hunk ./src/Darcs/UI/Commands/ShowTags.hs 79
-    printTags :: PatchSet p wW wZ -> IO ()
-    printTags = mapM_ process . patchSetTags
+    printTags :: MatchableRP p => PatchSet p wW wZ -> IO ()
+    printTags ps = do
+      checkMatchSyntax (maybeToList (fmap OnePattern (O.covering ? opts)))
+      case findTags ps of
+        Nothing -> fail "No patches matching the pattern have been found."
+        Just ts -> mapM_ process ts
hunk ./src/Darcs/UI/Commands/ShowTags.hs 98
+    findTags :: MatchableRP p => PatchSet p wX wY -> Maybe [String]
+    findTags =
+      case O.covering ? opts of
+        Nothing -> Just . patchSetTags
+        Just pat -> tagsCovering (matchAPatch [OnePattern pat])
hunk ./src/Darcs/UI/Options/All.hs 235
+    -- show tags
+    , covering
+
hunk ./src/Darcs/UI/Options/All.hs 1298
+-- ** show tags
+
+covering :: PrimDarcsOption (Maybe String)
+covering = singleStrArg [] ["covering"] F.Covering arg "PATTERN"
+    "show (only) tags covering the latest patch that matches PATTERN"
+  where arg (F.Covering s) = Just s; arg _ = Nothing
+
hunk ./src/Darcs/UI/Options/Flags.hs 101
+               | Covering String

[improve help text for --covering option
Ben Franksen <[email protected]>**20241130131159
 Ignore-this: 3e66699252b53e87656255ce54747d27a771be440ed4cfa74d768c63c6c4c933c3bc66badac2de
] hunk ./src/Darcs/UI/Options/All.hs 1302
-    "show (only) tags covering the latest patch that matches PATTERN"
+    "show tags that depend on the latest patch that matches PATTERN"

Attachment: resolve-issue2288_-add-__covering-pattern-option-to-show-tags-command_0.dpatch
Description: application/darcs-patch

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

Reply via email to