Read the .hg-annotate-ignore-revs file using hg.cat

This was the only file we were reading directly from the repository
working directory, and we need to avoid reading directly from it in
order to be able to do clone without updating (#1469).
This commit is contained in:
Marco Castelluccio 2020-04-22 13:27:23 +02:00
Родитель 2f32de887d
Коммит 9c645e35b6
3 изменённых файлов: 22 добавлений и 15 удалений

Просмотреть файл

@ -859,12 +859,14 @@ def calculate_experiences(commits, first_pushdate, save=True):
update_complex_experiences("component", day, commit.components)
def set_commits_to_ignore(repo_dir, commits):
def set_commits_to_ignore(hg, repo_dir, commits):
# Skip commits which are in .hg-annotate-ignore-revs or which have
# 'ignore-this-changeset' in their description (mostly consisting of very
# large and not meaningful formatting changes).
with open(os.path.join(repo_dir, ".hg-annotate-ignore-revs"), "r") as f:
ignore_revs = set(l[:40] for l in f)
ignore_revs_content = hg.cat(
[os.path.join(repo_dir, ".hg-annotate-ignore-revs").encode("ascii")], rev=b"-1"
).decode("utf-8")
ignore_revs = set(l[:40] for l in ignore_revs_content.splitlines())
backouts = set(commit.backedoutby for commit in commits if commit.ever_backedout)
@ -973,7 +975,7 @@ def download_commits(
logger.info("Downloading file->component mapping...")
download_component_mapping()
set_commits_to_ignore(repo_dir, commits)
set_commits_to_ignore(hg, repo_dir, commits)
commits_num = len(commits)

Просмотреть файл

@ -204,11 +204,12 @@ def mock_repo(tmpdir, monkeypatch):
# Create the repo
hglib.init(str(local_dir))
(local_dir / ".hg-annotate-ignore-revs").write_text("", encoding="ascii")
# Add several commits on a test file to create some history
test_file = local_dir / "test.txt"
with hglib.open(str(local_dir)) as repo:
(local_dir / ".hg-annotate-ignore-revs").write_text("", encoding="ascii")
repo.add(str(local_dir / ".hg-annotate-ignore-revs").encode("utf-8"))
# Add several commits on a test file to create some history
test_file = local_dir / "test.txt"
for i in range(4):
test_file.write_text(f"Version {i}", encoding="utf-8")
repo.add([str(test_file).encode("utf-8")])

Просмотреть файл

@ -459,8 +459,7 @@ def test_download_commits(fake_hg_repo, use_single_process):
# Remove the mock DB generated by the mock_data fixture.
os.remove("data/commits.json")
with open(os.path.join(local, ".hg-annotate-ignore-revs"), "w") as f:
f.write("not_existing_hash\n")
add_file(hg, local, ".hg-annotate-ignore-revs", "not_existing_hash\n")
add_file(hg, local, "file1", "1\n2\n3\n4\n5\n6\n7\n")
commit(hg, date=datetime(1991, 4, 16, tzinfo=timezone.utc))
@ -560,13 +559,18 @@ def test_get_directories():
) == {"dom", "tools", "tools/code-coverage"}
def test_set_commits_to_ignore(tmpdir):
tmp_path = tmpdir.strpath
def test_set_commits_to_ignore(fake_hg_repo):
hg, local, remote = fake_hg_repo
repository.path_to_component = {}
with open(os.path.join(tmp_path, ".hg-annotate-ignore-revs"), "w") as f:
f.write("commit1\ncommit2\n8ba995b74e18334ab3707f27e9eb8f4e37ba3d29\n")
add_file(
hg,
local,
".hg-annotate-ignore-revs",
"commit1\ncommit2\n8ba995b74e18334ab3707f27e9eb8f4e37ba3d29\n",
)
commit(hg)
def create_commit(node, desc, bug_id, backedoutby):
return repository.Commit(
@ -597,7 +601,7 @@ def test_set_commits_to_ignore(tmpdir):
),
]
repository.set_commits_to_ignore(tmp_path, commits)
repository.set_commits_to_ignore(hg, local, commits)
leftovers = [commit for commit in commits if commit.ignored]
assert len(leftovers) == 4
assert set(commit.node for commit in leftovers) == {