add: Display progress meter when hashing files.

* add: Display progress meter when hashing files.
* add: Support --json-progress option.
This commit is contained in:
Joey Hess 2019-06-25 13:12:47 -04:00
parent 554b307931
commit 42c386fc47
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 35 additions and 6 deletions

View file

@ -14,6 +14,8 @@ git-annex (7.20190616) UNRELEASED; urgency=medium
output the feed content that was downloaded. output the feed content that was downloaded.
* init: Fix a reversion in the last release that prevented automatically * init: Fix a reversion in the last release that prevented automatically
generating and setting a description for the repository. generating and setting a description for the repository.
* add: Display progress meter when hashing files.
* add: Support --json-progress option.
-- Joey Hess <id@joeyh.name> Sat, 15 Jun 2019 12:38:25 -0400 -- Joey Hess <id@joeyh.name> Sat, 15 Jun 2019 12:38:25 -0400

View file

@ -20,12 +20,12 @@ import Annex.FileMatcher
import Annex.Link import Annex.Link
import Annex.Version import Annex.Version
import Annex.Tmp import Annex.Tmp
import Messages.Progress
import Git.FilePath import Git.FilePath
import Utility.Metered
cmd :: Command cmd :: Command
cmd = notBareRepo $ cmd = notBareRepo $
withGlobalOptions [jobsOption, jsonOptions, fileMatchingOptions] $ withGlobalOptions [jobsOption, jsonOptions, jsonProgressOption, fileMatchingOptions] $
command "add" SectionCommon "add files to annex" command "add" SectionCommon "add files to annex"
paramPaths (seek <$$> optParser) paramPaths (seek <$$> optParser)
@ -142,7 +142,11 @@ perform file = withOtherTmp $ \tmpdir -> do
{ lockingFile = lockingfile { lockingFile = lockingfile
, hardlinkFileTmpDir = Just tmpdir , hardlinkFileTmpDir = Just tmpdir
} }
lockDown cfg file >>= ingestAdd nullMeterUpdate >>= finish ld <- lockDown cfg file
let sizer = keySource <$> ld
v <- metered Nothing sizer $ \_meter meterupdate ->
ingestAdd meterupdate ld
finish v
where where
finish (Just key) = next $ cleanup key True finish (Just key) = next $ cleanup key True
finish Nothing = stop finish Nothing = stop

View file

@ -15,6 +15,8 @@ import Utility.Metered
import Types import Types
import Types.Messages import Types.Messages
import Types.Key import Types.Key
import Types.KeySource
import Utility.InodeCache
import qualified Messages.JSON as JSON import qualified Messages.JSON as JSON
import Messages.Concurrent import Messages.Concurrent
@ -24,14 +26,24 @@ import qualified System.Console.Concurrent as Console
{- Class of things from which a size can be gotten to display a progress {- Class of things from which a size can be gotten to display a progress
- meter. -} - meter. -}
class MeterSize t where class MeterSize t where
getMeterSize :: t -> Annex (Maybe Integer) getMeterSize :: t -> Annex (Maybe FileSize)
instance MeterSize (Maybe Integer) where instance MeterSize t => MeterSize (Maybe t) where
getMeterSize = pure getMeterSize Nothing = pure Nothing
getMeterSize (Just t) = getMeterSize t
instance MeterSize FileSize where
getMeterSize = pure . Just
instance MeterSize Key where instance MeterSize Key where
getMeterSize = pure . keySize getMeterSize = pure . keySize
instance MeterSize InodeCache where
getMeterSize = pure . Just . inodeCacheFileSize
instance MeterSize KeySource where
getMeterSize = maybe (pure Nothing) getMeterSize . inodeCache
{- When the key's size is not known, the file is statted to get the size. {- When the key's size is not known, the file is statted to get the size.
- This allows uploads of keys without size to still have progress - This allows uploads of keys without size to still have progress
- displayed. - displayed.

View file

@ -13,6 +13,7 @@
module Utility.InodeCache ( module Utility.InodeCache (
InodeCache, InodeCache,
InodeComparisonType(..), InodeComparisonType(..),
inodeCacheFileSize,
compareStrong, compareStrong,
compareWeak, compareWeak,
@ -58,6 +59,9 @@ data InodeCachePrim = InodeCachePrim FileID FileSize MTime
newtype InodeCache = InodeCache InodeCachePrim newtype InodeCache = InodeCache InodeCachePrim
deriving (Show) deriving (Show)
inodeCacheFileSize :: InodeCache -> FileSize
inodeCacheFileSize (InodeCache (InodeCachePrim _ sz _)) = sz
{- Inode caches can be compared in two different ways, either weakly {- Inode caches can be compared in two different ways, either weakly
- or strongly. -} - or strongly. -}
data InodeComparisonType = Weakly | Strongly data InodeComparisonType = Weakly | Strongly

1
debian/control vendored
View file

@ -12,6 +12,7 @@ Build-Depends:
libghc-pcre-light-dev, libghc-pcre-light-dev,
libghc-cryptonite-dev, libghc-cryptonite-dev,
libghc-memory-dev, libghc-memory-dev,
libghc-deepseq-dev,
libghc-attoparsec-dev, libghc-attoparsec-dev,
libghc-sandi-dev, libghc-sandi-dev,
libghc-utf8-string-dev, libghc-utf8-string-dev,

View file

@ -68,6 +68,10 @@ annexed content, and other symlinks.
Enable JSON output. This is intended to be parsed by programs that use Enable JSON output. This is intended to be parsed by programs that use
git-annex. Each line of output is a JSON object. git-annex. Each line of output is a JSON object.
* `--json-progress`
Include progress objects in JSON output.
* `--json-error-messages` * `--json-error-messages`
Messages that would normally be output to standard error are included in Messages that would normally be output to standard error are included in

View file

@ -3,3 +3,5 @@ ATM there is no `--json-progress` in `git annex add` (only `--json`), so no feed
Cheers! Cheers!
[[!meta author=yoh]] [[!meta author=yoh]]
> [[done]] --[[Joey]]