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

Changeset 280604 in webkit


Ignore:
Timestamp:
Aug 3, 2021, 12:00:33 PM (5 years ago)
Author:
Jonathan Bedard
Message:

[webkitscmpy] Add access to git config
https://bugs.webkit.org/show_bug.cgi?id=228597
<rdar://problem/81283644>

Reviewed by Aakash Jain.

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

(Git.config): Return git configuration as dictionary.

  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
  • Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:

(test_config): Test repository configuration.
(test_global_config): Test global configuration.

Location:
trunk/Tools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r280602 r280604  
     12021-08-03  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [webkitscmpy] Add access to `git config`
     4        https://bugs.webkit.org/show_bug.cgi?id=228597
     5        <rdar://problem/81283644>
     6
     7        Reviewed by Aakash Jain.
     8
     9        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
     10        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
     11        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
     12        (Git.config): Return git configuration as dictionary.
     13        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
     14        * Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:
     15        (test_config): Test repository configuration.
     16        (test_global_config): Test global configuration.
     17
    1182021-08-03  Jonathan Bedard  <jbedard@apple.com>
    219
  • trunk/Tools/Scripts/libraries/webkitscmpy/setup.py

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

    r280483 r280604  
    4747    )
    4848
    49 version = Version(1, 0, 4)
     49version = Version(1, 0, 5)
    5050
    5151AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py

    r280440 r280604  
    267267        return run([cls.executable(), 'rev-parse', '--show-toplevel'], cwd=path, capture_output=True).returncode == 0
    268268
     269    @decorators.hybridmethod
     270    def config(context):
     271        args = [context.executable(), 'config', '-l']
     272        kwargs = dict(capture_output=True, encoding='utf-8')
     273
     274        if isinstance(context, type):
     275            args += ['--global']
     276        else:
     277            kwargs['cwd'] = context.root_path
     278
     279        command = run(args, **kwargs)
     280        if command.returncode:
     281            sys.stderr.write("Failed to run '{}'{}\n".format(
     282                ' '.join(args),
     283                '' if isinstance(context, type) else ' in {}'.format(context.root_path),
     284            ))
     285            return {}
     286
     287        result = {}
     288        for line in command.stdout.splitlines():
     289            parts = line.split('=')
     290            result[parts[0]] = '='.join(parts[1:])
     291        return result
     292
    269293    def __init__(self, path, dev_branches=None, prod_branches=None, contributors=None, id=None, cached=sys.version_info > (3, 0)):
    270294        super(Git, self).__init__(path, dev_branches=dev_branches, prod_branches=prod_branches, contributors=contributors, id=id)
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py

    r279445 r280604  
    2929from mock import patch
    3030
    31 from webkitcorepy import mocks, OutputCapture, StringIO
     31from webkitcorepy import decorators, mocks, OutputCapture, StringIO
    3232from webkitscmpy import local, Commit, Contributor
    3333from webkitscmpy.program.canonicalize.committer import main as committer_main
     
    341341                completion=mocks.ProcessCompletion(returncode=0),
    342342            ), mocks.Subprocess.Route(
     343                self.executable, 'config', '-l',
     344                cwd=self.path,
     345                generator=lambda *args, **kwargs:
     346                    mocks.ProcessCompletion(
     347                        returncode=0,
     348                        stdout='\n'.join(['{}={}'.format(key, value) for key, value in self.config().items()])
     349                    ),
     350            ), mocks.Subprocess.Route(
     351                self.executable, 'config', '-l', '--global',
     352                generator=lambda *args, **kwargs:
     353                    mocks.ProcessCompletion(
     354                        returncode=0,
     355                        stdout='\n'.join(['{}={}'.format(key, value) for key, value in Git.config().items()])
     356                    ),
     357            ), mocks.Subprocess.Route(
    343358                self.executable,
    344359                cwd=self.path,
     
    571586                if previous.branch_point == commit.identifier:
    572587                    end = commit.hash
     588
     589    @decorators.hybridmethod
     590    def config(context):
     591        if isinstance(context, type):
     592            return {
     593                'user.name': 'tapple@webkit.org',
     594                'sendemail.transferencoding': 'base64',
     595            }
     596
     597        # Parse a .git/config that looks like this
     598        # [core]
     599        #     repositoryformatversion = 0
     600        # [branch "main"]
     601        #     remote = origin
     602        #         merge = refs/heads/main
     603        RE_SINGLE_TOP = re.compile(r'^\[\s*(?P<key>\S+)\s*\]')
     604        RE_MULTI_TOP = re.compile(r'^\[\s*(?P<keya>\S+) "(?P<keyb>\S+)"\s*\]')
     605        RE_ELEMENT = re.compile(r'^\s+(?P<key>\S+)\s*=\s*(?P<value>\S+)')
     606
     607        top = None
     608        result = Git.config()
     609        with open(os.path.join(context.path, '.git', 'config'), 'r') as configfile:
     610            for line in configfile.readlines():
     611                match = RE_MULTI_TOP.match(line)
     612                if match:
     613                    top = '{}.{}'.format(match.group('keya'), match.group('keyb'))
     614                    continue
     615                match = RE_SINGLE_TOP.match(line)
     616                if match:
     617                    top = match.group('key')
     618                    continue
     619
     620                match = RE_ELEMENT.match(line)
     621                if top and match:
     622                    result['{}.{}'.format(top, match.group('key'))] = match.group('value')
     623        return result
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py

    r280440 r280604  
    408408            self.assertEqual(repo.cache.to_revision(identifier='6@main'), None)
    409409
     410    def test_config(self):
     411        with mocks.local.Git(self.path, git_svn=True) as m:
     412            repo = local.Git(self.path)
     413
     414            self.assertEqual(repo.config()['user.name'], 'tapple@webkit.org')
     415            self.assertEqual(repo.config()['core.filemode'], 'true')
     416            self.assertEqual(repo.config()['remote.origin.url'], 'git@example.org:/mock/repository')
     417            self.assertEqual(repo.config()['svn-remote.svn.url'], 'https://svn.example.org/repository/webkit')
     418            self.assertEqual(repo.config()['svn-remote.svn.fetch'], 'trunk:refs/remotes/origin/main')
     419
     420    def test_global_config(self):
     421        with mocks.local.Git(self.path, git_svn=True), OutputCapture():
     422            self.assertEqual(local.Git.config()['user.name'], 'tapple@webkit.org')
     423            self.assertEqual(local.Git.config()['sendemail.transferencoding'], 'base64')
     424
    410425
    411426class TestGitHub(testing.TestCase):
Note: See TracChangeset for help on using the changeset viewer.