[darcs-users] darcs patch: Made --summary --xml-output work for other commands th...

Reinier Lamers tux_rocker at reinier.de
Sat Mar 28 20:59:27 UTC 2009


Hi all,

I'd say: amend to move the insert_before_lastline to the Printer module in 
src/Printer.lhs, and import it from there to Changes.lhs and Arguments.lhs. 
For the rest it's fine.

It might be nice to send a patch to add documentation of this as well. It's 
most relevant for people implementing tools on top of darcs.

On Friday 27 March 2009 21:14:53 Florian Gilcher wrote:
>   Who?
>    A bloody Haskell beginner. Please review the code and bury me under evil
> comments ;).

We're not the style police. Beginner-ish code is alright if it's not dangerous 
or buggy. And this doesn't look particularly beginnerish :-)

>] hunk ./src/Darcs/Arguments.lhs 100

>-import Darcs.Hopefully ( PatchInfoAnd, info )
>-import Darcs.Patch ( RepoPatch, Patchy, showNicely, description )
>+import Darcs.Hopefully ( PatchInfoAnd, info, hopefullyM )
>+import Darcs.Patch ( RepoPatch, Patchy, showNicely, description,
> xml_summary )
>hunk ./src/Darcs/Arguments.lhs 119
>-import Printer ( Doc, putDocLn, text, vsep, ($$), vcat )
>+import ByteStringUtils ( linesPS )
>+import Printer ( Doc, putDocLn, text, vsep, ($$), vcat,

Some import shuffling, alright...

>hunk ./src/Darcs/Arguments.lhs 1111
>           putDocLn $ put_mode
>      where put_mode = if XMLOutput `elem` opts
>                       then (text "<patches>" $$
>-                            vcat (mapFL (to_xml . info) patches) $$
>+                            vcat (mapFL (indent . xml_info) patches) $$
>                             text "</patches>")
>                       else (vsep $ mapFL (showFriendly opts) patches)
>            putInfo = if XMLOutput `elem` opts then \_ -> return () else

Print the XML in indented form, and use a function xml_info to discriminate 
between summarized and non-summarized.

> putDocLn hunk ./src/Darcs/Arguments.lhs 1115
>+           xml_info pl
>+              | Summary `elem` opts = xml_with_summary pl
>+              | otherwise = (to_xml . info) pl

Do what we did before unless --summary is given. In that case use 
xml_with_summary below.

>+
>+           xml_with_summary hp
>+               | Just p <- hopefullyM hp = insert_before_lastline
>+                                            (to_xml $ info hp) (indent $
> xml_summary p) +           xml_with_summary hp = to_xml (info hp)
>+           indent = prefix "    "

Is that a pattern guard? Do those work with GHC 6.6? Anyway, it appears to be 
cut n pasted from Changes.lhs so it works.

>+insert_before_lastline :: Doc -> Doc -> Doc
>+insert_before_lastline a b =
>+    case reverse $ map packedString $ linesPS $ renderPS a of
>+    (ll:ls) -> vcat (reverse ls) $$ b $$ ll
>+    [] -> impossible

Shouldn't we move this to src/Printer.lhs? That's where the commonly used 
functions on Doc's reside.

Regards,
Reinier


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.osuosl.org/pipermail/darcs-users/attachments/20090328/ae56bd0d/attachment.pgp>


More information about the darcs-users mailing list