Changeset 270358 in webkit
- Timestamp:
- Dec 2, 2020 11:29:59 AM (3 years ago)
- Location:
- trunk/Tools
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r270354 r270358 1 2020-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 1 33 2020-12-02 Aakash Jain <aakash_jain@apple.com> 2 34 -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py
r270349 r270358 47 47 ) 48 48 49 version = Version(0, 4, 2)49 version = Version(0, 4, 3) 50 50 51 51 AutoInstall.register(Package('dateutil', Version(2, 8, 1), pypi_name='python-dateutil')) -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py
r270004 r270358 152 152 return sorted(set(['/'.join(branch.split('/')[2:]) if branch.startswith('remotes/origin/') else branch for branch in result])) 153 153 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): 155 155 if revision and not self.is_svn: 156 156 raise self.Exception('This git checkout does not support SVN revisions') … … 173 173 default_branch = self.default_branch 174 174 parsed_branch_point = None 175 log_format = ['-1'] if include_log else ['-1', '--format=short'] 175 176 176 177 if identifier is not None: … … 205 206 raise self.Exception('Identifier {} cannot be found on the specified branch in the current checkout'.format(identifier)) 206 207 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, 208 209 cwd=self.root_path, 209 210 capture_output=True, … … 225 226 raise ValueError('Cannot define both tag and branch') 226 227 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') 228 229 if log.returncode: 229 230 raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag)) … … 231 232 else: 232 233 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') 234 235 if log.returncode: 235 236 raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD')) … … 266 267 timestamp=int(commit_time.stdout.lstrip()), 267 268 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): 272 273 if not isinstance(argument, six.string_types): 273 274 raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument))) … … 280 281 identifier=parsed_commit.identifier, 281 282 branch=parsed_commit.branch, 283 include_log=include_log, 282 284 ) 283 285 … … 288 290 if output.returncode: 289 291 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) 291 293 292 294 def checkout(self, argument): -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py
r270349 r270358 258 258 return candidate 259 259 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): 261 261 if hash: 262 262 raise ValueError('SVN does not support Git hashes') … … 362 362 [self.executable(), 'log', '-l', '1', '-r', str(revision), branch_arg], cwd=self.root_path, 363 363 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): 367 367 author_line = split_log[1] 368 368 for line in split_log[2:8]: … … 374 374 message = '\n'.join(split_log[3:-1]) 375 375 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') 378 379 author = Contributor.by_email.get( 379 380 email, … … 382 383 Contributor(name=email, emails=[email]), 383 384 ), 384 ) 385 ) if email else None 385 386 message = None 386 387 -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program.py
r270254 r270358 55 55 @classmethod 56 56 def parser(cls, parser, loggers=None): 57 arguments.LoggingGroup(57 output_args = arguments.LoggingGroup( 58 58 parser, 59 59 loggers=loggers, 60 60 help='{} amount of logging and commit information displayed' 61 ).add_argument( 61 ) 62 output_args.add_argument( 62 63 '--json', '-j', 63 64 help='Convert the commit to a machine-readable JSON object', … … 65 66 dest='json', 66 67 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, 67 75 ) 68 76 … … 76 84 def main(cls, args, repository): 77 85 try: 78 commit = repository.find(args.argument[0] )86 commit = repository.find(args.argument[0], include_log=args.include_log) 79 87 except (local.Scm.Exception, ValueError) as exception: 80 88 # ValueErrors and Scm exceptions usually contain enough information to be displayed -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py
r270349 r270358 140 140 return { 141 141 'Last Changed Rev': response['lp1:version-name'], 142 'Last Changed Author': response ['lp1:creator-displayname'],142 'Last Changed Author': response.get('lp1:creator-displayname'), 143 143 'Last Changed Date': ' '.join(response['lp1:creationdate'].split('T')).split('.')[0], 144 144 'Revision': revision, … … 316 316 return self._commit_count(revision=self._metadata_cache[branch][0], branch=self.default_branch) 317 317 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): 319 319 if hash: 320 320 raise ValueError('SVN does not support Git hashes') … … 369 369 raise ValueError('Cannot define both tag and revision') 370 370 revision = Commit._parse_revision(revision, do_assert=True) 371 branch = self._branch_for(revision) 371 branch = self._branch_for(revision) or self.default_branch 372 372 info = self.info(cached=True, branch=branch, revision=revision) 373 373 … … 412 412 '<S:limit>1</S:limit>\n' 413 413 '</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: 417 417 response = xmltodict.parse(response.text) 418 418 response = response.get('S:log-report', {}).get('S:log-item') … … 420 420 name = response.get('D:creator-displayname') 421 421 message = response.get('D:comment', None) 422 if not name:423 raise self.Exception('Failed to find creator name')424 422 425 423 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') 427 426 message = None 428 name = info ['Last Changed Author']427 name = info.get('Last Changed Author') 429 428 430 429 author = Contributor.by_email.get( … … 434 433 Contributor(name=name, emails=[name] if '@' in name else []), 435 434 ), 436 ) 435 ) if name else None 437 436 438 437 return Commit( -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py
r269891 r270358 64 64 raise NotImplementedError() 65 65 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): 67 67 raise NotImplementedError() 68 68 … … 86 86 return sorted(filtered_candidates)[0] 87 87 88 def find(self, argument ):88 def find(self, argument, include_log=True): 89 89 if not isinstance(argument, six.string_types): 90 90 raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument))) … … 99 99 100 100 if argument == 'HEAD': 101 result = self.commit( )101 result = self.commit(include_log=include_log) 102 102 103 103 elif argument in self.branches: 104 result = self.commit(branch=argument )104 result = self.commit(branch=argument, include_log=include_log) 105 105 106 106 elif argument in self.tags: 107 result = self.commit(tag=argument )107 result = self.commit(tag=argument, include_log=include_log) 108 108 109 109 else: … … 117 117 identifier=parsed_commit.identifier, 118 118 branch=parsed_commit.branch, 119 include_log=include_log, 119 120 ) 120 121 … … 125 126 identifier=result.identifier - offset, 126 127 branch=result.branch, 128 include_log=include_log, 127 129 ) 128 130 -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/find_unittest.py
r270254 r270358 191 191 )) 192 192 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 239 239 self.assertEqual('621652add7fc416099bd2063366cc38ff61afe36', repository.checkout('tag-1').hash) 240 240 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 219 219 self.assertEqual(9, repository.commit().revision) 220 220 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 221 225 222 226 class TestRemoteSvn(unittest.TestCase): … … 302 306 with mocks.remote.Svn(): 303 307 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.