[MERGE] Cope with ghosts in mainline history

Aaron Bentley aaron at aaronbentley.com
Mon Apr 13 16:54:31 BST 2009


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

Jelmer Vernooij wrote:
> The updated (attached) patch should fix this.

> @@ -1025,11 +1025,25 @@
>              # To figure out the revno for a random revision, we need to build
>              # the revision history, and count its length.
>              # We don't care about the order, just how long it is.
> -            # Alternatively, we could start at the current location, and count
> -            # backwards. But there is no guarantee that we will find it since
> -            # it may be a merged revision.
> -            revno = len(list(self.repository.iter_reverse_revision_history(
> -                                                                revision_id)))
> +            try:
> +                revno = len(list(self.repository.iter_reverse_revision_history(
> +                    revision_id)))
> +            except errors.RevisionNotPresent:
> +                # One of the left hand side ancestors is a ghost
> +                # we could start at the current location, and count
> +                # backwards. But there is no guarantee that we will find the 
> +                # revno since we may be looking at a merged revision id
> +                try:
> +                    # Default to 1, if we can't find anything else
> +                    revno = 1
> +                    for distance, revid in enumerate(
> +                        self.repository.iter_reverse_revision_history(
> +                            source_revision_id)):
> +                        if revid == revision_id:
> +                            revno = source_revno - distance
> +                            break
> +                except KeyError:
> +                    pass

Probably a better option in the general case is to use
Graph.find_distance_to_null.  As long as there is common ancestry
between source and target, this code ought to be able to determine a
revno, so it would hardly ever need to fall back to 1.

I don't know if Graph.find_distance_to_null been subjected to hard ghost
testing, but if not, making it robust would be worthwhile.

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

iEYEARECAAYFAknjYDQACgkQ0F+nu1YWqI3iTwCfYFBwKmD1BwagHBURzBWoNUTk
bL0An2PM8CImrGyES1EJgsAyqwG74rVP
=Cd8l
-----END PGP SIGNATURE-----



More information about the bazaar mailing list