Skip to content

Commit

Permalink
[git-webkit] Improve 'trace' regexes
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=246543
rdar://101188306

Rubber-stamped by Aakash Jain.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/trace.py:
(Relationship): Improve regexes for follow-up fixes.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/trace_unittest.py:
(TestRelationship.test_follow_up): Update relationship name.
(TestCommitsStory.test_follow_up): Ditto.
(TestTrace.test_revert_a):
(TestTrace.test_revert_b):
(TestTrace.test_revert): Renamed test_revert_a.
(TestTrace.test_follow_up_a):
(TestTrace.test_follow_up_b):
(TestTrace.test_follow_up_c):
(TestTrace.test_regression):
(TestTrace.test_gardening):

Canonical link: https://commits.webkit.org/255687@main
  • Loading branch information
JonWBedard committed Oct 18, 2022
1 parent 8c46e24 commit 1fe7fc8
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Tools/Scripts/libraries/webkitscmpy/setup.py
Expand Up @@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='5.6.24',
version='5.6.25',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
Expand Down
Expand Up @@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path():
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)

version = Version(5, 6, 24)
version = Version(5, 6, 25)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
Expand Down
18 changes: 13 additions & 5 deletions Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/trace.py
Expand Up @@ -31,13 +31,21 @@
COMMIT_REF_BASE = r'r?R?[a-f0-9A-F]+.?\d*@?[0-9a-zA-z\-/]*'
COMPOUND_COMMIT_REF = r'(?P<primary>{})(?P<secondary> \({}\))?'.format(COMMIT_REF_BASE, COMMIT_REF_BASE)
CHERRY_PICK_RE = re.compile(r'[Cc]herry[- ][Pp]ick {}'.format(COMPOUND_COMMIT_REF))
REVERT_RE = re.compile(r'Reverts? {}'.format(COMPOUND_COMMIT_REF))
REVERT_RE = [
re.compile(r'Reverts? {}'.format(COMPOUND_COMMIT_REF)),
re.compile(r'Reverts? \[{}\]'.format(COMPOUND_COMMIT_REF)),
re.compile(r'Reverts? \({}\)'.format(COMPOUND_COMMIT_REF)),
]
FOLLOW_UP_FIXES_RE = [
re.compile(r'Fix following {}'.format(COMPOUND_COMMIT_REF)),
re.compile(r'Follow-? ?up fix to {}'.format(COMPOUND_COMMIT_REF)),
re.compile(r'Follow-? ?up fix {}'.format(COMPOUND_COMMIT_REF)),
re.compile(r'Follow-? ?up to {}'.format(COMPOUND_COMMIT_REF)),
re.compile(r'Follow-? ?up {}'.format(COMPOUND_COMMIT_REF)),
re.compile(r'\[?[Gg]ardening\]?:? REGRESSION \(?{}\)?'.format(COMPOUND_COMMIT_REF)),
re.compile(r'REGRESSION ?\(?{}\)?'.format(COMPOUND_COMMIT_REF)),
re.compile(r'\[?[Gg]ardening\]?:? REGRESSION \({}\)'.format(COMPOUND_COMMIT_REF)),
re.compile(r'\[?[Gg]ardening\]?:? REGRESSION {}'.format(COMPOUND_COMMIT_REF)),
re.compile(r'REGRESSION ?\({}\)'.format(COMPOUND_COMMIT_REF)),
re.compile(r'REGRESSION ?{}'.format(COMPOUND_COMMIT_REF)),
re.compile(r'\[?[Gg]ardening\]?:? [Tt]est-? ?[Aa]ddition \(?{}\)?'.format(COMPOUND_COMMIT_REF)),
re.compile(r'[Tt]est-? ?[Aa]ddition \(?{}\)?'.format(COMPOUND_COMMIT_REF)),
]
Expand All @@ -49,7 +57,7 @@ class Relationship(object):
'references', 'referenced by',
'cherry-picked', 'original',
'reverts', 'reverted by',
'follow-up', 'follow-up by',
'follow-up to', 'followed-up by',
)
REFERENCES, REFERENCED_BY, \
CHERRY_PICK, ORIGINAL, \
Expand Down Expand Up @@ -79,7 +87,7 @@ def parse(cls, commit):

for type, regexes in {
cls.ORIGINAL: [CHERRY_PICK_RE],
cls.REVERTS: [REVERT_RE],
cls.REVERTS: REVERT_RE,
cls.FOLLOW_UP: FOLLOW_UP_FIXES_RE,
}.items():
for regex in regexes:
Expand Down
128 changes: 121 additions & 7 deletions Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/trace_unittest.py
Expand Up @@ -70,25 +70,25 @@ def test_revert(self):

def test_follow_up(self):
self.assertEqual(
('follow-up', ['1230@main', '0123456789ab']), Relationship.parse(Commit(
('follow-up to', ['1230@main', '0123456789ab']), Relationship.parse(Commit(
hash='deadbeef1234', revision=1234, identifier='1234@main',
message='Fix following 1230@main (0123456789ab)',
))
)
self.assertEqual(
('follow-up', ['1230@main']), Relationship.parse(Commit(
('follow-up to', ['1230@main']), Relationship.parse(Commit(
hash='deadbeef1234', revision=1234, identifier='1234@main',
message='Follow-up 1230@main, it broke the build',
))
)
self.assertEqual(
('follow-up', ['1230@main']), Relationship.parse(Commit(
('follow-up to', ['1230@main']), Relationship.parse(Commit(
hash='deadbeef1234', revision=1234, identifier='1234@main',
message='REGRESSION 1230@main',
))
)
self.assertEqual(
('follow-up', ['1230@main']), Relationship.parse(Commit(
('follow-up to', ['1230@main']), Relationship.parse(Commit(
hash='deadbeef1234', revision=1234, identifier='1234@main',
message='Test-addition (1230@main)',
))
Expand Down Expand Up @@ -136,11 +136,11 @@ def test_follow_up(self):
self.assertEqual(story.by_issue, {})
self.assertEqual(
[str(rel) for rel in story.relations.get('1230@main', [])],
['1234@main follow-up by'],
['1234@main followed-up by'],
)
self.assertEqual(
[str(rel) for rel in story.relations.get('0123456789ab', [])],
['1234@main follow-up by'],
['1234@main followed-up by'],
)


Expand All @@ -160,7 +160,7 @@ def test_none(self):
))
self.assertEqual(captured.stderr.getvalue(), 'No repository provided\n')

def test_revert(self):
def test_revert_a(self):
with OutputCapture() as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), Terminal.override_atty(sys.stdin, isatty=False):
repo.head = Commit(
hash='deadbeef1234', revision=10, identifier='6@main',
Expand All @@ -179,6 +179,120 @@ def test_revert(self):
)
self.assertEqual(captured.stderr.getvalue(), '')

def test_revert_b(self):
with OutputCapture() as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), Terminal.override_atty(sys.stdin, isatty=False):
repo.head = Commit(
hash='deadbeef1234', revision=10, identifier='6@main',
message='Revert [5@main]', timestamp=int(time.time()),
author=repo.head.author,
)
repo.commits['main'].append(repo.head)

self.assertEqual(0, program.main(
args=('trace', '6@main', '--limit', '1'),
path=self.path,
))
self.assertEqual(
captured.stdout.getvalue(),
'6@main | deadbeef1234 | Revert [5@main]\n reverts 5@main | d8bce26fa65c | Patch Series\n',
)
self.assertEqual(captured.stderr.getvalue(), '')

def test_follow_up_a(self):
with OutputCapture() as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), Terminal.override_atty(sys.stdin, isatty=False):
repo.head = Commit(
hash='deadbeef1234', revision=10, identifier='6@main',
message='Follow-up 5@main', timestamp=int(time.time()),
author=repo.head.author,
)
repo.commits['main'].append(repo.head)

self.assertEqual(0, program.main(
args=('trace', '6@main', '--limit', '1'),
path=self.path,
))
self.assertEqual(
captured.stdout.getvalue(),
'6@main | deadbeef1234 | Follow-up 5@main\n follow-up to 5@main | d8bce26fa65c | Patch Series\n',
)
self.assertEqual(captured.stderr.getvalue(), '')

def test_follow_up_b(self):
with OutputCapture() as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), Terminal.override_atty(sys.stdin, isatty=False):
repo.head = Commit(
hash='deadbeef1234', revision=10, identifier='6@main',
message='Follow up to 5@main', timestamp=int(time.time()),
author=repo.head.author,
)
repo.commits['main'].append(repo.head)

self.assertEqual(0, program.main(
args=('trace', '6@main', '--limit', '1'),
path=self.path,
))
self.assertEqual(
captured.stdout.getvalue(),
'6@main | deadbeef1234 | Follow up to 5@main\n follow-up to 5@main | d8bce26fa65c | Patch Series\n',
)
self.assertEqual(captured.stderr.getvalue(), '')

def test_follow_up_c(self):
with OutputCapture() as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), Terminal.override_atty(sys.stdin, isatty=False):
repo.head = Commit(
hash='deadbeef1234', revision=10, identifier='6@main',
message='Followup fix to 5@main', timestamp=int(time.time()),
author=repo.head.author,
)
repo.commits['main'].append(repo.head)

self.assertEqual(0, program.main(
args=('trace', '6@main', '--limit', '1'),
path=self.path,
))
self.assertEqual(
captured.stdout.getvalue(),
'6@main | deadbeef1234 | Followup fix to 5@main\n follow-up to 5@main | d8bce26fa65c | Patch Series\n',
)
self.assertEqual(captured.stderr.getvalue(), '')

def test_regression(self):
with OutputCapture() as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), Terminal.override_atty(sys.stdin, isatty=False):
repo.head = Commit(
hash='deadbeef1234', revision=10, identifier='6@main',
message='REGRESSION (5@main) Fix the build', timestamp=int(time.time()),
author=repo.head.author,
)
repo.commits['main'].append(repo.head)

self.assertEqual(0, program.main(
args=('trace', '6@main', '--limit', '1'),
path=self.path,
))
self.assertEqual(
captured.stdout.getvalue(),
'6@main | deadbeef1234 | REGRESSION (5@main) Fix the build\n follow-up to 5@main | d8bce26fa65c | Patch Series\n',
)
self.assertEqual(captured.stderr.getvalue(), '')

def test_gardening(self):
with OutputCapture() as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), Terminal.override_atty(sys.stdin, isatty=False):
repo.head = Commit(
hash='deadbeef1234', revision=10, identifier='6@main',
message='[Gardening]: REGRESSION 5@main', timestamp=int(time.time()),
author=repo.head.author,
)
repo.commits['main'].append(repo.head)

self.assertEqual(0, program.main(
args=('trace', '6@main', '--limit', '1'),
path=self.path,
))
self.assertEqual(
captured.stdout.getvalue(),
'6@main | deadbeef1234 | [Gardening]: REGRESSION 5@main\n follow-up to 5@main | d8bce26fa65c | Patch Series\n',
)
self.assertEqual(captured.stderr.getvalue(), '')

def test_invalid_revert(self):
with OutputCapture() as captured, mocks.local.Git(self.path) as repo, mocks.local.Svn(), Terminal.override_atty(sys.stdin, isatty=False):
repo.head = Commit(
Expand Down

0 comments on commit 1fe7fc8

Please sign in to comment.