Possible bug in Internal Python API

Dirkjan Ochtman dirkjan at ochtman.nl
Fri Aug 13 02:48:24 CDT 2010


It looks like you don't really understand Mercurial's data model or the API...

On Fri, Aug 13, 2010 at 03:44, Miguel Araujo <muchochini at gmail.com> wrote:
> repository = localrepo.localrepository(ui.ui(), '/path/to/repo/')
> current_ctx = context.changectx(repository)
> current_ctx.rev()
>
> This code works perfectly in my own laptop against a clone of my repository.
> I get last Change context. However, If I do the same in my server against my
> main tree I get a -1. Funny thing is I don't get any  repo.RepoError. My
> repositoriy object has a root property which points to the right path and I
> can get a changelog and move over it.

This is because the repo on your server doesn't have a working
directory checked out. Getting a changectx() by default gets you the
revision the working directory is at (so not necessarily the last
revision in the repository!).

> If I try the same thing against a local clone (in the server) of that
> repository, it fails but works. It doesn't get the last Change Context which
> has rev 44, but it gets something (21). So it looks like you should be
> working on a clone and not the main tree. If I do:

So you may have more than one heads (or have different branches and
you don't have the default branch checked out on your laptop). Cloning
gets you a working copy on the latest cset on the default branch by
default.

> repository = localrepo.localrepository(ui.ui(), '/path/to/repo/')
> current_ctx = context.changectx(repository.changelog.tip())
> current_ctx.rev()
>
> This works without problems in my laptop, but I haven't found a way to make
> it work in my server. When I do it, I get:
> *** AttributeError: 'str' object has no attribute 'lookup'

This is silly code, context.changectx()'s first argument must be a
repository, not a string (which is what you're passing here). I'm
pretty sure this doesn't work on your laptop, either.

> I have to say that my laptop and server run the same Mercurial version. This
> erratic behavior makes me think there could be a bug in the API. I have
> thought about moving over all the changelog till the last one, but I need a
> better performance solution, because this will be plugged into big
> repositories with lots of commits.

I would advise you to read some more docs and familiarize yourself
with Mercurial some more before you try to write code against it.

Also check out the MercurialApi wiki page for nice API usage patterns
(such as using repo['tip'] to get a changectx).

Cheers,

Dirkjan


More information about the Mercurial-devel mailing list