⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 274483 in webkit


Ignore:
Timestamp:
Mar 16, 2021, 9:34:00 AM (6 years ago)
Author:
Jonathan Bedard
Message:

[webkitscmpy] Decode multiple commit representations
​https://bugs.webkit.org/show_bug.cgi?id=223224
<rdar://problem/75455129>

Reviewed by Dewei Zhu.

  • Scripts/libraries/webkitscmpy/setup.py: Bump version.
  • Scripts/libraries/webkitscmpy/webkitscmpy/init.py: Ditto.
  • Scripts/libraries/webkitscmpy/webkitscmpy/commit.py:

(Commit.from_json): Decode old results database style commit representations.

  • Scripts/libraries/webkitscmpy/webkitscmpy/test/commit_unittest.py:
Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r274481 r274483  
     12021-03-16  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [webkitscmpy] Decode multiple commit representations
     4        https://bugs.webkit.org/show_bug.cgi?id=223224
     5        <rdar://problem/75455129>
     6
     7        Reviewed by Dewei Zhu.
     8
     9        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
     10        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
     11        * Scripts/libraries/webkitscmpy/webkitscmpy/commit.py:
     12        (Commit.from_json): Decode old results database style commit representations.
     13        * Scripts/libraries/webkitscmpy/webkitscmpy/test/commit_unittest.py:
     14
    1152021-03-16  Dean Johnson  <dean_johnson@apple.com>
    216
  • trunk/Tools/Scripts/libraries/webkitscmpy/setup.py

    r274251 r274483  
    3030setup(
    3131    name='webkitscmpy',
    32     version='0.13.1',
     32    version='0.13.2',
    3333    description='Library designed to interact with git and svn repositories.',
    3434    long_description=readme(),
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py

    r274251 r274483  
    4747    )
    4848
    49 version = Version(0, 13, 1)
     49version = Version(0, 13, 2)
    5050
    5151AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/commit.py

    r274080 r274483  
    147147        return None
    148148
     149    @classmethod
     150    def from_json(cls, data):
     151        data = data if isinstance(data, dict) else json.loads(data)
     152        hash_from_id = None
     153        revision_from_id = cls._parse_revision(data.get('id'))
     154        if not revision_from_id:
     155            hash_from_id = cls._parse_hash(data.get('id'))
     156
     157        return cls(
     158            repository_id=data.get('repository_id'),
     159            branch=data.get('branch'),
     160            hash=data.get('hash', hash_from_id),
     161            revision=data.get('revision', revision_from_id),
     162            timestamp=data.get('timestamp'),
     163            identifier=data.get('identifier'),
     164            branch_point=data.get('branch_point'),
     165            order=data.get('order'),
     166            author=data.get('author', data.get('committer')),
     167            message=data.get('message'),
     168        )
     169
    149170    def __init__(
    150171        self,
    … …  
    185206            )
    186207
     208        if isinstance(timestamp, six.string_types) and timestamp.isdigit():
     209            timestamp = int(timestamp)
    187210        if timestamp and not isinstance(timestamp, int):
    188211            raise TypeError("Expected 'timestamp' to be of type int, got '{}'".format(timestamp))
    189212        self.timestamp = timestamp
    190213
     214        if isinstance(order, six.string_types) and order.isdigit():
     215            order = int(order)
    191216        if order and not isinstance(order, int):
    192217            raise TypeError("Expected 'order' to be of type int, got '{}'".format(order))
    … …  
    195220        if author and isinstance(author, dict) and author.get('name'):
    196221            self.author = Contributor(author.get('name'), author.get('emails'))
     222        elif author and isinstance(author, six.string_types) and '@' in author:
     223            self.author = Contributor(author, author)
    197224        elif author and not isinstance(author, Contributor):
    198225            raise TypeError("Expected 'author' to be of type {}, got '{}'".format(Contributor, author))
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/commit_unittest.py

    r273765 r274483  
    254254
    255255        self.assertEqual(commit_a, commit_b)
     256
     257    def test_from_json(self):
     258        self.assertEqual(
     259            Commit.from_json(dict(
     260                repository_id='webkit',
     261                id=1234,
     262                timestamp=1000,
     263            )), Commit(
     264                repository_id='webkit',
     265                revision=1234,
     266                timestamp=1000,
     267            ),
     268        )
     269
     270        self.assertEqual(
     271            Commit.from_json(dict(
     272                repository_id='webkit',
     273                id='c3bd784f8b88bd03f64467ddd3304ed8be28acbe',
     274                timestamp=2000,
     275            )), Commit(
     276                repository_id='webkit',
     277                hash='c3bd784f8b88bd03f64467ddd3304ed8be28acbe',
     278                timestamp=2000,
     279            ),
     280        )
     281
     282    def test_from_json_str(self):
     283        contributor = Contributor.from_scm_log('Author: jbedard@apple.com <jbedard@apple.com>')
     284        self.assertEqual(
     285            Commit.from_json('''{
     286    "revision": 1,
     287    "hash": "c3bd784f8b88bd03f64467ddd3304ed8be28acbe",
     288    "identifier": "1@main",
     289    "timestamp": 1000,
     290    "author": "jbedard@apple.com",
     291    "message": "Message"
     292}'''), Commit(
     293                revision=1,
     294                hash='c3bd784f8b88bd03f64467ddd3304ed8be28acbe',
     295                identifier='1@main',
     296                timestamp=1000,
     297                author=Contributor.Encoder().default(contributor),
     298                message='Message'
     299            ),
     300        )
Note: See TracChangeset for help on using the changeset viewer.