From fd304dce60bfbfd962783c2f50ff3ec085af4746 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 21 Feb 2019 13:38:27 -0400 Subject: [PATCH] split out Types.Import and some changes to the types in it --- Database/ContentIdentifier.hs | 2 +- Database/Types.hs | 2 +- Remote/Helper/ExportImport.hs | 2 +- Types/Import.hs | 43 +++++++++++++++++++++++++++++++++++ Types/Remote.hs | 24 +++---------------- git-annex.cabal | 1 + 6 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 Types/Import.hs diff --git a/Database/ContentIdentifier.hs b/Database/ContentIdentifier.hs index 660e645109..e8157f17bb 100644 --- a/Database/ContentIdentifier.hs +++ b/Database/ContentIdentifier.hs @@ -29,7 +29,7 @@ import qualified Database.Queue as H import Database.Init import Annex.Locations import Annex.Common hiding (delete) -import Types.Remote (ContentIdentifier(..)) +import Types.Import import Database.Persist.Sql hiding (Key) import Database.Persist.TH diff --git a/Database/Types.hs b/Database/Types.hs index 5145450345..a3a6061e4f 100644 --- a/Database/Types.hs +++ b/Database/Types.hs @@ -23,7 +23,7 @@ import Key import Utility.InodeCache import Git.Types (Ref(..)) import Types.UUID -import Types.Remote (ContentIdentifier(..)) +import Types.Import -- A serialized Key newtype SKey = SKey String diff --git a/Remote/Helper/ExportImport.hs b/Remote/Helper/ExportImport.hs index ce74bb0415..e9bb9a7feb 100644 --- a/Remote/Helper/ExportImport.hs +++ b/Remote/Helper/ExportImport.hs @@ -52,7 +52,7 @@ instance HasImportUnsupported (RemoteConfig -> RemoteGitConfig -> Annex Bool) wh instance HasImportUnsupported (ImportActions Annex) where importUnsupported = ImportActions - { listContents = return Nothing + { listImportableContents = return Nothing , retrieveExportWithContentIdentifier = \_ _ _ _ -> return Nothing , storeExportWithContentIdentifier = \_ _ _ _ _ -> return Nothing } diff --git a/Types/Import.hs b/Types/Import.hs new file mode 100644 index 0000000000..d31780167d --- /dev/null +++ b/Types/Import.hs @@ -0,0 +1,43 @@ +{- git-annex import types + - + - Copyright 2019 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Types.Import where + +import qualified Data.ByteString as S +import Data.Char + +import Types.Export +import Utility.QuickCheck +import Utility.FileSystemEncoding + +{- Location of content on a remote that can be imported. + - This is just an alias to ExportLocation, because both are referring to a + - location on the remote. -} +type ImportLocation = ExportLocation + +{- An identifier for content stored on a remote that has been imported into + - the repository. It should be reasonably short since it is stored in the + - git-annex branch. -} +newtype ContentIdentifier = ContentIdentifier S.ByteString + deriving (Eq, Ord, Show) + +instance Arbitrary ContentIdentifier where + -- Avoid non-ascii ContentIdentifiers because fully arbitrary + -- strings may not be encoded using the filesystem + -- encoding, which is normally applied to all input. + arbitrary = ContentIdentifier . encodeBS + <$> arbitrary `suchThat` all isAscii + +{- List of files that can be imported from a remote. -} +data ImportableContents = ImportableContents + { importableContents :: [(ImportLocation, ContentIdentifier)] + , importableHistory :: [ImportableContents] + -- ^ Used by remotes that support importing historical versions of + -- files that are stored in them. This is equivilant to a git + -- commit history. + } + deriving (Show) diff --git a/Types/Remote.hs b/Types/Remote.hs index dea51aaf32..4a010041bd 100644 --- a/Types/Remote.hs +++ b/Types/Remote.hs @@ -21,14 +21,11 @@ module Types.Remote , RetrievalSecurityPolicy(..) , isExportSupported , ExportActions(..) - , ContentIdentifier(..) - , ContentHistory(..) , ImportActions(..) ) where import qualified Data.Map as M -import qualified Data.ByteString as S import Data.Ord import qualified Git @@ -40,12 +37,12 @@ import Types.Creds import Types.UrlContents import Types.NumCopies import Types.Export +import Types.Import import Config.Cost import Utility.Metered import Git.Types (RemoteName) import Utility.SafeCommand import Utility.Url -import Utility.QuickCheck type RemoteConfigKey = String @@ -244,28 +241,13 @@ data ExportActions a = ExportActions , renameExport :: Key -> ExportLocation -> ExportLocation -> a Bool } -{- An identifier for content stored on a remote. It should be reasonably - - short since it is stored in the git-annex branch. -} -newtype ContentIdentifier = ContentIdentifier S.ByteString - deriving (Eq, Ord, Show, Arbitrary) - -{- Some remotes may support importing a history of versions of content that - - is stored in them. This is equivilant to a git commit history. -} -data ContentHistory t - = ContentHistoryNode t - | ContentHistory - { contentHistoryCurrent :: t - , contentHistoryPrev :: [ContentHistory t] - } - deriving (Show) - data ImportActions a = ImportActions -- Finds the current set of files that are stored in the remote, -- along with their content identifiers. -- -- May also find old versions of files that are still stored in the - -- remote, and return a ContentHistory with multiple nodes. - { listContents :: a (Maybe (ContentHistory [(ExportLocation, ContentIdentifier)])) + -- remote. + { listImportableContents :: a (Maybe ImportableContents) -- Retrieves a file from the remote. Ensures that the file -- it retrieves has the requested ContentIdentifier. -- diff --git a/git-annex.cabal b/git-annex.cabal index ff1e9b2249..0756fdec1a 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -976,6 +976,7 @@ Executable git-annex Types.FileMatcher Types.GitConfig Types.Group + Types.Import Types.Key Types.KeySource Types.LockCache