⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 282714 in webkit


Ignore:
Timestamp:
Sep 17, 2021, 5:22:35 PM (5 years ago)
Author:
Jonathan Bedard
Message:

[webkitscmpy] Refactor PR branch management
​https://bugs.webkit.org/show_bug.cgi?id=230432
<rdar://problem/83258413>

Reviewed by Stephanie Lewis.

  • Scripts/libraries/webkitscmpy/setup.py: Bump version.
  • Scripts/libraries/webkitscmpy/webkitscmpy/init.py: Ditto.
  • Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py:

(Branch): Specify that the 'eng' prefix is for pull-requests.
(Branch.normalize_branch_name): Normalized branch names should consider other developement prefixes.
(Branch.editable): Check if a branch is editable. Only includes development branches at the moment,
will include commit-queue in the near future.
(Branch.branch_point): Moved from pull_request.py.
(Branch.main):
(Branch.normalize_issue): Renamed normalize_branch_name.

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

(Pull.main): branch_point is now owned Branch command.

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

(PullRequest.main): Match DEV_BRANCHES instead of PREFIX, branch_point is now owned Branch command.
(PullRequest.branch_point): Moved to branch.py.

Location:
trunk/Tools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r282711 r282714  
     12021-09-17  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [webkitscmpy] Refactor PR branch management
     4        https://bugs.webkit.org/show_bug.cgi?id=230432
     5        <rdar://problem/83258413>
     6
     7        Reviewed by Stephanie Lewis.
     8
     9        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
     10        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
     11        * Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py:
     12        (Branch): Specify that the 'eng' prefix is for pull-requests.
     13        (Branch.normalize_branch_name): Normalized branch names should consider other developement prefixes.
     14        (Branch.editable): Check if a branch is editable. Only includes development branches at the moment,
     15        will include commit-queue in the near future.
     16        (Branch.branch_point): Moved from pull_request.py.
     17        (Branch.main):
     18        (Branch.normalize_issue): Renamed normalize_branch_name.
     19        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py:
     20        (Pull.main): branch_point is now owned Branch command.
     21        * Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py:
     22        (PullRequest.main): Match DEV_BRANCHES instead of PREFIX, branch_point is now owned Branch command.
     23        (PullRequest.branch_point): Moved to branch.py.
     24
    1252021-09-17  Kate Cheney  <katherine_cheney@apple.com>
    226
  • trunk/Tools/Scripts/libraries/webkitscmpy/setup.py

    r282409 r282714  
    3030setup(
    3131    name='webkitscmpy',
    32     version='2.2.0',
     32    version='2.2.1',
    3333    description='Library designed to interact with git and svn repositories.',
    3434    long_description=readme(),
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py

    r282409 r282714  
    4747    )
    4848
    49 version = Version(2, 2, 0)
     49version = Version(2, 2, 1)
    5050
    5151AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py

    r281363 r282714  
    2626from .command import Command
    2727
    28 from webkitcorepy import run, Terminal
     28from webkitcorepy import run, string_utils, Terminal
    2929from webkitscmpy import local, log
    3030
    … …  
    3434    help = 'Create a local development branch from the current checkout state'
    3535
    36     PREFIX = 'eng'
     36    PR_PREFIX = 'eng'
    3737
    3838    @classmethod
    … …  
    4545
    4646    @classmethod
    47     def normalize_issue(cls, issue):
    48         if not issue or issue.startswith(cls.PREFIX):
    49             return issue
    50         return '{}/{}'.format(cls.PREFIX, issue)
     47    def normalize_branch_name(cls, name, repository=None):
     48        if not name or (repository or local.Scm).DEV_BRANCHES.match(name):
     49            return name
     50        return '{}/{}'.format(cls.PR_PREFIX, name)
     51
     52    @classmethod
     53    def editable(cls, branch, repository=None):
     54        if (repository or local.Scm).DEV_BRANCHES.match(branch):
     55            return True
     56        return False
     57
     58    @classmethod
     59    def branch_point(cls, repository):
     60        cnt = 0
     61        commit = None
     62        while not commit or cls.editable(commit.branch, repository=repository):
     63            cnt += 1
     64            commit = repository.find(argument='HEAD~{}'.format(cnt), include_log=False, include_identifier=False)
     65            if cnt > 1 or commit.branch != repository.branch:
     66                log.warning('    Found {}...'.format(string_utils.pluralize(cnt, 'commit')))
     67            else:
     68                log.warning('    No commits on editable branch')
     69
     70        return commit
    5171
    5272    @classmethod
    … …  
    5878        if not args.issue:
    5979            args.issue = Terminal.input('Branch name: ')
    60         args.issue = cls.normalize_issue(args.issue)
     80        args.issue = cls.normalize_branch_name(args.issue)
    6181
    6282        if run([repository.executable(), 'check-ref-format', args.issue], capture_output=True).returncode:
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py

    r281821 r282714  
    2323import sys
    2424
     25from .branch import Branch
    2526from .command import Command
    26 from .pull_request import PullRequest
    2727from webkitscmpy import local
    2828
    … …  
    4040
    4141        if isinstance(repository, local.Git):
    42             branch_point = PullRequest.branch_point(args, repository, **kwargs)
     42            branch_point = Branch.branch_point(repository)
    4343            return repository.pull(rebase=True, branch=branch_point.branch)
    4444        return repository.pull()
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py

    r282404 r282714  
    2626from .branch import Branch
    2727
    28 from webkitcorepy import arguments, run, string_utils
     28from webkitcorepy import arguments, run
    2929from webkitscmpy import local, log, remote
    3030
    … …  
    8383
    8484    @classmethod
    85     def branch_point(cls, args, repository, **kwargs):
    86         cnt = 0
    87         commit = None
    88         while not commit or commit.branch.startswith(Branch.PREFIX):
    89             cnt += 1
    90             commit = repository.find(argument='HEAD~{}'.format(cnt), include_log=False, include_identifier=False)
    91             log.warning('    Found {}...'.format(string_utils.pluralize(cnt, 'commit')))
    92 
    93         return commit
    94 
    95     @classmethod
    9685    def main(cls, args, repository, **kwargs):
    9786        if not isinstance(repository, local.Git):
    … …  
    9988            return 1
    10089
    101         if not repository.branch.startswith(Branch.PREFIX):
     90        if not repository.DEV_BRANCHES.match(repository.branch):
    10291            if Branch.main(args, repository, **kwargs):
    10392                sys.stderr.write("Abandoning pushing pull-request because '{}' could not be created\n".format(args.issue))
    … …  
    111100            return result
    112101
    113         branch_point = cls.branch_point(args, repository, **kwargs)
     102        branch_point = Branch.branch_point(repository)
    114103        if args.rebase or (args.rebase is None and repository.config().get('pull.rebase')):
    115104            log.warning("Rebasing '{}' on '{}'...".format(repository.branch, branch_point.branch))
Note: See TracChangeset for help on using the changeset viewer.