module Darcs.Patch.Index.Types where
import Darcs.Prelude
import Darcs.Patch.Info ( makePatchname, PatchInfo )
import Darcs.Util.Hash( SHA1, sha1short, sha1zero )
import Darcs.Util.Path ( anchorPath, AnchoredPath )
import Data.Binary ( Binary(..) )
data FileId = FileId {FileId -> AnchoredPath
cname::AnchoredPath,FileId -> Int
count::Int}
deriving (FileId -> FileId -> Bool
(FileId -> FileId -> Bool)
-> (FileId -> FileId -> Bool) -> Eq FileId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FileId -> FileId -> Bool
== :: FileId -> FileId -> Bool
$c/= :: FileId -> FileId -> Bool
/= :: FileId -> FileId -> Bool
Eq,Int -> FileId -> ShowS
[FileId] -> ShowS
FileId -> String
(Int -> FileId -> ShowS)
-> (FileId -> String) -> ([FileId] -> ShowS) -> Show FileId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FileId -> ShowS
showsPrec :: Int -> FileId -> ShowS
$cshow :: FileId -> String
show :: FileId -> String
$cshowList :: [FileId] -> ShowS
showList :: [FileId] -> ShowS
Show,Eq FileId
Eq FileId =>
(FileId -> FileId -> Ordering)
-> (FileId -> FileId -> Bool)
-> (FileId -> FileId -> Bool)
-> (FileId -> FileId -> Bool)
-> (FileId -> FileId -> Bool)
-> (FileId -> FileId -> FileId)
-> (FileId -> FileId -> FileId)
-> Ord FileId
FileId -> FileId -> Bool
FileId -> FileId -> Ordering
FileId -> FileId -> FileId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FileId -> FileId -> Ordering
compare :: FileId -> FileId -> Ordering
$c< :: FileId -> FileId -> Bool
< :: FileId -> FileId -> Bool
$c<= :: FileId -> FileId -> Bool
<= :: FileId -> FileId -> Bool
$c> :: FileId -> FileId -> Bool
> :: FileId -> FileId -> Bool
$c>= :: FileId -> FileId -> Bool
>= :: FileId -> FileId -> Bool
$cmax :: FileId -> FileId -> FileId
max :: FileId -> FileId -> FileId
$cmin :: FileId -> FileId -> FileId
min :: FileId -> FileId -> FileId
Ord)
instance Binary FileId where
put :: FileId -> Put
put (FileId AnchoredPath
rfp Int
i) = (AnchoredPath, Int) -> Put
forall t. Binary t => t -> Put
put (AnchoredPath
rfp,Int
i)
get :: Get FileId
get = do
(AnchoredPath
rfp,Int
cnt) <- Get (AnchoredPath, Int)
forall t. Binary t => Get t
get
FileId -> Get FileId
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (FileId -> Get FileId) -> FileId -> Get FileId
forall a b. (a -> b) -> a -> b
$ AnchoredPath -> Int -> FileId
FileId AnchoredPath
rfp Int
cnt
showFileId :: FileId -> String
showFileId :: FileId -> String
showFileId (FileId AnchoredPath
fn Int
i) = Int -> String
forall a. Show a => a -> String
show Int
iString -> ShowS
forall a. [a] -> [a] -> [a]
++String
"#"String -> ShowS
forall a. [a] -> [a] -> [a]
++String -> AnchoredPath -> String
anchorPath String
"." AnchoredPath
fn
newtype PatchId = PID {PatchId -> SHA1
patchId :: SHA1}
deriving (Get PatchId
[PatchId] -> Put
PatchId -> Put
(PatchId -> Put)
-> Get PatchId -> ([PatchId] -> Put) -> Binary PatchId
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
$cput :: PatchId -> Put
put :: PatchId -> Put
$cget :: Get PatchId
get :: Get PatchId
$cputList :: [PatchId] -> Put
putList :: [PatchId] -> Put
Binary,Int -> PatchId -> ShowS
[PatchId] -> ShowS
PatchId -> String
(Int -> PatchId -> ShowS)
-> (PatchId -> String) -> ([PatchId] -> ShowS) -> Show PatchId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PatchId -> ShowS
showsPrec :: Int -> PatchId -> ShowS
$cshow :: PatchId -> String
show :: PatchId -> String
$cshowList :: [PatchId] -> ShowS
showList :: [PatchId] -> ShowS
Show,Eq PatchId
Eq PatchId =>
(PatchId -> PatchId -> Ordering)
-> (PatchId -> PatchId -> Bool)
-> (PatchId -> PatchId -> Bool)
-> (PatchId -> PatchId -> Bool)
-> (PatchId -> PatchId -> Bool)
-> (PatchId -> PatchId -> PatchId)
-> (PatchId -> PatchId -> PatchId)
-> Ord PatchId
PatchId -> PatchId -> Bool
PatchId -> PatchId -> Ordering
PatchId -> PatchId -> PatchId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PatchId -> PatchId -> Ordering
compare :: PatchId -> PatchId -> Ordering
$c< :: PatchId -> PatchId -> Bool
< :: PatchId -> PatchId -> Bool
$c<= :: PatchId -> PatchId -> Bool
<= :: PatchId -> PatchId -> Bool
$c> :: PatchId -> PatchId -> Bool
> :: PatchId -> PatchId -> Bool
$c>= :: PatchId -> PatchId -> Bool
>= :: PatchId -> PatchId -> Bool
$cmax :: PatchId -> PatchId -> PatchId
max :: PatchId -> PatchId -> PatchId
$cmin :: PatchId -> PatchId -> PatchId
min :: PatchId -> PatchId -> PatchId
Ord,PatchId -> PatchId -> Bool
(PatchId -> PatchId -> Bool)
-> (PatchId -> PatchId -> Bool) -> Eq PatchId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PatchId -> PatchId -> Bool
== :: PatchId -> PatchId -> Bool
$c/= :: PatchId -> PatchId -> Bool
/= :: PatchId -> PatchId -> Bool
Eq)
pid2string :: PatchId -> String
pid2string :: PatchId -> String
pid2string = SHA1 -> String
forall a. Show a => a -> String
show (SHA1 -> String) -> (PatchId -> SHA1) -> PatchId -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchId -> SHA1
patchId
short :: PatchId -> Int
short :: PatchId -> Int
short (PID SHA1
sha1) = Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Int) -> Word32 -> Int
forall a b. (a -> b) -> a -> b
$ SHA1 -> Word32
sha1short SHA1
sha1
zero :: PatchId
zero :: PatchId
zero = SHA1 -> PatchId
PID SHA1
sha1zero
makePatchID :: PatchInfo -> PatchId
makePatchID :: PatchInfo -> PatchId
makePatchID = SHA1 -> PatchId
PID (SHA1 -> PatchId) -> (PatchInfo -> SHA1) -> PatchInfo -> PatchId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfo -> SHA1
makePatchname