Title: [282714] trunk/Tools
Revision
282714
Author
jbed...@apple.com
Date
2021-09-17 17:22:35 -0700 (Fri, 17 Sep 2021)

Log 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.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (282713 => 282714)


--- trunk/Tools/ChangeLog	2021-09-18 00:16:18 UTC (rev 282713)
+++ trunk/Tools/ChangeLog	2021-09-18 00:22:35 UTC (rev 282714)
@@ -1,3 +1,27 @@
+2021-09-17  Jonathan Bedard  <jbed...@apple.com>
+
+        [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.
+
 2021-09-17  Kate Cheney  <katherine_che...@apple.com>
 
         Remove unnecessary ITP memory store code

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (282713 => 282714)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-09-18 00:16:18 UTC (rev 282713)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-09-18 00:22:35 UTC (rev 282714)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='2.2.0',
+    version='2.2.1',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (282713 => 282714)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-09-18 00:16:18 UTC (rev 282713)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-09-18 00:22:35 UTC (rev 282714)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(2, 2, 0)
+version = Version(2, 2, 1)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('monotonic', Version(1, 5)))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py (282713 => 282714)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py	2021-09-18 00:16:18 UTC (rev 282713)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/branch.py	2021-09-18 00:22:35 UTC (rev 282714)
@@ -25,7 +25,7 @@
 
 from .command import Command
 
-from webkitcorepy import run, Terminal
+from webkitcorepy import run, string_utils, Terminal
 from webkitscmpy import local, log
 
 
@@ -33,7 +33,7 @@
     name = 'branch'
     help = 'Create a local development branch from the current checkout state'
 
-    PREFIX = 'eng'
+    PR_PREFIX = 'eng'
 
     @classmethod
     def parser(cls, parser, loggers=None):
@@ -44,12 +44,32 @@
         )
 
     @classmethod
-    def normalize_issue(cls, issue):
-        if not issue or issue.startswith(cls.PREFIX):
-            return issue
-        return '{}/{}'.format(cls.PREFIX, issue)
+    def normalize_branch_name(cls, name, repository=None):
+        if not name or (repository or local.Scm).DEV_BRANCHES.match(name):
+            return name
+        return '{}/{}'.format(cls.PR_PREFIX, name)
 
     @classmethod
+    def editable(cls, branch, repository=None):
+        if (repository or local.Scm).DEV_BRANCHES.match(branch):
+            return True
+        return False
+
+    @classmethod
+    def branch_point(cls, repository):
+        cnt = 0
+        commit = None
+        while not commit or cls.editable(commit.branch, repository=repository):
+            cnt += 1
+            commit = repository.find(argument='HEAD~{}'.format(cnt), include_log=False, include_identifier=False)
+            if cnt > 1 or commit.branch != repository.branch:
+                log.warning('    Found {}...'.format(string_utils.pluralize(cnt, 'commit')))
+            else:
+                log.warning('    No commits on editable branch')
+
+        return commit
+
+    @classmethod
     def main(cls, args, repository, **kwargs):
         if not isinstance(repository, local.Git):
             sys.stderr.write("Can only 'branch' on a native Git repository\n")
@@ -57,7 +77,7 @@
 
         if not args.issue:
             args.issue = Terminal.input('Branch name: ')
-        args.issue = cls.normalize_issue(args.issue)
+        args.issue = cls.normalize_branch_name(args.issue)
 
         if run([repository.executable(), 'check-ref-format', args.issue], capture_output=True).returncode:
             sys.stderr.write("'{}' is an invalid branch name, cannot create it\n".format(args.issue))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py (282713 => 282714)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py	2021-09-18 00:16:18 UTC (rev 282713)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py	2021-09-18 00:22:35 UTC (rev 282714)
@@ -22,8 +22,8 @@
 
 import sys
 
+from .branch import Branch
 from .command import Command
-from .pull_request import PullRequest
 from webkitscmpy import local
 
 
@@ -39,6 +39,6 @@
             return 1
 
         if isinstance(repository, local.Git):
-            branch_point = PullRequest.branch_point(args, repository, **kwargs)
+            branch_point = Branch.branch_point(repository)
             return repository.pull(rebase=True, branch=branch_point.branch)
         return repository.pull()

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py (282713 => 282714)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2021-09-18 00:16:18 UTC (rev 282713)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull_request.py	2021-09-18 00:22:35 UTC (rev 282714)
@@ -25,7 +25,7 @@
 from .command import Command
 from .branch import Branch
 
-from webkitcorepy import arguments, run, string_utils
+from webkitcorepy import arguments, run
 from webkitscmpy import local, log, remote
 
 
@@ -82,23 +82,12 @@
         return 0
 
     @classmethod
-    def branch_point(cls, args, repository, **kwargs):
-        cnt = 0
-        commit = None
-        while not commit or commit.branch.startswith(Branch.PREFIX):
-            cnt += 1
-            commit = repository.find(argument='HEAD~{}'.format(cnt), include_log=False, include_identifier=False)
-            log.warning('    Found {}...'.format(string_utils.pluralize(cnt, 'commit')))
-
-        return commit
-
-    @classmethod
     def main(cls, args, repository, **kwargs):
         if not isinstance(repository, local.Git):
             sys.stderr.write("Can only '{}' on a native Git repository\n".format(cls.name))
             return 1
 
-        if not repository.branch.startswith(Branch.PREFIX):
+        if not repository.DEV_BRANCHES.match(repository.branch):
             if Branch.main(args, repository, **kwargs):
                 sys.stderr.write("Abandoning pushing pull-request because '{}' could not be created\n".format(args.issue))
                 return 1
@@ -110,7 +99,7 @@
         if result:
             return result
 
-        branch_point = cls.branch_point(args, repository, **kwargs)
+        branch_point = Branch.branch_point(repository)
         if args.rebase or (args.rebase is None and repository.config().get('pull.rebase')):
             log.warning("Rebasing '{}' on '{}'...".format(repository.branch, branch_point.branch))
             if repository.pull(rebase=True, branch=branch_point.branch):
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to