Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 167 lines (148 sloc) 5.865 kb
e35e41e @kolmodin Make merging respect categories
kolmodin authored
1 module Diff
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
2 ( runDiff
3 , DiffMode(..)
e35e41e @kolmodin Make merging respect categories
kolmodin authored
4 ) where
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored
5
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
6 import Control.Monad ( forM_, mplus )
5078263 @kolmodin Make diffing respect categories
kolmodin authored
7 import Data.Char
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
8 import qualified Data.Map as Map
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
9 import Network.URI
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
10 import Control.Exception ( assert )
11 import Data.Maybe ( fromJust, listToMaybe )
12 import Data.List ( sortBy, groupBy )
13 import Data.Ord ( comparing )
5078263 @kolmodin Make diffing respect categories
kolmodin authored
14
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
15 import qualified Portage.Version as Portage
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
16 import qualified Portage.Overlay as Portage
17 import qualified Portage.Cabal as Portage
18 import qualified Portage.PackageId as Portage
19
20 import qualified Data.Version as Cabal
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
21
22 -- cabal
23 import Distribution.Verbosity
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
24 import Distribution.Text(display)
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
25 import qualified Distribution.Package as Cabal
26 import qualified Distribution.Simple.PackageIndex as Cabal
27 import qualified Distribution.InstalledPackageInfo as Cabal
28 import Distribution.Simple.Utils (equating)
29
30 -- cabal-install
31 import qualified Distribution.Client.IndexUtils as Index (getAvailablePackages )
32 import qualified Distribution.Client.Types as Cabal
33 import Distribution.Client.Utils (mergeBy, MergeResult(..))
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
34
35 data DiffMode
36 = ShowAll
37 | ShowMissing
38 | ShowAdditions
39 | ShowNewer
40 | ShowCommon
eef57f0 @kolmodin Allow to diff by package name
kolmodin authored
41 | ShowPackages [String]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
42 deriving Eq
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored
43
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
44 type DiffState a = MergeResult a a
3eb19fc New diff style
der_eq@freenet.de authored
45
5078263 @kolmodin Make diffing respect categories
kolmodin authored
46 tabs :: String -> String
47 tabs str = let len = length str in str++(if len < 3*8
48 then replicate (3*8-len) ' '
49 else "")
50
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
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
54 EQ -> "="
55 GT -> ">"
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
56 LT -> "<") ++ display y
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
57 OnlyInLeft x -> display x ++ ">none"
58 OnlyInRight y -> "none<" ++ display y) ++ "]"
59
60 runDiff :: Verbosity -> FilePath -> DiffMode -> Cabal.Repo -> IO ()
61 runDiff verbosity overlayPath dm repo = do
62 -- get package list from hackage
63 pkgDB <- Index.getAvailablePackages verbosity [ repo ]
64 let (Cabal.AvailablePackageDb hackageIndex _) = pkgDB
65
66 -- get package list from the overlay
67 overlay0 <- (Portage.loadLazy overlayPath)
68 let overlayIndex = Portage.fromOverlay (Portage.reduceOverlay overlay0)
69
70 let (subHackage, subOverlay)
71 = case dm of
72 ShowPackages pkgs ->
73 (concatMap (Cabal.searchByNameSubstring hackageIndex) pkgs
74 ,concatMap (Cabal.searchByNameSubstring overlayIndex) pkgs)
75 _ ->
76 (Cabal.allPackages hackageIndex
77 ,Cabal.allPackages overlayIndex)
78 diff subHackage subOverlay dm
79
80 data PackageCompareInfo = PackageCompareInfo {
81 name :: Cabal.PackageName,
82 hackageVersions :: [ Cabal.Version ],
83 overlayVersions :: [ Portage.Version ]
84 }
85
86 diff :: [Cabal.AvailablePackage]
87 -> [Portage.ExistingEbuild]
88 -> DiffMode
89 -> IO ()
90 diff hackage overlay dm =
91
92 error "Diff.diff not implemented"
93
94 -- | We get the 'PackageCompareInfo' by combining the info for the overlay
95 -- and hackage versions of a package.
96 --
97 -- * We're building info about a various versions of a single named package so
98 -- the input package info records are all supposed to refer to the same
99 -- package name.
100 --
101 mergePackageInfo :: [Portage.ExistingEbuild]
102 -> [Cabal.AvailablePackage]
103 -> PackageCompareInfo
104 mergePackageInfo overlay hackage =
105 assert (length overlay + length hackage > 0) $
106 PackageCompareInfo {
107 name = combine (Cabal.pkgName . Cabal.packageId) latestHackage
108 (Cabal.pkgName . Cabal.packageId) latestOverlay,
109 hackageVersions = map (Cabal.pkgVersion . Cabal.packageId) hackage,
110 overlayVersions = map (Portage.pkgVersion . Portage.ebuildId) overlay
111 }
112 where
113 combine f x g y = fromJust (fmap f x `mplus` fmap g y)
114 latestHackage = latestOf hackage
115 latestOverlay = latestOf overlay
116 latestOf :: Cabal.Package pkg => [pkg] -> Maybe pkg
117 latestOf = listToMaybe . sortBy (comparing (Cabal.pkgVersion . Cabal.packageId))
118
119 -- | Rearrange installed and available packages into groups referring to the
120 -- same package by name. In the result pairs, the lists are guaranteed to not
121 -- both be empty.
122 --
123 mergePackages :: [Cabal.InstalledPackageInfo] -> [Cabal.AvailablePackage]
124 -> [([Cabal.InstalledPackageInfo], [Cabal.AvailablePackage])]
125 mergePackages installed available =
126 map collect
127 $ mergeBy (\i a -> fst i `compare` fst a)
128 (groupOn (Cabal.pkgName . Cabal.packageId) installed)
129 (groupOn (Cabal.pkgName . Cabal.packageId) available)
130 where
131 collect (OnlyInLeft (_,is) ) = (is, [])
132 collect ( InBoth (_,is) (_,as)) = (is, as)
133 collect (OnlyInRight (_,as)) = ([], as)
5078263 @kolmodin Make diffing respect categories
kolmodin authored
134
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
135 groupOn :: Ord key => (a -> key) -> [a] -> [(key,[a])]
136 groupOn key = map (\xs -> (key (head xs), xs))
137 . groupBy (equating key)
138 . sortBy (comparing key)
139 {-
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
140 diff :: Portage -> Portage -> DiffMode -> IO ()
5078263 @kolmodin Make diffing respect categories
kolmodin authored
141 diff pt1 pt2 mode = do
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
142 let pkgs1 = Map.map (OnlyLeft . eVersion . maximum) pt1
143 let pkgs2 = Map.map (OnlyRight . eVersion . maximum) pt2
144 let union = Map.unionWith (\(OnlyLeft x) (OnlyRight y) -> Both x y) pkgs1 pkgs2
145 let showFilter st = case mode of
146 ShowAll -> True
147 ShowMissing -> case st of
148 OnlyLeft _ -> True
149 Both x y -> x > y
150 OnlyRight _ -> False
151 ShowAdditions -> case st of
152 OnlyLeft _ -> False
153 Both x y -> x < y
154 OnlyRight _ -> True
155 ShowNewer -> case st of
156 OnlyLeft _ -> False
157 Both x y -> x > y
158 OnlyRight _ -> False
159 ShowCommon -> case st of
160 OnlyLeft _ -> False
161 Both x y -> x == y
162 OnlyRight _ -> False
eef57f0 @kolmodin Allow to diff by package name
kolmodin authored
163 ShowPackages _ -> True
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
164 let packages = filter (showFilter . snd) (Map.assocs union)
165 mapM_ (putStrLn . uncurry showDiffState) packages
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
166 -}
Something went wrong with that request. Please try again.