git-annex log --totalsizes
authorJoey Hess <joeyh@joeyh.name>
Mon, 13 Nov 2023 17:15:07 +0000 (13:15 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 13 Nov 2023 17:15:36 +0000 (13:15 -0400)
Note that dead repositories are not yet handled so their sizes show as
nonzero after they are marked dead.

Sponsored-By: unqueued on Patreon
Command/Log.hs

index 0a86c8ad5e56fc6d051eda36e572976ebaf8c8e8..da521b43a9bef96c152d05b514ad8125f61fd397 100644 (file)
@@ -46,6 +46,7 @@ data LogOptions = LogOptions
        , allOption :: Bool
        , sizesOfOption :: Maybe (DeferredParse UUID)
        , sizesOption :: Bool
+       , totalSizesOption :: Bool
        , whenOption :: Maybe Duration
        , rawDateOption :: Bool
        , bytesOption :: Bool
@@ -71,6 +72,10 @@ optParser desc = LogOptions
                ( long "sizes"
                <> help "display history of sizes of all repositories"
                )
+       <*> switch
+               ( long "totalsizes"
+               <> help "display history of total sizes of all repositories"
+               )
        <*> optional (option (eitherReader parseDuration)
                ( long "when" <> metavar paramTime
                <> help "when to display changed size"
@@ -108,7 +113,7 @@ seek :: LogOptions -> CommandSeek
 seek o = ifM (null <$> Annex.Branch.getUnmergedRefs)
        ( maybe (pure Nothing) (Just <$$> getParsed) (sizesOfOption o) >>= \case
                Just u -> sizeHistoryInfo (Just u) o
-               Nothing -> if sizesOption o
+               Nothing -> if sizesOption o || totalSizesOption o
                        then sizeHistoryInfo Nothing o
                        else go 
        , giveup "This repository is read-only, and there are unmerged git-annex branches, which prevents displaying location log changes. (Set annex.merge-annex-branches to false to ignore the unmerged git-annex branches.)"
@@ -405,7 +410,9 @@ sizeHistoryInfo mu o = do
                us = case mu of
                        Just u -> [u]
                        Nothing -> M.keys uuidmap
-               sizes = map (\u -> fromMaybe 0 (M.lookup u sizemap)) us
+               sizes
+                       | totalSizesOption o = [sum (M.elems sizemap)]
+                       | otherwise = map (\u -> fromMaybe 0 (M.lookup u sizemap)) us
                dt = maybe 1 durationToPOSIXTime (whenOption o)
 
        displayts zone t output = putStrLn $ ts ++ "," ++ output