Skip to content
Newer
Older
100644 189 lines (168 sloc) 6.41 KB
e35e41e @kolmodin Make merging respect categories
kolmodin authored Aug 19, 2007
1 module Diff
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored Aug 31, 2008
2 ( runDiff
3 , DiffMode(..)
e35e41e @kolmodin Make merging respect categories
kolmodin authored Aug 19, 2007
4 ) where
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored Sep 21, 2005
5
ef321f4 @kolmodin Cleanup warnings in Diff.hs
kolmodin authored Mar 1, 2009
6 import Control.Monad ( mplus )
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
7 import Control.Exception ( assert )
8 import Data.Maybe ( fromJust, listToMaybe )
ef321f4 @kolmodin Cleanup warnings in Diff.hs
kolmodin authored Mar 1, 2009
9 import Data.List ( sortBy, groupBy )
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
10 import Data.Ord ( comparing )
5078263 @kolmodin Make diffing respect categories
kolmodin authored Aug 18, 2007
11
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
12 import qualified Portage.Overlay as Portage
13 import qualified Portage.Cabal as Portage
14 import qualified Portage.PackageId as Portage
15
16 import qualified Data.Version as Cabal
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored Aug 31, 2008
17
18 -- cabal
19 import Distribution.Verbosity
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored Sep 7, 2008
20 import Distribution.Text(display)
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
21 import qualified Distribution.Package as Cabal
60d04de @kolmodin adapt to cabal-1.8 and cabal-install-0.7.5 (HEADs)
kolmodin authored Nov 29, 2009
22 import qualified Distribution.Client.PackageIndex as Index
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
23 import Distribution.Simple.Utils (equating)
24
25 -- cabal-install
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored Oct 6, 2011
26 import qualified Distribution.Client.IndexUtils as Index (getSourcePackages)
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
27 import qualified Distribution.Client.Types as Cabal
28 import Distribution.Client.Utils (mergeBy, MergeResult(..))
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored Aug 31, 2008
29
30 data DiffMode
31 = ShowAll
32 | ShowMissing
33 | ShowAdditions
34 | ShowNewer
35 | ShowCommon
eef57f0 @kolmodin Allow to diff by package name
kolmodin authored Oct 4, 2008
36 | ShowPackages [String]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored Aug 31, 2008
37 deriving Eq
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored Sep 21, 2005
38
3eb19fc New diff style
der_eq@freenet.de authored Jul 30, 2007
39
ef321f4 @kolmodin Cleanup warnings in Diff.hs
kolmodin authored Mar 1, 2009
40 {-
41 type DiffState a = MergeResult a a
5078263 @kolmodin Make diffing respect categories
kolmodin authored Aug 18, 2007
42 tabs :: String -> String
43 tabs str = let len = length str in str++(if len < 3*8
44 then replicate (3*8-len) ' '
45 else "")
46
ef321f4 @kolmodin Cleanup warnings in Diff.hs
kolmodin authored Mar 1, 2009
47
48 -- TODO: is the new showPackageCompareInfo showing the packages in the same
49 -- way as showDiffState did?
50
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
51 showDiffState :: Cabal.PackageName -> DiffState Portage.Version -> String
52 showDiffState pkg st = (tabs (display pkg)) ++ " [" ++ (case st of
53 InBoth x y -> display x ++ (case compare x y of
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored Aug 31, 2008
54 EQ -> "="
55 GT -> ">"
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored Sep 7, 2008
56 LT -> "<") ++ display y
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
57 OnlyInLeft x -> display x ++ ">none"
58 OnlyInRight y -> "none<" ++ display y) ++ "]"
ef321f4 @kolmodin Cleanup warnings in Diff.hs
kolmodin authored Mar 1, 2009
59 -}
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
60
61 runDiff :: Verbosity -> FilePath -> DiffMode -> Cabal.Repo -> IO ()
62 runDiff verbosity overlayPath dm repo = do
63 -- get package list from hackage
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored Oct 6, 2011
64 pkgDB <- Index.getSourcePackages verbosity [ repo ]
65 let (Cabal.SourcePackageDb hackageIndex _) = pkgDB
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
66
67 -- get package list from the overlay
68 overlay0 <- (Portage.loadLazy overlayPath)
69 let overlayIndex = Portage.fromOverlay (Portage.reduceOverlay overlay0)
70
71 let (subHackage, subOverlay)
72 = case dm of
73 ShowPackages pkgs ->
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored Oct 6, 2011
74 (concatMap (concatMap snd . Index.searchByNameSubstring hackageIndex) pkgs
75 ,concatMap (concatMap snd . Index.searchByNameSubstring overlayIndex) pkgs)
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
76 _ ->
60d04de @kolmodin adapt to cabal-1.8 and cabal-install-0.7.5 (HEADs)
kolmodin authored Nov 29, 2009
77 (Index.allPackages hackageIndex
78 ,Index.allPackages overlayIndex)
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
79 diff subHackage subOverlay dm
80
81 data PackageCompareInfo = PackageCompareInfo {
82 name :: Cabal.PackageName,
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
83 -- hackageVersions :: [ Cabal.Version ],
84 -- overlayVersions :: [ Cabal.Version ]
85 hackageVersion :: Maybe Cabal.Version,
86 overlayVersion :: Maybe Cabal.Version
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
87 } deriving Show
88
89 showPackageCompareInfo :: PackageCompareInfo -> String
90 showPackageCompareInfo pkgCmpInfo =
91 display (name pkgCmpInfo) ++ " ["
92 ++ hackageS ++ sign ++ overlayS ++ "]"
93 where
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
94 overlay = overlayVersion pkgCmpInfo
95 hackage = hackageVersion pkgCmpInfo
96 hackageS = maybe "none" display hackage
97 overlayS = maybe "none" display overlay
98 sign = case compare hackage overlay of
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
99 EQ -> "="
100 GT -> ">"
101 LT -> "<"
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
102
ac5deac @trofi port to (bundled) Cabal-1.12
trofi authored Oct 6, 2011
103 diff :: [Cabal.SourcePackage]
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
104 -> [Portage.ExistingEbuild]
105 -> DiffMode
106 -> IO ()
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
107 diff hackage overlay dm = do
108 mapM_ (putStrLn . showPackageCompareInfo) pkgCmpInfos
109 where
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
110 merged = mergePackages (map (Portage.normalizeCabalPackageId . Cabal.packageId) hackage)
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
111 (map Portage.ebuildCabalId overlay)
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
112 pkgCmpInfos = filter pkgFilter (map (uncurry mergePackageInfo) merged)
113 pkgFilter :: PackageCompareInfo -> Bool
114 pkgFilter pkgCmpInfo =
115 let om = overlayVersion pkgCmpInfo
116 hm = hackageVersion pkgCmpInfo
117 st = case (om,hm) of
118 (Just ov, Just hv) -> InBoth ov hv
119 (Nothing, Just hv) -> OnlyInRight hv
120 (Just ov, Nothing) -> OnlyInLeft ov
ef321f4 @kolmodin Cleanup warnings in Diff.hs
kolmodin authored Mar 1, 2009
121 _ -> error "impossible"
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
122 in
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
123 case dm of
124 ShowAll -> True
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
125 ShowPackages _ -> True -- already filtered
126 ShowNewer -> case st of
127 InBoth o h -> h>o
128 _ -> False
129 ShowMissing -> case st of
3b9e456 @kolmodin Fix 'hackport diff additions' and 'hackport diff common'
kolmodin authored Feb 8, 2009
130 OnlyInLeft _ -> False
131 InBoth x y -> x < y
132 OnlyInRight _ -> True
133 ShowAdditions -> case st of
134 OnlyInLeft _ -> True
135 InBoth x y -> x > y
136 OnlyInRight _ -> False
137 ShowCommon -> case st of
138 OnlyInLeft _ -> False
139 InBoth x y -> x == y
140 OnlyInRight _ -> False
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
141
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
142 -- | We get the 'PackageCompareInfo' by combining the info for the overlay
143 -- and hackage versions of a package.
144 --
145 -- * We're building info about a various versions of a single named package so
146 -- the input package info records are all supposed to refer to the same
147 -- package name.
148 --
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
149 mergePackageInfo :: [Cabal.PackageIdentifier]
150 -> [Cabal.PackageIdentifier]
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
151 -> PackageCompareInfo
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
152 mergePackageInfo hackage overlay =
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
153 assert (length overlay + length hackage > 0) $
154 PackageCompareInfo {
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
155 name = combine Cabal.pkgName latestHackage
156 Cabal.pkgName latestOverlay,
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
157 -- hackageVersions = map Cabal.pkgVersion hackage,
158 -- overlayVersions = map Cabal.pkgVersion overlay
159 hackageVersion = fmap Cabal.pkgVersion latestHackage,
160 overlayVersion = fmap Cabal.pkgVersion latestOverlay
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
161 }
162 where
163 combine f x g y = fromJust (fmap f x `mplus` fmap g y)
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
164 latestHackage = latestOf hackage
165 latestOverlay = latestOf overlay
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
166 latestOf :: [Cabal.PackageIdentifier] -> Maybe Cabal.PackageIdentifier
8925e89 @kolmodin Add 'hackport diff missing'
kolmodin authored Feb 8, 2009
167 latestOf = listToMaybe . reverse . sortBy (comparing Cabal.pkgVersion)
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
168
169 -- | Rearrange installed and available packages into groups referring to the
170 -- same package by name. In the result pairs, the lists are guaranteed to not
171 -- both be empty.
172 --
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
173 mergePackages :: [Cabal.PackageIdentifier] -> [Cabal.PackageIdentifier]
174 -> [([Cabal.PackageIdentifier], [Cabal.PackageIdentifier])]
175 mergePackages hackage overlay =
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
176 map collect
177 $ mergeBy (\i a -> fst i `compare` fst a)
8543927 @kolmodin Make 'hackport diff' work again
kolmodin authored Feb 8, 2009
178 (groupOn Cabal.pkgName hackage)
179 (groupOn Cabal.pkgName overlay)
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
180 where
181 collect (OnlyInLeft (_,is) ) = (is, [])
182 collect ( InBoth (_,is) (_,as)) = (is, as)
183 collect (OnlyInRight (_,as)) = ([], as)
5078263 @kolmodin Make diffing respect categories
kolmodin authored Aug 18, 2007
184
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored Feb 7, 2009
185 groupOn :: Ord key => (a -> key) -> [a] -> [(key,[a])]
186 groupOn key = map (\xs -> (key (head xs), xs))
187 . groupBy (equating key)
188 . sortBy (comparing key)
Something went wrong with that request. Please try again.