swh.loader.mercurial.identify module#

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

Bases: NamedTuple

Represent a Mercurial revision author.

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

fullname: bytes#

full name of the author

name: bytes | None#

name of the author

email: bytes | None#

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, bytes | None][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: NamedTuple

Represent a Mercurial revision.

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

node_id: bytes#

raw bytes of the revision hash

author: HgAuthor#

author of the revision

timestamp: bytes#

timestamp of the revision

offset: bytes#

offset of the revision

parents: List[bytes]#

hex bytes of the revision’s parents

extras: Dict[bytes, bytes]#

metadata of the revision

description: bytes#

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: NamedTuple

Represent a Mercurial branch.

Create new instance of HgBranch(name, node_id)

name: bytes#

name of the branch

node_id: bytes#

row bytes of the target revision hash

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

Bases: NamedTuple

Represent a Mercurial tag.

Create new instance of HgTag(name, node_id)

name: bytes#

name of the tag

node_id: bytes#

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: bytes | str | None = 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: NamedTuple

Represent a swh revision identity.

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

swhid: CoreSWHID#

SWH Identifier of the revision.

node_id: bytes#

node_id hex bytes

directory_swhid: CoreSWHID#

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: bytes | None = None, node_id_2_swhid: Dict[bytes, CoreSWHID] | None = 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: NamedTuple

Represent a swh release identity.

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

swhid: CoreSWHID#

SWH Identifier of the release.

node_id: bytes#

node_id hex bytes

name: bytes#

name of the release

swh.loader.mercurial.identify.identify_release(hg: Hg, node_id_2_swhid: Dict[bytes, CoreSWHID] | None = 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: Dict[bytes, CoreSWHID] | None = None, releases: List[ReleaseIdentity] | None = 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.