Diff
Modified: trunk/Tools/ChangeLog (273436 => 273437)
--- trunk/Tools/ChangeLog 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/ChangeLog 2021-02-24 22:02:34 UTC (rev 273437)
@@ -1,3 +1,37 @@
+2021-02-24 Jonathan Bedard <jbed...@apple.com>
+
+ [webkitscmpy] Add flag for caller to opt out of identifier computation
+ https://bugs.webkit.org/show_bug.cgi?id=222337
+ <rdar://problem/74667858>
+
+ Reviewed by Dewei Zhu.
+
+ * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
+ (Git.commit): Allow caller to opt-out of retrieving the identifier.
+ (Git.find): Ditto.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
+ (Svn.commit): Allow caller to opt-out of retrieving the identifier.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/remote/bitbucket.py:
+ (BitBucket.commit): Allow caller to opt-out of retrieving the identifier.
+ (BitBucket.find): Ditto.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py:
+ (GitHub.commit): Allow caller to opt-out of retrieving the identifier.
+ (GitHub.find): Ditto.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py:
+ (Svn.commit): Allow caller to opt-out of retrieving the identifier.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py:
+ (ScmBase.commit): Allow caller to opt-out of retrieving the identifier.
+ (ScmBase.find): Ditto.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:
+ (TestGit.test_no_identifier):
+ (TestGitHub.test_no_identifier):
+ (TestBitBucket.test_no_identifier):
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py:
+ (TestLocalSvn.test_no_identifier):
+ (TestRemoteSvn.test_no_identifier):
+
2021-02-24 Russell Epstein <repst...@apple.com>
Revert r272735. rdar://problem/74674837
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -29,7 +29,7 @@
setup(
name='webkitscmpy',
- version='0.10.1',
+ version='0.11.1',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -46,7 +46,7 @@
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)
-version = Version(0, 10, 1)
+version = Version(0, 11, 1)
AutoInstall.register(Package('entrypoints', Version(0, 3, 0)))
AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -150,7 +150,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, include_log=True):
+ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True, include_identifier=True):
if revision and not self.is_svn:
raise self.Exception('This git checkout does not support SVN revisions')
elif revision:
@@ -241,9 +241,9 @@
branch = self.prioritize_branches(self._branches_for(hash))
- if not identifier:
+ if not identifier and include_identifier:
identifier = self._commit_count(hash if branch == default_branch else '{}..{}'.format(default_branch, hash))
- branch_point = None if branch == default_branch else self._commit_count(hash) - identifier
+ branch_point = None if not include_identifier or branch == default_branch else self._commit_count(hash) - identifier
if branch_point and parsed_branch_point and branch_point != parsed_branch_point:
raise ValueError("Provided 'branch_point' does not match branch point of specified branch")
@@ -260,7 +260,7 @@
return Commit(
hash=hash,
revision=revision,
- identifier=identifier,
+ identifier=identifier if include_identifier else None,
branch_point=branch_point,
branch=branch,
timestamp=int(commit_time.stdout.lstrip()),
@@ -268,7 +268,7 @@
message='\n'.join(line[4:] for line in log.stdout.splitlines()[4:]) if include_log else None,
)
- def find(self, argument, include_log=True):
+ def find(self, argument, include_log=True, include_identifier=True):
if not isinstance(argument, six.string_types):
raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
@@ -286,6 +286,7 @@
identifier=parsed_commit.identifier,
branch=parsed_commit.branch,
include_log=include_log,
+ include_identifier=include_identifier,
)
output = run(
@@ -294,7 +295,7 @@
)
if output.returncode:
raise ValueError("'{}' is not an argument recognized by git".format(argument))
- return self.commit(hash=output.stdout.rstrip(), include_log=include_log)
+ return self.commit(hash=output.stdout.rstrip(), include_log=include_log, include_identifier=include_identifier)
def checkout(self, argument):
if not isinstance(argument, six.string_types):
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -260,7 +260,7 @@
return partial[1:].rstrip('/')
return candidate
- def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
+ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True, include_identifier=True):
if hash:
raise ValueError('SVN does not support Git hashes')
@@ -340,7 +340,7 @@
minutes=int(tz_diff[3:5]),
) * (1 if tz_diff[0] == '-' else -1)
- if not identifier:
+ if include_identifier and not identifier:
if branch != self.default_branch and revision > self._metadata_cache.get(self.default_branch, [0])[-1]:
self._cache_revisions(branch=self.default_branch)
if revision not in self._metadata_cache.get(branch, []):
@@ -347,7 +347,7 @@
self._cache_revisions(branch=branch)
identifier = self._commit_count(revision=revision, branch=branch)
- branch_point = None if branch == self.default_branch else self._commit_count(branch=branch)
+ branch_point = None if not include_identifier or branch == self.default_branch else self._commit_count(branch=branch)
if branch_point and parsed_branch_point and branch_point != parsed_branch_point:
raise ValueError("Provided 'branch_point' does not match branch point of specified branch")
@@ -380,7 +380,7 @@
return Commit(
revision=int(revision),
branch=branch,
- identifier=identifier,
+ identifier=identifier if include_identifier else None,
branch_point=branch_point,
timestamp=int(calendar.timegm(date.timetuple())) if date else None,
author=author,
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/bitbucket.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/bitbucket.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/bitbucket.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -136,7 +136,7 @@
return []
return sorted([details.get('displayId') for details in response if details.get('displayId')])
- def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
+ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True, include_identifier=True):
if revision:
raise self.Exception('Cannot map revisions to commits on BitBucket')
@@ -214,11 +214,11 @@
branch = None
branch_point = None
- if branch and branch == self.default_branch:
+ if include_identifier and branch and branch == self.default_branch:
if not identifier:
identifier = self._distance(commit_data['id'])
- elif branch:
+ elif include_identifier and branch:
if not identifier:
identifier = self._distance(commit_data['id'], magnitude=256, condition=lambda val: self.default_branch not in val)
branch_point = self._distance(commit_data['id']) - identifier
@@ -230,7 +230,7 @@
hash=commit_data['id'],
revision=revision,
branch_point=branch_point,
- identifier=identifier,
+ identifier=identifier if include_identifier else None,
branch=branch,
timestamp=int(commit_data['committerTimestamp'] / 100),
author=self.contributors.create(
@@ -239,7 +239,7 @@
), message=commit_data['message'] if include_log else None,
)
- def find(self, argument, include_log=True):
+ def find(self, argument, include_log=True, include_identifier=True):
if not isinstance(argument, six.string_types):
raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
@@ -257,9 +257,10 @@
identifier=parsed_commit.identifier,
branch=parsed_commit.branch,
include_log=include_log,
+ include_identifier=include_identifier,
)
commit_data = self.request('commits/{}'.format(argument))
if not commit_data:
raise ValueError("'{}' is not an argument recognized by git".format(argument))
- return self.commit(hash=commit_data['id'], include_log=include_log)
+ return self.commit(hash=commit_data['id'], include_log=include_log, include_identifier=include_identifier)
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -235,7 +235,7 @@
return []
return sorted([details.get('name') for details in response if details.get('name')])
- def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
+ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True, include_identifier=True):
if revision:
raise self.Exception('Cannot map revisions to commits on GitHub')
@@ -309,7 +309,7 @@
branch = None
branch_point = None
- if branch and branch == self.default_branch:
+ if include_identifier and branch and branch == self.default_branch:
if not identifier:
result = self._count_for_ref(ref=commit_data['sha'])
if not result:
@@ -316,7 +316,7 @@
raise Exception('{} {}'.format(result, commit_data['sha']))
identifier, _ = result
- elif branch:
+ elif include_identifier and branch:
if not identifier:
identifier = self._difference(self.default_branch, commit_data['sha'])
branch_point = self._count_for_ref(ref=commit_data['sha'])[0] - identifier
@@ -331,7 +331,7 @@
hash=commit_data['sha'],
revision=revision,
branch_point=branch_point,
- identifier=identifier,
+ identifier=identifier if include_identifier else None,
branch=branch,
timestamp=int(calendar.timegm(date.timetuple())),
author=self.contributors.create(
@@ -340,7 +340,7 @@
), message=commit_data['commit']['message'] if include_log else None,
)
- def find(self, argument, include_log=True):
+ def find(self, argument, include_log=True, include_identifier=True):
if not isinstance(argument, six.string_types):
raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
@@ -358,9 +358,10 @@
identifier=parsed_commit.identifier,
branch=parsed_commit.branch,
include_log=include_log,
+ include_identifier=include_identifier,
)
commit_data = self.request('commits/{}'.format(argument))
if not commit_data:
raise ValueError("'{}' is not an argument recognized by git".format(argument))
- return self.commit(hash=commit_data['sha'], include_log=include_log)
+ return self.commit(hash=commit_data['sha'], include_log=include_log, include_identifier=include_identifier)
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/svn.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -323,7 +323,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, include_log=True):
+ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True, include_identifier=True):
if hash:
raise ValueError('SVN does not support Git hashes')
@@ -396,7 +396,7 @@
date = datetime.strptime(info['Last Changed Date'], '%Y-%m-%d %H:%M:%S') if info.get('Last Changed Date') else None
- if not identifier:
+ if include_identifier and not identifier:
if branch != self.default_branch and revision > self._metadata_cache.get(self.default_branch, [0])[-1]:
self._cache_revisions(branch=self.default_branch)
if revision not in self._metadata_cache.get(branch, []):
@@ -403,7 +403,7 @@
self._cache_revisions(branch=branch)
identifier = self._commit_count(revision=revision, branch=branch)
- branch_point = None if branch == self.default_branch else self._commit_count(branch=branch)
+ branch_point = None if not include_identifier or branch == self.default_branch else self._commit_count(branch=branch)
if branch_point and parsed_branch_point and branch_point != parsed_branch_point:
raise ValueError("Provided 'branch_point' does not match branch point of specified branch")
@@ -439,7 +439,7 @@
return Commit(
revision=int(revision),
branch=branch,
- identifier=identifier,
+ identifier=identifier if include_identifier else None,
branch_point=branch_point,
timestamp=int(calendar.timegm(date.timetuple())) if date else None,
author=author,
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/scm_base.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -66,7 +66,7 @@
def tags(self):
raise NotImplementedError()
- def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True):
+ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True, include_identifier=True):
raise NotImplementedError()
def prioritize_branches(self, branches):
@@ -88,7 +88,7 @@
filtered_candidates = branches
return sorted(filtered_candidates)[0]
- def find(self, argument, include_log=True):
+ def find(self, argument, include_log=True, include_identifier=True):
if not isinstance(argument, six.string_types):
raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
@@ -104,13 +104,13 @@
argument = self.default_branch
if argument == 'HEAD':
- result = self.commit(include_log=include_log)
+ result = self.commit(include_log=include_log, include_identifier=include_identifier)
elif argument in self.branches:
- result = self.commit(branch=argument, include_log=include_log)
+ result = self.commit(branch=argument, include_log=include_log, include_identifier=include_identifier)
elif argument in self.tags:
- result = self.commit(tag=argument, include_log=include_log)
+ result = self.commit(tag=argument, include_log=include_log, include_identifier=include_identifier)
else:
if offset:
@@ -126,6 +126,7 @@
identifier=parsed_commit.identifier,
branch=parsed_commit.branch,
include_log=include_log,
+ include_identifier=include_identifier,
)
if not offset:
@@ -135,6 +136,7 @@
identifier=result.identifier - offset,
branch=result.branch,
include_log=include_log,
+ include_identifier=include_identifier,
)
@classmethod
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -272,6 +272,12 @@
self.assertEqual(str(local.Git(self.path).find('4@trunk')), '4@main')
self.assertEqual(str(local.Git(self.path).find('4@master')), '4@main')
+ def test_no_identifier(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).find('main', include_identifier=False).identifier)
+
+
class TestGitHub(unittest.TestCase):
remote = 'https://github.example.com/WebKit/webkit'
@@ -380,7 +386,11 @@
self.assertEqual(str(remote.GitHub(self.remote).find('4@trunk')), '4@main')
self.assertEqual(str(remote.GitHub(self.remote).find('4@master')), '4@main')
+ def test_no_identifier(self):
+ with mocks.remote.GitHub():
+ self.assertIsNone(remote.GitHub(self.remote).find('main', include_identifier=False).identifier)
+
class TestBitBucket(unittest.TestCase):
remote = 'https://bitbucket.example.com/projects/WEBKIT/repos/webkit'
@@ -488,3 +498,7 @@
with mocks.remote.BitBucket():
self.assertEqual(str(remote.BitBucket(self.remote).find('4@trunk')), '4@main')
self.assertEqual(str(remote.BitBucket(self.remote).find('4@master')), '4@main')
+
+ def test_no_identifier(self):
+ with mocks.remote.BitBucket():
+ self.assertIsNone(remote.BitBucket(self.remote).find('main', include_identifier=False).identifier)
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py (273436 => 273437)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py 2021-02-24 21:39:38 UTC (rev 273436)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py 2021-02-24 22:02:34 UTC (rev 273437)
@@ -227,7 +227,11 @@
self.assertEqual(str(local.Svn(self.path).find('4@main')), '4@trunk')
self.assertEqual(str(local.Svn(self.path).find('4@master')), '4@trunk')
+ def test_no_identifier(self):
+ with mocks.local.Svn(self.path), OutputCapture():
+ self.assertIsNone(local.Svn(self.path).find('trunk', include_identifier=False).identifier)
+
class TestRemoteSvn(unittest.TestCase):
remote = 'https://svn.example.org/repository/webkit'
@@ -320,3 +324,7 @@
with mocks.remote.Svn():
self.assertEqual(str(remote.Svn(self.remote).find('4@main')), '4@trunk')
self.assertEqual(str(remote.Svn(self.remote).find('4@master')), '4@trunk')
+
+ def test_no_identifier(self):
+ with mocks.remote.Svn():
+ self.assertIsNone(remote.Svn(self.remote).find('trunk', include_identifier=False).identifier)