Stefan Saasen avatar Stefan Saasen committed 1d5fff8

Move functions related to the local workspace/repository out of the ObjectStore into Git.Repository

Comments (0)

Files changed (2)

src/Git/Repository.hs

+{-# LANGUAGE OverloadedStrings, RecordWildCards, DoAndIfThenElse #-}
+
+module Git.Repository (
+    checkoutHead
+  , readHead
+  , resolveTree
+) where
+
+import qualified Data.ByteString.Char8 as C
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Lazy as L
+import qualified Codec.Compression.Zlib as Z
+import qualified Crypto.Hash.SHA1 as SHA1
+import qualified Data.Attoparsec.ByteString.Char8 as AC
+import Control.Applicative ((<|>))
+-- FIXME -> don't use isJust/fromJust
+import Data.Maybe                                           (isJust, fromJust)
+import Text.Printf                                          (printf)
+import Git.Pack.Packfile
+import Git.Pack.Delta                                       (patch)
+import Git.Common                                           (GitRepository(..), eitherToMaybe)
+-- Tree
+import Git.Store.Blob
+import Git.Store.ObjectStore
+import System.FilePath
+import System.Directory
+import Control.Monad                                        (unless, liftM)
+import Data.Char                                            (isSpace)
+import Debug.Trace
+
+type ObjectId = String
+
+-- | Updates files in the working tree to match the given <tree-ish>
+--
+--
+--
+checkoutHead :: GitRepository -> IO ()
+checkoutHead repo = error "repo"
+
+-- | Resolve a tree given a <tree-ish>
+-- Similar to `parse_tree_indirect` defined in tree.c
+resolveTree :: GitRepository -> ObjectId -> IO String
+resolveTree repo sha = do
+        obj <- readObject repo sha
+        return $ show obj
+
+
+readHead :: GitRepository -> IO ObjectId
+readHead repo = do
+    let gitDir = getGitDirectory repo
+    ref <- C.readFile (gitDir </> "HEAD")
+    -- TODO check if valid HEAD
+    let unwrappedRef = C.unpack $ strip $ head $ tail $ C.split ':' ref
+    obj <- C.readFile (gitDir </> unwrappedRef)
+    return $ C.unpack $ strip obj
+  where strip = C.takeWhile (not . isSpace) . C.dropWhile isSpace
+
+

src/Git/Store/ObjectStore.hs

   , pathForPack
   , createGitRepositoryFromPackfile
   , updateHead
-  --  PRIVATE
-  , checkoutHead
-  , readHead
-  , resolveTree
+  -- ?
+  , readObject
+  , createRef
+  , getGitDirectory
 ) where
 
 import qualified Data.ByteString.Char8 as C
     unpackPackfile repo pack
     updateHead repo pack
 
--- | Updates files in the working tree to match the given <tree-ish>
---
---
---
-checkoutHead :: GitRepository -> IO ()
-checkoutHead repo = error "repo"
-
--- | Resolve a tree given a <tree-ish>
--- Similar to `parse_tree_indirect` defined in tree.c
-resolveTree :: GitRepository -> ObjectId -> IO String
-resolveTree repo sha = do
-        obj <- readObject repo sha
-        return $ show obj
-
-
-readHead :: GitRepository -> IO ObjectId
-readHead repo = do
-    let gitDir = getGitDirectory repo
-    ref <- C.readFile (gitDir </> "HEAD")
-    -- TODO check if valid HEAD
-    let unwrappedRef = C.unpack $ strip $ head $ tail $ C.split ':' ref
-    obj <- C.readFile (gitDir </> unwrappedRef)
-    return $ C.unpack $ strip obj
-  where strip = C.takeWhile (not . isSpace) . C.dropWhile isSpace
-
 
 -- TODO properly handle the error condition here
 unpackPackfile :: GitRepository -> Packfile -> IO ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.