Changeset 270358 in webkit


Ignore:
Timestamp:
Dec 2, 2020 11:29:59 AM (3 years ago)
Author:
Jonathan Bedard
Message:

[webkitscmpy] Provide switch to exclude commit message
https://bugs.webkit.org/show_bug.cgi?id=219409
<rdar://problem/71866445>

Rubber-stamped by Aakash Jain.

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

(Git.commit): Pass --format-short if the user is opting out of the commit message.
(Git.find): Add include_log flag, pass to commit(...) function.

  • Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:

(Svn.commit): Skip network call to retrieve commit message if include_log is false.

  • Scripts/libraries/webkitscmpy/webkitscmpy/program.py:

(Find.parser): Add --log and --no-log flags.
(Find.main): Allow user to skip network call to retrieve commit message.

  • Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py:

(Svn.info): Support case were SVN cannot determine the author.
(Svn.commit): Skip network call to retrieve commit message if include_log is false.

  • Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py:

(ScmBase.commit): Add include_log flag.
(ScmBase.find): Add include_log flag, pass to commit(...) function.

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

(TestFind.test_no_log_svn):
(TestFind.test_no_log_git):

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

(TestGit.test_no_log):

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

(TestLocalSvn.test_no_log):
(TestRemoteSvn.test_no_log):

Location:
trunk/Tools
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r270354 r270358  
     12020-12-02  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [webkitscmpy] Provide switch to exclude commit message
     4        https://bugs.webkit.org/show_bug.cgi?id=219409
     5        <rdar://problem/71866445>
     6
     7        Rubber-stamped by Aakash Jain.
     8
     9        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Bump version.
     10        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
     11        (Git.commit): Pass --format-short if the user is opting out of the commit message.
     12        (Git.find): Add include_log flag, pass to commit(...) function.
     13        * Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
     14        (Svn.commit): Skip network call to retrieve commit message if include_log is false.
     15        * Scripts/libraries/webkitscmpy/webkitscmpy/program.py:
     16        (Find.parser): Add --log and --no-log flags.
     17        (Find.main): Allow user to skip network call to retrieve commit message.
     18        * Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py:
     19        (Svn.info): Support case were SVN cannot determine the author.
     20        (Svn.commit): Skip network call to retrieve commit message if include_log is false.
     21        * Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py:
     22        (ScmBase.commit): Add include_log flag.
     23        (ScmBase.find): Add include_log flag, pass to commit(...) function.
     24        * Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py:
     25        (TestFind.test_no_log_svn):
     26        (TestFind.test_no_log_git):
     27        * Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:
     28        (TestGit.test_no_log):
     29        * Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py:
     30        (TestLocalSvn.test_no_log):
     31        (TestRemoteSvn.test_no_log):
     32
    1332020-12-02  Aakash Jain  <aakash_jain@apple.com>
    234
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py

    r270349 r270358  
    4747    )
    4848
    49 version = Version(0, 4, 2)
     49version = Version(0, 4, 3)
    5050
    5151AutoInstall.register(Package('dateutil', Version(2, 8, 1), pypi_name='python-dateutil'))
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py

    r270004 r270358  
    152152        return sorted(set(['/'.join(branch.split('/')[2:]) if branch.startswith('remotes/origin/') else branch for branch in result]))
    153153
    154     def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None):
     154    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
    155155        if revision and not self.is_svn:
    156156            raise self.Exception('This git checkout does not support SVN revisions')
     
    173173        default_branch = self.default_branch
    174174        parsed_branch_point = None
     175        log_format = ['-1'] if include_log else ['-1', '--format=short']
    175176
    176177        if identifier is not None:
     
    205206                raise self.Exception('Identifier {} cannot be found on the specified branch in the current checkout'.format(identifier))
    206207            log = run(
    207                 [self.executable(), 'log', '{}~{}'.format(branch or 'HEAD', base_count - identifier), '-1'],
     208                [self.executable(), 'log', '{}~{}'.format(branch or 'HEAD', base_count - identifier)] + log_format,
    208209                cwd=self.root_path,
    209210                capture_output=True,
     
    225226                raise ValueError('Cannot define both tag and branch')
    226227
    227             log = run([self.executable(), 'log', branch or tag, '-1'], cwd=self.root_path, capture_output=True, encoding='utf-8')
     228            log = run([self.executable(), 'log', branch or tag] + log_format, cwd=self.root_path, capture_output=True, encoding='utf-8')
    228229            if log.returncode:
    229230                raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag))
     
    231232        else:
    232233            hash = Commit._parse_hash(hash, do_assert=True)
    233             log = run([self.executable(), 'log', hash or 'HEAD', '-1'], cwd=self.root_path, capture_output=True, encoding='utf-8')
     234            log = run([self.executable(), 'log', hash or 'HEAD'] + log_format, cwd=self.root_path, capture_output=True, encoding='utf-8')
    234235            if log.returncode:
    235236                raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD'))
     
    266267            timestamp=int(commit_time.stdout.lstrip()),
    267268            author=Contributor.from_scm_log(log.stdout.splitlines()[1]),
    268             message='\n'.join(line[4:] for line in log.stdout.splitlines()[4:]),
    269         )
    270 
    271     def find(self, argument):
     269            message='\n'.join(line[4:] for line in log.stdout.splitlines()[4:]) if include_log else None,
     270        )
     271
     272    def find(self, argument, include_log=True):
    272273        if not isinstance(argument, six.string_types):
    273274            raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
     
    280281                identifier=parsed_commit.identifier,
    281282                branch=parsed_commit.branch,
     283                include_log=include_log,
    282284            )
    283285
     
    288290        if output.returncode:
    289291            raise ValueError("'{}' is not an argument recognized by git".format(argument))
    290         return self.commit(hash=output.stdout.rstrip())
     292        return self.commit(hash=output.stdout.rstrip(), include_log=include_log)
    291293
    292294    def checkout(self, argument):
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py

    r270349 r270358  
    258258        return candidate
    259259
    260     def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None):
     260    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
    261261        if hash:
    262262            raise ValueError('SVN does not support Git hashes')
     
    362362            [self.executable(), 'log', '-l', '1', '-r', str(revision), branch_arg], cwd=self.root_path,
    363363            capture_output=True, encoding='utf-8',
    364         )
    365         split_log = log.stdout.splitlines()
    366         if not log.returncode or len(split_log) >= 3:
     364        ) if include_log else None
     365        split_log = log.stdout.splitlines() if log else []
     366        if log and (not log.returncode or len(split_log) >= 3):
    367367            author_line = split_log[1]
    368368            for line in split_log[2:8]:
     
    374374            message = '\n'.join(split_log[3:-1])
    375375        else:
    376             self.log('Failed to connect to remote, cannot compute commit message')
    377             email = info['Last Changed Author']
     376            if include_log:
     377                self.log('Failed to connect to remote, cannot compute commit message')
     378            email = info.get('Last Changed Author')
    378379            author = Contributor.by_email.get(
    379380                email,
     
    382383                    Contributor(name=email, emails=[email]),
    383384                ),
    384             )
     385            ) if email else None
    385386            message = None
    386387
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program.py

    r270254 r270358  
    5555    @classmethod
    5656    def parser(cls, parser, loggers=None):
    57         arguments.LoggingGroup(
     57        output_args = arguments.LoggingGroup(
    5858            parser,
    5959            loggers=loggers,
    6060            help='{} amount of logging and commit information displayed'
    61         ).add_argument(
     61        )
     62        output_args.add_argument(
    6263            '--json', '-j',
    6364            help='Convert the commit to a machine-readable JSON object',
     
    6566            dest='json',
    6667            default=False,
     68        )
     69        output_args.add_argument(
     70            '--log', '--no-log',
     71            help='Include the commit message for the requested commit',
     72            action=arguments.NoAction,
     73            dest='include_log',
     74            default=True,
    6775        )
    6876
     
    7684    def main(cls, args, repository):
    7785        try:
    78             commit = repository.find(args.argument[0])
     86            commit = repository.find(args.argument[0], include_log=args.include_log)
    7987        except (local.Scm.Exception, ValueError) as exception:
    8088            # ValueErrors and Scm exceptions usually contain enough information to be displayed
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py

    r270349 r270358  
    140140        return {
    141141            'Last Changed Rev': response['lp1:version-name'],
    142             'Last Changed Author': response['lp1:creator-displayname'],
     142            'Last Changed Author': response.get('lp1:creator-displayname'),
    143143            'Last Changed Date': ' '.join(response['lp1:creationdate'].split('T')).split('.')[0],
    144144            'Revision': revision,
     
    316316        return self._commit_count(revision=self._metadata_cache[branch][0], branch=self.default_branch)
    317317
    318     def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None):
     318    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
    319319        if hash:
    320320            raise ValueError('SVN does not support Git hashes')
     
    369369                raise ValueError('Cannot define both tag and revision')
    370370            revision = Commit._parse_revision(revision, do_assert=True)
    371             branch = self._branch_for(revision)
     371            branch = self._branch_for(revision) or self.default_branch
    372372            info = self.info(cached=True, branch=branch, revision=revision)
    373373
     
    412412                    '<S:limit>1</S:limit>\n'
    413413                    '</S:log-report>\n'.format(revision=revision),
    414         )
    415 
    416         if response.status_code == 200:
     414        ) if include_log else None
     415
     416        if response and response.status_code == 200:
    417417            response = xmltodict.parse(response.text)
    418418            response = response.get('S:log-report', {}).get('S:log-item')
     
    420420            name = response.get('D:creator-displayname')
    421421            message = response.get('D:comment', None)
    422             if not name:
    423                 raise self.Exception('Failed to find creator name')
    424422
    425423        else:
    426             self.log('Failed to connect to remote, cannot compute commit message')
     424            if include_log:
     425                self.log('Failed to connect to remote, cannot compute commit message')
    427426            message = None
    428             name = info['Last Changed Author']
     427            name = info.get('Last Changed Author')
    429428
    430429        author = Contributor.by_email.get(
     
    434433                Contributor(name=name, emails=[name] if '@' in name else []),
    435434            ),
    436         )
     435        ) if name else None
    437436
    438437        return Commit(
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py

    r269891 r270358  
    6464        raise NotImplementedError()
    6565
    66     def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None):
     66    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
    6767        raise NotImplementedError()
    6868
     
    8686        return sorted(filtered_candidates)[0]
    8787
    88     def find(self, argument):
     88    def find(self, argument, include_log=True):
    8989        if not isinstance(argument, six.string_types):
    9090            raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
     
    9999
    100100        if argument == 'HEAD':
    101             result = self.commit()
     101            result = self.commit(include_log=include_log)
    102102
    103103        elif argument in self.branches:
    104             result = self.commit(branch=argument)
     104            result = self.commit(branch=argument, include_log=include_log)
    105105
    106106        elif argument in self.tags:
    107             result = self.commit(tag=argument)
     107            result = self.commit(tag=argument, include_log=include_log)
    108108
    109109        else:
     
    117117                identifier=parsed_commit.identifier,
    118118                branch=parsed_commit.branch,
     119                include_log=include_log,
    119120            )
    120121
     
    125126            identifier=result.identifier - offset,
    126127            branch=result.branch,
     128            include_log=include_log,
    127129        )
    128130
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py

    r270254 r270358  
    191191            ))
    192192        self.assertEqual(captured.stdout.getvalue(), '2.2@branch-a | 621652add7fc, r7 | 7th commit\n')
     193
     194    def test_no_log_svn(self):
     195        with mocks.local.Git(), mocks.local.Svn(self.path), MockTime, OutputCapture() as captured:
     196            self.assertEqual(0, program.main(
     197                args=('find', 'trunk', '--no-log', '-q'),
     198                path=self.path,
     199            ))
     200        self.assertEqual(captured.stdout.getvalue(), '4@trunk | r6\n')
     201
     202    def test_no_log_git(self):
     203        with mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime, OutputCapture() as captured:
     204            self.assertEqual(0, program.main(
     205                args=('find', 'main', '--no-log', '-q'),
     206                path=self.path,
     207            ))
     208        self.assertEqual(captured.stdout.getvalue(), '4@main | bae5d1e90999, r6\n')
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py

    r269401 r270358  
    239239                self.assertEqual('621652add7fc416099bd2063366cc38ff61afe36', repository.checkout('tag-1').hash)
    240240                self.assertEqual('621652add7fc416099bd2063366cc38ff61afe36', repository.commit().hash)
     241
     242    def test_no_log(self):
     243        for mock in [mocks.local.Git(self.path), mocks.local.Git(self.path, git_svn=True)]:
     244            with mock:
     245                self.assertIsNone(local.Git(self.path).commit(identifier='4@main', include_log=False).message)
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py

    r270247 r270358  
    219219            self.assertEqual(9, repository.commit().revision)
    220220
     221    def test_no_log(self):
     222        with mocks.local.Svn(self.path), OutputCapture():
     223            self.assertIsNone(local.Svn(self.path).commit(identifier='4@trunk', include_log=False).message)
     224
    221225
    222226class TestRemoteSvn(unittest.TestCase):
     
    302306        with mocks.remote.Svn():
    303307            self.assertEqual(7, remote.Svn(self.remote).commit(identifier='2.2@tags/tag-1').revision)
     308
     309    def test_no_log(self):
     310        with mocks.remote.Svn():
     311            self.assertIsNone(remote.Svn(self.remote).commit(identifier='4@trunk', include_log=False).message)
Note: See TracChangeset for help on using the changeset viewer.