1 % Copyright (C) 2002-2005 David Roundy
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
20 {-# OPTIONS_GHC -cpp -fno-warn-orphans #-}
23 module Darcs.Patch.Show ( showPatch_, showNamedPrefix )
26 import Prelude hiding ( pi )
28 import Printer ( Doc, renderString, vcat,
31 import Darcs.Patch.Core ( Patch(..) )
32 import Darcs.Patch.Prim ( showPrim, FileNameFormat(..) )
33 import Darcs.Patch.Info ( PatchInfo, showPatchInfo )
34 import Darcs.Ordered ( FL(NilFL), mapFL )
38 \section{Patch string formatting}
40 Of course, in order to store our patches in a file, we'll have to save them
41 as some sort of strings. The convention is that each patch string will end
42 with a newline, but on parsing we skip any amount of whitespace between
45 instance Show (Patch C(x y)) where
46 show p = renderString (showPatch_ p) ++ "\n"
48 showPatch_ :: Patch C(a b) -> Doc
49 showPatch_ (PP p) = showPrim OldFormat p
50 showPatch_ (ComP NilFL) = blueText "{" $$ blueText "}"
51 showPatch_ (ComP ps) = blueText "{"
52 $$ vcat (mapFL showPatch_ ps)
54 showPatch_ (Merger _ _ p1 p2) = showMerger "merger" p1 p2
55 showPatch_ (Regrem _ _ p1 p2) = showMerger "regrem" p1 p2
58 \paragraph{Merger patches}
59 Merge two patches. The MERGERVERSION is included to allow some degree of
60 backwards compatibility if the merger algorithm needs to be changed.
67 showMerger :: String -> Patch C(a b) -> Patch C(d e) -> Doc
68 showMerger merger_name p1 p2 =
69 blueText merger_name <+> text "0.0" <+> blueText "("
75 \paragraph{Named patches}
77 Named patches are displayed as a ``patch id'' which is in square brackets,
78 followed by a patch. Optionally, after the patch id (but before the patch
79 itself) can come a list of dependencies surrounded by angle brackets. Each
80 dependency consists of a patch id.
83 showNamedPrefix :: PatchInfo -> [PatchInfo] -> Doc
84 showNamedPrefix n d = showPatchInfo n
86 $$ vcat (map showPatchInfo d)