Example #1
0
def test_get_commits_to_ignore(tmpdir):
    tmp_path = tmpdir.strpath

    with open(os.path.join(tmp_path, ".hg-annotate-ignore-revs"), "w") as f:
        f.write("commit1\ncommit2\n8ba995b74e18334ab3707f27e9eb8f4e37ba3d29\n")

    def create_commit(node, desc, bug, backedoutby):
        return repository.Commit(
            node=node,
            author="author",
            desc=desc,
            date=datetime(2019, 1, 1),
            pushdate=datetime(2019, 1, 1),
            bug=bug,
            backedoutby=backedoutby,
            author_email="*****@*****.**",
            files=["dom/file1.cpp"],
            file_copies={},
            reviewers=("reviewer1", "reviewer2"),
        )

    commits = [
        create_commit("commit", "", 123, ""),
        create_commit("commit_backout", "", 123, ""),
        create_commit("commit_backedout", "", 123, "commit_backout"),
        create_commit("commit_no_bug", "", b"", ""),
        create_commit(
            "8ba995b74e18334ab3707f27e9eb8f4e37ba3d29",
            "commit in .hg-annotate-ignore-revs",
            123,
            "",
        ),
        create_commit("commit_with_ignore_in_desc",
                      "prova\nignore-this-changeset\n", 123, ""),
    ]

    leftovers = repository.get_commits_to_ignore(tmp_path, commits)
    assert len(leftovers) == 4
    assert set(commit.node for commit in leftovers) == {
        "commit_backout",
        "commit_no_bug",
        "8ba995b74e18334ab3707f27e9eb8f4e37ba3d29",
        "commit_with_ignore_in_desc",
    }
Example #2
0
def get_commits_to_ignore(repo_dir):
    commits_to_ignore = []

    # TODO: Make repository analyze all commits, even those to ignore, but add a field "ignore" or a function should_ignore that analyzes the commit data. This way we don't have to clone the Mercurial repository in this script.
    with hglib.open(repo_dir) as hg:
        revs = repository.get_revs(hg, -10000)

    commits = repository.hg_log_multi(repo_dir, revs)

    commits_to_ignore = []

    def append_commits_to_ignore(commits, type_):
        for commit in commits:
            commits_to_ignore.append(
                {
                    "mercurial_rev": commit.node,
                    "git_rev": vcs_map.mercurial_to_git(commit.node),
                    "type": type_,
                }
            )

    append_commits_to_ignore(
        list(repository.get_commits_to_ignore(repo_dir, commits)), ""
    )

    logger.info(
        f"{len(commits_to_ignore)} commits to ignore (excluding backed-out commits)"
    )

    append_commits_to_ignore(
        (commit for commit in commits if commit.backedoutby), "backedout"
    )

    logger.info(
        f"{len(commits_to_ignore)} commits to ignore (including backed-out commits)"
    )

    with open("commits_to_ignore.csv", "w") as f:
        writer = csv.DictWriter(f, fieldnames=["mercurial_rev", "git_rev", "type"])
        writer.writeheader()
        writer.writerows(commits_to_ignore)

    return commits_to_ignore