diff options
author | Joey Hess <joey@kitenet.net> | 2011-11-16 02:23:34 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-11-16 02:41:46 -0400 |
commit | 9290095fc21953cd1fe0a71f7c8a454934194e3b (patch) | |
tree | c4ac1373ca1961e5f76ba80b840491b7077c5ab9 /Annex | |
parent | 272a67921cdc6d8d40641a9cb71b744ef1f76128 (diff) |
improve type signatures with a Ref newtype
In git, a Ref can be a Sha, or a Branch, or a Tag. I added type aliases for
those. Note that this does not prevent mixing up of eg, refs and branches
at the type level. Since git really doesn't care, except rare cases like
git update-ref, or git tag -d, that seems ok for now.
There's also a tree-ish, but let's just use Ref for it. A given Sha or Ref
may or may not be a tree-ish, depending on the object type, so there seems
no point in trying to represent it at the type level.
Diffstat (limited to 'Annex')
-rw-r--r-- | Annex/Branch.hs | 47 | ||||
-rw-r--r-- | Annex/CatFile.hs | 3 |
2 files changed, 25 insertions, 25 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs index a75773e19..a62a1384c 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -31,19 +31,17 @@ import qualified Git.UnionMerge import qualified Annex import Annex.CatFile -type GitRef = String - {- Name of the branch that is used to store git-annex's information. -} -name :: GitRef -name = "git-annex" +name :: Git.Ref +name = Git.Ref "git-annex" {- Fully qualified name of the branch. -} -fullname :: GitRef -fullname = "refs/heads/" ++ name +fullname :: Git.Ref +fullname = Git.Ref $ "refs/heads/" ++ show name {- Branch's name in origin. -} -originname :: GitRef -originname = "origin/" ++ name +originname :: Git.Ref +originname = Git.Ref $ "origin/" ++ show name {- A separate index file for the branch. -} index :: Git.Repo -> FilePath @@ -104,7 +102,8 @@ create :: Annex () create = unlessM hasBranch $ do e <- hasOrigin if e - then inRepo $ Git.run "branch" [Param name, Param originname] + then inRepo $ Git.run "branch" + [Param $ show name, Param $ show originname] else withIndex' True $ inRepo $ Git.commit "branch created" fullname [] @@ -140,8 +139,8 @@ update = onceonly $ do let merge_desc = if null branches then "update" else "merging " ++ - (unwords $ map Git.refDescribe branches) ++ - " into " ++ name + (unwords $ map (show . Git.refDescribe) branches) ++ + " into " ++ show name unless (null branches) $ do showSideAction merge_desc {- Note: This merges the branches into the index. @@ -164,12 +163,12 @@ update = onceonly $ do {- Checks if the second branch has any commits not present on the first - branch. -} -changedBranch :: String -> String -> Annex Bool +changedBranch :: Git.Branch -> Git.Branch -> Annex Bool changedBranch origbranch newbranch = not . L.null <$> diffs where diffs = inRepo $ Git.pipeRead [ Param "log" - , Param (origbranch ++ ".." ++ newbranch) + , Param (show origbranch ++ ".." ++ show newbranch) , Params "--oneline -n1" ] @@ -181,7 +180,7 @@ changedBranch origbranch newbranch = not . L.null <$> diffs - every commit present in all the other refs, as well as in the - git-annex branch. -} -tryFastForwardTo :: [String] -> Annex Bool +tryFastForwardTo :: [Git.Ref] -> Annex Bool tryFastForwardTo [] = return True tryFastForwardTo (first:rest) = do -- First, check that the git-annex branch does not contain any @@ -194,7 +193,7 @@ tryFastForwardTo (first:rest) = do where no_ff = return False do_ff branch = do - inRepo $ Git.run "update-ref" [Param fullname, Param branch] + inRepo $ Git.run "update-ref" [Param $ show fullname, Param $ show branch] return True findbest c [] = return $ Just c findbest c (r:rs) @@ -220,9 +219,9 @@ disableUpdate = Annex.changeState setupdated old = Annex.branchstate s {- Checks if a git ref exists. -} -refExists :: GitRef -> Annex Bool +refExists :: Git.Ref -> Annex Bool refExists ref = inRepo $ Git.runBool "show-ref" - [Param "--verify", Param "-q", Param ref] + [Param "--verify", Param "-q", Param $ show ref] {- Does the main git-annex branch exist? -} hasBranch :: Annex Bool @@ -238,12 +237,12 @@ hasSomeBranch = not . null <$> siblingBranches {- List of git-annex (refs, branches), including the main one and any - from remotes. Duplicate refs are filtered out. -} -siblingBranches :: Annex [(String, String)] +siblingBranches :: Annex [(Git.Ref, Git.Branch)] siblingBranches = do - r <- inRepo $ Git.pipeRead [Param "show-ref", Param name] - return $ nubBy uref $ map (pair . words . L.unpack) (L.lines r) + r <- inRepo $ Git.pipeRead [Param "show-ref", Param $ show name] + return $ nubBy uref $ map (gen . words . L.unpack) (L.lines r) where - pair l = (head l, last l) + gen l = (Git.Ref $ head l, Git.Ref $ last l) uref (a, _) (b, _) = a == b {- Applies a function to modifiy the content of a file. @@ -291,7 +290,7 @@ get' staleok file = fromcache =<< getCache file files :: Annex [FilePath] files = withIndexUpdate $ do bfiles <- inRepo $ Git.pipeNullSplit - [Params "ls-tree --name-only -r -z", Param fullname] + [Params "ls-tree --name-only -r -z", Param $ show fullname] jfiles <- getJournalledFiles return $ jfiles ++ bfiles @@ -346,10 +345,10 @@ stageJournalFiles = do hClose toh exitSuccess hClose toh - s <- hGetContents fromh + shas <- map Git.Ref . lines <$> hGetContents fromh -- update the index, also in just one command Git.UnionMerge.update_index g $ - index_lines (lines s) $ map fileJournal fs + index_lines shas (map fileJournal fs) hClose fromh forceSuccess pid mapM_ removeFile paths diff --git a/Annex/CatFile.hs b/Annex/CatFile.hs index 0541f7269..1d996edfd 100644 --- a/Annex/CatFile.hs +++ b/Annex/CatFile.hs @@ -13,10 +13,11 @@ module Annex.CatFile ( import qualified Data.ByteString.Lazy.Char8 as L import Common.Annex +import qualified Git import qualified Git.CatFile import qualified Annex -catFile :: String -> FilePath -> Annex L.ByteString +catFile :: Git.Branch -> FilePath -> Annex L.ByteString catFile branch file = do h <- catFileHandle liftIO $ Git.CatFile.catFile h branch file |