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

Changeset 271258 in webkit


Ignore:
Timestamp:
Jan 7, 2021, 1:15:47 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

[webkitscmpy] Use .git/config to verify if repository is git-svn
https://bugs.webkit.org/show_bug.cgi?id=220427
<rdar://problem/72899735>

Patch by Jonathan Bedard <JonWBedard@gmail.com> on 2021-01-07
Reviewed by Dewei Zhu.

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

(Git.is_svn): Use .git/config to verify if a repository is git-svn.

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

(Git): Populate .git/config if the provided path is writeable.

  • Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py:

(TestFind.test_revision_git_svn): Use a temporary directory so files
can be written.

  • Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:

(TestGit.test_scm_type): Use a temporary directory so files can be written.
(TestGit.test_info): Ditto.
(TestGit.test_commit_revision): Ditto.

Location:
trunk/Tools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r271245 r271258  
     12021-01-07  Jonathan Bedard  <JonWBedard@gmail.com>
     2
     3        [webkitscmpy] Use .git/config to verify if repository is git-svn
     4        https://bugs.webkit.org/show_bug.cgi?id=220427
     5        <rdar://problem/72899735>
     6
     7        Reviewed by Dewei Zhu.
     8
     9        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Bump version number.
     10        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
     11        (Git.is_svn): Use .git/config to verify if a repository is git-svn.
     12        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
     13        (Git): Populate .git/config if the provided path is writeable.
     14        * Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py:
     15        (TestFind.test_revision_git_svn): Use a temporary directory so files
     16        can be written.
     17        * Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:
     18        (TestGit.test_scm_type): Use a temporary directory so files can be written.
     19        (TestGit.test_info): Ditto.
     20        (TestGit.test_commit_revision): Ditto.
     21
    1222021-01-07  Chris Dumez  <cdumez@apple.com>
    223
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py

    r271203 r271258  
    1 # Copyright (C) 2020 Apple Inc. All rights reserved.
     1# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    4747    )
    4848
    49 version = Version(0, 7, 1)
     49version = Version(0, 7, 2)
    5050
    5151AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py

    r270871 r271258  
    1 # Copyright (C) 2020 Apple Inc. All rights reserved.
     1# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2222
    2323import logging
     24import os
    2425import re
    2526import six
     
    6566    @decorators.Memoize()
    6667    def is_svn(self):
    67         try:
    68             return run(
    69                 [self.executable(), 'svn', 'find-rev', 'r1'],
    70                 cwd=self.root_path,
    71                 capture_output=True,
    72                 encoding='utf-8',
    73                 timeout=1,
    74             ).returncode == 0
    75         except TimeoutExpired:
     68        config = os.path.join(self.root_path, '.git/config')
     69        if not os.path.isfile(config):
     70            return False
     71
     72        with open(config, 'r') as config:
     73            for line in config.readlines():
     74                if line.startswith('[svn-remote "svn"]'):
     75                    return True
    7676            return False
    7777
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py

    r271182 r271258  
    1 # Copyright (C) 2020 Apple Inc. All rights reserved.
     1# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    6363        self.remotes = {'origin/{}'.format(branch): commits[-1] for branch, commits in self.commits.items()}
    6464        self.tags = {}
     65
     66        # If the directory provided actually exists, populate it
     67        if os.path.isdir(self.path):
     68            if not os.path.isdir(os.path.join(self.path, '.git')):
     69                os.mkdir(os.path.join(self.path, '.git'))
     70            with open(os.path.join(self.path, '.git', 'config'), 'w') as config:
     71                config.write(
     72                    '[core]\n'
     73                    '    repositoryformatversion = 0\n'
     74                    '   filemode = true\n'
     75                    '   bare = false\n'
     76                    '   logallrefupdates = true\n'
     77                    '   ignorecase = true\n'
     78                    '   precomposeunicode = true\n'
     79                    '[remote "origin"]\n'
     80                    '    url = {remote}\n'
     81                    '    fetch = +refs/heads/*:refs/remotes/origin/*\n'
     82                    '[branch "{branch}"]\n'
     83                    '    remote = origin\n'
     84                    '    merge = refs/heads/{branch}\n'.format(
     85                        remote=self.remote,
     86                        branch=self.default_branch,
     87                    ))
     88                if git_svn:
     89                    domain = 'webkit.org'
     90                    if self.remote.startswith('https://'):
     91                        domain = self.remote.split('/')[2]
     92                    elif '@' in self.remote:
     93                        domain = self.remote.split('@')[1].split(':')[0]
     94
     95                    config.write(
     96                        '[svn-remote "svn"]\n'
     97                        '    url = https://svn.{domain}/repository/webkit\n'
     98                        '    fetch = trunk:refs/remotes/origin/{branch}'.format(
     99                            domain=domain,
     100                            branch=self.default_branch,
     101                        )
     102                    )
    65103
    66104        if git_svn:
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py

    r270956 r271258  
    1 # Copyright (C) 2020 Apple Inc. All rights reserved.
     1# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2222
    2323import json
     24import shutil
     25import tempfile
    2426import unittest
    2527
     
    114116
    115117    def test_revision_git_svn(self):
    116         with OutputCapture() as captured, mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime:
    117             self.assertEqual(0, program.main(
    118                 args=('find', 'r5', '-q'),
    119                 path=self.path,
    120             ))
    121         self.assertEqual(captured.stdout.getvalue(), '2.2@branch-b | 3cd32e352410, r5 | 5th commit\n')
     118        try:
     119            dirname = tempfile.mkdtemp()
     120            with OutputCapture() as captured, mocks.local.Git(dirname, git_svn=True, remote='git@example.org:{}'.format(self.path)), mocks.local.Svn(), MockTime:
     121                self.assertEqual(0, program.main(
     122                    args=('find', 'r5', '-q'),
     123                    path=dirname,
     124                ))
     125            self.assertEqual(captured.stdout.getvalue(), '2.2@branch-b | 3cd32e352410, r5 | 5th commit\n')
     126        finally:
     127            shutil.rmtree(dirname)
    122128
    123129    def test_standard(self):
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py

    r270944 r271258  
    1 # Copyright (C) 2020 Apple Inc. All rights reserved.
     1# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2222
    2323import os
     24import shutil
     25import tempfile
    2426import unittest
    2527
     
    7880
    7981    def test_scm_type(self):
    80         with mocks.local.Git(self.path), MockTime, LoggerCapture():
    81             self.assertTrue(local.Git(self.path).is_git)
    82             self.assertFalse(local.Git(self.path).is_svn)
    83 
    84         with mocks.local.Git(self.path, git_svn=True), MockTime, LoggerCapture():
    85             self.assertTrue(local.Git(self.path).is_git)
    86             self.assertTrue(local.Git(self.path).is_svn)
     82        try:
     83            dirname = tempfile.mkdtemp()
     84            with mocks.local.Git(dirname, remote='git@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
     85                self.assertTrue(local.Git(dirname).is_git)
     86                self.assertFalse(local.Git(dirname).is_svn)
     87
     88            with mocks.local.Git(dirname, git_svn=True, remote='git@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
     89                self.assertTrue(local.Git(dirname).is_git)
     90                self.assertTrue(local.Git(dirname).is_svn)
     91
     92        finally:
     93            shutil.rmtree(dirname)
    8794
    8895    def test_info(self):
    89         with mocks.local.Git(self.path), MockTime, LoggerCapture():
    90             with self.assertRaises(local.Git.Exception):
    91                 self.assertEqual(dict(), local.Git(self.path).info())
    92 
    93         with mocks.local.Git(self.path, git_svn=True), MockTime:
    94             self.assertDictEqual(
    95                 {
    96                     'Path': '.',
    97                     'Repository Root': 'git@example.org:/mock/repository',
    98                     'URL': 'git@example.org:/mock/repository/main',
    99                     'Revision': '6',
    100                     'Node Kind': 'directory',
    101                     'Schedule': 'normal',
    102                     'Last Changed Author': 'jbedard@apple.com',
    103                     'Last Changed Rev': '6',
    104                     'Last Changed Date': datetime.fromtimestamp(1601665000).strftime('%Y-%m-%d %H:%M:%S'),
    105                 }, local.Git(self.path).info(),
    106             )
     96        try:
     97            dirname = tempfile.mkdtemp()
     98            with mocks.local.Git(dirname, remote='git@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
     99                with self.assertRaises(local.Git.Exception):
     100                    self.assertEqual(dict(), local.Git(dirname).info())
     101
     102            with mocks.local.Git(dirname, git_svn=True, remote='git@example.org:{}'.format(self.path)), MockTime:
     103                self.assertDictEqual(
     104                    {
     105                        'Path': '.',
     106                        'Repository Root': 'git@example.org:/mock/repository',
     107                        'URL': 'git@example.org:/mock/repository/main',
     108                        'Revision': '6',
     109                        'Node Kind': 'directory',
     110                        'Schedule': 'normal',
     111                        'Last Changed Author': 'jbedard@apple.com',
     112                        'Last Changed Rev': '6',
     113                        'Last Changed Date': datetime.fromtimestamp(1601665000).strftime('%Y-%m-%d %H:%M:%S'),
     114                    }, local.Git(dirname).info(),
     115                )
     116        finally:
     117            shutil.rmtree(dirname)
    107118
    108119    def test_commit_revision(self):
    109         with mocks.local.Git(self.path), MockTime, LoggerCapture():
    110             with self.assertRaises(local.Git.Exception):
    111                 self.assertEqual(None, local.Git(self.path).commit(revision=1))
    112 
    113         with mocks.local.Git(self.path, git_svn=True), MockTime, LoggerCapture():
    114             self.assertEqual('1@main', str(local.Git(self.path).commit(revision=1)))
    115             self.assertEqual('2@main', str(local.Git(self.path).commit(revision=2)))
    116             self.assertEqual('2.1@branch-a', str(local.Git(self.path).commit(revision=3)))
    117             self.assertEqual('3@main', str(local.Git(self.path).commit(revision=4)))
    118             self.assertEqual('2.2@branch-b', str(local.Git(self.path).commit(revision=5)))
    119             self.assertEqual('4@main', str(local.Git(self.path).commit(revision=6)))
    120             self.assertEqual('2.2@branch-a', str(local.Git(self.path).commit(revision=7)))
    121             self.assertEqual('2.3@branch-b', str(local.Git(self.path).commit(revision=8)))
    122 
    123             # Out-of-bounds commit
    124             with self.assertRaises(local.Git.Exception):
    125                 self.assertEqual(None, local.Git(self.path).commit(revision=10))
     120        try:
     121            dirname = tempfile.mkdtemp()
     122            with mocks.local.Git(dirname), MockTime, LoggerCapture():
     123                with self.assertRaises(local.Git.Exception):
     124                    self.assertEqual(None, local.Git(dirname).commit(revision=1))
     125
     126            with mocks.local.Git(dirname, git_svn=True, remote='git@example.org:{}'.format(self.path)), MockTime, LoggerCapture():
     127                self.assertEqual('1@main', str(local.Git(dirname).commit(revision=1)))
     128                self.assertEqual('2@main', str(local.Git(dirname).commit(revision=2)))
     129                self.assertEqual('2.1@branch-a', str(local.Git(dirname).commit(revision=3)))
     130                self.assertEqual('3@main', str(local.Git(dirname).commit(revision=4)))
     131                self.assertEqual('2.2@branch-b', str(local.Git(dirname).commit(revision=5)))
     132                self.assertEqual('4@main', str(local.Git(dirname).commit(revision=6)))
     133                self.assertEqual('2.2@branch-a', str(local.Git(dirname).commit(revision=7)))
     134                self.assertEqual('2.3@branch-b', str(local.Git(dirname).commit(revision=8)))
     135
     136                # Out-of-bounds commit
     137                with self.assertRaises(local.Git.Exception):
     138                    self.assertEqual(None, local.Git(dirname).commit(revision=10))
     139        finally:
     140            shutil.rmtree(dirname)
    126141
    127142    def test_commit_hash(self):
Note: See TracChangeset for help on using the changeset viewer.