Permalink
Browse files

idx: search all idx files for a given sha

  • Loading branch information...
kfish committed May 10, 2011
1 parent 41ffcc3 commit 35f75983f57812fdf9648da16a6c4e9eb9dd6541
Showing with 22 additions and 8 deletions.
  1. +18 −3 Git/PackIndex.hs
  2. +4 −5 tools/ght.hs
View
@@ -3,7 +3,7 @@
module Git.PackIndex (
dumpRawPackIndex,
- findInPackIndex,
+ findInPackIdxs,
-- * Paths
idxPath
@@ -17,6 +17,7 @@ import Data.Word (Word32)
import Foreign.Ptr
import Foreign.Storable
import Data.Storable.Endian
+import System.Directory
import System.FilePath
import System.IO.MMap
import System.Posix.Types
@@ -100,6 +101,15 @@ outOfRange = error "Index out of range"
------------------------------------------------------------
+idxFiles :: IO [FilePath]
+idxFiles = do
+ packDir <- gitPath ("objects" </> "pack")
+ map (packDir </>) . filter isIdx <$> getDirectoryContents packDir
+ where
+ isIdx = (== ".idx") . takeExtension
+
+------------------------------------------------------------
+
idxFind :: IDX -> BS.ByteString -> IO (Maybe (IDX, Int))
idxFind idx sha = idxFind' 0 (idxSize idx)
where
@@ -118,8 +128,13 @@ idxFind idx sha = idxFind' 0 (idxSize idx)
where
i = floor ((fromIntegral (lo + hi)) / 2.0)
-findInPackIndex :: FilePath -> BS.ByteString -> IO ()
-findInPackIndex fp sha = do
+findInPackIdxs :: BS.ByteString -> IO ()
+findInPackIdxs sha = do
+ idxs <- idxFiles
+ mapM_ (findInPackIndex' sha) idxs
+
+findInPackIndex' :: BS.ByteString -> FilePath -> IO ()
+findInPackIndex' sha fp = do
idx <- readIdx fp
m'i <- idxFind idx sha
case m'i of
View
@@ -179,14 +179,13 @@ ghtFindIdx = defCmd {
cmdName = "find-idx",
cmdHandler = ghtFindIdxHandler,
cmdCategory = "Blob management",
- cmdShortDesc = "Find a SHA in a pack index",
- cmdExamples = [("Find SHA1 333fff in pack-abcd.idx", "abcd 333fff")]
+ cmdShortDesc = "Find a SHA in any pack index",
+ cmdExamples = [("Find SHA1 333fff", "333fff")]
}
ghtFindIdxHandler = do
- (fp:sha:_) <- appArgs
- fp' <- liftIO $ fIdx [fp]
- liftIO $ findInPackIndex fp' (readDigestBS sha)
+ (sha:_) <- appArgs
+ liftIO $ findInPackIdxs (readDigestBS sha)
------------------------------------------------------------
-- show-raw

0 comments on commit 35f7598

Please sign in to comment.