The Mercurial wire protocol

Mercurial performs all of its network transactions over HTTP or SSH.

Mercurial performs all of its network transactions over HTTP or SSH.

See also the [HTTPCommandProtocol] and the [SSHCommandProtocol].

Overview

The first three functions are used to efficiently track back through a remote tree to find the roots of all the new branches, without a massive number of round trips or needing to send the entire changelog list.

The fourth actually gets all the changes in one go.

The Protocol

The network protocol looks like this:

heads()

 return a list of heads
 (everything new must be an ancestor of one of these heads, so start here)

branches(list)

 for node in list:
   follow the linear section of a branch back to its branchpoint
   return (tip, base, p1, p2)
   (this reduces round trips for long linear branches)

between(list)

 for tip, base in list:
   walk back a linear branch, return elements 1, 2, 4, 8..
   (and this lets us do bisection search if we diverge in the middle of one of these long branches)

changegroup(roots)

 find all changesets descended from roots and return them as a single changegroup

A changegroup is a single stream containing:

A group is a list of chunks:


Hgweb/remoterepository currently runs this all through zlib which makes sense on WANs, but less sense on LANs.