require "annex/objects/" before key in pointer files
authorJoey Hess <joeyh@joeyh.name>
Mon, 7 Dec 2015 19:45:08 +0000 (15:45 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 7 Dec 2015 19:45:08 +0000 (15:45 -0400)
This removes ambiguity, because while someone might have "WORM--foo" in a
file that's not intended to be a git-annex pointer file,
"annex/objects/WORM--foo" is less likely.

Also, 664cc987e806800ef46794f356003321170c1060 had a caveat about symlink
targets being parsed as pointer files, and now the same parser is used for
both.

I did not include any hash directories before the key in the pointer file,
as they're not needed. However, if they were included, the parser would
still work ok.

Annex/CatFile.hs
Command/Smudge.hs
doc/todo/smudge.mdwn

index 47ea86a31f0dbbe9a78950daf174f55a3f2dfc57..7c0022ca59ec607bf824972d2451a4daf426ec23 100644 (file)
@@ -83,16 +83,8 @@ catFileStop = do
 
 {- From ref to a symlink or a pointer file, get the key. -}
 catKey :: Ref -> Annex (Maybe Key)
-catKey ref = do
-       o <- catObject ref
-       if L.length o > maxsz
-               then return Nothing -- too big
-               else do
-                       let l = decodeBS o
-                       let l' = fromInternalGitPath l
-                       return $ if isLinkToAnnex l'
-                               then fileKey $ takeFileName l'
-                               else parsePointer l
+catKey ref = parsePointer . fromInternalGitPath . decodeBS . L.take maxsz 
+       <$> catObject ref
   where
        -- Want to avoid buffering really big files in git into memory.
        -- 8192 bytes is plenty for a pointer to a key.
@@ -102,7 +94,11 @@ catKey ref = do
 
 {- Only look at the first line of a pointer file. -}
 parsePointer :: String -> Maybe Key
-parsePointer s = headMaybe (lines s) >>= file2key
+parsePointer s = headMaybe (lines s) >>= go
+  where
+       go l
+               | isLinkToAnnex l = file2key $ takeFileName l
+               | otherwise = Nothing
 
 {- Gets a symlink target. -}
 catSymLinkTarget :: Sha -> Annex String
index c2dc285401b728e95f372e0dc33fe010f824120e..e08afed6bb3a69faff7744c9ea91c527f0894251 100644 (file)
@@ -18,6 +18,7 @@ import Types.KeySource
 import Backend
 import Logs.Location
 import qualified Database.AssociatedFiles as AssociatedFiles
+import Git.FilePath
 
 import qualified Data.ByteString.Lazy as B
 
@@ -104,7 +105,8 @@ ingest file = do
 -- Could add a newline and some text explaining this file is a pointer.
 -- parsePointer only looks at the first line.
 emitPointer :: Key -> IO ()
-emitPointer = putStrLn . key2file
+emitPointer k = putStrLn $ toInternalGitPath $
+       pathSeparator:objectDir </> key2file k
 
 updateAssociatedFiles :: Key -> FilePath -> Annex ()
 updateAssociatedFiles k f = do
index 74a1435809cc4db448362013233169071721e73b..eb8ce416bc1a7f76b2411e3165cba24211dadda2 100644 (file)
@@ -158,7 +158,8 @@ Using git-annex on a crippled filesystem that does not support symlinks.
 Data:
 
 * An annex pointer file has as its first line the git-annex key
-  that it's standing in for. Subsequent lines of the file might
+  that it's standing in for (prefixed with "annex/objects/", similar to
+  an annex symlink target). Subsequent lines of the file might
   be a message saying that the file's content is not currently available.
   An annex pointer file is checked into the git repository the same way
   that an annex symlink is checked in.