WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-217534-20201013092214.patch (text/plain), 37.41 KB, created by
Jonathan Bedard
on 2020-10-13 09:22:15 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Jonathan Bedard
Created:
2020-10-13 09:22:15 PDT
Size:
37.41 KB
patch
obsolete
>Index: Tools/ChangeLog >=================================================================== >--- Tools/ChangeLog (revision 268394) >+++ Tools/ChangeLog (working copy) >@@ -1,3 +1,57 @@ >+2020-10-12 Jonathan Bedard <jbedard@apple.com> >+ >+ [webkitscmpy] Add `git-webkit find` >+ https://bugs.webkit.org/show_bug.cgi?id=217534 >+ <rdar://problem/70152431> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * Scripts/git-webkit: Added. >+ * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Bump version. >+ * Scripts/libraries/webkitcorepy/webkitcorepy/arguments.py: >+ (NoAction.__call__): >+ (CountAction): Create an action to increment or decrement a variable by a value. >+ (CallbackAction): Create an action which will trigger a callback when set. >+ (LoggingGroup): Create a group which allows the user to change logging behavior. >+ * Scripts/libraries/webkitscmpy/git-webkit: Added. >+ * Scripts/libraries/webkitscmpy/setup.py: Add webkitscmpy.program and git-webkit. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Bump version. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/commit.py: >+ (Commit): Make the 12 character hash based on a class variable. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py: >+ (Git.default_branch): Fallback to 'master' or 'main' if the remote isn't available. >+ (Git.find): Use git to match branches and tags to a hash instead of trying to do it ourselves. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py: >+ (Scm.find): Add function to convert generic string arguments to a commit, and then find that commit in >+ the repository. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py: >+ (Svn): Support a few different SVN binary paths. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py: Add rev-parse branch/tag/HEAD -> hash conversion. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/program: Added. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py: Added. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py: Added. >+ (Command): Base class for all commands. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/program/find.py: Added. >+ (Find): >+ (Find.parser): Configure parser for 'find' sub-program. >+ (Find.main): Given an identifier, revision, hash or branch name, find and print the matching commit from >+ the repository in scope. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/program/main.py: Added. >+ (main): Entry point to git-<project> scripts. >+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py: Added. >+ (TestFind): >+ (TestFind.test_basic_git): >+ (TestFind.test_basic_git_svn): >+ (TestFind.test_basic_svn): >+ (TestFind.test_branch_tilde): >+ (TestFind.test_identifier_git): >+ (TestFind.test_identifier_git_svn): >+ (TestFind.test_identifier_svn): >+ (TestFind.test_hash): >+ (TestFind.test_revision_svn): >+ (TestFind.test_revision_git_svn): >+ (TestFind.test_standard): >+ > 2020-10-13 Adrian Perez de Castro <aperez@igalia.com> > > [GTK] Add support for gamepad tests >Index: Tools/Scripts/git-webkit >=================================================================== >--- Tools/Scripts/git-webkit (nonexistent) >+++ Tools/Scripts/git-webkit (working copy) >@@ -0,0 +1,32 @@ >+#!/usr/bin/env python >+ >+# Copyright (C) 2020 Apple Inc. All rights reserved. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# 1. Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# 2. Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY >+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON >+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+import os >+import webkitpy >+import sys >+ >+from webkitscmpy import local, program >+ >+sys.exit(program.main(repository=local.Scm.from_path(os.path.dirname(__file__)))) >+ > >Property changes on: Tools/Scripts/git-webkit >___________________________________________________________________ >Added: svn:executable >## -0,0 +1 ## >+* >\ No newline at end of property >Index: Tools/Scripts/libraries/webkitcorepy/webkitcorepy/arguments.py >=================================================================== >--- Tools/Scripts/libraries/webkitcorepy/webkitcorepy/arguments.py (revision 268374) >+++ Tools/Scripts/libraries/webkitcorepy/webkitcorepy/arguments.py (working copy) >@@ -21,6 +21,9 @@ > # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > import argparse >+import logging >+ >+from webkitcorepy import log > > > class NoAction(argparse.Action): >@@ -29,3 +32,57 @@ class NoAction(argparse.Action): > > def __call__(self, parser, namespace, values, option_string=None): > setattr(namespace, self.dest, False if option_string.startswith('--no') else True) >+ >+ >+def CountAction(value=1): >+ class Action(argparse.Action): >+ def __init__(self, option_strings, dest, **kwargs): >+ super(Action, self).__init__(option_strings, dest, nargs=0, **kwargs) >+ >+ def __call__(self, parser, namespace, values, option_string): >+ setattr(namespace, self.dest, getattr(namespace, self.dest) + value) >+ >+ return Action >+ >+ >+def CallbackAction(action, callback=lambda namespace: None): >+ class Action(action): >+ def __call__(self, parser, namespace, values, option_strings): >+ super(Action, self).__call__(parser, namespace, values, option_strings) >+ callback(namespace) >+ >+ return Action >+ >+ >+def LoggingGroup(parser, loggers=None, default=logging.WARNING, help='{} amount of logging'): >+ if not isinstance(parser, argparse.ArgumentParser): >+ raise ValueError('Provided parser is not a {}'.format(type(argparse.ArgumentParser))) >+ >+ if not loggers: >+ loggers = [logging.getLogger(), log] >+ for logger in loggers: >+ logger.setLevel(default) >+ >+ def verbose_callback(namespace): >+ verbosity = getattr(namespace, 'verbose') >+ log_level = default - verbosity * 10 >+ >+ setattr(namespace, 'log_level', log_level) >+ >+ for logger in loggers: >+ logger.setLevel(log_level) >+ >+ group = parser.add_argument_group('Logging') >+ group.add_argument( >+ '--verbose', '-v', >+ dest='verbose', default=0, >+ help=help.format('Increase'), >+ action=CallbackAction(CountAction(value=1), callback=verbose_callback), >+ ) >+ group.add_argument( >+ '--quiet', '-q', >+ dest='verbose', default=0, >+ help=help.format('Decrease'), >+ action=CallbackAction(CountAction(value=-1), callback=verbose_callback), >+ ) >+ return group >Index: Tools/Scripts/libraries/webkitscmpy/git-webkit >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/git-webkit (nonexistent) >+++ Tools/Scripts/libraries/webkitscmpy/git-webkit (working copy) >@@ -0,0 +1,30 @@ >+#!/usr/bin/env python >+ >+# Copyright (C) 2020 Apple Inc. All rights reserved. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# 1. Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# 2. Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY >+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON >+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+import sys >+ >+from webkitscmpy import program >+ >+ >+sys.exit(program.main()) > >Property changes on: Tools/Scripts/libraries/webkitscmpy/git-webkit >___________________________________________________________________ >Added: svn:executable >## -0,0 +1 ## >+* >\ No newline at end of property >Index: Tools/Scripts/libraries/webkitscmpy/setup.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/setup.py (revision 268374) >+++ Tools/Scripts/libraries/webkitscmpy/setup.py (working copy) >@@ -53,8 +53,10 @@ setup( > 'webkitscmpy.local', > 'webkitscmpy.mocks', > 'webkitscmpy.mocks.local', >+ 'webkitscmpy.program', > 'webkitscmpy.test', > ], >+ scripts=['git-webkit'], > install_requires=['python-dateutil', 'webkitcorepy'], > include_package_data=True, > zip_safe=False, >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (revision 268374) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (working copy) >@@ -46,7 +46,7 @@ except ImportError: > "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`" > ) > >-version = Version(0, 1, 3) >+version = Version(0, 2, 0) > > AutoInstall.register(Package('dateutil', Version(2, 8, 1), pypi_name='python-dateutil')) > >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/commit.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/commit.py (revision 268374) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/commit.py (working copy) >@@ -33,6 +33,7 @@ class Commit(object): > REVISION_RE = re.compile(r'^[Rr]?(?P<revision>\d+)$') > IDENTIFIER_RE = re.compile(r'^((?P<branch_point>\d+)\.)?(?P<identifier>-?\d+)(@(?P<branch>\S+))?$') > NUMBER_RE = re.compile(r'^-?\d*$') >+ DISPLAY_SIZE = 12 > > class Encoder(json.JSONEncoder): > >@@ -130,7 +131,7 @@ class Commit(object): > return (identifier[0], identifier[1], branch) > > @classmethod >- def parse(cls, arg): >+ def parse(cls, arg, do_assert=True): > if cls._parse_identifier(arg): > return Commit(identifier=arg) > >@@ -140,7 +141,9 @@ class Commit(object): > if cls._parse_hash(arg): > return Commit(hash=arg) > >- raise ValueError("'{}' cannot be converted to a commit object".format(arg)) >+ if do_assert: >+ raise ValueError("'{}' cannot be converted to a commit object".format(arg)) >+ return None > > def __init__( > self, >@@ -211,7 +214,7 @@ class Commit(object): > result += ' on {}'.format(self.branch) > result += '\n' > if self.hash: >- result += ' git hash: {}'.format(self.hash[:12]) >+ result += ' git hash: {}'.format(self.hash[:self.DISPLAY_SIZE]) > if self.branch: > result += ' on {}'.format(self.branch) > result += '\n' >@@ -242,7 +245,7 @@ class Commit(object): > if self.revision: > return 'r{}'.format(self.revision) > if self.hash: >- return self.hash[:12] >+ return self.hash[:self.DISPLAY_SIZE] > if self.identifier is not None: > return str(self.identifier) > raise ValueError('Incomplete commit format') >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py (revision 268374) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py (working copy) >@@ -22,6 +22,7 @@ > > > import re >+import six > > from webkitcorepy import run, decorators, TimeoutExpired > from webkitscmpy.local import Scm >@@ -87,6 +88,11 @@ class Git(Scm): > def default_branch(self): > result = run([self.executable, 'rev-parse', '--abbrev-ref', 'origin/HEAD'], cwd=self.path, capture_output=True, encoding='utf-8') > if result.returncode: >+ candidates = self.branches >+ if 'master' in candidates: >+ return 'master' >+ if 'main' in candidates: >+ return 'main' > return None > return '/'.join(result.stdout.rstrip().split('/')[1:]) > >@@ -250,3 +256,24 @@ class Git(Scm): > author=Contributor.from_scm_log(log.stdout.splitlines()[1]), > message='\n'.join(line[4:] for line in log.stdout.splitlines()[4:]), > ) >+ >+ def find(self, argument): >+ if not isinstance(argument, six.string_types): >+ raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument))) >+ >+ parsed_commit = Commit.parse(argument, do_assert=False) >+ if parsed_commit: >+ return self.commit( >+ hash=parsed_commit.hash, >+ revision=parsed_commit.revision, >+ identifier=parsed_commit.identifier, >+ branch=parsed_commit.branch, >+ ) >+ >+ output = run( >+ [self.executable, 'rev-parse', argument], >+ cwd=self.root_path, capture_output=True, encoding='utf-8', >+ ) >+ if output.returncode: >+ raise ValueError("'{}' is not an arguement recognized by git".format(argument)) >+ return self.commit(hash=output.stdout.rstrip()) >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py (revision 268374) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py (working copy) >@@ -23,10 +23,11 @@ > > import logging > import re >+import six > import sys > > from logging import NullHandler >-from webkitscmpy import log >+from webkitscmpy import log, Commit > > > class Scm(object): >@@ -48,7 +49,7 @@ class Scm(object): > return local.Git(path) > if local.Svn.is_checkout(path): > return local.Svn(path) >- raise OSError('{} is not a known SCM type') >+ raise OSError("'{}' is not a known SCM type".format(path)) > > def __init__(self, path, dev_branches=None, prod_branches=None): > if not isinstance(path, str): >@@ -89,6 +90,44 @@ class Scm(object): > def remote(self, name=None): > raise NotImplementedError() > >+ def find(self, argument): >+ if not isinstance(argument, six.string_types): >+ raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument))) >+ >+ offset = 0 >+ if '~' in argument: >+ for s in argument.split('~')[1:]: >+ if s and not s.isdigit(): >+ raise ValueError("'{}' is not a valid argument to Scm.find()".format(argument)) >+ offset += int(s) if s else 1 >+ argument = argument.split('~')[0] >+ >+ if argument == 'HEAD': >+ result = self.commit() >+ >+ elif argument in self.branches: >+ result = self.commit(branch=argument) >+ >+ else: >+ if offset: >+ raise ValueError("'~' offsets are not supported for revisions and identifiers") >+ >+ parsed_commit = Commit.parse(argument) >+ return self.commit( >+ hash=parsed_commit.hash, >+ revision=parsed_commit.revision, >+ identifier=parsed_commit.identifier, >+ branch=parsed_commit.branch, >+ ) >+ >+ if not offset: >+ return result >+ >+ return self.commit( >+ identifier=result.identifier - offset, >+ branch=result.branch, >+ ) >+ > def commit(self, hash=None, revision=None, identifier=None, branch=None): > raise NotImplementedError() > >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py (revision 268374) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py (working copy) >@@ -37,7 +37,7 @@ from webkitscmpy import Commit, Contribu > > > class Svn(Scm): >- executable = '/usr/local/bin/svn' >+ executable = '/usr/bin/svn' if os.path.exists('/usr/bin/svn') else '/usr/local/bin/svn' > LOG_RE = re.compile(r'r(?P<revision>\d+) \| (?P<email>.*) \| (?P<date>.*)') > CACHE_VERSION = Version(1) > >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py (revision 268374) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py (working copy) >@@ -221,6 +221,13 @@ nothing to commit, working tree clean > stdout='origin/{}\n'.format(default_branch), > ), > ), mocks.Subprocess.Route( >+ local.Git.executable, 'rev-parse', '.*', >+ cwd=self.path, >+ generator=lambda *args, **kwargs: mocks.ProcessCompletion( >+ returncode=0, >+ stdout='{}\n'.format(self.find(args[2]).hash), >+ ) if self.find(args[2]) else mocks.ProcessCompletion(returncode=128) >+ ), mocks.Subprocess.Route( > local.Git.executable, 'log', re.compile(r'.+'), '-1', > cwd=self.path, > generator=lambda *args, **kwargs: mocks.ProcessCompletion( >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py (nonexistent) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py (working copy) >@@ -0,0 +1,26 @@ >+# Copyright (C) 2020 Apple Inc. All rights reserved. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# 1. Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# 2. Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND >+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR >+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR >+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER >+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, >+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+from webkitscmpy.program.command import Command >+from webkitscmpy.program.find import Find >+ >+from webkitscmpy.program.main import main >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py (nonexistent) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py (working copy) >@@ -0,0 +1,40 @@ >+# Copyright (C) 2020 Apple Inc. All rights reserved. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# 1. Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# 2. Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY >+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON >+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+import sys >+ >+ >+class Command(object): >+ name = None >+ help = None >+ >+ @classmethod >+ def parser(cls, parser, repository): >+ if cls.name is None: >+ raise NotImplementedError('Command does not have a name') >+ if cls.help is None: >+ raise NotImplementedError("'{}' does not have a help message") >+ >+ @classmethod >+ def main(cls, repository): >+ sys.stderr.write('No command specified\n') >+ return -1 >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/find.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/find.py (nonexistent) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/find.py (working copy) >@@ -0,0 +1,98 @@ >+# Copyright (C) 2020 Apple Inc. All rights reserved. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# 1. Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# 2. Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY >+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON >+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+import json >+import logging >+import sys >+ >+from datetime import datetime >+from webkitcorepy import arguments >+from webkitscmpy import Commit, local >+from webkitscmpy.program import Command >+ >+ >+class Find(Command): >+ name = 'find' >+ help = 'Given an identifier, revision or hash, normalize and print the commit' >+ >+ @classmethod >+ def parser(cls, parser, repository, loggers=None): >+ arguments.LoggingGroup( >+ parser, >+ loggers=loggers, >+ help='{} amount of logging and commit information displayed' >+ ).add_argument( >+ '--json', '-j', >+ help='Convert the commit to a machine-readable JSON object', >+ action='store_true', >+ dest='json', >+ default=False, >+ ) >+ >+ parser.add_argument( >+ 'argument', nargs=1, >+ type=str, default=None, >+ help='String representation of a commit or branch to be normalized', >+ ) >+ >+ @classmethod >+ def main(cls, args, repository): >+ try: >+ commit = repository.find(args.argument[0]) >+ except (local.Scm.Exception, ValueError) as exception: >+ # ValueErrors and Scm exceptions usually contain enough information to be displayed >+ # to the user as an error >+ sys.stderr.write(str(exception) + '\n') >+ return 1 >+ >+ if args.verbose > 0 and not commit.message: >+ sys.stderr.write("Failed to find the commit message for '{}'\n".format(commit)) >+ return 1 >+ >+ if args.json: >+ print(json.dumps(commit, cls=Commit.Encoder, indent=4)) >+ return 0 >+ >+ if args.verbose < 0: >+ print('{identifier} | {hash}{revision}{title}'.format( >+ identifier=commit, >+ hash=commit.hash[:Commit.DISPLAY_SIZE] if commit.hash else '', >+ revision='{}r{}'.format(', ' if commit.hash else '', commit.revision) if commit.revision else '', >+ title=' | {}'.format(commit.message.splitlines()[0]) if commit.message else '' >+ )) >+ return 0 >+ >+ if commit.message: >+ print('Title: {}'.format(commit.message.splitlines()[0])) >+ print('Author: {}'.format(commit.author)) >+ print('Identifier: {}'.format(commit)) >+ print(datetime.fromtimestamp(commit.timestamp).strftime('Date: %a %b %d %H:%M:%S %Y')) >+ if args.verbose > 0 or commit.revision: >+ print('Revision: {}'.format(commit.revision or 'N/A')) >+ if args.verbose > 0 or commit.hash: >+ print('Hash: {}'.format(commit.hash[:Commit.DISPLAY_SIZE] if commit.hash else 'N/A')) >+ >+ if args.verbose > 0: >+ for line in commit.message.splitlines(): >+ print(' {}'.format(line)) >+ >+ return 0 >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/main.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/main.py (nonexistent) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/main.py (working copy) >@@ -0,0 +1,54 @@ >+# Copyright (C) 2020 Apple Inc. All rights reserved. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# 1. Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# 2. Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY >+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON >+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+import argparse >+import os >+import logging >+ >+from webkitcorepy import arguments, log as webkitcorepy_log >+from webkitscmpy import local, log >+from webkitscmpy.program import Find >+ >+ >+def main(args=None, repository=None, loggers=None): >+ logging.basicConfig(level=logging.WARNING) >+ >+ loggers = [logging.getLogger(), webkitcorepy_log, log] + (loggers or []) >+ >+ if not repository: >+ repository = local.Scm.from_path(path=os.getcwd()) >+ >+ parser = argparse.ArgumentParser( >+ description='Custom git tooling from the WebKit team to interact with a ' + >+ 'repository using identifers', >+ ) >+ arguments.LoggingGroup(parser) >+ subparsers = parser.add_subparsers(help='sub-command help') >+ >+ for program in [Find]: >+ subparser = subparsers.add_parser(program.name, help=program.help) >+ subparser.set_defaults(main=program.main) >+ program.parser(subparser, repository=repository, loggers=loggers) >+ >+ parsed = parser.parse_args(args=args) >+ >+ return parsed.main(args=parsed, repository=repository) >Index: Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py >=================================================================== >--- Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py (nonexistent) >+++ Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py (working copy) >@@ -0,0 +1,167 @@ >+# Copyright (C) 2020 Apple Inc. All rights reserved. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# 1. Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# 2. Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND >+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR >+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR >+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER >+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, >+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+import json >+import unittest >+ >+from webkitcorepy import OutputCapture >+from webkitcorepy.mocks import Time as MockTime >+from webkitscmpy import local, program, mocks >+ >+ >+class TestFind(unittest.TestCase): >+ path = '/mock/repository' >+ >+ def test_basic_git(self): >+ with mocks.local.Git(self.path), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', 'HEAD', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '4@main | bae5d1e90999\n') >+ >+ def test_basic_git_svn(self): >+ with mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', 'HEAD', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '4@main | bae5d1e90999, r6 | 6th commit\n') >+ >+ def test_basic_svn(self): >+ with mocks.local.Git(), mocks.local.Svn(self.path), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', 'HEAD', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '4@trunk | r6 | 6th commit\n') >+ >+ def test_branch_tilde(self): >+ with mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', 'branch-a~1', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '2.1@branch-a | a30ce8494bf1, r3 | 3rd commit\n') >+ >+ def test_identifier_git(self): >+ with mocks.local.Git(self.path), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', '2@main', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '2@main | fff83bb2d917\n') >+ >+ def test_identifier_git_svn(self): >+ with mocks.local.Git(self.path), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', '2@main', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '2@main | fff83bb2d917\n') >+ >+ def test_identifier_svn(self): >+ with mocks.local.Git(), mocks.local.Svn(self.path), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', '2@trunk', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '2@trunk | r2 | 2nd commit\n') >+ >+ def test_hash(self): >+ with mocks.local.Git(self.path), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', '3cd32e352410', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '2.2@branch-b | 3cd32e352410\n') >+ >+ def test_revision_svn(self): >+ with mocks.local.Git(), mocks.local.Svn(self.path), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', 'r5', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '2.2@branch-b | r5 | 5th commit\n') >+ >+ def test_revision_git_svn(self): >+ with mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', 'r5', '-q'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual(captured.stdout.getvalue(), '2.2@branch-b | 3cd32e352410, r5 | 5th commit\n') >+ >+ def test_standard(self): >+ with mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', '3@main'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual( >+ captured.stdout.getvalue(), >+ '''Title: 4th commit >+Author: Jonathan Bedard <jbedard@apple.com> >+Identifier: 3@main >+Date: Fri Oct 02 11:23:20 2020 >+Revision: 4 >+Hash: 1abe25b443e9 >+''', >+ ) >+ >+ def test_verbose(self): >+ with mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', '3@main', '-v'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ self.assertEqual( >+ captured.stdout.getvalue(), >+ '''Title: 4th commit >+Author: Jonathan Bedard <jbedard@apple.com> >+Identifier: 3@main >+Date: Fri Oct 02 11:23:20 2020 >+Revision: 4 >+Hash: 1abe25b443e9 >+ 4th commit >+ svn-id: https://svn.webkit.orgrepository/repository/trunk@4 268f45cc-cd09-0410-ab3c-d52691b4dbfc >+''', >+ ) >+ >+ def test_json(self): >+ with mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime, OutputCapture() as captured: >+ self.assertEqual(0, program.main( >+ args=('find', '3@main', '--json'), >+ repository=local.Scm.from_path(self.path), >+ )) >+ >+ decoded = json.loads(captured.stdout.getvalue()) >+ self.assertDictEqual( >+ decoded, dict( >+ identifier='3@main', >+ hash='1abe25b443e985f93b90d830e4a7e3731336af4d', >+ revision=4, >+ author='jbedard@apple.com', >+ timestamp=1601663000, >+ branch='main', >+ message='4th commit\nsvn-id: https://svn.webkit.orgrepository/repository/trunk@4 268f45cc-cd09-0410-ab3c-d52691b4dbfc', >+ ))
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 217534
:
410988
|
411055
|
411150
|
411181
|
411225
|
411226
|
411250
|
411273
|
411285