def reposetup()

in hgext/mozext/__init__.py [0:0]


def reposetup(ui, repo):
    """Custom repository implementation.

    Our custom repository class tracks remote tree references so users can
    reference specific revisions on remotes.
    """

    if not repo.local():
        return

    orig_findtags = repo._findtags
    orig_lookup = repo.lookup

    class remotestrackingrepo(repo.__class__):
        @repofilecache(b"remoterefs")
        def remoterefs(self):
            return remoterefs(self)

        @util.propertycache
        def changetracker(self):
            if ui.configbool(b"mozext", b"disable_local_database"):
                return None
            try:
                return ChangeTracker(
                    self.vfs.join(b"changetracker.db"), bytestype=pycompat.bytestr
                )
            except Exception as e:
                raise error.Abort(e.message)

        def _update_remote_refs(self, remote, tree):
            existing_refs = set()
            incoming_refs = set()

            for ref in self.remoterefs:
                if ref.startswith(b"%s/" % tree):
                    existing_refs.add(ref)

            for branch, nodes in remote.branchmap().items():
                # Don't store RELBRANCH refs for non-release trees, as they are
                # meaningless and cruft from yesteryear.
                if branch.endswith(b"RELBRANCH"):
                    if tree not in TREE_ALIASES[b"releases"]:
                        continue

                ref = b"%s/%s" % (tree, branch)
                incoming_refs.add(ref)

                for node in nodes:
                    self.remoterefs[ref] = node

            # Prune old refs.
            for ref in existing_refs - incoming_refs:
                try:
                    del self.remoterefs[ref]
                except KeyError:
                    pass

            with self.wlock():
                self.remoterefs.write()

        def _revision_milestone(self, rev):
            """Look up the Gecko milestone of a revision."""
            fctx = self.filectx(b"config/milestone.txt", changeid=rev)
            lines = fctx.data().splitlines()
            lines = [l for l in lines if not l.startswith(b"#") and l.strip()]

            if not lines:
                return None

            return lines[0]

        def _beta_releases(self):
            """Obtain information for each beta release."""
            return self._release_versions(b"beta/")

        def _release_releases(self):
            return self._release_versions(b"release/")

        def _release_versions(self, prefix):
            d = {}

            for key, node in self.remoterefs.items():
                if not key.startswith(prefix):
                    continue

                key = key[len(prefix) :]

                if not key.startswith(b"GECKO") or not key.endswith(b"RELBRANCH"):
                    continue

                version, date, _relbranch = key.split(b"_")
                version = version[5:]
                after = b""
                marker = b""

                if b"b" in version:
                    marker = b"b"
                    version, after = version.split(b"b")

                if len(version) > 2:
                    major, minor = version[0:2], version[2:]
                else:
                    major, minor = version

                version = b"%s.%s" % (major, minor)
                if marker:
                    version += b"%s%s" % (marker, after)

                d[version] = (key, node, major, minor, marker or None, after or None)

            return d

        def _earliest_version_ancestors(self, versions):
            """Take a set of versions and generate earliest version ancestors.

            This function takes the output of _release_versions as an input
            and calculates the set of revisions corresponding to each version's
            introduced ancestors. Put another way, it returns a dict of version
            to revision set where each set is disjoint and presence in a
            version's set indicates that particular version introduced that
            revision.

            This computation is computational expensive. Callers are encouraged
            to cache it.
            """
            d = {}
            seen = set()
            for version, e in sorted(versions.items()):
                version_rev = self[e[1]].rev()
                ancestors = set(
                    self.changelog.findmissingrevs(common=seen, heads=[version_rev])
                )
                d[version] = ancestors
                seen |= ancestors

            return d

        def reset_bug_database(self):
            if not self.changetracker:
                return

            self.changetracker.wipe_bugs()
            self.sync_bug_database()

        def sync_bug_database(self):
            if not self.changetracker:
                return

            for rev in self:
                ui.makeprogress(b"changeset", rev, total=len(self))
                ctx = self[rev]
                bugs = parse_bugs(ctx.description())
                if bugs:
                    self.changetracker.associate_bugs_with_changeset(bugs, ctx.node())

            ui.makeprogress(b"changeset", None)

    repo.__class__ = remotestrackingrepo

    if ui.configbool(b"mozext", b"reject_pushes_with_repo_names"):
        ui.setconfig(b"hooks", b"prepushkey.reject_repo_names", reject_repo_names_hook)