From e6f32bd11c94221f82fe9acf6ecb74be2fab4a76 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 14 Jan 2014 15:36:33 -0400 Subject: Fix a long-standing bug that could cause the wrong index file to be used when committing to the git-annex branch, if GIT_INDEX_FILE is set in the environment. This typically resulted in git-annex branch log files being committed to the master branch and later showing up in the work tree. (These log files can be safely removed.) --- Annex/Branch.hs | 5 ++++- Assistant/XMPP/Git.hs | 7 ++++--- Remote/Git.hs | 9 +++++---- Remote/Glacier.hs | 3 ++- Remote/Hook.hs | 4 ++-- debian/changelog | 5 +++++ doc/bugs/Weird_directories_appearing.mdwn | 9 +++++++++ 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Annex/Branch.hs b/Annex/Branch.hs index 658ad731f..5a9522689 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -29,6 +29,7 @@ module Annex.Branch ( import qualified Data.ByteString.Lazy.Char8 as L import qualified Data.Set as S import qualified Data.Map as M +import qualified Data.AssocList as A import qualified Control.Exception as E import Common.Annex @@ -342,10 +343,12 @@ withIndex' bootstrapping a = do let keyenv = words "USER PATH GIT_EXEC_PATH HOSTNAME HOME" let getEnvPair k = maybe Nothing (\v -> Just (k, v)) <$> getEnv k e <- liftIO $ catMaybes <$> forM keyenv getEnvPair + let e' = ("GIT_INDEX_FILE", f):e #else e <- liftIO getEnvironment + let e' = A.addEntry "GIT_INDEX_FILE" f e #endif - let g' = g { gitEnv = Just $ ("GIT_INDEX_FILE", f):e } + let g' = g { gitEnv = Just e' } r <- tryAnnex $ do Annex.changeState $ \s -> s { Annex.repo = g' } diff --git a/Assistant/XMPP/Git.hs b/Assistant/XMPP/Git.hs index 97b974f82..54cc6596f 100644 --- a/Assistant/XMPP/Git.hs +++ b/Assistant/XMPP/Git.hs @@ -43,6 +43,7 @@ import Control.Concurrent import System.Timeout import qualified Data.ByteString as B import qualified Data.Map as M +import qualified Data.AssocList as A {- Largest chunk of data to send in a single XMPP message. -} chunkSize :: Int @@ -114,13 +115,13 @@ xmppPush cid gitpush = do env <- liftIO getEnvironment path <- liftIO getSearchPath - let myenv = M.fromList + let myenv = A.addEntries [ ("PATH", intercalate [searchPathSeparator] $ tmpdir:path) , (relayIn, show inf) , (relayOut, show outf) , (relayControl, show controlf) ] - `M.union` M.fromList env + env inh <- liftIO $ fdToHandle readpush outh <- liftIO $ fdToHandle writepush @@ -132,7 +133,7 @@ xmppPush cid gitpush = do {- This can take a long time to run, so avoid running it in the - Annex monad. Also, override environment. -} g <- liftAnnex gitRepo - r <- liftIO $ gitpush $ g { gitEnv = Just $ M.toList myenv } + r <- liftIO $ gitpush $ g { gitEnv = Just myenv } liftIO $ do mapM_ killThread [t1, t2] diff --git a/Remote/Git.hs b/Remote/Git.hs index 900b60926..4c6b95f60 100644 --- a/Remote/Git.hs +++ b/Remote/Git.hs @@ -54,6 +54,7 @@ import Control.Concurrent import Control.Concurrent.MSampleVar import System.Process (std_in, std_err) import qualified Data.Map as M +import qualified Data.AssocList as A import Control.Exception.Extensible remote :: RemoteType @@ -414,13 +415,13 @@ fsckOnRemote r params Just (c, ps) -> batchCommand c ps | otherwise = return $ do program <- readProgramFile - env <- getEnvironment r' <- Git.Config.read r - let env' = + env <- getEnvironment + let env' = A.addEntries [ ("GIT_WORK_TREE", Git.repoPath r') , ("GIT_DIR", Git.localGitDir r') - ] ++ env - batchCommandEnv program (Param "fsck" : params) (Just env') + ] env + batchCommandEnv program (Param "fsck" : params) $ Just env' {- The passed repair action is run in the Annex monad of the remote. -} repairRemote :: Git.Repo -> Annex Bool -> Annex (IO Bool) diff --git a/Remote/Glacier.hs b/Remote/Glacier.hs index 78b573506..f0ff8d738 100644 --- a/Remote/Glacier.hs +++ b/Remote/Glacier.hs @@ -9,6 +9,7 @@ module Remote.Glacier (remote, jobList) where import qualified Data.Map as M import qualified Data.Text as T +import Data.AssocList as A import System.Environment import Common.Annex @@ -232,7 +233,7 @@ glacierEnv c u = go =<< getRemoteCredPairFor "glacier" c creds go Nothing = return Nothing go (Just (user, pass)) = do e <- liftIO getEnvironment - return $ Just $ (uk, user):(pk, pass):e + return $ Just $ A.addEntries [(uk, user), (pk, pass)] e creds = AWS.creds u (uk, pk) = credPairEnvironment creds diff --git a/Remote/Hook.hs b/Remote/Hook.hs index 056ad264c..d2ce48ddb 100644 --- a/Remote/Hook.hs +++ b/Remote/Hook.hs @@ -9,6 +9,7 @@ module Remote.Hook (remote) where import qualified Data.ByteString.Lazy as L import qualified Data.Map as M +import qualified Data.AssocList as A import System.Environment import Common.Annex @@ -77,8 +78,7 @@ hookSetup mu c = do hookEnv :: Action -> Key -> Maybe FilePath -> IO (Maybe [(String, String)]) hookEnv action k f = Just <$> mergeenv (fileenv f ++ keyenv) where - mergeenv l = M.toList . M.union (M.fromList l) - <$> M.fromList <$> getEnvironment + mergeenv l = A.addEntries l <$> getEnvironment env s v = ("ANNEX_" ++ s, v) keyenv = catMaybes [ Just $ env "KEY" (key2file k) diff --git a/debian/changelog b/debian/changelog index e844c5020..f1d76b781 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,11 @@ git-annex (5.20140108) UNRELEASED; urgency=medium * map: Fix display of v5 direct mode repos. * repair: Support old git versions from before git fsck --no-dangling was implemented. + * Fix a long-standing bug that could cause the wrong index file to be used + when committing to the git-annex branch, if GIT_INDEX_FILE is set in the + environment. This typically resulted in git-annex branch log files being + committed to the master branch and later showing up in the work tree. + (These log files can be safely removed.) -- Joey Hess Wed, 08 Jan 2014 13:13:54 -0400 diff --git a/doc/bugs/Weird_directories_appearing.mdwn b/doc/bugs/Weird_directories_appearing.mdwn index 5b2e59793..ea85cead6 100644 --- a/doc/bugs/Weird_directories_appearing.mdwn +++ b/doc/bugs/Weird_directories_appearing.mdwn @@ -71,3 +71,12 @@ Where does the e6a directory comes from? I don't suspect a bug there, but in my Thanks! Florian + +> [[fixed|done]] +> +> I know someone reported this a looong time ago (years), and I cannot find +> that bug report. Probably I closed it because I was unable to find a way +> to reproduce it. +> +> The spurious log files can be safely removed from your working tree. +> --[[Joey]] -- cgit v1.2.3