1 % Copyright (C) 2002-2005 David Roundy 2 % 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) 6 % any later version. 7 % 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. 12 % 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. 17 18 19 \begin{code} 20 {-# OPTIONS_GHC -cpp -fno-warn-orphans -fglasgow-exts #-} 21 {-# LANGUAGE CPP #-} 22 23 module Darcs.Patch.Show ( showPatch_, showNamedPrefix ) 24 where 25 26 import Prelude hiding ( pi ) 27 28 import Printer ( Doc, renderString, vcat, 29 text, blueText, 30 ($$), (<+>) ) 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 ) 35 #include "gadts.h" 36 \end{code} 37 38 \section{Patch string formatting} 39 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 43 patches. 44 \begin{code} 45 instance Show (Patch C(x y)) where 46 show p = renderString (showPatch_ p) ++ "\n" 47 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) 53 $$ blueText "}" 54 showPatch_ (Merger _ _ p1 p2) = showMerger "merger" p1 p2 55 showPatch_ (Regrem _ _ p1 p2) = showMerger "regrem" p1 p2 56 \end{code} 57 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. 61 \begin{verbatim} 62 merger MERGERVERSION 63 <first patch> 64 <second patch> 65 \end{verbatim} 66 \begin{code} 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 "(" 70 $$ showPatch_ p1 71 $$ showPatch_ p2 72 $$ blueText ")" 73 \end{code} 74 75 \paragraph{Named patches} 76 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. 81 82 \begin{code} 83 showNamedPrefix :: PatchInfo -> [PatchInfo] -> Doc 84 showNamedPrefix n d = showPatchInfo n 85 $$ blueText "<" 86 $$ vcat (map showPatchInfo d) 87 $$ blueText ">" 88 89 \end{code}