move hashObject to HashObject library and generalize it to support all git object types
This commit is contained in:
parent
f1bd72ea54
commit
f596084a59
4 changed files with 36 additions and 22 deletions
|
@ -10,7 +10,6 @@ module Git.UnionMerge (
|
|||
merge_index
|
||||
) where
|
||||
|
||||
import System.Cmd.Utils
|
||||
import qualified Data.Text.Lazy as L
|
||||
import qualified Data.Text.Lazy.Encoding as L
|
||||
import qualified Data.Set as S
|
||||
|
@ -21,6 +20,8 @@ import Git.Sha
|
|||
import Git.CatFile
|
||||
import Git.Command
|
||||
import Git.UpdateIndex
|
||||
import Git.HashObject
|
||||
import Git.Types
|
||||
|
||||
{- Performs a union merge between two branches, staging it in the index.
|
||||
- Any previously staged changes in the index will be lost.
|
||||
|
@ -72,7 +73,7 @@ mergeFile :: String -> FilePath -> CatFileHandle -> Repo -> IO (Maybe String)
|
|||
mergeFile info file h repo = case filter (/= nullSha) [Ref asha, Ref bsha] of
|
||||
[] -> return Nothing
|
||||
(sha:[]) -> use sha
|
||||
shas -> use =<< either return (hashObject repo . unlines) =<<
|
||||
shas -> use =<< either return (hashObject repo BlobObject . unlines) =<<
|
||||
calcMerge . zip shas <$> mapM getcontents shas
|
||||
where
|
||||
[_colonmode, _bmode, asha, bsha, _status] = words info
|
||||
|
@ -80,18 +81,6 @@ mergeFile info file h repo = case filter (/= nullSha) [Ref asha, Ref bsha] of
|
|||
L.decodeUtf8 <$> catObject h s
|
||||
use sha = return $ Just $ update_index_line sha file
|
||||
|
||||
{- Injects some content into git, returning its Sha. -}
|
||||
hashObject :: Repo -> String -> IO Sha
|
||||
hashObject repo content = getSha subcmd $ do
|
||||
(h, s) <- pipeWriteRead (map Param params) content repo
|
||||
length s `seq` do
|
||||
forceSuccess h
|
||||
reap -- XXX unsure why this is needed
|
||||
return s
|
||||
where
|
||||
subcmd = "hash-object"
|
||||
params = [subcmd, "-w", "--stdin"]
|
||||
|
||||
{- Calculates a union merge between a list of refs, with contents.
|
||||
-
|
||||
- When possible, reuses the content of an existing ref, rather than
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue