fix init default description reversion

init: Fix a reversion in the last release that prevented automatically
generating and setting a description for the repository.

Seemed best to factor out uuidDescMapRaw that does not
have the default mempty descrition behavior.

I don't much like that behavior, but I know things depend on it.
One thing in particular is `git annex info` which lists the uuids and
descriptions; if the current repo has been initialized in some way that
means it does not have a description, it would not show up w/o that.

(Not only repos created due to this bug might lack that. For example a repo
that was marked dead and had --drop-dead delete its git-annex branch info,
and then came back from the dead would similarly not be in the uuid.log.
Also there have been other versions of git-annex that didn't set a default
description; for years there was no default description.)
This commit is contained in:
Joey Hess 2019-06-20 20:30:24 -04:00
parent 7264203eb1
commit 84e729fda5
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 28 additions and 6 deletions

View file

@ -92,7 +92,7 @@ initialize mdescription mversion = checkCanInitialize $ do
u <- getUUID
{- Avoid overwriting existing description with a default
- description. -}
whenM (pure (isJust mdescription) <||> not . M.member u <$> uuidDescMap) $
whenM (pure (isJust mdescription) <||> not . M.member u <$> uuidDescMapRaw) $
describeUUID u =<< genDescription mdescription
-- Everything except for uuid setup, shared clone setup, and initial

View file

@ -12,6 +12,8 @@ git-annex (7.20190616) UNRELEASED; urgency=medium
fix a case where importfeed downloaded a partial feed from such a server.
* importfeed: When there's a problem parsing the feed, --debug will
output the feed content that was downloaded.
* init: Fix a reversion in the last release that prevented automatically
generating and setting a description for the repository.
-- Joey Hess <id@joeyh.name> Sat, 15 Jun 2019 12:38:25 -0400

View file

@ -11,7 +11,8 @@ module Logs.UUID (
uuidLog,
describeUUID,
uuidDescMap,
uuidDescMapLoad
uuidDescMapLoad,
uuidDescMapRaw,
) where
import Types.UUID
@ -38,13 +39,13 @@ describeUUID uuid desc = do
uuidDescMap :: Annex UUIDDescMap
uuidDescMap = maybe uuidDescMapLoad return =<< Annex.getState Annex.uuiddescmap
{- Read the uuidLog into a simple Map.
{- Read the uuidLog into a map, and cache it for later use.
-
- The UUID of the current repository is included explicitly, since
- it may not have been described and otherwise would not appear. -}
- If the current repository has not been described, it is still included
- in the map with an empty description. -}
uuidDescMapLoad :: Annex UUIDDescMap
uuidDescMapLoad = do
m <- simpleMap . parseUUIDLog <$> Annex.Branch.get uuidLog
m <- uuidDescMapRaw
u <- Annex.UUID.getUUID
let m' = M.insertWith preferold u mempty m
Annex.changeState $ \s -> s { Annex.uuiddescmap = Just m' }
@ -52,5 +53,9 @@ uuidDescMapLoad = do
where
preferold = flip const
{- Read the uuidLog into a map. Includes only actually set descriptions. -}
uuidDescMapRaw :: Annex UUIDDescMap
uuidDescMapRaw = simpleMap . parseUUIDLog <$> Annex.Branch.get uuidLog
parseUUIDLog :: L.ByteString -> Log UUIDDesc
parseUUIDLog = parseLogOld (UUIDDesc <$> A.takeByteString)

View file

@ -94,3 +94,5 @@ init ok
```
Note that the description for here is a blank string.
> [[fixed|done]] --[[Joey]]

View file

@ -0,0 +1,13 @@
[[!comment format=mdwn
username="joey"
subject="""comment 3"""
date="2019-06-21T00:12:51Z"
content="""
Thanks Kyle, that does point at the problem. In uuidDescMapLoad
it implicitly adds the UUID of the current repo, with an empty
description if none is set. So, the added check of uuidDescMap
always finds the UUID in it already. Your uuidDescMapLoad hack
avoids this by loading the map before the current repo has a UUID.
Fixed more cleanly..
"""]]