diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-01-27 17:38:06 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-01-27 17:38:06 -0400 |
commit | df81023501e2b0d930ec90cc6f5a6c6735f84818 (patch) | |
tree | 5bd3b9d8f91464bd27c9d86f700b975a76067147 /Annex | |
parent | 1e07d61b9669f85a02551d7858177bd33ffaea6f (diff) |
Repository tuning parameters can now be passed when initializing a repository for the first time.
* init: Repository tuning parameters can now be passed when initializing a
repository for the first time. For details, see
http://git-annex.branchable.com/tuning/
* merge: Refuse to merge changes from a git-annex branch of a repo
that has been tuned in incompatable ways.
Diffstat (limited to 'Annex')
-rw-r--r-- | Annex/AutoMerge.hs | 2 | ||||
-rw-r--r-- | Annex/Branch.hs | 11 | ||||
-rw-r--r-- | Annex/Content.hs | 2 | ||||
-rw-r--r-- | Annex/Difference.hs | 60 | ||||
-rw-r--r-- | Annex/Direct.hs | 6 | ||||
-rw-r--r-- | Annex/Init.hs | 2 | ||||
-rw-r--r-- | Annex/View.hs | 2 |
7 files changed, 79 insertions, 6 deletions
diff --git a/Annex/AutoMerge.hs b/Annex/AutoMerge.hs index 92cccc004..f0f183dfb 100644 --- a/Annex/AutoMerge.hs +++ b/Annex/AutoMerge.hs @@ -134,7 +134,7 @@ resolveMerge' (Just us) them u = do makelink key = do let dest = variantFile file key - l <- inRepo $ gitAnnexLink dest key + l <- calcRepo $ gitAnnexLink dest key replacewithlink dest l stageSymlink dest =<< hashSymlink l diff --git a/Annex/Branch.hs b/Annex/Branch.hs index 2191ec263..c67270312 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -49,9 +49,11 @@ import Annex.Perms import Logs import Logs.Transitions import Logs.Trust.Pure +import Logs.Difference.Pure import Annex.ReplaceFile import qualified Annex.Queue import Annex.Branch.Transitions +import qualified Annex {- Name of the branch that is used to store git-annex's information. -} name :: Git.Ref @@ -160,6 +162,7 @@ updateTo pairs = do <$> getLocal transitionsLog unless (null branches) $ do showSideAction merge_desc + mapM_ checkBranchDifferences refs mergeIndex jl refs let commitrefs = nub $ fullname:refs unlessM (handleTransitions jl localtransitions commitrefs) $ do @@ -537,3 +540,11 @@ performTransitionsLocked jl ts neednewlocalbranch transitionedrefs = do apply rest hasher file content' trustmap PreserveFile -> apply rest hasher file content trustmap + +checkBranchDifferences :: Git.Ref -> Annex () +checkBranchDifferences ref = do + theirdiffs <- allDifferences . parseDifferencesLog . decodeBS + <$> catFile ref differenceLog + mydiffs <- annexDifferences <$> Annex.getGitConfig + when (theirdiffs /= mydiffs) $ + error "Remote repository is tuned in incompatable way; cannot be merged with local repository." diff --git a/Annex/Content.hs b/Annex/Content.hs index 73f27fd28..a78cf674c 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -446,7 +446,7 @@ removeAnnex (ContentLock key) = withObjectLoc key remove removedirect removeInodeCache key mapM_ (resetfile cache) fs resetfile cache f = whenM (sameInodeCache f cache) $ do - l <- inRepo $ gitAnnexLink f key + l <- calcRepo $ gitAnnexLink f key secureErase f replaceFile f $ makeAnnexLink l diff --git a/Annex/Difference.hs b/Annex/Difference.hs new file mode 100644 index 000000000..cb363e80c --- /dev/null +++ b/Annex/Difference.hs @@ -0,0 +1,60 @@ +{- git-annex repository differences + - + - Copyright 2015 Joey Hess <id@joeyh.name> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Annex.Difference ( + module Types.Difference, + setDifferences, +) where + +import Common.Annex +import Types.Difference +import Logs.Difference +import Config +import Annex.UUID +import Logs.UUID +import Annex.Version +import qualified Annex + +import qualified Data.Map as M + +-- Differences are only allowed to be tweaked when initializing a +-- repository for the first time, and then only if there is not another +-- known uuid. If the repository was cloned from elsewhere, it inherits +-- the existing settings. +-- +-- Must be called before setVersion, so it can check if this is the first +-- time the repository is being initialized. +setDifferences :: Annex () +setDifferences = do + u <- getUUID + otherds <- either error return + =<< sanityCheckDifferences . allDifferences + <$> recordedDifferences + ds <- mappend otherds . annexDifferences <$> Annex.getGitConfig + when (ds /= mempty) $ do + ds'@(Differences l) <- ifM (isJust <$> getVersion) + ( do + oldds <- recordedDifferencesFor u + when (ds /= oldds) $ + warning $ "Cannot change tunable parameters in already initialized repository." + return oldds + , if otherds == mempty + then ifM (not . null . filter (/= u) . M.keys <$> uuidMap) + ( do + warning "Cannot change tunable parameters in a clone of an existing repository." + return mempty + , return ds + ) + else if otherds /= ds + then do + warning "The specified tunable parameters differ from values being used in other clones of this repository." + return otherds + else return ds + ) + forM_ l $ \d -> + setConfig (ConfigKey $ differenceConfigKey d) (differenceConfigVal d) + recordDifferences ds' u diff --git a/Annex/Direct.hs b/Annex/Direct.hs index 06d0342c1..1c733cb55 100644 --- a/Annex/Direct.hs +++ b/Annex/Direct.hs @@ -86,7 +86,7 @@ stageDirect = do deletegit file stageannexlink file key = do - l <- inRepo $ gitAnnexLink file key + l <- calcRepo $ gitAnnexLink file key stageSymlink file =<< hashSymlink l void $ addAssociatedFile key file @@ -131,7 +131,7 @@ addDirect file cache = do return False got (Just (key, _)) = ifM (sameInodeCache file [cache]) ( do - l <- inRepo $ gitAnnexLink file key + l <- calcRepo $ gitAnnexLink file key stageSymlink file =<< hashSymlink l addInodeCache key cache void $ addAssociatedFile key file @@ -282,7 +282,7 @@ updateWorkTree d oldref = do - with the content. -} movein item makeabs k f = unlessM (goodContent k f) $ do preserveUnannexed item makeabs f oldref - l <- inRepo $ gitAnnexLink f k + l <- calcRepo $ gitAnnexLink f k replaceFile f $ makeAnnexLink l toDirect k f diff --git a/Annex/Init.hs b/Annex/Init.hs index 24c5e18b1..3f27a1172 100644 --- a/Annex/Init.hs +++ b/Annex/Init.hs @@ -27,6 +27,7 @@ import Logs.UUID import Logs.Trust.Basic import Types.TrustLevel import Annex.Version +import Annex.Difference import Annex.UUID import Config import Annex.Direct @@ -73,6 +74,7 @@ initialize' = do checkCrippledFileSystem unlessM isBare $ hookWrite preCommitHook + setDifferences setVersion supportedVersion ifM (crippledFileSystem <&&> not <$> isBare) ( do diff --git a/Annex/View.hs b/Annex/View.hs index 3a9168f6c..315cc7df2 100644 --- a/Annex/View.hs +++ b/Annex/View.hs @@ -354,7 +354,7 @@ applyView' mkviewedfile getfilemetadata view = do let metadata' = getfilemetadata f `unionMetaData` metadata forM_ (genviewedfiles f metadata') $ \fv -> do f' <- fromRepo $ fromTopFilePath $ asTopFilePath fv - stagesymlink uh hasher f' =<< inRepo (gitAnnexLink f' k) + stagesymlink uh hasher f' =<< calcRepo (gitAnnexLink f' k) go uh hasher f Nothing | "." `isPrefixOf` f = do s <- liftIO $ getSymbolicLinkStatus f |