Backed out changeset 5153f0eaf518 (bug 1676533) as requested by glandium. CLOSED TREE

This commit is contained in:
Butkovits Atila
2020-12-02 07:58:47 +02:00
parent a9f3873e33
commit 27cfdf79f2
4 changed files with 17 additions and 146 deletions

View File

@@ -51,10 +51,6 @@ class CannotDeleteFromRootOfRepositoryException(Exception):
the repository, which is not permitted."""
class NonexistentFile(Exception):
"""Represents that we attempted to get the content of a file that does not exist."""
def get_tool_path(tool):
"""Obtain the path of `tool`."""
if os.path.isabs(tool) and os.path.exists(tool):
@@ -113,7 +109,6 @@ class Repository(object):
pass
def _run(self, *args, **runargs):
universal_newlines = runargs.get("universal_newlines", True)
return_codes = runargs.get("return_codes", [])
cmd = (self._tool,) + args
@@ -122,7 +117,7 @@ class Repository(object):
cmd,
cwd=self.path,
env=ensure_subprocess_env(self._env),
universal_newlines=universal_newlines,
universal_newlines=True,
)
except subprocess.CalledProcessError as e:
if e.returncode in return_codes:
@@ -233,14 +228,6 @@ class Repository(object):
example, commits to the repo during the Finder's lifetime.
"""
@abc.abstractmethod
def get_file_content(self, path, revision=None):
"""Return as a bytestring the contents of the file as of the given
revision, or the current revision if none is provided.
Returns the file content or raises NonexistentFile if the file cannot be found.
"""
@abc.abstractmethod
def working_directory_clean(self, untracked=False, ignored=False):
"""Determine if the working directory is free of modifications.
@@ -345,16 +332,12 @@ class HgRepository(Repository):
self._client.close()
def _run(self, *args, **runargs):
universal_newlines = runargs.get("universal_newlines", True)
if not self._client.server:
return super(HgRepository, self)._run(*args, **runargs)
# hglib requires bytes on python 3
args = [a.encode("utf-8") if not isinstance(a, bytes) else a for a in args]
res = self._client.rawcommand(args)
if universal_newlines:
return res.decode("utf-8")
return res
return self._client.rawcommand(args).decode("utf-8")
def get_commit_time(self):
newest_public_revision_time = self._run(
@@ -473,15 +456,6 @@ class HgRepository(Repository):
)
return FileListFinder(files)
def get_file_content(self, path, revision=None):
args = ["cat", path]
if revision:
args += ["-r", revision]
try:
return self._run(*args, universal_newlines=False)
except subprocess.CalledProcessError as e:
raise NonexistentFile("Could not find file; got error %s" % e)
def working_directory_clean(self, untracked=False, ignored=False):
args = ["status", "--modified", "--added", "--removed", "--deleted"]
if untracked:
@@ -621,13 +595,6 @@ class GitRepository(Repository):
files = [p for p in self._run("ls-files", "-z").split("\0") if p]
return FileListFinder(files)
def get_file_content(self, path, revision=None):
revision = revision or "HEAD"
try:
return self._run("show", revision + ":" + path, universal_newlines=False)
except subprocess.CalledProcessError as e:
raise NonexistentFile("Could not find file; got error %s" % e)
def working_directory_clean(self, untracked=False, ignored=False):
args = ["status", "--porcelain"]

View File

@@ -2,7 +2,6 @@
subsuite=mozversioncontrol
[test_context_manager.py]
[test_file_content.py]
[test_push_to_try.py]
[test_workdir_outgoing.py]
[test_working_directory.py]

View File

@@ -1,53 +0,0 @@
from __future__ import absolute_import
import mozunit
from mozversioncontrol import (
get_repository_object,
NonexistentFile,
)
STEPS = {
"hg": [
"""
echo "foo" > bar
""",
"""
hg commit -m "Updated bar"
""",
],
"git": [
"""
echo "foo" > bar
""",
"""
git commit -am "Updated bar"
""",
],
}
def test_file_content(repo):
vcs = get_repository_object(repo.strpath)
head_ref = vcs.head_ref
assert vcs.get_file_content("foo") == b"foo\n"
assert vcs.get_file_content("bar") == b"bar\n"
next(repo.step)
assert vcs.get_file_content("foo") == b"foo\n"
assert vcs.get_file_content("bar") == b"bar\n"
next(repo.step)
assert vcs.get_file_content("foo") == b"foo\n"
assert vcs.get_file_content("bar") == b"foo\n"
assert vcs.get_file_content("bar", revision=head_ref) == b"bar\n"
# Ensure a file that can't be found throws the right error.
good = False
try:
vcs.get_file_content("baz", revision=head_ref)
except NonexistentFile:
good = True
assert good
if __name__ == "__main__":
mozunit.main()

View File

@@ -3,16 +3,12 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function, unicode_literals
import hashlib
import io
import os
import six
import subprocess
from mozbuild.util import memoize
import mozpack.path as mozpath
from mozversioncontrol import get_repository_object, NonexistentFile
from mozversioncontrol import get_repository_object
import hashlib
import io
import six
@memoize
@@ -25,34 +21,9 @@ def hash_path(path):
return hashlib.sha256(fh.read()).hexdigest()
@memoize
def hash_path_as_of_base_revision(base_path, path):
repo = get_repository(base_path)
base_revision = get_base_revision(base_path)
return hashlib.sha256(
repo.get_file_content(path, revision=base_revision)
).hexdigest()
@memoize
def get_repository(base_path):
return get_repository_object(base_path)
@memoize
def get_file_finder(base_path):
return get_repository(base_path).get_tracked_files_finder()
@memoize
def get_dirty(base_path):
repo = get_repository(base_path)
return set(repo.get_outgoing_files()) | set(repo.get_changed_files())
@memoize
def get_base_revision(base_path):
return get_repository(base_path).base_ref
return get_repository_object(base_path).get_tracked_files_finder()
def hash_paths(base_path, patterns):
@@ -73,28 +44,15 @@ def hash_paths(base_path, patterns):
files.update(found)
else:
raise Exception("%s did not match anything" % pattern)
dirty = set()
include_local_changes = os.environ.get("MACH_ARTIFACT_INCLUDE_LOCAL_CHANGES", False)
try:
dirty = get_dirty(base_path)
except subprocess.CalledProcessError:
include_local_changes = True
for path in sorted(files.keys()):
path_hash = None
# If the file is dirty, and we haven't been asked specifically to include
# local changes, read the file contents from the VCS directly. Otherwise, read
# the contents from the filesystem.
if not include_local_changes and path in dirty:
try:
path_hash = hash_path_as_of_base_revision(base_path, path)
except NonexistentFile:
# If the file didn't exist at the base revision, that's fine,
# just continue to the next file.
continue
if path_hash is None:
path_hash = hash_path(mozpath.abspath(mozpath.join(base_path, path)))
h.update(six.ensure_binary("{} {}\n".format(path_hash, mozpath.normsep(path))))
if path.endswith((".pyc", ".pyd", ".pyo")):
continue
h.update(
six.ensure_binary(
"{} {}\n".format(
hash_path(mozpath.abspath(mozpath.join(base_path, path))),
mozpath.normsep(path),
)
)
)
return h.hexdigest()