2017-09-18 17:57:25 +00:00
|
|
|
{- git-annex exports
|
|
|
|
-
|
2021-03-05 18:03:51 +00:00
|
|
|
- Copyright 2017-2021 Joey Hess <id@joeyh.name>
|
2017-09-18 17:57:25 +00:00
|
|
|
-
|
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
|
|
|
-}
|
|
|
|
|
2021-03-05 18:03:51 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
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
|
2023-04-12 21:18:29 +00:00
|
|
|
import Git.Quote
|
2018-11-13 19:50:06 +00:00
|
|
|
import Messages
|
2017-09-18 17:57:25 +00:00
|
|
|
|
2021-03-05 18:17:48 +00:00
|
|
|
import Data.Maybe
|
2021-10-06 00:20:08 +00:00
|
|
|
import qualified Data.ByteString.Short as S (fromShort, toShort)
|
2021-03-05 18:17:48 +00:00
|
|
|
|
2021-03-05 18:03:51 +00:00
|
|
|
-- From a sha pointing to the content of a file to the key
|
|
|
|
-- to use to export it. When the file is annexed, it's the annexed key.
|
|
|
|
-- When the file is stored in git, it's a special type of key to indicate
|
|
|
|
-- that.
|
|
|
|
exportKey :: Git.Sha -> Annex Key
|
2017-09-18 17:57:25 +00:00
|
|
|
exportKey sha = mk <$> catKey sha
|
|
|
|
where
|
2021-03-05 18:03:51 +00:00
|
|
|
mk (Just k) = k
|
|
|
|
mk Nothing = gitShaKey sha
|
|
|
|
|
|
|
|
-- Encodes a git sha as a key. This is used to represent a non-annexed
|
|
|
|
-- file that is stored on a special remote, which necessarily needs a
|
|
|
|
-- key.
|
|
|
|
--
|
|
|
|
-- This is not the same as a SHA1 key, because the mapping needs to be
|
|
|
|
-- bijective, also because git may not always use SHA1, and because git
|
|
|
|
-- takes a SHA1 of the file size + content, while git-annex SHA1 keys
|
|
|
|
-- only checksum the content.
|
|
|
|
gitShaKey :: Git.Sha -> Key
|
|
|
|
gitShaKey (Git.Ref s) = mkKey $ \kd -> kd
|
2021-10-06 00:20:08 +00:00
|
|
|
{ keyName = S.toShort s
|
2021-03-05 18:03:51 +00:00
|
|
|
, keyVariety = OtherKey "GIT"
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Reverse of gitShaKey
|
|
|
|
keyGitSha :: Key -> Maybe Git.Sha
|
|
|
|
keyGitSha k
|
|
|
|
| fromKey keyVariety k == OtherKey "GIT" =
|
2021-10-06 00:20:08 +00:00
|
|
|
Just (Git.Ref (S.fromShort (fromKey keyName k)))
|
2021-03-05 18:03:51 +00:00
|
|
|
| otherwise = Nothing
|
2017-09-19 18:20:47 +00:00
|
|
|
|
2021-03-05 18:17:48 +00:00
|
|
|
-- Is a key storing a git sha, and not used for an annexed file?
|
|
|
|
isGitShaKey :: Key -> Bool
|
|
|
|
isGitShaKey = isJust . keyGitSha
|
|
|
|
|
2019-04-09 17:03:59 +00:00
|
|
|
warnExportImportConflict :: Remote -> Annex ()
|
|
|
|
warnExportImportConflict r = do
|
2020-12-17 20:25:46 +00:00
|
|
|
isimport <- Remote.isImportSupported r
|
|
|
|
isexport <- Remote.isExportSupported r
|
|
|
|
let (ops, resolvcmd) = case (isexport, isimport) of
|
|
|
|
(False, True) -> ("imported from", "git-annex import")
|
|
|
|
(True, False) -> ("exported to", "git-annex export")
|
|
|
|
_ -> ("exported to and/or imported from", "git-annex export")
|
filter out control characters in warning messages
Converted warning and similar to use StringContainingQuotedPath. Most
warnings are static strings, some do refer to filepaths that need to be
quoted, and others don't need quoting.
Note that, since quote filters out control characters of even
UnquotedString, this makes all warnings safe, even when an attacker
sneaks in a control character in some other way.
When json is being output, no quoting is done, since json gets its own
quoting.
This does, as a side effect, make warning messages in json output not
be indented. The indentation is only needed to offset warning messages
underneath the display of the file they apply to, so that's ok.
Sponsored-by: Brett Eisenberg on Patreon
2023-04-10 18:47:32 +00:00
|
|
|
toplevelWarning True $ UnquotedString $ unwords
|
2020-12-17 20:25:46 +00:00
|
|
|
[ "Conflict detected. Different trees have been"
|
|
|
|
, ops, Remote.name r ++ ". Use"
|
|
|
|
, resolvcmd
|
|
|
|
, "to resolve this conflict."
|
|
|
|
]
|