[PATCH 2 of 5] verify the store
Adrian Buehlmann
adrian at cadifra.com
Wed Jul 30 18:25:35 CDT 2008
On 31.07.2008 00:25, Matt Mackall wrote:
> On Wed, 2008-07-30 at 20:48 +0200, Adrian Buehlmann wrote:
>> + class checkstore:
>> + def err(self, text):
>> + ui.warn(_(" store: %s\n") % text)
>> + errors[0] += 1
>> +
>> + def __init__(self, store):
>> + self.datafiles = []
>> + for f, size in store.datafiles(self.err):
>> + if size > 0:
>> + self.datafiles.append(f)
>> +
>> + def check(self, fl, f):
>> + for ff in fl.files():
>> + if not ff in self.datafiles:
>> + self.err(_("missing entry '%s'") % f)
>
> This is a good example of when making something a class is overkill.
Full ack. Mostly a leftover from the variant I sent earlier this week,
which still had an orphan check, which I removed for this series.
> This happens so often that I'm tempted to say that people can't use the
> class keyword without asking me first.
That's true. But at least I got the store classes in without asking first :-)
> In this case, we've got a class that gets used exactly once to create an
> object that has a single attribute and a single method (I'm discounting
> err as it doesn't even use self!). The following is less code, is easier
> to read, and does more:
>
> storefiles = {}
> for f, size in store.datafiles(lambda m: err(None, m)):
> if size > 0:
> storefiles[f] = True
>
> for f in files:
> ...
> for ff in fl.files():
> try:
> del storefiles[ff]
> except KeyError:
> err(linkrev, "missing revlog!", ff)
>
> for f in storefiles:
> err(None, "orphan revlog!", f)
>
> And we've actually already got (most of) the missing check in
> checklog(), so it's mostly the new orphan check that's interesting.
I will gladly use your code sketch for the next round.
More information about the Mercurial-devel
mailing list