From 712c9fc590800d52369415a792d57493caf5f025 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 7 Dec 2015 15:45:08 -0400 Subject: [PATCH] require "annex/objects/" before key in pointer files 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 | 18 +++++++----------- Command/Smudge.hs | 4 +++- doc/todo/smudge.mdwn | 3 ++- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Annex/CatFile.hs b/Annex/CatFile.hs index 47ea86a31f..7c0022ca59 100644 --- a/Annex/CatFile.hs +++ b/Annex/CatFile.hs @@ -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 diff --git a/Command/Smudge.hs b/Command/Smudge.hs index c2dc285401..e08afed6bb 100644 --- a/Command/Smudge.hs +++ b/Command/Smudge.hs @@ -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 diff --git a/doc/todo/smudge.mdwn b/doc/todo/smudge.mdwn index 74a1435809..eb8ce416bc 100644 --- a/doc/todo/smudge.mdwn +++ b/doc/todo/smudge.mdwn @@ -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.