Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New diff style

  • Loading branch information...
commit 3eb19fc4d00d5828b7a33b459e5c34abbce0a701 1 parent 3754021
der_eq@freenet.de authored
Showing with 62 additions and 9 deletions.
  1. +20 −4 Diff.hs
  2. +18 −0 Index.hs
  3. +24 −5 Main.hs
24 Diff.hs
View
@@ -1,13 +1,29 @@
module Diff where
-import Data.Set
+import Data.Set as Set
+import Data.Map as Map
diffSet :: (Eq a,Ord a)
=> Set a -- ^ Set 1
-> Set a -- ^ Set 2
-> (Set a,Set a,Set a) -- ^ (Things in 1 but not in 2,Things in 2 but not in 1,Things in both sets)
diffSet set1 set2 = let
- int = intersection set1 set2
- in1 = difference set1 int
- in2 = difference set2 int in (in1,in2,int)
+ int = Set.intersection set1 set2
+ in1 = Set.difference set1 int
+ in2 = Set.difference set2 int in (in1,in2,int)
+data DiffState a
+ = OnlyLeft a
+ | OnlyRight a
+ | Both a a
+
+diffBest :: (Ord k,Eq a)
+ => Map k a
+ -> Map k a
+ -> Map k (DiffState a)
+diffBest map1 map2 = Map.unionWith mergeDiffState
+ (Map.map OnlyLeft map1)
+ (Map.map OnlyRight map2)
+ where
+ mergeDiffState :: DiffState a -> DiffState a -> DiffState a
+ mergeDiffState (OnlyLeft x) (OnlyRight y) = Both x y
18 Index.hs
View
@@ -2,13 +2,19 @@ module Index where
import Data.List(isSuffixOf)
import Data.Maybe(mapMaybe)
+import qualified Data.Set as Set
+import qualified Data.Map as Map
+import Data.Version (Version,parseVersion)
import Codec.Compression.GZip(decompress)
import Data.ByteString.Lazy.Char8(ByteString,unpack)
import Codec.Archive.Tar
import Distribution.PackageDescription
+import Distribution.Package
import System.FilePath.Posix
+import MaybeRead (readPMaybe)
type Index = [(String,String,PackageDescription)]
+type IndexMap = Map.Map String (Set.Set Version)
readIndex :: ByteString -> Index
readIndex str = let
@@ -26,3 +32,15 @@ searchIndex f ind = mapMaybe (\(name,vers,pd) -> if f name vers
then Just pd
else Nothing
) ind
+
+indexMapFromList :: [PackageIdentifier] -> IndexMap
+indexMapFromList = foldl (\mp (PackageIdentifier {pkgName = name,pkgVersion = vers})
+ -> Map.alter ((Just).(maybe (Set.singleton vers) (Set.insert vers))) name mp) Map.empty
+
+indexToPackageIdentifier :: Index -> [PackageIdentifier]
+indexToPackageIdentifier = mapMaybe (\(name,vers_str,_) -> do
+ vers <- readPMaybe parseVersion vers_str
+ return $ PackageIdentifier {pkgName = name,pkgVersion = vers})
+
+bestVersions :: IndexMap -> Map.Map String Version
+bestVersions = Map.map Set.findMax
29 Main.hs
View
@@ -12,6 +12,7 @@ import System.IO
import Data.Char
import Data.List
import qualified Data.Set as Set
+import qualified Data.Map as Map
import Action
import Error
@@ -54,16 +55,34 @@ merge pid = do
ebuild <- fixSrc pid (cabal2ebuild pkg)
mergeEbuild portTree ebuild
+tabs :: String -> String
+tabs str = let len = length str in str++(if len < 3*8
+ then replicate (3*8-len) ' '
+ else "")
+
+showDiffState :: String -> DiffState Version -> String
+showDiffState name st = (tabs name) ++ " [" ++ (case st of
+ Both x y -> showVersion x ++ (case compare x y of
+ EQ -> "="
+ GT -> ">"
+ LT -> "<") ++ showVersion y
+ OnlyLeft x -> showVersion x ++ ">none"
+ OnlyRight y -> "none<"++showVersion y)++"]"
+
diff :: DiffMode -> HPAction ()
diff mode = do
cfg <- getCfg
portTree <- getPortageTree
cache <- readCache portTree
- let serverPkgs'=map (\(_,_,pd)-> (package pd) {pkgName=map toLower (pkgName $ package pd)}) cache
+ --let serverPkgs = map (\(_,_,pd)-> (package pd) {pkgName=map toLower (pkgName $ package pd)}) cache
+ let serverPkgs = bestVersions $ indexMapFromList $ indexToPackageIdentifier cache
portTree <- getPortageTree
- portagePkgs <- portageGetPackages portTree
- let (inport,inhack,inboth)=diffSet (Set.fromList portagePkgs) (Set.fromList serverPkgs')
- let showPkgSet set = mapM_ (\pkg->echoLn (pkgName pkg++"-"++showVersion (pkgVersion pkg))) (Set.elems set)
+ portagePkgs' <- portageGetPackages portTree
+ let portagePkgs = bestVersions $ indexMapFromList portagePkgs'
+ let diff = diffBest serverPkgs portagePkgs
+ mapM_ (\(name,st) -> info $ showDiffState name st) (Map.assocs diff)
+ --let (inport,inhack,inboth)=diffSet (Set.fromList portagePkgs) (Set.fromList serverPkgs)
+ {-let showPkgSet set = mapM_ (\pkg->echoLn (pkgName pkg++"-"++showVersion (pkgVersion pkg))) (Set.elems set)
let vindent = case verbosity cfg of
Silent -> id
_ -> indent
@@ -75,7 +94,7 @@ diff mode = do
vindent $ showPkgSet inport)
when (mode==ShowAll || mode==ShowCommon) (do
info "Packages in the overlay and hackage:"
- vindent $ showPkgSet inboth)
+ vindent $ showPkgSet inboth)-}
update :: HPAction ()
update = do
Please sign in to comment.
Something went wrong with that request. Please try again.