summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-04-11 12:45:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-04-11 12:45:49 -0400
commitc924542e61607d725fbfa51ffbf88d825b4d3382 (patch)
treee76c12eec3942efc2c2ab006d5737822bfb500f4
parent378f61d0ef5564aab28442f09b2462ce7013ce1b (diff)
bup: Properly handle key names with spaces or other things that are not legal git refs.
Continue using the key name as bup ref name, to preserve backwards compatability, unless it is an illegal git ref. In that case, use a sha256 of the key name instead.
-rw-r--r--Git/Ref.hs4
-rw-r--r--Remote/Bup.hs20
-rw-r--r--debian/changelog2
-rw-r--r--doc/bugs/Problem_with_bup:_cannot_lock_refs.mdwn2
4 files changed, 22 insertions, 6 deletions
diff --git a/Git/Ref.hs b/Git/Ref.hs
index 29b69de9b..ee2f02187 100644
--- a/Git/Ref.hs
+++ b/Git/Ref.hs
@@ -67,8 +67,8 @@ matchingUniq ref repo = nubBy uniqref <$> matching ref repo
{- Checks if a String is a legal git ref name.
-
- The rules for this are complex; see git-check-ref-format(1) -}
-legalRef :: Bool -> String -> Bool
-legalRef allowonelevel s = all (== False) illegal
+legal :: Bool -> String -> Bool
+legal allowonelevel s = all (== False) illegal
where
illegal =
[ any ("." `isPrefixOf`) pathbits
diff --git a/Remote/Bup.hs b/Remote/Bup.hs
index 54aff7505..108181594 100644
--- a/Remote/Bup.hs
+++ b/Remote/Bup.hs
@@ -17,11 +17,14 @@ import qualified Git
import qualified Git.Command
import qualified Git.Config
import qualified Git.Construct
+import qualified Git.Ref
import Config
import Remote.Helper.Ssh
import Remote.Helper.Special
import Remote.Helper.Encryptable
import Crypto
+import Data.ByteString.Lazy.UTF8 (fromString)
+import Data.Digest.Pure.SHA
type BupRepo = String
@@ -103,7 +106,7 @@ bupSplitParams r buprepo k src = do
let os = map Param $ words o
showOutput -- make way for bup output
return $ bupParams "split" buprepo
- (os ++ [Param "-n", Param (show k), src])
+ (os ++ [Param "-n", Param (bupRef k), src])
store :: Git.Repo -> BupRepo -> Key -> Annex Bool
store r buprepo k = do
@@ -121,7 +124,7 @@ storeEncrypted r buprepo (cipher, enck) k = do
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
retrieve buprepo k f = do
- let params = bupParams "join" buprepo [Param $ show k]
+ let params = bupParams "join" buprepo [Param $ bupRef k]
liftIO $ catchBoolIO $ do
tofile <- openFile f WriteMode
pipeBup params Nothing (Just tofile)
@@ -131,7 +134,7 @@ retrieveCheap _ _ _ = return False
retrieveEncrypted :: BupRepo -> (Cipher, Key) -> Key -> FilePath -> Annex Bool
retrieveEncrypted buprepo (cipher, enck) _ f = do
- let params = bupParams "join" buprepo [Param $ show enck]
+ let params = bupParams "join" buprepo [Param $ bupRef enck]
liftIO $ catchBoolIO $ do
(pid, h) <- hPipeFrom "bup" $ toCommand params
withDecryptedContent cipher (L.hGetContents h) $ L.writeFile f
@@ -158,7 +161,7 @@ checkPresent r bupr k
where
params =
[ Params "show-ref --quiet --verify"
- , Param $ "refs/heads/" ++ show k]
+ , Param $ "refs/heads/" ++ bupRef k]
{- Store UUID in the annex.uuid setting of the bup repository. -}
storeBupUUID :: UUID -> BupRepo -> Annex ()
@@ -230,5 +233,14 @@ bup2GitRemote r
| "/" `isPrefixOf` d = d
| otherwise = "/~/" ++ d
+{- Converts a key into a git ref name, which bup-split -n will use to point
+ - to it. -}
+bupRef :: Key -> String
+bupRef k
+ | Git.Ref.legal True shown = shown
+ | otherwise = "git-annex-" ++ showDigest (sha256 (fromString shown))
+ where
+ shown = show k
+
bupLocal :: BupRepo -> Bool
bupLocal = notElem ':'
diff --git a/debian/changelog b/debian/changelog
index 2372820cc..274879f6e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
git-annex (3.20120407) UNRELEASED; urgency=low
* bugfix: Adding a dotfile also caused all non-dotfiles to be added.
+ * bup: Properly handle key names with spaces or other things that are
+ not legal git refs.
-- Joey Hess <joeyh@debian.org> Sun, 08 Apr 2012 12:23:42 -0400
diff --git a/doc/bugs/Problem_with_bup:_cannot_lock_refs.mdwn b/doc/bugs/Problem_with_bup:_cannot_lock_refs.mdwn
index ea3407577..f8df1f082 100644
--- a/doc/bugs/Problem_with_bup:_cannot_lock_refs.mdwn
+++ b/doc/bugs/Problem_with_bup:_cannot_lock_refs.mdwn
@@ -48,3 +48,5 @@ I tried to restart my session, in case bup adds my username to a group or someth
> A workaround is to switch to the SHA256 backend
> (`git annex migrate --backend=SHA256`), which avoids spaces in its keys.
> --[[Joey]]
+
+>> Now fixed in git. [[done]] --[[Joey]]