Title: [270358] trunk/Tools
Revision
270358
Author
[email protected]
Date
2020-12-02 11:29:59 -0800 (Wed, 02 Dec 2020)

Log 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):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (270357 => 270358)


--- trunk/Tools/ChangeLog	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/ChangeLog	2020-12-02 19:29:59 UTC (rev 270358)
@@ -1,3 +1,35 @@
+2020-12-02  Jonathan Bedard  <[email protected]>
+
+        [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):
+
 2020-12-02  Aakash Jain  <[email protected]>
 
         [build.webkit.org] Add unit-tests based on new buildbot

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(0, 4, 2)
+version = Version(0, 4, 3)
 
 AutoInstall.register(Package('dateutil', Version(2, 8, 1), pypi_name='python-dateutil'))
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -151,7 +151,7 @@
         result = [branch.lstrip(' *') for branch in filter(lambda branch: '->' not in branch, branch.stdout.splitlines())]
         return sorted(set(['/'.join(branch.split('/')[2:]) if branch.startswith('remotes/origin/') else branch for branch in result]))
 
-    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None):
+    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
         if revision and not self.is_svn:
             raise self.Exception('This git checkout does not support SVN revisions')
         elif revision:
@@ -172,6 +172,7 @@
 
         default_branch = self.default_branch
         parsed_branch_point = None
+        log_format = ['-1'] if include_log else ['-1', '--format=short']
 
         if identifier is not None:
             if revision:
@@ -204,7 +205,7 @@
             if identifier > base_count:
                 raise self.Exception('Identifier {} cannot be found on the specified branch in the current checkout'.format(identifier))
             log = run(
-                [self.executable(), 'log', '{}~{}'.format(branch or 'HEAD', base_count - identifier), '-1'],
+                [self.executable(), 'log', '{}~{}'.format(branch or 'HEAD', base_count - identifier)] + log_format,
                 cwd=self.root_path,
                 capture_output=True,
                 encoding='utf-8',
@@ -224,13 +225,13 @@
             if branch and tag:
                 raise ValueError('Cannot define both tag and branch')
 
-            log = run([self.executable(), 'log', branch or tag, '-1'], cwd=self.root_path, capture_output=True, encoding='utf-8')
+            log = run([self.executable(), 'log', branch or tag] + log_format, cwd=self.root_path, capture_output=True, encoding='utf-8')
             if log.returncode:
                 raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag))
 
         else:
             hash = Commit._parse_hash(hash, do_assert=True)
-            log = run([self.executable(), 'log', hash or 'HEAD', '-1'], cwd=self.root_path, capture_output=True, encoding='utf-8')
+            log = run([self.executable(), 'log', hash or 'HEAD'] + log_format, cwd=self.root_path, capture_output=True, encoding='utf-8')
             if log.returncode:
                 raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD'))
 
@@ -265,10 +266,10 @@
             branch=branch,
             timestamp=int(commit_time.stdout.lstrip()),
             author=Contributor.from_scm_log(log.stdout.splitlines()[1]),
-            message='\n'.join(line[4:] for line in log.stdout.splitlines()[4:]),
+            message='\n'.join(line[4:] for line in log.stdout.splitlines()[4:]) if include_log else None,
         )
 
-    def find(self, argument):
+    def find(self, argument, include_log=True):
         if not isinstance(argument, six.string_types):
             raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
 
@@ -279,6 +280,7 @@
                 revision=parsed_commit.revision,
                 identifier=parsed_commit.identifier,
                 branch=parsed_commit.branch,
+                include_log=include_log,
             )
 
         output = run(
@@ -287,7 +289,7 @@
         )
         if output.returncode:
             raise ValueError("'{}' is not an argument recognized by git".format(argument))
-        return self.commit(hash=output.stdout.rstrip())
+        return self.commit(hash=output.stdout.rstrip(), include_log=include_log)
 
     def checkout(self, argument):
         if not isinstance(argument, six.string_types):

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -257,7 +257,7 @@
             return partial[1:].rstrip('/')
         return candidate
 
-    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None):
+    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
         if hash:
             raise ValueError('SVN does not support Git hashes')
 
@@ -361,9 +361,9 @@
         log = run(
             [self.executable(), 'log', '-l', '1', '-r', str(revision), branch_arg], cwd=self.root_path,
             capture_output=True, encoding='utf-8',
-        )
-        split_log = log.stdout.splitlines()
-        if not log.returncode or len(split_log) >= 3:
+        ) if include_log else None
+        split_log = log.stdout.splitlines() if log else []
+        if log and (not log.returncode or len(split_log) >= 3):
             author_line = split_log[1]
             for line in split_log[2:8]:
                 if Contributor.SVN_PATCH_FROM_RE.match(line):
@@ -373,8 +373,9 @@
             author = Contributor.from_scm_log(author_line)
             message = '\n'.join(split_log[3:-1])
         else:
-            self.log('Failed to connect to remote, cannot compute commit message')
-            email = info['Last Changed Author']
+            if include_log:
+                self.log('Failed to connect to remote, cannot compute commit message')
+            email = info.get('Last Changed Author')
             author = Contributor.by_email.get(
                 email,
                 Contributor.by_name.get(
@@ -381,7 +382,7 @@
                     email,
                     Contributor(name=email, emails=[email]),
                 ),
-            )
+            ) if email else None
             message = None
 
         return Commit(

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -54,11 +54,12 @@
 
     @classmethod
     def parser(cls, parser, loggers=None):
-        arguments.LoggingGroup(
+        output_args = arguments.LoggingGroup(
             parser,
             loggers=loggers,
             help='{} amount of logging and commit information displayed'
-        ).add_argument(
+        )
+        output_args.add_argument(
             '--json', '-j',
             help='Convert the commit to a machine-readable JSON object',
             action='',
@@ -65,6 +66,13 @@
             dest='json',
             default=False,
         )
+        output_args.add_argument(
+            '--log', '--no-log',
+            help='Include the commit message for the requested commit',
+            action=""
+            dest='include_log',
+            default=True,
+        )
 
         parser.add_argument(
             'argument', nargs=1,
@@ -75,7 +83,7 @@
     @classmethod
     def main(cls, args, repository):
         try:
-            commit = repository.find(args.argument[0])
+            commit = repository.find(args.argument[0], include_log=args.include_log)
         except (local.Scm.Exception, ValueError) as exception:
             # ValueErrors and Scm exceptions usually contain enough information to be displayed
             # to the user as an error

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -139,7 +139,7 @@
 
         return {
             'Last Changed Rev': response['lp1:version-name'],
-            'Last Changed Author': response['lp1:creator-displayname'],
+            'Last Changed Author': response.get('lp1:creator-displayname'),
             'Last Changed Date': ' '.join(response['lp1:creationdate'].split('T')).split('.')[0],
             'Revision': revision,
         }
@@ -315,7 +315,7 @@
             return len(self._metadata_cache[branch])
         return self._commit_count(revision=self._metadata_cache[branch][0], branch=self.default_branch)
 
-    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None):
+    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
         if hash:
             raise ValueError('SVN does not support Git hashes')
 
@@ -368,7 +368,7 @@
             if tag:
                 raise ValueError('Cannot define both tag and revision')
             revision = Commit._parse_revision(revision, do_assert=True)
-            branch = self._branch_for(revision)
+            branch = self._branch_for(revision) or self.default_branch
             info = self.info(cached=True, branch=branch, revision=revision)
 
         else:
@@ -411,21 +411,20 @@
                     '<S:end-revision>{revision}</S:end-revision>\n'
                     '<S:limit>1</S:limit>\n'
                     '</S:log-report>\n'.format(revision=revision),
-        )
+        ) if include_log else None
 
-        if response.status_code == 200:
+        if response and response.status_code == 200:
             response = xmltodict.parse(response.text)
             response = response.get('S:log-report', {}).get('S:log-item')
 
             name = response.get('D:creator-displayname')
             message = response.get('D:comment', None)
-            if not name:
-                raise self.Exception('Failed to find creator name')
 
         else:
-            self.log('Failed to connect to remote, cannot compute commit message')
+            if include_log:
+                self.log('Failed to connect to remote, cannot compute commit message')
             message = None
-            name = info['Last Changed Author']
+            name = info.get('Last Changed Author')
 
         author = Contributor.by_email.get(
             name,
@@ -433,7 +432,7 @@
                 name,
                 Contributor(name=name, emails=[name] if '@' in name else []),
             ),
-        )
+        ) if name else None
 
         return Commit(
             revision=int(revision),

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -63,7 +63,7 @@
     def tags(self):
         raise NotImplementedError()
 
-    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None):
+    def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
         raise NotImplementedError()
 
     def prioritize_branches(self, branches):
@@ -85,7 +85,7 @@
             filtered_candidates = branches
         return sorted(filtered_candidates)[0]
 
-    def find(self, argument):
+    def find(self, argument, include_log=True):
         if not isinstance(argument, six.string_types):
             raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
 
@@ -98,13 +98,13 @@
             argument = argument.split('~')[0]
 
         if argument == 'HEAD':
-            result = self.commit()
+            result = self.commit(include_log=include_log)
 
         elif argument in self.branches:
-            result = self.commit(branch=argument)
+            result = self.commit(branch=argument, include_log=include_log)
 
         elif argument in self.tags:
-            result = self.commit(tag=argument)
+            result = self.commit(tag=argument, include_log=include_log)
 
         else:
             if offset:
@@ -116,6 +116,7 @@
                 revision=parsed_commit.revision,
                 identifier=parsed_commit.identifier,
                 branch=parsed_commit.branch,
+                include_log=include_log,
             )
 
         if not offset:
@@ -124,6 +125,7 @@
         return self.commit(
             identifier=result.identifier - offset,
             branch=result.branch,
+            include_log=include_log,
         )
 
     @classmethod

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -190,3 +190,19 @@
                 path=self.path,
             ))
         self.assertEqual(captured.stdout.getvalue(), '2.2@branch-a | 621652add7fc, r7 | 7th commit\n')
+
+    def test_no_log_svn(self):
+        with mocks.local.Git(), mocks.local.Svn(self.path), MockTime, OutputCapture() as captured:
+            self.assertEqual(0, program.main(
+                args=('find', 'trunk', '--no-log', '-q'),
+                path=self.path,
+            ))
+        self.assertEqual(captured.stdout.getvalue(), '4@trunk | r6\n')
+
+    def test_no_log_git(self):
+        with mocks.local.Git(self.path, git_svn=True), mocks.local.Svn(), MockTime, OutputCapture() as captured:
+            self.assertEqual(0, program.main(
+                args=('find', 'main', '--no-log', '-q'),
+                path=self.path,
+            ))
+        self.assertEqual(captured.stdout.getvalue(), '4@main | bae5d1e90999, r6\n')

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -238,3 +238,8 @@
 
                 self.assertEqual('621652add7fc416099bd2063366cc38ff61afe36', repository.checkout('tag-1').hash)
                 self.assertEqual('621652add7fc416099bd2063366cc38ff61afe36', repository.commit().hash)
+
+    def test_no_log(self):
+        for mock in [mocks.local.Git(self.path), mocks.local.Git(self.path, git_svn=True)]:
+            with mock:
+                self.assertIsNone(local.Git(self.path).commit(identifier='4@main', include_log=False).message)

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py (270357 => 270358)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py	2020-12-02 19:29:04 UTC (rev 270357)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py	2020-12-02 19:29:59 UTC (rev 270358)
@@ -218,7 +218,11 @@
             self.assertEqual(9, repository.checkout('tag-1').revision)
             self.assertEqual(9, repository.commit().revision)
 
+    def test_no_log(self):
+        with mocks.local.Svn(self.path), OutputCapture():
+            self.assertIsNone(local.Svn(self.path).commit(identifier='4@trunk', include_log=False).message)
 
+
 class TestRemoteSvn(unittest.TestCase):
     remote = 'https://svn.webkit.org/repository/webkit'
 
@@ -301,3 +305,7 @@
     def test_tag_previous(self):
         with mocks.remote.Svn():
             self.assertEqual(7, remote.Svn(self.remote).commit(identifier='2.2@tags/tag-1').revision)
+
+    def test_no_log(self):
+        with mocks.remote.Svn():
+            self.assertIsNone(remote.Svn(self.remote).commit(identifier='4@trunk', include_log=False).message)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to