From d8b894c5cbb430c17e61f8c2d001c03b567bfb12 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 2 Jun 2016 15:58:22 -0400 Subject: better avoid switching to direct mode in clone of adjusted branch repo --- Annex/AdjustedBranch.hs | 14 ++++++++++---- Annex/Init.hs | 31 +++++++++++++++++-------------- 2 files changed, 27 insertions(+), 18 deletions(-) (limited to 'Annex') diff --git a/Annex/AdjustedBranch.hs b/Annex/AdjustedBranch.hs index 2d2a98531..67c36f399 100644 --- a/Annex/AdjustedBranch.hs +++ b/Annex/AdjustedBranch.hs @@ -20,6 +20,7 @@ module Annex.AdjustedBranch ( adjustToCrippledFileSystem, updateAdjustedBranch, propigateAdjustedCommits, + AdjustedClone(..), checkAdjustedClone, isGitVersionSupported, checkVersionSupported, @@ -539,6 +540,8 @@ diffTreeToTreeItem dti = TreeItem (Git.DiffTree.dstmode dti) (Git.DiffTree.dstsha dti) +data AdjustedClone = InAdjustedClone | NotInAdjustedClone | NeedUpgradeForAdjustedClone + {- Cloning a repository that has an adjusted branch checked out will - result in the clone having the same adjusted branch checked out -- but - the origbranch won't exist in the clone, nor will the basis. @@ -547,12 +550,12 @@ diffTreeToTreeItem dti = TreeItem - The repository may also need to be upgraded to a new version, if the - current version is too old to support adjusted branches. Returns True - when this is the case. -} -checkAdjustedClone :: Annex Bool +checkAdjustedClone :: Annex AdjustedClone checkAdjustedClone = go =<< inRepo Git.Branch.current where - go Nothing = return False + go Nothing = return NotInAdjustedClone go (Just currbranch) = case adjustedToOriginal currbranch of - Nothing -> return False + Nothing -> return NotInAdjustedClone Just (adj, origbranch) -> do let remotebranch = Git.Ref.underBase "refs/remotes/origin" origbranch let basis@(BasisBranch bb) = basisBranch (originalToAdjusted origbranch adj) @@ -560,7 +563,10 @@ checkAdjustedClone = go =<< inRepo Git.Branch.current setBasisBranch basis remotebranch unlessM (inRepo $ Git.Ref.exists origbranch) $ inRepo $ Git.Branch.update' origbranch remotebranch - not <$> versionSupportsUnlockedPointers + ifM versionSupportsUnlockedPointers + ( return InAdjustedClone + , return NeedUpgradeForAdjustedClone + ) -- git 2.2.0 needed for GIT_COMMON_DIR which is needed -- by updateAdjustedBranch to use withWorkTreeRelated. diff --git a/Annex/Init.hs b/Annex/Init.hs index 8c20e5e12..f2996993a 100644 --- a/Annex/Init.hs +++ b/Annex/Init.hs @@ -93,20 +93,23 @@ initialize' mversion = do whenM versionSupportsUnlockedPointers $ do configureSmudgeFilter Database.Keys.scanAssociatedFiles - whenM checkAdjustedClone $ - void $ upgrade True - ifM (crippledFileSystem <&&> (not <$> isBare)) - ( ifM versionSupportsUnlockedPointers - ( adjustToCrippledFileSystem - , do - enableDirectMode - setDirect True - ) - -- Handle case where this repo was cloned from a - -- direct mode repo - , unlessM isBare - switchHEADBack - ) + v <- checkAdjustedClone + case v of + NeedUpgradeForAdjustedClone -> void $ upgrade True + InAdjustedClone -> return () + NotInAdjustedClone -> + ifM (crippledFileSystem <&&> (not <$> isBare)) + ( ifM versionSupportsUnlockedPointers + ( adjustToCrippledFileSystem + , do + enableDirectMode + setDirect True + ) + -- Handle case where this repo was cloned from a + -- direct mode repo + , unlessM isBare + switchHEADBack + ) createInodeSentinalFile False uninitialize :: Annex () -- cgit v1.2.3