import Annex.Locations as X
import Annex.Debug as X (fastDebug, debug)
import Messages as X
-import Git.Filename as X
+import Git.Quote as X
#ifndef mingw32_HOST_OS
import System.Posix.IO as X hiding (createPipe)
#endif
import Types.Key
import qualified Git
import qualified Types.Remote as Remote
-import Git.Filename
+import Git.Quote
import Messages
import Data.Maybe
import Utility.LockFile.LockStatus
import Config (pidLockFile)
import Messages (warning)
-import Git.Filename
+import Git.Quote
import System.Posix
import Git.Command
import Git.FilePath
import Git.DiffTreeItem
-import qualified Git.Filename
+import qualified Git.Quote
import qualified Git.Ref
import Utility.Attoparsec
<*> (maybe (fail "bad dstsha") return . extractSha =<< nextword)
<* A8.char ' '
<*> A.takeByteString
- <*> pure (asTopFilePath $ fromInternalGitPath $ Git.Filename.unquote f)
+ <*> pure (asTopFilePath $ fromInternalGitPath $ Git.Quote.unquote f)
where
nextword = A8.takeTill (== ' ')
import Common
import Git
-import Git.Filename
+import Git.Quote
import qualified System.FilePath.ByteString as P
import qualified System.FilePath.Posix.ByteString
+++ /dev/null
-{- Some git commands output quoted filenames, in a rather annoyingly complex
- - C-style encoding.
- -
- - Copyright 2010-2023 Joey Hess <id@joeyh.name>
- -
- - Licensed under the GNU AGPL version 3 or higher.
- -}
-
-{-# LANGUAGE OverloadedStrings, TypeSynonymInstances #-}
-
-module Git.Filename (
- unquote,
- quote,
- noquote,
- QuotePath(..),
- StringContainingQuotedPath(..),
- quotedPaths,
- prop_quote_unquote_roundtrip,
-) where
-
-import Common
-import Utility.Format (decode_c, encode_c, encode_c', isUtf8Byte)
-import Utility.QuickCheck
-import Utility.SafeOutput
-
-import Data.Char
-import Data.Word
-import Data.String
-import qualified Data.ByteString as S
-import qualified Data.Semigroup as Sem
-import Prelude
-
-unquote :: S.ByteString -> RawFilePath
-unquote b = case S.uncons b of
- Nothing -> b
- Just (h, t)
- | h /= q -> b
- | otherwise -> case S.unsnoc t of
- Nothing -> b
- Just (i, l)
- | l /= q -> b
- | otherwise -> decode_c i
- where
- q :: Word8
- q = fromIntegral (ord '"')
-
--- always encodes and double quotes, even in cases that git does not
-quoteAlways :: RawFilePath -> S.ByteString
-quoteAlways s = "\"" <> encode_c needencode s <> "\""
- where
- needencode c = isUtf8Byte c || c == fromIntegral (ord '"')
-
--- git config core.quotePath controls whether to quote unicode characters
-newtype QuotePath = QuotePath Bool
-
-class Quoteable t where
- -- double quotes and encodes when git would
- quote :: QuotePath -> t -> S.ByteString
-
- noquote :: t -> S.ByteString
-
-instance Quoteable RawFilePath where
- quote (QuotePath qp) s = case encode_c' needencode s of
- Nothing -> s
- Just s' -> "\"" <> s' <> "\""
- where
- needencode c
- | c == fromIntegral (ord '"') = True
- | qp = isUtf8Byte c
- | otherwise = False
-
- noquote = id
-
--- Allows building up a string that contains paths, which will get quoted.
--- With OverloadedStrings, strings are passed through without quoting.
--- Eg: QuotedPath f <> ": not found"
-data StringContainingQuotedPath
- = UnquotedString String
- | UnquotedByteString S.ByteString
- | QuotedPath RawFilePath
- | StringContainingQuotedPath :+: StringContainingQuotedPath
- deriving (Show, Eq)
-
-quotedPaths :: [RawFilePath] -> StringContainingQuotedPath
-quotedPaths [] = mempty
-quotedPaths (p:ps) = QuotedPath p <> if null ps
- then mempty
- else " " <> quotedPaths ps
-
-instance Quoteable StringContainingQuotedPath where
- quote _ (UnquotedString s) = safeOutput (encodeBS s)
- quote _ (UnquotedByteString s) = safeOutput s
- quote qp (QuotedPath p) = quote qp p
- quote qp (a :+: b) = quote qp a <> quote qp b
-
- noquote (UnquotedString s) = encodeBS s
- noquote (UnquotedByteString s) = s
- noquote (QuotedPath p) = p
- noquote (a :+: b) = noquote a <> noquote b
-
-instance IsString StringContainingQuotedPath where
- fromString = UnquotedByteString . encodeBS
-
-instance Sem.Semigroup StringContainingQuotedPath where
- UnquotedString a <> UnquotedString b = UnquotedString (a <> b)
- UnquotedByteString a <> UnquotedByteString b = UnquotedByteString (a <> b)
- a <> b = a :+: b
-
-instance Monoid StringContainingQuotedPath where
- mempty = UnquotedByteString mempty
-
--- Encoding and then decoding roundtrips only when the string does not
--- contain high unicode, because eg, both "\12345" and "\227\128\185"
--- are encoded to "\343\200\271".
---
--- That is not a real-world problem, and using TestableFilePath
--- limits what's tested to ascii, so avoids running into it.
-prop_quote_unquote_roundtrip :: TestableFilePath -> Bool
-prop_quote_unquote_roundtrip ts =
- s == fromRawFilePath (unquote (quoteAlways (toRawFilePath s)))
- where
- s = fromTestableFilePath ts
import Git
import Git.Command
import Git.FilePath
-import qualified Git.Filename
+import qualified Git.Quote
import Utility.Attoparsec
import Numeric
-- sha
<*> (Ref <$> A8.takeTill A8.isSpace)
- fileparser = asTopFilePath . Git.Filename.unquote <$> A.takeByteString
+ fileparser = asTopFilePath . Git.Quote.unquote <$> A.takeByteString
sizeparser = fmap Just A8.decimal
--- /dev/null
+{- Some git commands output quoted filenames, in a rather annoyingly complex
+ - C-style encoding.
+ -
+ - Copyright 2010-2023 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
+{-# LANGUAGE OverloadedStrings, TypeSynonymInstances #-}
+
+module Git.Quote (
+ unquote,
+ quote,
+ noquote,
+ QuotePath(..),
+ StringContainingQuotedPath(..),
+ quotedPaths,
+ prop_quote_unquote_roundtrip,
+) where
+
+import Common
+import Utility.Format (decode_c, encode_c, encode_c', isUtf8Byte)
+import Utility.QuickCheck
+import Utility.SafeOutput
+
+import Data.Char
+import Data.Word
+import Data.String
+import qualified Data.ByteString as S
+import qualified Data.Semigroup as Sem
+import Prelude
+
+unquote :: S.ByteString -> RawFilePath
+unquote b = case S.uncons b of
+ Nothing -> b
+ Just (h, t)
+ | h /= q -> b
+ | otherwise -> case S.unsnoc t of
+ Nothing -> b
+ Just (i, l)
+ | l /= q -> b
+ | otherwise -> decode_c i
+ where
+ q :: Word8
+ q = fromIntegral (ord '"')
+
+-- always encodes and double quotes, even in cases that git does not
+quoteAlways :: RawFilePath -> S.ByteString
+quoteAlways s = "\"" <> encode_c needencode s <> "\""
+ where
+ needencode c = isUtf8Byte c || c == fromIntegral (ord '"')
+
+-- git config core.quotePath controls whether to quote unicode characters
+newtype QuotePath = QuotePath Bool
+
+class Quoteable t where
+ -- double quotes and encodes when git would
+ quote :: QuotePath -> t -> S.ByteString
+
+ noquote :: t -> S.ByteString
+
+instance Quoteable RawFilePath where
+ quote (QuotePath qp) s = case encode_c' needencode s of
+ Nothing -> s
+ Just s' -> "\"" <> s' <> "\""
+ where
+ needencode c
+ | c == fromIntegral (ord '"') = True
+ | qp = isUtf8Byte c
+ | otherwise = False
+
+ noquote = id
+
+-- Allows building up a string that contains paths, which will get quoted.
+-- With OverloadedStrings, strings are passed through without quoting.
+-- Eg: QuotedPath f <> ": not found"
+data StringContainingQuotedPath
+ = UnquotedString String
+ | UnquotedByteString S.ByteString
+ | QuotedPath RawFilePath
+ | StringContainingQuotedPath :+: StringContainingQuotedPath
+ deriving (Show, Eq)
+
+quotedPaths :: [RawFilePath] -> StringContainingQuotedPath
+quotedPaths [] = mempty
+quotedPaths (p:ps) = QuotedPath p <> if null ps
+ then mempty
+ else " " <> quotedPaths ps
+
+instance Quoteable StringContainingQuotedPath where
+ quote _ (UnquotedString s) = safeOutput (encodeBS s)
+ quote _ (UnquotedByteString s) = safeOutput s
+ quote qp (QuotedPath p) = quote qp p
+ quote qp (a :+: b) = quote qp a <> quote qp b
+
+ noquote (UnquotedString s) = encodeBS s
+ noquote (UnquotedByteString s) = s
+ noquote (QuotedPath p) = p
+ noquote (a :+: b) = noquote a <> noquote b
+
+instance IsString StringContainingQuotedPath where
+ fromString = UnquotedByteString . encodeBS
+
+instance Sem.Semigroup StringContainingQuotedPath where
+ UnquotedString a <> UnquotedString b = UnquotedString (a <> b)
+ UnquotedByteString a <> UnquotedByteString b = UnquotedByteString (a <> b)
+ a <> b = a :+: b
+
+instance Monoid StringContainingQuotedPath where
+ mempty = UnquotedByteString mempty
+
+-- Encoding and then decoding roundtrips only when the string does not
+-- contain high unicode, because eg, both "\12345" and "\227\128\185"
+-- are encoded to "\343\200\271".
+--
+-- That is not a real-world problem, and using TestableFilePath
+-- limits what's tested to ascii, so avoids running into it.
+prop_quote_unquote_roundtrip :: TestableFilePath -> Bool
+prop_quote_unquote_roundtrip ts =
+ s == fromRawFilePath (unquote (quoteAlways (toRawFilePath s)))
+ where
+ s = fromTestableFilePath ts
import Types.ActionItem
import Annex.Common
import qualified Git
-import qualified Git.Filename
+import qualified Git.Quote
import Utility.Metered
import Utility.Percentage
import Utility.PID
import qualified Data.ByteString.Char8 as B8
import qualified System.FilePath.ByteString as P
-describeTransfer :: Git.Filename.QuotePath -> Transfer -> TransferInfo -> String
+describeTransfer :: Git.Quote.QuotePath -> Transfer -> TransferInfo -> String
describeTransfer qp t info = unwords
[ show $ transferDirection t
, show $ transferUUID t
import Annex.Debug
import Annex.Concurrent.Utility
import Utility.SafeOutput
-import Git.Filename
+import Git.Quote
import qualified Messages.JSON as JSON
import qualified Annex
import Messages.Concurrent
import qualified Messages.JSON as JSON
import Messages.JSON (JSONBuilder)
-import Git.Filename
+import Git.Quote
import Types.GitConfig
import qualified Data.ByteString as S
import Messages.Progress
import qualified Messages.JSON as JSON
import Utility.Metered (BytesProcessed, setMeterTotalSize)
-import Git.Filename
+import Git.Quote
import Control.Monad.IO.Class (MonadIO)
import qualified Utility.ShellEscape
import qualified Annex
-import qualified Git.Filename
+import qualified Git.Quote
import qualified Git.Types
import qualified Git.Ref
import qualified Git.LsTree
properties :: TestTree
properties = localOption (QuickCheckTests 1000) $ testGroup "QuickCheck" $
- [ testProperty "prop_quote_unquote_roundtrip" Git.Filename.prop_quote_unquote_roundtrip
+ [ testProperty "prop_quote_unquote_roundtrip" Git.Quote.prop_quote_unquote_roundtrip
, testProperty "prop_encode_c_decode_c_roundtrip" Utility.Format.prop_encode_c_decode_c_roundtrip
, testProperty "prop_isomorphic_key_encode" Key.prop_isomorphic_key_encode
, testProperty "prop_isomorphic_shellEscape" Utility.ShellEscape.prop_isomorphic_shellEscape
import Key
import Types.Transfer
import Git.FilePath
-import Git.Filename (StringContainingQuotedPath(..))
+import Git.Quote (StringContainingQuotedPath(..))
import Utility.FileSystemEncoding
data ActionItem
import Git.ConfigTypes
import Git.Remote (isRemoteKey, remoteKeyToRemoteName)
import Git.Branch (CommitMode(..))
-import Git.Filename (QuotePath(..))
+import Git.Quote (QuotePath(..))
import Utility.DataUnits
import Config.Cost
import Types.UUID
Git.Env
Git.FileMode
Git.FilePath
- Git.Filename
Git.FilterProcess
Git.Fsck
Git.GCrypt
Git.Objects
Git.PktLine
Git.Queue
+ Git.Quote
Git.Ref
Git.RefLog
Git.Remote