The active mergestate is stored in ".hg/merge" when a merge is triggered by commands like "hg merge", "hg rebase", etc. until the merge is completed or aborted to track the 3-way merge state of individual files.
The contents of the directory are:
The local version of the conflicting files are stored with their filenames as the hash of their paths.
This mergestate file record is used by hg version prior to 2.9.1 and contains less data than "state2". If there is no contradiction with "state2", we can assume that both are written at the same time. In this case, data from "state2" is used. Otherwise, we use "state". We read/write both "state" and "state2" records to ensure backward compatibility.
This record stores a superset of data in "state", including new kinds of records in the future.
Each record can contain arbitrary content and has an associated type. This 'type' should be a letter. If 'type' is uppercase, the record is mandatory: versions of Mercurial that don't support it should abort. If 'type' is lowercase, the record can be safely ignored.
Currently known records:
Merge record states (indexed by filename):
The resolve command transitions between 'u' and 'r' for conflicts and 'pu' and 'pr' for path conflicts.
This format is a list of arbitrary records of the form:
[type][length][content]
'type' is a single character, 'length' is a 4 byte integer, and 'content' is an arbitrary byte sequence of length 'length'.
Mercurial versions prior to 3.7 have a bug where if there are unsupported mandatory merge records, attempting to clear out the merge state with hg update --clean or similar aborts. The 't' record type works around that by writing out what those versions treat as an advisory record, but later versions interpret as special: the first character is the 'real' record type and everything onwards is the data.