filter out control characters in all other Messages
This does, as a side effect, make long notes in json output not be indented. The indentation is only needed to offset them underneath the display of the file they apply to, so that's ok. Sponsored-by: Brock Spratlen on Patreon
This commit is contained in:
parent
a0e6fa18eb
commit
8b6c7bdbcc
54 changed files with 183 additions and 164 deletions
|
@ -30,13 +30,12 @@ module Git.FilePath (
|
|||
|
||||
import Common
|
||||
import Git
|
||||
import qualified Git.Filename as Filename
|
||||
import Git.Filename
|
||||
|
||||
import qualified System.FilePath.ByteString as P
|
||||
import qualified System.FilePath.Posix.ByteString
|
||||
import GHC.Generics
|
||||
import Control.DeepSeq
|
||||
import qualified Data.ByteString as S
|
||||
|
||||
{- A RawFilePath, relative to the top of the git repository. -}
|
||||
newtype TopFilePath = TopFilePath { getTopFilePath :: RawFilePath }
|
||||
|
@ -49,9 +48,9 @@ data BranchFilePath = BranchFilePath Ref TopFilePath
|
|||
deriving (Show, Eq, Ord)
|
||||
|
||||
{- Git uses the branch:file form to refer to a BranchFilePath -}
|
||||
descBranchFilePath :: Filename.QuotePath -> BranchFilePath -> S.ByteString
|
||||
descBranchFilePath qp (BranchFilePath b f) =
|
||||
fromRef' b <> ":" <> Filename.quote qp (getTopFilePath f)
|
||||
descBranchFilePath :: BranchFilePath -> StringContainingQuotedPath
|
||||
descBranchFilePath (BranchFilePath b f) =
|
||||
UnquotedByteString (fromRef' b) <> ":" <> QuotedPath (getTopFilePath f)
|
||||
|
||||
{- Path to a TopFilePath, within the provided git repo. -}
|
||||
fromTopFilePath :: TopFilePath -> Git.Repo -> RawFilePath
|
||||
|
|
|
@ -76,6 +76,7 @@ instance Quoteable RawFilePath where
|
|||
-- Eg: QuotedPath f <> ": not found"
|
||||
data StringContainingQuotedPath
|
||||
= UnquotedString String
|
||||
| UnquotedByteString S.ByteString
|
||||
| QuotedPath RawFilePath
|
||||
| StringContainingQuotedPath :+: StringContainingQuotedPath
|
||||
deriving (Show, Eq)
|
||||
|
@ -88,10 +89,12 @@ quotedPaths (p:ps) = QuotedPath p <> if null 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
|
||||
|
||||
|
@ -100,10 +103,11 @@ instance IsString StringContainingQuotedPath where
|
|||
|
||||
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 = UnquotedString mempty
|
||||
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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue