Example #1
0
def hg_log(hg: hglib.client, revs: List[bytes]) -> List[Commit]:
    if len(revs) == 0:
        return []

    template = "{node}\\0{author}\\0{desc}\\0{bug}\\0{backedoutby}\\0{author|email}\\0{pushdate|hgdate}\\0{reviewers}\\0{backsoutnodes}\\0"

    args = hglib.util.cmdbuilder(
        b"log",
        template=template,
        no_merges=True,
        rev=revs,
        branch="tip",
    )
    x = hg.rawcommand(args)
    out = x.split(b"\x00")[:-1]

    commits = []
    for rev in hglib.util.grouper(template.count("\\0"), out):
        assert b" " in rev[6]
        pushdate_timestamp = rev[6].split(b" ", 1)[0]
        if pushdate_timestamp != b"0":
            pushdate = datetime.utcfromtimestamp(float(pushdate_timestamp))
        else:
            pushdate = datetime.utcnow()

        bug_id = int(rev[3].decode("ascii")) if rev[3] else None

        reviewers = (
            list(set(sys.intern(r) for r in rev[7].decode("utf-8").split(" ")))
            if rev[7] != b""
            else []
        )

        backsout = (
            list(set(sys.intern(r) for r in rev[8].decode("utf-8").split(" ")))
            if rev[8] != b""
            else []
        )

        commits.append(
            Commit(
                node=sys.intern(rev[0].decode("ascii")),
                author=sys.intern(rev[1].decode("utf-8")),
                desc=rev[2].decode("utf-8"),
                pushdate=pushdate,
                bug_id=bug_id,
                backsout=backsout,
                backedoutby=rev[4].decode("ascii"),
                author_email=rev[5].decode("utf-8"),
                reviewers=reviewers,
            )
        )

    return commits
Example #2
0
    def run_annotate(self, hg: hglib.client, rev: str,
                     path: str) -> Optional[Tuple[Tuple[str, int], ...]]:
        args = hglib.util.cmdbuilder(
            b"annotate",
            os.path.join(self.repo_dir, path).encode("ascii"),
            r=rev,
            line=True,
            changeset=True,
        )
        try:
            out = hg.rawcommand(args)
        except hglib.error.CommandError as e:
            if b"no such file in rev" not in e.err:
                raise

            # The file was removed.
            return None

        def _collect() -> Iterator[Tuple[str, int]]:
            for line in out.splitlines():
                orig_changeset, orig_line, _ = line.split(b":", 2)
                yield orig_changeset.decode("ascii"), int(orig_line)

        return tuple(_collect())
Example #3
0
def hg_log(hg: hglib.client, revs: list[bytes]) -> tuple[Commit, ...]:
    if len(revs) == 0:
        return tuple()

    template = "{node}\\0{author}\\0{desc}\\0{bug}\\0{backedoutby}\\0{author|email}\\0{pushdate|hgdate}\\0{reviewers}\\0{backsoutnodes}\\0"

    args = hglib.util.cmdbuilder(
        b"log",
        template=template,
        no_merges=True,
        rev=revs,
        branch="tip",
    )
    x = hg.rawcommand(args)
    out = x.split(b"\x00")[:-1]

    commits = []
    for rev in hglib.util.grouper(template.count("\\0"), out):
        assert b" " in rev[6]
        pushdate_timestamp = rev[6].split(b" ", 1)[0]
        if pushdate_timestamp != b"0":
            pushdate = datetime.utcfromtimestamp(float(pushdate_timestamp))
        else:
            pushdate = datetime.utcnow()

        bug_id = int(rev[3].decode("ascii")) if rev[3] else None

        reviewers = (list(
            set(
                sys.intern(r) for r in rev[7].decode("utf-8").split(" ")
                if r not in (
                    "",
                    "testonly",
                    "gaia-bump",
                    "me",
                    "fix",
                    "wpt-fix",
                    "testing",
                    "bustage",
                    "test-only",
                    "blocking",
                    "blocking-fennec",
                    "blocking1.9",
                    "backout",
                    "trivial",
                    "DONTBUILD",
                    "blocking-final",
                    "blocking-firefox3",
                    "test",
                    "bustage-fix",
                    "release",
                    "tests",
                    "lint-fix",
                ))) if rev[7] != b"" else [])

        backsout = (list(
            set(sys.intern(r) for r in rev[8].decode("utf-8").split(" ")))
                    if rev[8] != b"" else [])

        commits.append(
            Commit(
                node=sys.intern(rev[0].decode("ascii")),
                author=sys.intern(rev[1].decode("utf-8")),
                desc=rev[2].decode("utf-8"),
                pushdate=pushdate,
                bug_id=bug_id,
                backsout=backsout,
                backedoutby=rev[4].decode("ascii"),
                author_email=rev[5].decode("utf-8"),
                reviewers=reviewers,
            ))

    return tuple(commits)