always format pointer file with a trailing newline
authorJoey Hess <joeyh@joeyh.name>
Thu, 10 Dec 2015 20:06:58 +0000 (16:06 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 10 Dec 2015 20:06:58 +0000 (16:06 -0400)
Before the smudge filter added a trailing newline, but other things that
wrote formatPointer to a file did not.

also some new pointer staging code to use later

Annex/Link.hs
Command/Smudge.hs

index f405403f26b2bf21b482840b27da8d42050633e3..61c61b56135f6364fe8c851316eaa3f431e58797 100644 (file)
@@ -110,12 +110,23 @@ hashSymlink' :: Git.HashObject.HashObjectHandle -> LinkTarget -> Annex Sha
 hashSymlink' h linktarget = liftIO $ Git.HashObject.hashBlob h $
        toInternalGitPath linktarget
 
-{- Stages a symlink to the annex, using a Sha of its target. -}
+{- Stages a symlink to an annexed object, using a Sha of its target. -}
 stageSymlink :: FilePath -> Sha -> Annex ()
 stageSymlink file sha =
        Annex.Queue.addUpdateIndex =<<
                inRepo (Git.UpdateIndex.stageSymlink file sha)
 
+{- Injects a pointer file content into git, returning its Sha. -}
+hashPointerFile :: Key -> Annex Sha
+hashPointerFile key = inRepo $ Git.HashObject.hashObject BlobObject $
+       formatPointer key
+
+{- Stages a pointer file, using a Sha of its content -}
+stagePointerFile :: FilePath -> Sha -> Annex ()
+stagePointerFile file sha =
+       Annex.Queue.addUpdateIndex =<<
+               inRepo (Git.UpdateIndex.stageFile sha FileBlob file)
+
 {- Parses a symlink target or a pointer file to a Key.
  - Only looks at the first line, as pointer files can have subsequent
  - lines. -}
@@ -138,7 +149,8 @@ parseLinkOrPointer' s = headMaybe (lines (fromInternalGitPath s)) >>= go
                | otherwise = Nothing
 
 formatPointer :: Key -> String
-formatPointer k = toInternalGitPath $ pathSeparator:objectDir </> key2file k
+formatPointer k = 
+       toInternalGitPath (pathSeparator:objectDir </> key2file k) ++ "\n"
 
 {- Checks if a file is a pointer to a key. -}
 isPointerFile :: FilePath -> Annex (Maybe Key)
index 14d3a7f41dea0851492b45db17276e9c4f99e8eb..cd33b193ea49771d6be01b256979d12603b758dc 100644 (file)
@@ -99,4 +99,4 @@ ingest file = do
        return k
 
 emitPointer :: Key -> IO ()
-emitPointer = putStrLn . formatPointer
+emitPointer = putStr . formatPointer