swh.loader.mercurial.identify module#

class swh.loader.mercurial.identify.HgAuthor(fullname: bytes, name: Optional[bytes], email: Optional[bytes])[source]#

Bases: tuple

Represent a Mercurial revision author.

Create new instance of HgAuthor(fullname, name, email)

property fullname#

full name of the author

property name#

name of the author

property email#

email of the author

static from_bytes(data: bytes) HgAuthor[source]#

Convert bytes to an HgAuthor named tuple.

Expected format: “name <email>”

to_dict() Dict[str, Optional[bytes]][source]#
class swh.loader.mercurial.identify.HgRevision(node_id: bytes, author: HgAuthor, timestamp: bytes, offset: bytes, parents: List[bytes], extras: Dict[bytes, bytes], description: bytes)[source]#

Bases: tuple

Represent a Mercurial revision.

Create new instance of HgRevision(node_id, author, timestamp, offset, parents, extras, description)

property node_id#

raw bytes of the revision hash

property author#

author of the revision

property timestamp#

timestamp of the revision

property offset#

offset of the revision

property parents#

hex bytes of the revision’s parents

property extras#

metadata of the revision

property description#

description of the revision

static from_bytes(data: bytes, description: bytes) HgRevision[source]#

Convert bytes to an HgRevision named tuple.

Expected data format: ‘’’ node_id:{node} author:{author} timestamp_offset:[{timestamp}, {offset}] p1:{p1} p2:{p2} extras:{key1}={value1} … extras:{keyn}={value} ‘’’

branch() bytes[source]#
to_dict() Dict[source]#

Convert a HgRevision to a dict for SWHID computation

class swh.loader.mercurial.identify.HgBranch(name: bytes, node_id: bytes)[source]#

Bases: tuple

Represent a Mercurial branch.

Create new instance of HgBranch(name, node_id)

property name#

name of the branch

property node_id#

row bytes of the target revision hash

class swh.loader.mercurial.identify.HgTag(name: bytes, node_id: bytes)[source]#

Bases: tuple

Represent a Mercurial tag.

Create new instance of HgTag(name, node_id)

property name#

name of the tag

property node_id#

hex bytes of the target revision

class swh.loader.mercurial.identify.Hg(repository_root: Path)[source]#

Bases: object

Provide methods to extract data from a Mercurial repository.

root() Path[source]#

Return the root of the Mercurial repository.

log(rev: Optional[Union[bytes, str]] = None) List[HgRevision][source]#

Return the specified revisions of the Mercurial repository.

Mercurial revsets are supported. (See hg help revsets)

If no revision range is specified, return all revisions”.

up(rev: bytes) None[source]#

Update the repository working directory to the specified revision.

branches() List[HgBranch][source]#

List the repository named branches.

tip() HgRevision[source]#

Return the tip node-id.

tags() List[HgTag][source]#

Return the repository’s tags as defined in the .hgtags file.

.hgtags being like any other repository’s tracked file, its content can vary from revision to revision. The returned value therefore depends on the current revision of the repository.

swh.loader.mercurial.identify.identify_directory(path: Path) CoreSWHID[source]#

Return the SWHID of the given path.

class swh.loader.mercurial.identify.RevisionIdentity(swhid: CoreSWHID, node_id: bytes, directory_swhid: CoreSWHID)[source]#

Bases: tuple

Represent a swh revision identity.

Create new instance of RevisionIdentity(swhid, node_id, directory_swhid)

property swhid#

SWH Identifier of the revision.

property node_id#

node_id hex bytes

property directory_swhid#

SWH Identifier of the directory

dir_uri() str[source]#

Return the SWHID uri of the revision’s directory.

swh.loader.mercurial.identify.identify_revision(hg: Hg, rev: Optional[bytes] = None, node_id_2_swhid: Optional[Dict[bytes, CoreSWHID]] = None) Iterator[RevisionIdentity][source]#

Return the repository revision identities.

Parameters:
  • hg – A Hg repository instance

  • rev – An optional revision or Mercurial revsets (See hg help revsets) If not provided all the repository revisions will be computed.

  • node_id_2_swhid – An optional cache mapping hg node ids to SWHIDs It will be updated in place with new mappings.

class swh.loader.mercurial.identify.ReleaseIdentity(swhid: CoreSWHID, node_id: bytes, name: bytes)[source]#

Bases: tuple

Represent a swh release identity.

Create new instance of ReleaseIdentity(swhid, node_id, name)

property swhid#

SWH Identifier of the release.

property node_id#

node_id hex bytes

property name#

name of the release

swh.loader.mercurial.identify.identify_release(hg: Hg, node_id_2_swhid: Optional[Dict[bytes, CoreSWHID]] = None) Iterator[ReleaseIdentity][source]#

Return the repository’s release identities.

Parameters:
  • hg – A Hg repository instance

  • node_id_2_swhid – An optional cache mapping hg node ids to SWHIDs If not provided it will be computed using identify_revision.

swh.loader.mercurial.identify.identify_snapshot(hg: Hg, node_id_2_swhid: Optional[Dict[bytes, CoreSWHID]] = None, releases: Optional[List[ReleaseIdentity]] = None) CoreSWHID[source]#

Return the repository snapshot identity.

Parameters:
  • hg – A Hg repository instance

  • node_id_2_swhid – An optional cache mapping hg node ids to SWHIDs If not provided it will be computed using identify_revision.

  • release – an optional list of ReleaseIdentity. If not provided it will be computed using identify_release.