treat dead repos as 0 size

With this, git annex log --totalsizes can be compared with
git-annex info's "combined annex size of all repositories"
to double-check it works correctly.

In my sound repo, the two match.

In my big repo, the two report slightly different sizes,
with the former being 1.3 gb smaller than the latter.
I don't know the reason for this disreprency. Given the 30+tb size of
the repo, it's a small difference.

It seems possible that a bug in an old version of git-annex could
explain it. Eg, if an old git-annex lost a line when updating trust.log
or a location log in a merge, git-annex info would see only what it
replaced it with, while git-annex log will see the previous value as
well.

Sponsored-by: Leon Schuermann on Patreon
This commit is contained in:
Joey Hess 2023-11-13 14:46:51 -04:00
parent 38b9ebc5fd
commit 2ab11fe06e
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -23,12 +23,15 @@ import Logs
import Logs.Location
import Logs.UUID
import qualified Logs.Presence.Pure as PLog
import Logs.Trust.Pure (parseTrustLog)
import Logs.UUIDBased (simpleMap)
import qualified Annex
import qualified Annex.Branch
import qualified Remote
import qualified Git
import Git.Log
import Git.CatFile
import Types.TrustLevel
import Utility.DataUnits
import Utility.HumanTime
@ -300,7 +303,7 @@ sizeHistoryInfo mu o = do
forM_ l $ \c ->
feeder ((changed c, changetime c), newref c)
closer
go reader M.empty M.empty M.empty uuidmap dispst
go reader mempty mempty mempty uuidmap dispst
wait tid
void $ liftIO cleanup
where
@ -321,19 +324,20 @@ sizeHistoryInfo mu o = do
]
fileselector
go reader sizemap locmap deadmap uuidmap dispst = reader >>= \case
go reader sizemap locmap trustlog uuidmap dispst = reader >>= \case
Just ((Right k, t), Just logcontent) -> do
let !newlog = parselocationlog logcontent uuidmap
let !(sizemap', locmap') = case M.lookup k locmap of
Nothing -> addnew k sizemap locmap newlog
Just v -> update k sizemap locmap v newlog
dispst' <- displaysizes dispst uuidmap sizemap' t
go reader sizemap' locmap' deadmap uuidmap dispst'
dispst' <- displaysizes dispst trustlog uuidmap sizemap' t
go reader sizemap' locmap' trustlog uuidmap dispst'
Just ((Left (), t), Just logcontent) -> do
-- XXX todo update deadmap
go reader sizemap locmap deadmap uuidmap dispst
let !trustlog' = trustlog <> parseTrustLog logcontent
dispst' <- displaysizes dispst trustlog' uuidmap sizemap t
go reader sizemap locmap trustlog' uuidmap dispst'
Just (_, Nothing) ->
go reader sizemap locmap deadmap uuidmap dispst
go reader sizemap locmap trustlog uuidmap dispst
Nothing ->
displayendsizes dispst
@ -398,7 +402,7 @@ sizeHistoryInfo mu o = do
(M.elems uuidmap)
| otherwise = return ()
displaysizes (zone, displayedyet, prevt, prevoutput) uuidmap sizemap t
displaysizes (zone, displayedyet, prevt, prevoutput) trustlog uuidmap sizemap t
| t - prevt >= dt
&& (displayedyet || any (/= 0) sizes)
&& (prevoutput /= Just output) = do
@ -411,10 +415,17 @@ sizeHistoryInfo mu o = do
Just u -> [u]
Nothing -> M.keys uuidmap
sizes
| totalSizesOption o = [sum (M.elems sizemap)]
| otherwise = map (\u -> fromMaybe 0 (M.lookup u sizemap)) us
| totalSizesOption o = [sum (M.elems sizemap')]
| otherwise = map (\u -> fromMaybe 0 (M.lookup u sizemap')) us
dt = maybe 1 durationToPOSIXTime (whenOption o)
-- A verison of sizemap where uuids that are currently dead
-- have 0 size.
sizemap' = M.mapWithKey zerodead sizemap
zerodead u v = case M.lookup u (simpleMap trustlog) of
Just DeadTrusted -> 0
_ -> v
displayts zone t output = putStrLn $ ts ++ "," ++ output
where
ts = if rawDateOption o