golfing
This commit is contained in:
parent
24a8b7f141
commit
7c2c17f706
1 changed files with 17 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex command
|
{- git-annex command
|
||||||
-
|
-
|
||||||
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
- Copyright 2010-2011 Joey Hess <joey@kitenet.net>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -165,8 +165,7 @@ excludeReferenced [] = return [] -- optimisation
|
||||||
excludeReferenced l = do
|
excludeReferenced l = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
c <- liftIO $ Git.pipeRead g [Param "show-ref"]
|
c <- liftIO $ Git.pipeRead g [Param "show-ref"]
|
||||||
excludeReferenced'
|
removewith (getKeysReferenced : map getKeysReferencedInGit (refs c))
|
||||||
(getKeysReferenced : (map getKeysReferencedInGit $ refs c))
|
|
||||||
(S.fromList l)
|
(S.fromList l)
|
||||||
where
|
where
|
||||||
-- Skip the git-annex branches, and get all other unique refs.
|
-- Skip the git-annex branches, and get all other unique refs.
|
||||||
|
@ -175,18 +174,15 @@ excludeReferenced l = do
|
||||||
filter ourbranches .
|
filter ourbranches .
|
||||||
map words . lines
|
map words . lines
|
||||||
cmpheads a b = head a == head b
|
cmpheads a b = head a == head b
|
||||||
ourbranchend = "/" ++ Branch.name
|
ourbranchend = '/' : Branch.name
|
||||||
ourbranches ws = not $ ourbranchend `isSuffixOf` last ws
|
ourbranches ws = not $ ourbranchend `isSuffixOf` last ws
|
||||||
excludeReferenced' :: ([Annex [Key]]) -> S.Set Key -> Annex [Key]
|
removewith [] s = return $ S.toList s
|
||||||
excludeReferenced' [] s = return $ S.toList s
|
removewith (a:as) s
|
||||||
excludeReferenced' (a:as) s
|
| s == S.empty = return [] -- optimisation
|
||||||
| s == S.empty = return [] -- optimisation
|
| otherwise = do
|
||||||
| otherwise = do
|
referenced <- a
|
||||||
referenced <- a
|
let !s' = s `S.difference` S.fromList referenced
|
||||||
let !s' = remove referenced
|
removewith as s'
|
||||||
excludeReferenced' as s'
|
|
||||||
where
|
|
||||||
remove l = s `S.difference` S.fromList l
|
|
||||||
|
|
||||||
{- Finds items in the first, smaller list, that are not
|
{- Finds items in the first, smaller list, that are not
|
||||||
- present in the second, larger list.
|
- present in the second, larger list.
|
||||||
|
@ -216,14 +212,13 @@ getKeysReferencedInGit ref = do
|
||||||
findkeys [] =<< liftIO (LsTree.lsTree g ref)
|
findkeys [] =<< liftIO (LsTree.lsTree g ref)
|
||||||
where
|
where
|
||||||
findkeys c [] = return c
|
findkeys c [] = return c
|
||||||
findkeys c (l:ls) = do
|
findkeys c (l:ls)
|
||||||
if isSymLink (LsTree.mode l)
|
| isSymLink (LsTree.mode l) = do
|
||||||
then do
|
content <- catFile ref $ LsTree.file l
|
||||||
content <- catFile ref $ LsTree.file l
|
case fileKey (takeFileName content) of
|
||||||
case fileKey (takeFileName content) of
|
Nothing -> findkeys c ls
|
||||||
Nothing -> findkeys c ls
|
Just k -> findkeys (k:c) ls
|
||||||
Just k -> findkeys (k:c) ls
|
| otherwise = findkeys c ls
|
||||||
else findkeys c ls
|
|
||||||
|
|
||||||
{- Looks in the specified directory for bad/tmp keys, and returns a list
|
{- Looks in the specified directory for bad/tmp keys, and returns a list
|
||||||
- of those that might still have value, or might be stale and removable.
|
- of those that might still have value, or might be stale and removable.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue