From b32b895413ad420c290f38281969dbdb2e6fc2ab Mon Sep 17 00:00:00 2001 From: Bertram Felgenhauer Date: Sat, 8 Nov 2008 20:28:29 +0100 Subject: [PATCH] Follow upstream changes -- Bytestring updates (Patch from Marc Weber) --- src/Git/Base.hs | 10 +++++----- src/Git/Fast.hs | 36 ++++++++++++++++++------------------ src/git-darcs-import.hs | 4 ++-- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Git/Base.hs b/src/Git/Base.hs index 130d5b3..0198475 100644 --- a/src/Git/Base.hs +++ b/src/Git/Base.hs @@ -46,8 +46,8 @@ import System.Posix (createPipe, setFdOption, fdToHandle, FdOption (..)) import System.FilePath ((), FilePath) import Darcs.SlurpDirectory (Slurpy) -import FastPackedString (PackedString, lengthPS, hPutPS) -import FileName (FileName, fn2fp) +import Darcs.Patch.FileName (FileName, fn2fp) +import qualified Data.ByteString as B -- | path to git executable gitBinary :: FilePath @@ -127,12 +127,12 @@ failure msg = do stopGitFastImport liftIO $ exitFailure -gitWriteFilePS :: FileName -> PackedString -> Git () +gitWriteFilePS :: FileName -> B.ByteString -> Git () gitWriteFilePS f ps = do fastGitCommand ["M 644 inline " ++ quoteFN f, - "data " ++ show (lengthPS ps)] + "data " ++ show (B.length ps)] h <- getGitPipe - liftIO $ hPutPS h ps + liftIO $ B.hPut h ps incTouched gitRemoveFile :: FileName -> Git () diff --git a/src/Git/Fast.hs b/src/Git/Fast.hs index 4afaa3c..b0aedfc 100644 --- a/src/Git/Fast.hs +++ b/src/Git/Fast.hs @@ -39,12 +39,12 @@ import Darcs.Utils (withCurrentDirectory) import Darcs.IO (WriteableDirectory (..), ReadableDirectory (..)) import Darcs.Patch.Core (Named (..)) import Darcs.Patch.Info (make_filename) -import FastPackedString ( - PackedString, lengthPS, takePS, dropPS, linesPS, unlinesPS, - nilPS, readFilePS, writeFilePS, unpackPS) import FileName (fp2fn, (///), FileName) import Git.Base import Git.Metadata (GitInfo (..), extractGitInfo) +import qualified Data.ByteString as B +import qualified Data.ByteString.Char8 as BC +import ByteStringUtils (linesPS, unlinesPS) -- | location of inventory file -- format: @@ -70,27 +70,27 @@ makeRepository = do pid <- runProcess gitBinary ["init-db"] Nothing Nothing Nothing Nothing Nothing checkProcessExitCode "Failed to initialise git repo" pid - writeFilePS inventoryFile nilPS - writeFilePS marksFile nilPS + B.writeFile inventoryFile B.empty + B.writeFile marksFile B.empty -- createDirectory "_darcs" -- createDirectory "_darcs/prefs" -- | the inventory might be ahead of git's actual commits - repair. checkInventory :: IO Int checkInventory = do - inv <- liftIO $ readFilePS inventoryFile - mrk <- liftIO $ readFilePS marksFile + inv <- liftIO $ B.readFile inventoryFile + mrk <- liftIO $ B.readFile marksFile let is = tail (reverse (linesPS inv)) is' = dropWhile (\l -> snd (splitInventoryLine l) > lastMark) is ms = linesPS mrk lastMark = length ms - 1 - inv' = unlinesPS (reverse (nilPS : is')) + inv' = unlinesPS (reverse (B.empty : is')) m' | null is = 1 | otherwise = snd (splitInventoryLine (head is')) - commit = unpackPS (snd (splitMarkLine (ms !! (m'-1)))) + commit = BC.unpack (snd (splitMarkLine (ms !! (m'-1)))) when (length is' < length is) $ do putStrLn $ "resetting to " ++ commit - writeFilePS inventoryFile inv' + B.writeFile inventoryFile inv' pid <- runProcess "git" ["checkout", "-f", "-q", commit] Nothing Nothing Nothing Nothing Nothing checkProcessExitCode ("failed to check out tip (" ++ commit ++ ")") pid @@ -99,15 +99,15 @@ checkInventory = do -- | parse a line from our inventory file. return darcs hash and mark -- number. -splitInventoryLine :: PackedString -> (PackedString, Int) -splitInventoryLine ps = (takePS 64 ps, read . unpackPS . dropPS 66 $ ps) +splitInventoryLine :: B.ByteString -> (B.ByteString, Int) +splitInventoryLine ps = (B.take 64 ps, read . BC.unpack . B.drop 66 $ ps) -- | parse a line from git-fast-import's marks file. return mark number -- and commit -splitMarkLine :: PackedString -> (Int, PackedString) +splitMarkLine :: B.ByteString -> (Int, B.ByteString) splitMarkLine ps = - let l = lengthPS ps - in (read . tail . unpackPS . takePS (l-41) $ ps, dropPS (l-40) ps) + let l = B.length ps + in (read . tail . BC.unpack . B.take (l-41) $ ps, B.drop (l-40) ps) -- | run a Git action in a repository. initialises the repository if it's fresh. runGit :: Git b -- ^ pre initialisation hook, for setting options @@ -144,9 +144,9 @@ runGit pre root act = withCurrentDirectory root $ do -- | read the inventory, and return a list of pairs of -- mark and darcs patch file -getInventory :: Git [(PackedString, Int)] +getInventory :: Git [(B.ByteString, Int)] getInventory = liftIO $ do - inv <- readFilePS inventoryFile + inv <- B.readFile inventoryFile return $ map splitInventoryLine (init (linesPS inv)) -- | apply a patch and add it to the inventory. the repository must be clean. @@ -222,7 +222,7 @@ instance WriteableDirectory Git where gitWriteFilePS f ps mCreateDirectory f = do liftSlurpMonad $ mCreateDirectory f - mWriteFilePS (f /// directoryMarker) nilPS + mWriteFilePS (f /// directoryMarker) B.empty mRemoveDirectory f = do mRemoveFile (f /// directoryMarker) liftSlurpMonad $ mRemoveDirectory f diff --git a/src/git-darcs-import.hs b/src/git-darcs-import.hs index 8665370..4cfc86b 100644 --- a/src/git-darcs-import.hs +++ b/src/git-darcs-import.hs @@ -30,10 +30,10 @@ import Darcs.Patch.Ordered (mapRL) import Darcs.Patch (RepoPatch) import Darcs.Sealed (Sealed (..)) import Darcs.Hopefully (PatchInfoAnd, info, hopefully) -import FastPackedString (unpackPS) import Git.Base (Git, getVerbose, modifyVerbose, failure) import Git.Fast (runGit, getInventory, applyAndCommit) import System.Posix.Signals (installHandler, sigPIPE, Handler (..)) +import qualified Data.ByteString.Char8 as BC options :: [OptDescr (Git ())] options = [ @@ -76,7 +76,7 @@ convert opts src dst0 = do work :: RepoPatch p => [PatchInfoAnd p] -> Git () work ps = do inv <- liftM reverse getInventory - let inv' = map (unpackPS . fst) inv + let inv' = map (BC.unpack . fst) inv case match ps inv' of Nothing -> failure "Destination is not a prefix of source." Just ps' -> forM_ ps' $ \(i, p@(NamedP pip _ _)) -> do -- 2.11.4.GIT