summaryrefslogtreecommitdiff
path: root/Types/RefSpec.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-07 17:13:50 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-07 17:13:50 -0400
commit986b2eb33a8a973cc0690e4dfed0f5b50d0719f9 (patch)
tree519bb536f18287c8be890aaad6e6ef93639c8825 /Types/RefSpec.hs
parentcfb055f838da0c51a50224bf759b42fb263dcfec (diff)
unused: --used-refspec can now be configured to look at refs in the reflog. This provides a way to not consider old versions of files to be unused after they have reached a specified age, when the old refs in the reflog expire.
May be slow.
Diffstat (limited to 'Types/RefSpec.hs')
-rw-r--r--Types/RefSpec.hs16
1 files changed, 12 insertions, 4 deletions
diff --git a/Types/RefSpec.hs b/Types/RefSpec.hs
index 42f4c6226..091631abd 100644
--- a/Types/RefSpec.hs
+++ b/Types/RefSpec.hs
@@ -15,7 +15,11 @@ import Data.Either
type RefSpec = [RefSpecPart]
-data RefSpecPart = AddRef Ref | AddMatching Glob | RemoveMatching Glob
+data RefSpecPart
+ = AddRef Ref
+ | AddMatching Glob
+ | AddRefLog
+ | RemoveMatching Glob
allRefSpec :: RefSpec
allRefSpec = [AddMatching $ compileGlob "*" CaseSensative]
@@ -30,15 +34,19 @@ parseRefSpec v = case partitionEithers (map mk $ split ":" v) of
Right $ AddMatching $ compileGlob s CaseSensative
| otherwise = Right $ AddRef $ Ref s
mk ('-':s) = Right $ RemoveMatching $ compileGlob s CaseSensative
+ mk "reflog" = Right AddRefLog
mk s = Left $ "bad refspec item \"" ++ s ++ "\" (expected + or - prefix)"
-applyRefSpec :: RefSpec -> [Ref] -> [Ref]
-applyRefSpec refspec rs = go [] refspec
+applyRefSpec :: Monad m => RefSpec -> [Ref] -> m [Sha] -> m [Ref]
+applyRefSpec refspec rs getreflog = go [] refspec
where
- go c [] = reverse c
+ go c [] = return (reverse c)
go c (AddRef r : rest) = go (r:c) rest
go c (AddMatching g : rest) =
let add = filter (matchGlob g . fromRef) rs
in go (add ++ c) rest
+ go c (AddRefLog : rest) = do
+ reflog <- getreflog
+ go (reflog ++ c) rest
go c (RemoveMatching g : rest) =
go (filter (not . matchGlob g . fromRef) c) rest