Title: [293514] trunk/Tools
Revision
293514
Author
jbed...@apple.com
Date
2022-04-27 10:12:06 -0700 (Wed, 27 Apr 2022)

Log Message

[commits.webkit.org] Change branch forwarding behavior
https://bugs.webkit.org/show_bug.cgi?id=239136
<rdar://problem/91314217>

Reviewed by Dewei Zhu.

* Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py: Bump version.
* Tools/Scripts/libraries/reporelaypy/setup.py: Ditto.
* Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py:
(Checkout.Encoder.default): Encode forwarding list.
(Checkout.__init__): Add forwarding argument.
(Checkout.push_update): Add dest_branch argument.
(Checkout.forward_update): Trigger push_update based on forwarding arguments.
(Checkout.update_all): Use forward_update instead of pushing to every branch.
* Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py:
(HookProcessor.process_worker_hook): Extract remote from incoming data, invoke forward_update.
* Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py:
(CheckoutUnittest.test_json):

Canonical link: https://commits.webkit.org/250045@main

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (293513 => 293514)


--- trunk/Tools/ChangeLog	2022-04-27 17:06:09 UTC (rev 293513)
+++ trunk/Tools/ChangeLog	2022-04-27 17:12:06 UTC (rev 293514)
@@ -1,3 +1,24 @@
+2022-04-27  Jonathan Bedard  <jbed...@apple.com>
+
+        [commits.webkit.org] Change branch forwarding behavior
+        https://bugs.webkit.org/show_bug.cgi?id=239136
+        <rdar://problem/91314217>
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/libraries/reporelaypy/reporelaypy/__init__.py: Bump version.
+        * Scripts/libraries/reporelaypy/setup.py: Ditto.
+        * Scripts/libraries/reporelaypy/reporelaypy/checkout.py:
+        (Checkout.Encoder.default): Encode forwarding list.
+        (Checkout.__init__): Add forwarding argument.
+        (Checkout.push_update): Add dest_branch argument.
+        (Checkout.forward_update): Trigger push_update based on forwarding arguments.
+        (Checkout.update_all): Use forward_update instead of pushing to every branch.
+        * Scripts/libraries/reporelaypy/reporelaypy/hooks.py:
+        (HookProcessor.process_worker_hook): Extract remote from incoming data, invoke forward_update.
+        * Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py:
+        (CheckoutUnittest.test_json):
+
 2022-04-27  Kimmo Kinnunen  <kkinnu...@apple.com>
 
         test-webkitperl outputs git hints during the test

Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py (293513 => 293514)


--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py	2022-04-27 17:06:09 UTC (rev 293513)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py	2022-04-27 17:12:06 UTC (rev 293514)
@@ -44,7 +44,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(0, 5, 2)
+version = Version(0, 6, 0)
 
 import webkitflaskpy
 

Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py (293513 => 293514)


--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py	2022-04-27 17:06:09 UTC (rev 293513)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py	2022-04-27 17:12:06 UTC (rev 293514)
@@ -50,6 +50,7 @@
                 url=""
                 sentinal=obj.sentinal,
                 remotes=obj.remotes,
+                forwarding=obj.forwarding,
                 credentials=obj.credentials,
             )
             if obj.fallback_repository:
@@ -104,11 +105,17 @@
         with open(os.path.expanduser('~/.git-credentials'), 'w') as f:
             f.write(git_credentials_content)
 
-    def __init__(self, path, url="" http_proxy=None, sentinal=True, fallback_url=None, primary=True, remotes=None, credentials=None):
+    def __init__(
+        self, path, url="" http_proxy=None,
+        sentinal=True, fallback_url=None, primary=True,
+        remotes=None, credentials=None,
+        forwarding=None,
+    ):
         self.sentinal = sentinal
         self.path = path
         self.url = ""
         self.remotes = remotes or dict()
+        self.forwarding = forwarding or [('origin', list(self.remotes.keys()))]
         self.credentials = credentials or dict()
         self._repository = None
         self._child_process = None
@@ -204,8 +211,8 @@
                 return ref == line.split()[0]
         return False
 
-    def push_update(self, branch=None, tag=None, remote=None, track=False):
-        if not remote or remote in (self.REMOTE, 'fork'):
+    def push_update(self, branch=None, tag=None, remote=None, track=False, dest_branch=None):
+        if not remote or remote in ('fork',):
             return False
 
         if tag:
@@ -219,10 +226,26 @@
             return False
 
         return not run(
-            [self.repository.executable(), 'push', remote, branch, '-f'],
+            [self.repository.executable(), 'push', remote, '{}:{}'.format(branch, dest_branch or branch)],
             cwd=self.repository.root_path,
         ).returncode
 
+    def forward_update(self, branch=None, tag=None, remote=None, track=False):
+        for match, tos in self.forwarding:
+            if match not in (remote, '{}:{}'.format(remote, branch or tag)):
+                continue
+            for to in tos:
+                split = to.split(':', 1)
+                self.push_update(
+                    branch=branch,
+                    tag=tag,
+                    remote=split[0],
+                    track=track,
+                    dest_branch=split[1] if len(split) > 1 else None,
+                )
+            return
+        return
+
     def fetch(self, remote=REMOTE):
         return not run(
             [self.repository.executable(), 'fetch', remote],
@@ -273,7 +296,7 @@
             if branch in all_branches:
                 all_branches.remove(branch)
             self.update_for(branch=branch, remote=remote)
-            [self.push_update(branch=branch, remote=remote) for remote in self.remotes.keys()]
+            self.forward_update(branch=branch, remote=remote)
 
         # Then, track all untracked branches
         print('Tracking new branches...')
@@ -282,7 +305,7 @@
                 [self.repository.executable(), 'branch', '--track', branch, 'remotes/{}/{}'.format(remote, branch)],
                 cwd=self.repository.root_path,
             )
-            [self.push_update(branch=branch, remote=remote) for remote in self.remotes.keys()]
+            self.forward_update(branch=branch, remote=remote)
             self.repository.cache.populate(branch=branch)
 
         # Sync all tags
@@ -295,4 +318,4 @@
             remote_tags = set(self.repository.tags(remote=target_remote))
             for tag in origin_tags - remote_tags:
                 print(f'    {tag}')
-                self.push_update(tag=tag, remote=target_remote)
+                self.forward_update(tag=tag, remote=remote)

Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py (293513 => 293514)


--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py	2022-04-27 17:06:09 UTC (rev 293513)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py	2022-04-27 17:12:06 UTC (rev 293514)
@@ -23,6 +23,7 @@
 import hashlib
 import hmac
 import json
+import re
 import sys
 
 from flask import current_app, json as fjson, request
@@ -39,6 +40,7 @@
     TYPES = ('pull_request', 'push')
     BRANCH_PREFIX = 'refs/heads/'
     TAG_PREFIX = 'refs/tags/'
+    REMOTES_RE = re.compile(r'remote\.(?P<remote>\S+)\.url')
 
     @classmethod
     def is_valid(cls, type, data):
@@ -68,17 +70,27 @@
             return None
 
         branch = data.get('ref')
+        remote = ''
+        name = data.get('repository', {}).get('url', '').split('://')[-1]
+        if name and self.checkout.repository:
+            for config_arg, url in self.checkout.repository.config().items():
+                match = self.REMOTES_RE.match(config_arg)
+                if not match or '{}.git'.format(name) not in [url.split('@')[-1], url.split('://')[-1]]:
+                    continue
+                remote = match.group('remote')
+                break
+
         if type == 'push' and branch:
             try:
                 if branch.startswith(self.BRANCH_PREFIX):
                     branch = branch[len(self.BRANCH_PREFIX):]
                     self.checkout.update_for(branch, track=True)
-                    [self.checkout.push_update(branch=branch, remote=remote, track=True) for remote in self.checkout.remotes.keys()]
+                    self.checkout.forward_update(branch=branch, remote=remote, track=True)
 
                 if branch.startswith(self.TAG_PREFIX):
                     tag = branch[len(self.TAG_PREFIX):]
                     self.checkout.fetch()
-                    [self.checkout.push_update(tag=tag, remote=remote) for remote in self.checkout.remotes.keys()]
+                    self.checkout.forward_update(tag=tag, remote=remote)
 
             except BaseException as e:
                 sys.stderr.write('{}\n'.format(e))

Modified: trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py (293513 => 293514)


--- trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py	2022-04-27 17:06:09 UTC (rev 293513)
+++ trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/checkout_unittest.py	2022-04-27 17:12:06 UTC (rev 293514)
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 Apple Inc. All rights reserved.
+# Copyright (C) 2021-2022 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -54,6 +54,7 @@
                     path=self.path,
                     url=""
                     remotes={},
+                    forwarding=[('origin', [])],
                     credentials={
                         'https://github.com': dict(
                             username='username',

Modified: trunk/Tools/Scripts/libraries/reporelaypy/setup.py (293513 => 293514)


--- trunk/Tools/Scripts/libraries/reporelaypy/setup.py	2022-04-27 17:06:09 UTC (rev 293513)
+++ trunk/Tools/Scripts/libraries/reporelaypy/setup.py	2022-04-27 17:12:06 UTC (rev 293514)
@@ -30,7 +30,7 @@
 
 setup(
     name='reporelaypy',
-    version='0.5.2',
+    version='0.6.0',
     description='Library for visualizing, processing and storing test results.',
     long_description=readme(),
     classifiers=[
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to