def reposetup(ui, repo):
    if not repo.local():
        return

    class reviewboardrepo(repo.__class__):
        @localrepo.repofilecache("reviews")
        def reviews(self):
            return reviewstore(self)

        def commit(self, *args, **kwargs):
            """Override commit to generate a unique commit identifier.

            The commit identifier is used to track a logical commits across
            history rewrites, including grafting. This is used as an index
            of sorts in the review tool.
            """
            # Some callers of commit() may not pass named arguments. Slurp
            # extra from positional arguments.
            if len(args) == 7:
                assert "extra" not in kwargs
                kwargs["extra"] = args[6]
                args = tuple(args[0:6])

            extra = kwargs.setdefault("extra", {})
            if "commitid" not in extra and self.reviews.remoteurl:
                extra["commitid"] = genid(self)

            return super(reviewboardrepo, self).commit(*args, **kwargs)

    repo.__class__ = reviewboardrepo
    repo.noreviewboardpush = False
    repo.reviewid = None

    def prepushoutgoinghook(local, remote, outgoing):
        if "pushreview" in getreviewcaps(remote):
            # We can't simply look at outgoing.missingheads here because
            # Mercurial treats all revisions to `hg push` as "heads" in the
            # context of discovery. This is arguably a bug in Mercurial and may
            # be changed. This behavior was last observed in 3.2. So, in the
            # case of multiple missing heads, we run things through the DAG,
            # just in case.
            if len(outgoing.missingheads) > 1:
                # "%ln" is internal revset syntax for "a list of binary nodes."
                realmissingheads = local.revs("heads(%ln)", outgoing.missingheads)
                if len(realmissingheads) > 1:
                    raise util.Abort(
                        _("cannot push multiple heads to remote; " "limit pushed revisions using the -r argument.")
                    )

    repo.prepushoutgoinghooks.add("reviewboard", prepushoutgoinghook)

    # Need to use baseui because peers inherit the non-repo ui and the peer's
    # ui is what Mercurial's built-in HTTP auth uses for lookups.
    configureautobmoapikeyauth(repo.baseui)
def reposetup(ui, repo):
    if not repo.local():
        return

    class reviewboardrepo(repo.__class__):
        @localrepo.repofilecache('reviews')
        def reviews(self):
            return reviewstore(self)

        def commit(self, *args, **kwargs):
            """Override commit to generate a unique commit identifier.

            The commit identifier is used to track a logical commits across
            history rewrites, including grafting. This is used as an index
            of sorts in the review tool.
            """
            msg = ''
            if args:
                msg = args[0]
            elif kwargs and 'text' in kwargs:
                msg = kwargs['text']
                del kwargs['text']

            if self.reviews.remoteurl and msg:
                msg, changed = addcommitid(msg, repo=self)

            return super(reviewboardrepo, self).commit(msg, *args[1:], **kwargs)

    repo.__class__ = reviewboardrepo
    repo.noreviewboardpush = False
    repo.reviewid = None

    def prepushoutgoinghook(local, remote, outgoing):
        if 'pushreview' in getreviewcaps(remote):
            # We can't simply look at outgoing.missingheads here because
            # Mercurial treats all revisions to `hg push` as "heads" in the
            # context of discovery. This is arguably a bug in Mercurial and may
            # be changed. This behavior was last observed in 3.2. So, in the
            # case of multiple missing heads, we run things through the DAG,
            # just in case.
            if len(outgoing.missingheads) > 1:
                # "%ln" is internal revset syntax for "a list of binary nodes."
                realmissingheads = local.revs('heads(%ln)',
                                              outgoing.missingheads)
                if len(realmissingheads) > 1:
                    raise util.Abort(_('cannot push multiple heads to remote; '
                        'limit pushed revisions using the -r argument.'))

    repo.prepushoutgoinghooks.add('reviewboard', prepushoutgoinghook)

    # Need to use baseui because peers inherit the non-repo ui and the peer's
    # ui is what Mercurial's built-in HTTP auth uses for lookups.
    configureautobmoapikeyauth(repo.baseui)
def reposetup(ui, repo):
    if not repo.local():
        return

    class reviewboardrepo(repo.__class__):
        @localrepo.repofilecache('reviews')
        def reviews(self):
            return reviewstore(self)

    repo.__class__ = reviewboardrepo
    repo.noreviewboardpush = False
    repo.reviewid = None

    def prepushoutgoinghook(*args):
        # Mercurial 3.8 switched from local, remote, outgoing to a pushop arg
        if len(args) == 1:
            local = args[0].repo
            remote = args[0].remote
            outgoing = args[0].outgoing
        else:
            local, remote, outgoing = args

        if 'pushreview' in getreviewcaps(remote):
            # We can't simply look at outgoing.missingheads here because
            # Mercurial treats all revisions to `hg push` as "heads" in the
            # context of discovery. This is arguably a bug in Mercurial and may
            # be changed. This behavior was last observed in 3.2. So, in the
            # case of multiple missing heads, we run things through the DAG,
            # just in case.
            if len(outgoing.missingheads) > 1:
                # "%ln" is internal revset syntax for "a list of binary nodes."
                realmissingheads = local.revs('heads(%ln)',
                                              outgoing.missingheads)
                if len(realmissingheads) > 1:
                    raise util.Abort(_('cannot push multiple heads to remote; '
                        'limit pushed revisions using the -r argument.'))

    repo.prepushoutgoinghooks.add('reviewboard', prepushoutgoinghook)

    # Need to use baseui because peers inherit the non-repo ui and the peer's
    # ui is what Mercurial's built-in HTTP auth uses for lookups.
    configureautobmoapikeyauth(repo.baseui)
def reposetup(ui, repo):
    if not repo.local():
        return

    class reviewboardrepo(repo.__class__):
        @localrepo.repofilecache('reviews')
        def reviews(self):
            return reviewstore(self)

        def commit(self, *args, **kwargs):
            """Override commit to generate a unique commit identifier.

            The commit identifier is used to track a logical commits across
            history rewrites, including grafting. This is used as an index
            of sorts in the review tool.
            """
            msg = ''
            if args:
                msg = args[0]
            elif kwargs and 'text' in kwargs:
                msg = kwargs['text']
                del kwargs['text']

            if self.reviews.remoteurl and msg:
                msg, changed = addcommitid(msg, repo=self)

            return super(reviewboardrepo, self).commit(msg, *args[1:],
                                                       **kwargs)

    repo.__class__ = reviewboardrepo
    repo.noreviewboardpush = False
    repo.reviewid = None

    def prepushoutgoinghook(*args):
        # Mercurial 3.8 switched from local, remote, outgoing to a pushop arg
        if len(args) == 1:
            local = args[0].repo
            remote = args[0].remote
            outgoing = args[0].outgoing
        else:
            local, remote, outgoing = args

        if 'pushreview' in getreviewcaps(remote):
            # We can't simply look at outgoing.missingheads here because
            # Mercurial treats all revisions to `hg push` as "heads" in the
            # context of discovery. This is arguably a bug in Mercurial and may
            # be changed. This behavior was last observed in 3.2. So, in the
            # case of multiple missing heads, we run things through the DAG,
            # just in case.
            if len(outgoing.missingheads) > 1:
                # "%ln" is internal revset syntax for "a list of binary nodes."
                realmissingheads = local.revs('heads(%ln)',
                                              outgoing.missingheads)
                if len(realmissingheads) > 1:
                    raise util.Abort(
                        _('cannot push multiple heads to remote; '
                          'limit pushed revisions using the -r argument.'))

    repo.prepushoutgoinghooks.add('reviewboard', prepushoutgoinghook)

    # Need to use baseui because peers inherit the non-repo ui and the peer's
    # ui is what Mercurial's built-in HTTP auth uses for lookups.
    configureautobmoapikeyauth(repo.baseui)