git style filename quoting controlled by core.quotePath

This is by no means complete, but escaping filenames in actionItemDesc does
cover most commands.

Note that for ActionItemBranchFilePath, the value is branch:file, and I
choose to only quote the file part (if necessary). I considered quoting the
whole thing. But, branch names cannot contain control characters, and while
they can contain unicode, git coes not quote unicode when displaying branch
names. So, it would be surprising for git-annex to quote unicode in a
branch name.

The find command is the most obvious command that still needs to be
dealt with. There are probably other places that filenames also get
displayed, eg embedded in error messages.

Some other commands use ActionItemOther with a filename, I think that
ActionItemOther should either be pre-sanitized, or should explicitly not
be used for filenames, so that needs more work.

When --json is used, unicode does not get escaped, but control
characters were already escaped in json.

(Key escaping may turn out to be needed, but I'm ignoring that for now.)

Sponsored-by: unqueued on Patreon
This commit is contained in:
Joey Hess 2023-04-08 14:20:02 -04:00
parent 81bc57322f
commit d689a5b338
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
11 changed files with 78 additions and 45 deletions

View file

@ -30,6 +30,7 @@ module Git.FilePath (
import Common
import Git
import qualified Git.Filename as Filename
import qualified System.FilePath.ByteString as P
import qualified System.FilePath.Posix.ByteString
@ -48,9 +49,9 @@ data BranchFilePath = BranchFilePath Ref TopFilePath
deriving (Show, Eq, Ord)
{- Git uses the branch:file form to refer to a BranchFilePath -}
descBranchFilePath :: BranchFilePath -> S.ByteString
descBranchFilePath (BranchFilePath b f) =
fromRef' b <> ":" <> getTopFilePath f
descBranchFilePath :: Filename.QuotePath -> BranchFilePath -> S.ByteString
descBranchFilePath qp (BranchFilePath b f) =
fromRef' b <> ":" <> Filename.encode qp (getTopFilePath f)
{- Path to a TopFilePath, within the provided git repo. -}
fromTopFilePath :: TopFilePath -> Git.Repo -> RawFilePath