git annex add in adjusted unlocked branch

Cached the current branch lookup just because it seems unnecessary overhead
to run an extra git command per add to query the current branch.
This commit is contained in:
Joey Hess 2016-03-29 13:26:06 -04:00
parent 4226ae1040
commit 42b7ccc89f
Failed to extract signature
4 changed files with 29 additions and 5 deletions

View file

@ -136,6 +136,7 @@ data AnnexState = AnnexState
, workers :: [Either AnnexState (Async AnnexState)] , workers :: [Either AnnexState (Async AnnexState)]
, concurrentjobs :: Maybe Int , concurrentjobs :: Maybe Int
, keysdbhandle :: Maybe Keys.DbHandle , keysdbhandle :: Maybe Keys.DbHandle
, cachedcurrentbranch :: Maybe Git.Branch
} }
newState :: GitConfig -> Git.Repo -> AnnexState newState :: GitConfig -> Git.Repo -> AnnexState
@ -182,6 +183,7 @@ newState c r = AnnexState
, workers = [] , workers = []
, concurrentjobs = Nothing , concurrentjobs = Nothing
, keysdbhandle = Nothing , keysdbhandle = Nothing
, cachedcurrentbranch = Nothing
} }
{- Makes an Annex state object for the specified git repo. {- Makes an Annex state object for the specified git repo.

View file

@ -12,6 +12,7 @@ module Annex.AdjustedBranch (
originalToAdjusted, originalToAdjusted,
adjustedToOriginal, adjustedToOriginal,
fromAdjustedBranch, fromAdjustedBranch,
getAdjustment,
enterAdjustedBranch, enterAdjustedBranch,
updateAdjustedBranch, updateAdjustedBranch,
propigateAdjustedCommits, propigateAdjustedCommits,
@ -45,7 +46,7 @@ data Adjustment
| LockAdjustment | LockAdjustment
| HideMissingAdjustment | HideMissingAdjustment
| ShowMissingAdjustment | ShowMissingAdjustment
deriving (Show) deriving (Show, Eq)
reverseAdjustment :: Adjustment -> Adjustment reverseAdjustment :: Adjustment -> Adjustment
reverseAdjustment UnlockAdjustment = LockAdjustment reverseAdjustment UnlockAdjustment = LockAdjustment
@ -122,6 +123,9 @@ adjustedToOriginal b
bs = fromRef b bs = fromRef b
prefixlen = length adjustedBranchPrefix prefixlen = length adjustedBranchPrefix
getAdjustment :: Branch -> Maybe Adjustment
getAdjustment = fmap fst . adjustedToOriginal
fromAdjustedBranch :: Branch -> OrigBranch fromAdjustedBranch :: Branch -> OrigBranch
fromAdjustedBranch b = maybe b snd (adjustedToOriginal b) fromAdjustedBranch b = maybe b snd (adjustedToOriginal b)

View file

@ -35,6 +35,8 @@ import Logs.Location
import qualified Annex import qualified Annex
import qualified Annex.Queue import qualified Annex.Queue
import qualified Database.Keys import qualified Database.Keys
import qualified Git
import qualified Git.Branch
import Config import Config
import Utility.InodeCache import Utility.InodeCache
import Annex.ReplaceFile import Annex.ReplaceFile
@ -43,6 +45,7 @@ import Utility.CopyFile
import Utility.Touch import Utility.Touch
import Git.FilePath import Git.FilePath
import Annex.InodeSentinal import Annex.InodeSentinal
import Annex.AdjustedBranch
import Control.Exception (IOException) import Control.Exception (IOException)
@ -309,15 +312,32 @@ forceParams = ifM (Annex.getState Annex.force)
) )
{- Whether a file should be added unlocked or not. Default is to not, {- Whether a file should be added unlocked or not. Default is to not,
- unless symlinks are not supported. annex.addunlocked can override that. -} - unless symlinks are not supported. annex.addunlocked can override that.
- Also, when in an adjusted unlocked branch, always add files unlocked.
-}
addUnlocked :: Annex Bool addUnlocked :: Annex Bool
addUnlocked = isDirect <||> addUnlocked = isDirect <||>
(versionSupportsUnlockedPointers <&&> (versionSupportsUnlockedPointers <&&>
((not . coreSymlinks <$> Annex.getGitConfig) <||> ((not . coreSymlinks <$> Annex.getGitConfig) <||>
(annexAddUnlocked <$> Annex.getGitConfig) (annexAddUnlocked <$> Annex.getGitConfig) <||>
(maybe False (\b -> getAdjustment b == Just UnlockAdjustment) <$> cachedCurrentBranch)
) )
) )
cachedCurrentBranch :: Annex (Maybe Git.Branch)
cachedCurrentBranch = maybe cache (return . Just)
=<< Annex.getState Annex.cachedcurrentbranch
where
cache :: Annex (Maybe Git.Branch)
cache = do
mb <- inRepo Git.Branch.currentUnsafe
case mb of
Nothing -> return Nothing
Just b -> do
Annex.changeState $ \s ->
s { Annex.cachedcurrentbranch = Just b }
return (Just b)
{- Adds a file to the work tree for the key, and stages it in the index. {- Adds a file to the work tree for the key, and stages it in the index.
- The content of the key may be provided in a temp file, which will be - The content of the key may be provided in a temp file, which will be
- moved into place. -} - moved into place. -}

View file

@ -301,5 +301,3 @@ into adjusted view worktrees.]
(locking will cause the commits to fail) and so the assistant (locking will cause the commits to fail) and so the assistant
should not be running, or at least should have commits disabled should not be running, or at least should have commits disabled
when entering it. when entering it.
* When the adjusted branch unlocks files, behave as if annex.addunlocked is
set, so git annex add will add files unlocked.