[merge] knit index robustness/corruption?

Aaron Bentley aaron.bentley at utoronto.ca
Mon Jun 25 15:41:34 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
> I have, for some reason, a knit file with an incorrect index record.
> It does not look like the kind of problem that originated in Bazaar,
> so I suspect perhaps a network or even hardware error.  I have had a
> couple of hard crashes on this  machine is recent weeks.
> 
> The line in question, 4751, is in the middle of the file, pretty old,
> and in between other correct records.

It took me a minute to realize that record 4751 has "471v" where an int
is expected.

Since this is an unusual condition, I wonder whether this should be done
by a "repair" mode.  This fix does make the knit readable, but doesn't
doesn't provide a way to fix the index permanently, e.g. by regenerating
the index.

> === modified file 'bzrlib/knit.py'
> --- bzrlib/knit.py	2007-06-21 03:29:39 +0000
> +++ bzrlib/knit.py	2007-06-25 08:56:06 +0000
> @@ -76,6 +76,7 @@
>      osutils,
>      patiencediff,
>      progress,
> +    trace,
>      ui,
>      )
>  from bzrlib.errors import (
> @@ -1186,13 +1187,17 @@
>                  continue
>  
>              parents = []
> -            for value in rec[4:-1]:
> -                if value[0] == '.':
> -                    # uncompressed reference
> -                    parent_id = value[1:]
> -                else:
> -                    parent_id = history[int(value)]
> -                parents.append(parent_id)
> +            try:
> +                for value in rec[4:-1]:
> +                    if value[0] == '.':
> +                        # uncompressed reference
> +                        parent_id = value[1:]
> +                    else:
> +                        parent_id = history[int(value)]
> +                    parents.append(parent_id)
> +            except ValueError, e:
> +                trace.warning("mangled knit index line in %s: %r: %r; "
> +                        "skipping it." % (self, line, e))

I prefer to wrap exception handling as tightly as possible.  So
try:
    parent_id = history[int(value)]

or even

try:
    parent_index = int(value)
except:
    # warning, etc.
else:
    parent_id = history[parent_index]

would suit me better.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGf9Qe0F+nu1YWqI0RAn5fAJ40E3aVYn3l/0Yy2WtgyuvVZTcqCQCeNEy2
ZNKryMdrOJnoR6ufEwoLJRE=
=Qavw
-----END PGP SIGNATURE-----



More information about the bazaar mailing list