From f39f018ee0b2feaab0007b776cb0ff6436aff0e8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 6 Dec 2019 13:58:28 -0400 Subject: [PATCH] fix git ls-tree parser File mode is octal not decimal. This broke in the conversion to attoparsec. (I've submitted the content of Utility.Attoparsec to the attoparsec developers.) Test suite passes 100% now. --- COPYRIGHT | 35 ++++++++++++++++++++++++++++++++++- Git/LsTree.hs | 3 ++- Git/Types.hs | 2 +- Utility/Attoparsec.hs | 21 +++++++++++++++++++++ git-annex.cabal | 1 + 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Utility/Attoparsec.hs diff --git a/COPYRIGHT b/COPYRIGHT index a2324d7c58..858d7f0b74 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -29,6 +29,11 @@ Copyright: 2018 Joey Hess 2013 Michael Snoyman License: Expat +Files: Utility/Attoparsec.hs +Copyright: 2019 Joey Hess + 2007-2015 Bryan O'Sullivan +License: BSD-3-clause + Files: Utility/GitLFS.hs Copyright: © 2019 Joey Hess License: AGPL-3+ @@ -112,7 +117,35 @@ License: BSD-2-clause LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + +License: BSD-3-clause + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + . + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + . + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + . + 3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + . + THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + License: Expat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Git/LsTree.hs b/Git/LsTree.hs index aa3651a543..0196d21a1f 100644 --- a/Git/LsTree.hs +++ b/Git/LsTree.hs @@ -24,6 +24,7 @@ import Git.Command import Git.Sha import Git.FilePath import qualified Git.Filename +import Utility.Attoparsec import Numeric import Data.Either @@ -90,7 +91,7 @@ parseLsTree b = case A.parse parserLsTree b of parserLsTree :: A.Parser TreeItem parserLsTree = TreeItem -- mode - <$> A8.decimal + <$> octal <* A8.char ' ' -- type <*> A.takeTill (== 32) diff --git a/Git/Types.hs b/Git/Types.hs index 45adc1f377..f15e334732 100644 --- a/Git/Types.hs +++ b/Git/Types.hs @@ -112,7 +112,7 @@ fmtObjectType TreeObject = "tree" {- Types of items in a tree. -} data TreeItemType = TreeFile | TreeExecutable | TreeSymlink | TreeSubmodule - deriving (Eq) + deriving (Eq, Show) {- Git uses magic numbers to denote the type of a tree item. -} readTreeItemType :: S.ByteString -> Maybe TreeItemType diff --git a/Utility/Attoparsec.hs b/Utility/Attoparsec.hs new file mode 100644 index 0000000000..bd20e8e6d9 --- /dev/null +++ b/Utility/Attoparsec.hs @@ -0,0 +1,21 @@ +{- attoparsec utility functions + - + - Copyright 2019 Joey Hess + - Copyright 2007-2015 Bryan O'Sullivan + - + - License: BSD-3-clause + -} + +module Utility.Attoparsec where + +import qualified Data.Attoparsec.ByteString as A +import qualified Data.ByteString as B + +-- | Parse and decode an unsigned octal number. +-- +-- This parser does not accept a leading @\"0o\"@ string. +octal :: Integral a => A.Parser a +octal = B.foldl' step 0 `fmap` A.takeWhile1 isOctDigit + where + isOctDigit w = w >= 48 && w <= 55 + step a w = a * 8 + fromIntegral (w - 48) diff --git a/git-annex.cabal b/git-annex.cabal index 5d8ba73914..fa75218993 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -1020,6 +1020,7 @@ Executable git-annex Utility.Aeson Utility.Android Utility.Applicative + Utility.Attoparsec Utility.AuthToken Utility.Base64 Utility.Batch