Skip to content
Permalink
Browse files
[git-webkit] Extract revision from git svn dcommit
https://bugs.webkit.org/show_bug.cgi?id=236849
<rdar://problem/89155179>

Reviewed by Ryan Haddad.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
(Git): Thoroughly mock `dcommit`
* Tools/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.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/land_unittest.py:
(repository): Add revision to local commit.


Canonical link: https://commits.webkit.org/247644@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@290322 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Feb 22, 2022
1 parent 0c1a3cf commit 79ad9dca0039e316ea73d5ce74e5503e193bcc0e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 10 deletions.
@@ -1,3 +1,21 @@
2022-02-22 Jonathan Bedard <jbedard@apple.com>

[git-webkit] Extract revision from `git svn dcommit`
https://bugs.webkit.org/show_bug.cgi?id=236849
<rdar://problem/89155179>

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 <dino@apple.com>

Filter some build output from JSC
@@ -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=[
@@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path():
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package 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)))
@@ -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)
@@ -41,6 +41,7 @@ class Land(Command):

OOPS_RE = re.compile(r'\(O+P+S!*\)')
REVIEWED_BY_RE = re.compile('Reviewed by (?P<approver>.+)')
GIT_SVN_COMMITTED_RE = re.compile(r'Committed r(?P<revision>\d+)')
Copy link
@aj062

aj062 Feb 22, 2022

Member

Nit: this regex can be tightened to r'^Committed r(?P\d+)$'
(similar to https://github.com/WebKit/WebKit/blob/main/Tools/CISupport/ews-build/steps.py#L4188)

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:
@@ -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(

0 comments on commit 79ad9dc

Please sign in to comment.