Skip to content

Commit

Permalink
[webkitscmpy] Remove "i" from canonical identifier
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=217238
<rdar://problem/69888017>

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitscmpy/webkitscmpy/commit.py:
(Commit):
(Commit.pretty_print): Remove "i" from canonical identifier, add branch point.
(Commit.__repr__): Remove "i" from canonical identifier.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/commit_unittest.py:
(TestCommit.test_parse_revision):
(TestCommit.test_parse_identifier):
(TestCommit.test_parse):
(TestCommit.test_pretty_print):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@267895 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] committed Oct 2, 2020
1 parent 037307d commit ea87d23
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 38 deletions.
18 changes: 18 additions & 0 deletions Tools/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
2020-10-02 Jonathan Bedard <[email protected]>

[webkitscmpy] Remove "i" from canonical identifier
https://bugs.webkit.org/show_bug.cgi?id=217238
<rdar://problem/69888017>

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitscmpy/webkitscmpy/commit.py:
(Commit):
(Commit.pretty_print): Remove "i" from canonical identifier, add branch point.
(Commit.__repr__): Remove "i" from canonical identifier.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/commit_unittest.py:
(TestCommit.test_parse_revision):
(TestCommit.test_parse_identifier):
(TestCommit.test_parse):
(TestCommit.test_pretty_print):

2020-10-02 Philippe Normand <[email protected]>

[CMake] unused variable warning spam in UIScriptController.h
Expand Down
Original file line number Diff line number Diff line change
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(0, 0, 7)
version = Version(0, 0, 8)

from webkitscmpy.contributor import Contributor
from webkitscmpy.commit import Commit
Expand Down
14 changes: 8 additions & 6 deletions Tools/Scripts/libraries/webkitscmpy/webkitscmpy/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class Commit(object):
HASH_RE = re.compile(r'^[a-f0-9A-F]+$')
REVISION_RE = re.compile(r'^[Rr]?(?P<revision>\d+)$')
IDENTIFIER_RE = re.compile(r'^[Ii]?((?P<branch_point>\d+)\.)?(?P<identifier>-?\d+)(@(?P<branch>\S+))?$')
IDENTIFIER_RE = re.compile(r'^((?P<branch_point>\d+)\.)?(?P<identifier>-?\d+)(@(?P<branch>\S+))?$')
NUMBER_RE = re.compile(r'^-?\d*$')

@classmethod
Expand Down Expand Up @@ -195,9 +195,11 @@ def pretty_print(self, message=False):
result += ' on {}'.format(self.branch)
result += '\n'
if self.identifier:
result += ' identifier: i{}'.format(self.identifier)
if self.identifier:
result += ' identifier: {}'.format(self.identifier)
if self.branch:
result += ' on {}'.format(self.branch)
if self.branch_point:
result += ' branched from {}'.format(self.branch_point)
result += '\n'
if self.author:
result += ' by {}'.format(self.author)
Expand All @@ -213,15 +215,15 @@ def pretty_print(self, message=False):

def __repr__(self):
if self.branch_point and self.identifier and self.branch:
return 'i{}.{}@{}'.format(self.branch_point, self.identifier, self.branch)
return '{}.{}@{}'.format(self.branch_point, self.identifier, self.branch)
if self.identifier and self.branch:
return 'i{}@{}'.format(self.identifier, self.branch)
return '{}@{}'.format(self.identifier, self.branch)
if self.revision:
return 'r{}'.format(self.revision)
if self.hash:
return self.hash[:12]
if self.identifier:
return 'i{}'.format(self.identifier)
return str(self.identifier)
raise ValueError('Incomplete commit format')

def __hash__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,50 +46,33 @@ def test_parse_revision(self):
self.assertEqual(266896, Commit._parse_revision('266896'))
self.assertEqual(266896, Commit._parse_revision(266896))

self.assertEqual(None, Commit._parse_revision('i1234'))
self.assertEqual(None, Commit._parse_revision('c3bd784f8b88bd03'))
self.assertEqual(None, Commit._parse_revision('0'))
self.assertEqual(None, Commit._parse_revision('-1'))
self.assertEqual(None, Commit._parse_revision('3.141592'))
self.assertEqual(None, Commit._parse_revision(3.141592))

def test_parse_identifier(self):
self.assertEqual((None, 1234, None), Commit._parse_identifier('i1234'))
self.assertEqual((None, 1234, None), Commit._parse_identifier('I1234'))
self.assertEqual((None, 1234, None), Commit._parse_identifier('1234'))
self.assertEqual((None, 1234, None), Commit._parse_identifier(1234))

self.assertEqual((None, 1234, 'main'), Commit._parse_identifier('i1234@main'))
self.assertEqual((None, 1234, 'main'), Commit._parse_identifier('I1234@main'))
self.assertEqual((None, 1234, 'main'), Commit._parse_identifier('1234@main'))

self.assertEqual((None, 1234, 'eng/bug'), Commit._parse_identifier('i1234@eng/bug'))
self.assertEqual((None, 1234, 'eng/bug'), Commit._parse_identifier('I1234@eng/bug'))
self.assertEqual((None, 1234, 'eng/bug'), Commit._parse_identifier('1234@eng/bug'))

self.assertEqual((1234, 1, 'eng/bug'), Commit._parse_identifier('i1234.1@eng/bug'))
self.assertEqual((1234, 1, 'eng/bug'), Commit._parse_identifier('I1234.1@eng/bug'))
self.assertEqual((1234, 1, 'eng/bug'), Commit._parse_identifier('1234.1@eng/bug'))

self.assertEqual((None, 0, None), Commit._parse_identifier('0'))
self.assertEqual((None, -1, None), Commit._parse_identifier('-1'))

self.assertEqual((None, 0, 'eng/bug'), Commit._parse_identifier('i0@eng/bug'))
self.assertEqual((None, 0, 'eng/bug'), Commit._parse_identifier('I0@eng/bug'))
self.assertEqual((None, 0, 'eng/bug'), Commit._parse_identifier('0@eng/bug'))

self.assertEqual((None, -1, 'eng/bug'), Commit._parse_identifier('i-1@eng/bug'))
self.assertEqual((None, -1, 'eng/bug'), Commit._parse_identifier('I-1@eng/bug'))
self.assertEqual((None, -1, 'eng/bug'), Commit._parse_identifier('-1@eng/bug'))

self.assertEqual(None, Commit._parse_identifier('i1234-invalid'))
self.assertEqual(None, Commit._parse_identifier('1234-invalid'))
self.assertEqual(None, Commit._parse_identifier('r266896'))
self.assertEqual(None, Commit._parse_identifier('c3bd784f8b88bd03'))
self.assertEqual(None, Commit._parse_identifier(3.141592))

def test_parse(self):
self.assertEqual(Commit.parse('i123@main'), Commit(identifier=123, branch='main'))
self.assertEqual(Commit.parse('i123'), Commit(identifier=123))
self.assertEqual(Commit.parse('123@main'), Commit(identifier=123, branch='main'))
self.assertEqual(Commit.parse('123'), Commit(identifier=123))

self.assertEqual(Commit.parse('r123'), Commit(revision=123))
Expand All @@ -102,54 +85,69 @@ def test_parse(self):
def test_pretty_print(self):
self.assertEqual(
Commit(
identifier='i123@master',
identifier='123@master',
hash='c3bd784f8b88bd03f64467ddd3304ed8be28acbe',
author=Contributor('Jonathan Bedard', ['[email protected]']),
message='NOT PRINTED',
).pretty_print(),
'''i123@master
'''123@master
git hash: c3bd784f8b88 on master
identifier: i123 on master
identifier: 123 on master
by Jonathan Bedard <[email protected]>
''',
)

self.assertEqual(
Commit(
identifier='i123@trunk',
identifier='123@trunk',
revision='r123',
author=Contributor('Jonathan Bedard', ['[email protected]']),
timestamp=1000,
message='NOT PRINTED',
).pretty_print(),
'''i123@trunk
'''123@trunk
SVN revision: r123 on trunk
identifier: i123 on trunk
identifier: 123 on trunk
by Jonathan Bedard <[email protected]> @ {}
'''.format(datetime.utcfromtimestamp(1000)),
)

self.assertEqual(
Commit(
identifier='123.1@branch-a',
revision='r124',
author=Contributor('Jonathan Bedard', ['[email protected]']),
timestamp=1000,
message='NOT PRINTED',
).pretty_print(),
'''123.1@branch-a
SVN revision: r124 on branch-a
identifier: 1 on branch-a branched from 123
by Jonathan Bedard <[email protected]> @ {}
'''.format(datetime.utcfromtimestamp(1000)),
)

self.assertEqual(
Commit(
identifier='i123@trunk',
identifier='123@trunk',
revision='r123',
author=Contributor('Jonathan Bedard', ['[email protected]']),
timestamp=1000,
message='PRINTED\n',
).pretty_print(message=True),
'''i123@trunk
'''123@trunk
SVN revision: r123 on trunk
identifier: i123 on trunk
identifier: 123 on trunk
by Jonathan Bedard <[email protected]> @ {}
PRINTED
'''.format(datetime.utcfromtimestamp(1000)),
)

def test_repr(self):
self.assertEqual(str(Commit(identifier=123, branch='main')), 'i123@main')
self.assertEqual(str(Commit(branch_point=1234, identifier=1, branch='eng/1234')), 'i1234.1@eng/1234')
self.assertEqual(str(Commit(identifier=123)), 'i123')
self.assertEqual(str(Commit(identifier=123, branch='main')), '123@main')
self.assertEqual(str(Commit(branch_point=1234, identifier=1, branch='eng/1234')), '1234.1@eng/1234')
self.assertEqual(str(Commit(identifier=123)), '123')

self.assertEqual(str(Commit(revision=123)), 'r123')

Expand Down

0 comments on commit ea87d23

Please sign in to comment.