hg-review takes Mercurial’s approach to API stability:
Providing a stable CLI means that (possibly non-GPL) programs can interact with hg-review easily without fear of constant breaking.
Stable file formats mean that older versions of hg-review will be able to work with review data from newer versions (albeit with reduced functionality).
Not providing a stable internal implementation allows hg-review’s code to be kept clean and elegant. It means that Python programs will needs to use subprocesses to avoid breaking, but this is a tradeoff that the author feels is worth making.
The structure of hg-review’s data repository looks like this:
your-project/
|
+-- .hg/
| |
| +-- review
| | |
| | +-- {{ changeset hash }}
| | | |
| | | +-- .exists
| | | |
| | | +-- comments
| | | | |
| | | | +-- {{ comment hash }}
| | | | |
| | | | `-- other comments...
| | | |
| | | +-- signoffs
| | | |
| | | +-- {{ signoff hash }}
| | | |
| | | `-- other signoffs ...
| | |
| | `-- other changesets ...
| |
| `-- other files ...
|
`-- other files ...
All review data for a changeset is stored in:
.hg/review/{{ changeset hash }}/
A .exists file is included in that directory when code review for that changeset is initialized. This allows us to check if a given changeset has been initialized for code review very quickly.
Comments for a changeset are stored in:
.hg/review/{{ changeset hash }}/comments/{{ comment hash }}
Signoffs for a changeset are stored in:
.hg/review/{{ changeset hash }}/signoffs/{{ signoff hash }}
hg-review’s file format is (fairly) stable and is designed to be easily parsed to enable export to other code review systems.
Comment and signoff files are stored as JSON. The files are indented four spaces per level to make them more human-readable.
The .exists file is always empty. It simply exists to make looking up whether a given changeset has been initialized faster. It may go away in the future – do not depend on it.
Here is a sample comment file:
{
"author": "Steve Losh <steve@stevelosh.com>",
"file": [
"reykjavi\u0301k.txt",
"cmV5YWphdmnMgWsudHh0"
],
"hgdate": "Mon Jul 12 23:55:51 2010 -0400",
"lines": [
0
],
"message": "Sample.",
"node": "0e987f91e9b6628b26a30c5d00668a15fae8f22f",
"style": "markdown"
}
Comment files have some or all of the following fields:
Here is a sample signoff file:
{
"author": "Steve Losh <steve@stevelosh.com>",
"hgdate": "Tue Jul 13 00:16:00 2010 -0400",
"message": "Sample.",
"node": "0e987f91e9b6628b26a30c5d00668a15fae8f22f",
"opinion": "yes",
"style": "markdown"
}
Signoff files have some or all of the following fields:
hg-review’s command line interface is (fairly) stable. If you want to interact with review data for a repository this is the safest method to use.
See the command line interface documentation for more details.
hg-review’s internal Python implementation is not stable. It may change at any time. Relying on it virtually guarantees your application will break at some point.
For a more stable API you should use the command line interface.
The Python API will be documented later, but is not a high priority at the moment because of its volatility.