This is an archive of the discontinued Mercurial Phabricator instance.

wireproto: define and use types for wire protocol commands
ClosedPublic

Authored by indygreg on Feb 1 2018, 6:37 PM.

Details

Summary

Wire protocol commands have historically been declared as
2-tuples in wireproto.commands. There are some additional features I'd
like to implement that require going beyond 2-tuples. But because
the 2-tuple API (both destructuring assignment and direct assignment
into the dict) is used throughout the code base and in 3rd party
extensions, we can't do a trivial type change.

This commit creates a new "commandentry" type to represent declared
wire protocol commands. It implements getitem and iter so
it can quack like a 2-tuple. The @wireprotocommand decorator now
creates "commandentry" instances.

We also create a "commanddict" type to represent the dictionary of
declared wire protocol commands. It inherits from "dict" but provides
a custom setitem to coerce passed 2-tuples to "commandentry"
instances. wireproto.commands is now an instance of this type.

Various callers in core rely on the new functionality. And tests
pass. So I'm reasonably confident things will "just work" in 3rd
party extensions as well.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Feb 1 2018, 6:37 PM
durin42 added a subscriber: durin42.Feb 7 2018, 5:19 PM

I'm curious what registrations you need that don't fit in 2-tuples. Can I see a sample of where that's going?

I'm curious what registrations you need that don't fit in 2-tuples. Can I see a sample of where that's going?

I'll be adding additional attributes to @wireprotocommand in future series. One thing I know I'll add is a mechanism to limit which wire protocol versions/transports to expose a command to. This will prevent legacy commands from being exposed to modern protocols and vice versa.

durin42 accepted this revision.Feb 7 2018, 5:29 PM

I'm sold.

This revision is now accepted and ready to land.Feb 7 2018, 5:29 PM
This revision was automatically updated to reflect the committed changes.