How to create new methods

John Arbash Meinel john at arbash-meinel.com
Tue Apr 24 20:32:02 BST 2007


I have a question about how to create new methods, now that the smart
server has landed (with more intelligent Remote objects).

Specifically, I'm looking to create a "get_partial_revision_graph()"
function on Repository, and RemoteRepository does not inherit from any
base class. So from the first part, I would have to just copy and paste
the same implementation so that all tests pass. But any time I copy &
paste, I'm sure there is something wrong.

This function is a (potentially) good candidate for having a new verb,
because given two nodes, you don't have to download the complete graph.
Rather than the simple implementation, which grabs the full graph, and
removes a subset.

It would be nice (for compatibility) if we could have a way to "try the
new function, if not available, fall back to the slow method".

It isn't terrible to write this, though the inheritance hierarchy means
I need to write them as a non-member function.

I'm just trying to figure out what the best way to handle this is. Since
having an if/then or try/catch in every smart function (to fall back to
the VFS version) seems ugly (code wise). Rather than having something
more automatic. Like a decorator:

@needs_verbs(RemoteRepository.get_graph_subset)
def get_partial_revision_graph(self, start, end):
...

@needs_no_verbs
def get_partial_revision_graph(self, start, end):
...

Anyway, I don't really know the "best" thing. I'm just trying to come up
with ways to allow cross-version compatibility without having the code
become a mess of try/except.

John
=:->




More information about the bazaar mailing list