diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 5eca1904fb96..2a3cc5341fa4 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,21 @@ +2022-02-22 Jonathan Bedard + + [git-webkit] Extract revision from `git svn dcommit` + https://bugs.webkit.org/show_bug.cgi?id=236849 + + + Reviewed by Ryan Haddad. + + * Scripts/libraries/webkitscmpy/setup.py: Bump version. + * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto. + * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py: + (Git): Thoroughly mock `dcommit` + * Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py: + (Land.main): Extract committed SVN revision from `git svn dcommit` command to accurately + match landed commits to the pull request that generated them. + * Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py: + (repository): Add revision to local commit. + 2022-02-22 Dean Jackson Filter some build output from JSC diff --git a/Tools/Scripts/libraries/webkitscmpy/setup.py b/Tools/Scripts/libraries/webkitscmpy/setup.py index 5d47e41fd7e4..d25fb2d0bdf4 100644 --- a/Tools/Scripts/libraries/webkitscmpy/setup.py +++ b/Tools/Scripts/libraries/webkitscmpy/setup.py @@ -29,7 +29,7 @@ def readme(): setup( name='webkitscmpy', - version='4.3.1', + version='4.3.2', description='Library designed to interact with git and svn repositories.', long_description=readme(), classifiers=[ diff --git a/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py b/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py index fceaca2a1714..8470fc45fb3e 100644 --- a/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py +++ b/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py @@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path(): "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url `" ) -version = Version(4, 3, 1) +version = Version(4, 3, 2) AutoInstall.register(Package('fasteners', Version(0, 15, 0))) AutoInstall.register(Package('jinja2', Version(2, 11, 3))) diff --git a/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py b/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py index e61f2b2ac23a..0ccde2ecf1ce 100644 --- a/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py +++ b/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py @@ -160,7 +160,7 @@ def __init__( ), mocks.Subprocess.Route( self.executable, 'svn', 'dcommit', cwd=self.path, - completion=mocks.ProcessCompletion(returncode=0) + generator=lambda *args, **kwargs: self.dcommit(), ), ] @@ -907,6 +907,15 @@ def push(self, remote, branch): self.remotes['{}/{}'.format(remote, branch)] = self.commits[branch][-1] return mocks.ProcessCompletion(returncode=0) + def dcommit(self, remote='origin', branch=None): + branch = branch or self.default_branch + self.remotes['{}/{}'.format(remote, branch)] = self.commits[branch][-1] + return mocks.ProcessCompletion( + returncode=0, + stdout='Committed r{}\n\tM\tFiles/Changed.txt\n'.format(self.commits[branch][-1].revision), + ) + + def reset(self, index): self.head = self.commits[self.head.branch][-(index + 1)] return mocks.ProcessCompletion(returncode=0) diff --git a/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py b/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py index ae36e923a4ff..16475736fbfe 100644 --- a/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py +++ b/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/land.py @@ -41,6 +41,7 @@ class Land(Command): OOPS_RE = re.compile(r'\(O+P+S!*\)') REVIEWED_BY_RE = re.compile('Reviewed by (?P.+)') + GIT_SVN_COMMITTED_RE = re.compile(r'Committed r(?P\d+)') REMOTE = 'origin' MIRROR_TIMEOUT = 60 @@ -191,26 +192,48 @@ def main(cls, args, repository, identifier_template=None, canonical_svn=False, * if run([repository.executable(), 'svn', 'fetch'], cwd=repository.root_path).returncode: sys.stderr.write("Failed to update subversion refs\n".format(target)) return 1 if cls.revert_branch(repository, cls.REMOTE, target) else -1 - if run([repository.executable(), 'svn', 'dcommit'], cwd=repository.root_path).returncode: + + dcommit = run([repository.executable(), 'svn', 'dcommit'], cwd=repository.root_path, capture_output=True, encoding='utf-8') + if dcommit.returncode: + sys.stderr.write(dcommit.stdout) + sys.stderr.write(dcommit.stderr) sys.stderr.write("Failed to commit '{}' to Subversion remote\n".format(target)) return 1 if cls.revert_branch(repository, cls.REMOTE, target) else -1 + revisions = [] + for line in dcommit.stdout.splitlines(): + match = cls.GIT_SVN_COMMITTED_RE.match(line) + if not match: + continue + revisions.append(int(match.group('revision'))) + if not revisions: + sys.stderr.write(dcommit.stdout) + sys.stderr.write(dcommit.stderr) + sys.stderr.write("Failed to find revision in '{}' when committing to Subversion remote\n".format(target)) + return 1 if cls.revert_branch(repository, cls.REMOTE, target) else -1 + run([repository.executable(), 'reset', 'HEAD~{}'.format(len(commits)), '--hard'], cwd=repository.root_path) # Verify the mirror processed our change started = time.time() - original = repository.find('HEAD', include_log=False, include_identifier=False) - latest = original - while original.hash == latest.hash: + latest = repository.find('HEAD', include_log=True, include_identifier=False) + while latest.revision < revisions[-1]: if time.time() - started > cls.MIRROR_TIMEOUT: sys.stderr.write("Timed out waiting for the git-svn mirror, '{}' landed but not closed\n".format(pull_request or source_branch)) return 1 log.info(' Verifying mirror processesed change') time.sleep(5) run([repository.executable(), 'pull'], cwd=repository.root_path) - latest = repository.find('HEAD', include_log=False, include_identifier=False) + latest = repository.find('HEAD', include_log=True, include_identifier=False) + if repository.cache and target in repository.cache._last_populated: + del repository.cache._last_populated[target] + + commits = [] + for revision in revisions: + commits.append(repository.commit(revision=revision, include_log=True)) + commit = commits[-1] + if pull_request: run([repository.executable(), 'branch', '-f', source_branch, target], cwd=repository.root_path) - commits = list(repository.commits(begin=dict(argument='{}~{}'.format(source_branch, len(commits))), end=dict(branch=source_branch))) run([repository.executable(), 'push', '-f', remote_target, source_branch], cwd=repository.root_path) rmt.pull_requests.update( pull_request=pull_request, @@ -237,8 +260,8 @@ def main(cls, args, repository, identifier_template=None, canonical_svn=False, * sys.stderr.write("Failed to push '{}' to '{}'\n".format(target, cls.REMOTE)) return 1 if cls.revert_branch(repository, cls.REMOTE, target) else -1 repository.checkout(target) + commit = repository.commit(branch=target, include_log=False) - commit = repository.commit(branch=target, include_log=True) if identifier_template and commit.identifier: land_message = 'Landed {} ({})!'.format(identifier_template.format(commit).split(': ')[-1], commit.hash[:Commit.HASH_LABEL_SIZE]) else: diff --git a/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py b/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py index d05c80c081e3..7ab3353555c3 100644 --- a/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py +++ b/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py @@ -37,6 +37,7 @@ def repository(path, has_oops=True, remote=None, git_svn=False, issue_url=None): result.commits[branch] = [Commit( hash='a5fe8afe9bf7d07158fcd9e9732ff02a712db2fd', identifier='3.1@{}'.format(branch), + revision=10, timestamp=int(time.time()) - 60, author=Contributor('Tim Committer', ['tcommitter@webkit.org']), message='To Be Committed\n{}\nReviewed by {}.\n{}'.format(