2017-09-18 17:57:25 +00:00
|
|
|
{- git-annex exports
|
|
|
|
-
|
|
|
|
- Copyright 2017 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2017-09-18 17:57:25 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Annex.Export where
|
|
|
|
|
|
|
|
import Annex
|
|
|
|
import Annex.CatFile
|
2018-11-13 19:50:06 +00:00
|
|
|
import Types
|
2017-09-18 17:57:25 +00:00
|
|
|
import Types.Key
|
|
|
|
import qualified Git
|
2018-11-13 19:50:06 +00:00
|
|
|
import qualified Types.Remote as Remote
|
|
|
|
import Messages
|
2019-01-11 20:34:04 +00:00
|
|
|
import Utility.FileSystemEncoding
|
2017-09-18 17:57:25 +00:00
|
|
|
|
2017-09-25 13:49:33 +00:00
|
|
|
import Control.Applicative
|
2018-10-10 15:07:49 +00:00
|
|
|
import Data.Maybe
|
2017-09-25 13:49:33 +00:00
|
|
|
import Prelude
|
2017-09-19 18:20:47 +00:00
|
|
|
|
2017-09-18 17:57:25 +00:00
|
|
|
-- An export includes both annexed files and files stored in git.
|
|
|
|
-- For the latter, a SHA1 key is synthesized.
|
|
|
|
data ExportKey = AnnexKey Key | GitKey Key
|
|
|
|
deriving (Show, Eq, Ord)
|
|
|
|
|
|
|
|
asKey :: ExportKey -> Key
|
|
|
|
asKey (AnnexKey k) = k
|
|
|
|
asKey (GitKey k) = k
|
|
|
|
|
|
|
|
exportKey :: Git.Sha -> Annex ExportKey
|
|
|
|
exportKey sha = mk <$> catKey sha
|
|
|
|
where
|
|
|
|
mk (Just k) = AnnexKey k
|
2019-11-22 20:24:04 +00:00
|
|
|
mk Nothing = GitKey $ mkKey $ \k -> k
|
2019-01-11 20:34:04 +00:00
|
|
|
{ keyName = encodeBS $ Git.fromRef sha
|
2019-01-16 20:33:08 +00:00
|
|
|
, keyVariety = SHA1Key (HasExt False)
|
2017-09-18 17:57:25 +00:00
|
|
|
, keySize = Nothing
|
|
|
|
, keyMtime = Nothing
|
|
|
|
, keyChunkSize = Nothing
|
|
|
|
, keyChunkNum = Nothing
|
|
|
|
}
|
2017-09-19 18:20:47 +00:00
|
|
|
|
2019-04-09 17:03:59 +00:00
|
|
|
warnExportImportConflict :: Remote -> Annex ()
|
|
|
|
warnExportImportConflict r = do
|
|
|
|
ops <- Remote.isImportSupported r >>= return . \case
|
|
|
|
True -> "exported to and/or imported from"
|
|
|
|
False -> "exported to"
|
|
|
|
toplevelWarning True $
|
|
|
|
"Conflict detected. Different trees have been " ++ ops ++
|
|
|
|
Remote.name r ++
|
|
|
|
". Use git-annex export to resolve this conflict."
|