Skip to content
Permalink
Browse files
[webkitscmpy] Allow caller to differentiate remote branches
https://bugs.webkit.org/show_bug.cgi?id=231450
<rdar://problem/84042400>

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.branches): Change _branches_for to branches_for.
(Git.branches_for): Allow call to differentiate remote branches
to be returned, or return dictionary of all remotes.
(Git.commit): Change _branches_for to branches_for.
(Git._branches_for): Renamed branches_for.


Canonical link: https://commits.webkit.org/242726@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Oct 8, 2021
1 parent 852089d commit 0fc46d18873a53e040ac94f41a02795be37e2ddc
Showing 4 changed files with 40 additions and 8 deletions.
@@ -1,3 +1,20 @@
2021-10-08 Jonathan Bedard <jbedard@apple.com>

[webkitscmpy] Allow caller to differentiate remote branches
https://bugs.webkit.org/show_bug.cgi?id=231450
<rdar://problem/84042400>

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.branches): Change _branches_for to branches_for.
(Git.branches_for): Allow call to differentiate remote branches
to be returned, or return dictionary of all remotes.
(Git.commit): Change _branches_for to branches_for.
(Git._branches_for): Renamed branches_for.

2021-10-08 Michael Catanzaro <mcatanzaro@gnome.org>

Ensure webkitpy secret storage works successfully on Linux using only autoinstalled libraries
@@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='2.2.7',
version='2.2.8',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
@@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path():
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)

version = Version(2, 2, 7)
version = Version(2, 2, 8)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('monotonic', Version(1, 5)))
@@ -31,6 +31,7 @@
import time

from datetime import datetime, timedelta
from collections import defaultdict

from webkitcorepy import run, decorators, NestedFuzzyDict
from webkitscmpy.local import Scm
@@ -275,6 +276,7 @@ def to_identifier(self, hash=None, revision=None, populate=True, branch=None):
GIT_COMMIT = re.compile(r'commit (?P<hash>[0-9a-f]+)')
SSH_REMOTE = re.compile('(ssh://)?git@(?P<host>[^:/]+)[:/](?P<path>.+).git')
HTTP_REMOTE = re.compile('(?P<protocol>https?)://(?P<host>.+)/(?P<path>.+).git')
REMOTE_BRANCH = re.compile(r'remotes\/(?P<remote>[^\/]+)\/(?P<branch>.+)')

@classmethod
@decorators.Memoize()
@@ -388,7 +390,7 @@ def branch(self):

@property
def branches(self):
return self._branches_for()
return self.branches_for()

@property
def tags(self):
@@ -434,7 +436,7 @@ def _commit_count(self, native_parameter):
raise self.Exception('Failed to retrieve revision count for {}'.format(native_parameter))
return int(revision_count.stdout)

def _branches_for(self, hash=None):
def branches_for(self, hash=None, remote=True):
branch = run(
[self.executable(), 'branch', '-a'] + (['--contains', hash] if hash else []),
cwd=self.root_path,
@@ -443,8 +445,21 @@ def _branches_for(self, hash=None):
)
if branch.returncode:
raise self.Exception('Failed to retrieve branch list for {}'.format(self.root_path))
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]))
result = defaultdict(set)
for branch in [branch.lstrip(' *') for branch in filter(lambda branch: '->' not in branch, branch.stdout.splitlines())]:
match = self.REMOTE_BRANCH.match(branch)
if match:
result[match.group('remote')].add(match.group('branch'))
else:
result[None].add(branch)

if remote is False:
return sorted(result[None])
if remote is True:
return sorted(set.union(*result.values()))
if isinstance(remote, str):
return sorted(result[remote])
return result

def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True, include_identifier=True):
# Only git-svn checkouts can convert revisions to fully qualified commits, unless we happen to have a SVN cache built
@@ -514,7 +529,7 @@ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=Non
baseline = branch or 'HEAD'
is_default = baseline == default_branch
if baseline == 'HEAD':
is_default = default_branch in self._branches_for(baseline)
is_default = default_branch in self.branches_for(baseline)

if is_default and parsed_branch_point:
raise self.Exception('Cannot provide a branch point for a commit on the default branch')
@@ -565,7 +580,7 @@ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=Non
branch_point = None
# A commit is often on multiple branches, the canonical branch is the one with the highest priority
if branch != default_branch:
branch = self.prioritize_branches(self._branches_for(hash))
branch = self.prioritize_branches(self.branches_for(hash))

if not identifier and include_identifier:
cached_identifier = self.cache.to_identifier(hash=hash, branch=branch) if self.cache else None

0 comments on commit 0fc46d1

Please sign in to comment.