Title: [274771] trunk/Tools
Revision
274771
Author
[email protected]
Date
2021-03-22 12:02:52 -0700 (Mon, 22 Mar 2021)

Log Message

[webkitscmpy] Allow user to force canonicalization for a specific set of commits
https://bugs.webkit.org/show_bug.cgi?id=223579
<rdar://problem/75693154>

Reviewed by Aakash Jain.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/canonicalize/__init__.py:
(Canonicalize.parser): Add --number argument.
(Canonicalize.main): Use --number to set the number of commits to be canonicalized.
* Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py:
(TestCanonicalize.test_number):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (274770 => 274771)


--- trunk/Tools/ChangeLog	2021-03-22 19:01:56 UTC (rev 274770)
+++ trunk/Tools/ChangeLog	2021-03-22 19:02:52 UTC (rev 274771)
@@ -1,3 +1,19 @@
+2021-03-22  Jonathan Bedard  <[email protected]>
+
+        [webkitscmpy] Allow user to force canonicalization for a specific set of commits
+        https://bugs.webkit.org/show_bug.cgi?id=223579
+        <rdar://problem/75693154>
+
+        Reviewed by Aakash Jain.
+
+        * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/program/canonicalize/__init__.py:
+        (Canonicalize.parser): Add --number argument.
+        (Canonicalize.main): Use --number to set the number of commits to be canonicalized.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py:
+        (TestCanonicalize.test_number):
+
 2021-03-22  Tyler Wilcock  <[email protected]>
 
         AppleWin can't start due to "Failed to determine path to AAS directory." because iTunes changed the registry key

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (274770 => 274771)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-03-22 19:01:56 UTC (rev 274770)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2021-03-22 19:02:52 UTC (rev 274771)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='0.13.4',
+    version='0.13.5',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (274770 => 274771)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-03-22 19:01:56 UTC (rev 274770)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2021-03-22 19:02:52 UTC (rev 274771)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(0, 13, 4)
+version = Version(0, 13, 5)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('monotonic', Version(1, 5)))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/canonicalize/__init__.py (274770 => 274771)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/canonicalize/__init__.py	2021-03-22 19:01:56 UTC (rev 274770)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/canonicalize/__init__.py	2021-03-22 19:02:52 UTC (rev 274771)
@@ -56,6 +56,12 @@
             dest='remote',
             default='origin',
         )
+        output_args.add_argument(
+            '--number', '-n',  type=int,
+            help='Number of commits to be canonicalized, regardless of the state of the remote',
+            dest='number',
+            default=None,
+        )
 
     @classmethod
     def main(cls, args, repository, identifier_template=None, **kwargs):
@@ -70,21 +76,24 @@
         if not branch:
             sys.stderr.write('Failed to determine current branch\n')
             return -1
-        result = run([
-            repository.executable(), 'rev-list',
-            '--count', '--no-merges',
-            '{remote}/{branch}..{branch}'.format(remote=args.remote, branch=branch),
-        ], capture_output=True, cwd=repository.root_path)
-        if result.returncode:
-            sys.stderr.write('Failed to find local commits\n')
-            return -1
-        difference = int(result.stdout.rstrip())
-        if difference <= 0:
+
+        num_commits_to_canonicalize = args.number
+        if not num_commits_to_canonicalize:
+            result = run([
+                repository.executable(), 'rev-list',
+                '--count', '--no-merges',
+                '{remote}/{branch}..{branch}'.format(remote=args.remote, branch=branch),
+            ], capture_output=True, cwd=repository.root_path)
+            if result.returncode:
+                sys.stderr.write('Failed to find local commits\n')
+                return -1
+            num_commits_to_canonicalize = int(result.stdout.rstrip())
+        if num_commits_to_canonicalize <= 0:
             print('No local commits to be edited')
             return 0
-        log.warning('{} to be editted...'.format(string_utils.pluralize(difference, 'commit')))
+        log.warning('{} to be editted...'.format(string_utils.pluralize(num_commits_to_canonicalize, 'commit')))
 
-        base = repository.find('{}~{}'.format(branch, difference))
+        base = repository.find('{}~{}'.format(branch, num_commits_to_canonicalize))
         log.info('Base commit is {} (ref {})'.format(base, base.hash))
 
         log.debug('Saving contributors to temp file to be picked up by child processes')
@@ -148,6 +157,6 @@
         finally:
             os.remove(contributors)
 
-        print('{} successfully canonicalized!'.format(string_utils.pluralize(difference, 'commit')))
+        print('{} successfully canonicalized!'.format(string_utils.pluralize(num_commits_to_canonicalize, 'commit')))
 
         return 0

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py (274770 => 274771)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py	2021-03-22 19:01:56 UTC (rev 274770)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/canonicalize_unittest.py	2021-03-22 19:02:52 UTC (rev 274771)
@@ -198,3 +198,26 @@
             'Rewrite 0148c0df0faf248aa133d6d5ad911d7cb1b56a5b (2/2) (--- seconds passed, remaining --- predicted)\n'
             '2 commits successfully canonicalized!\n',
         )
+
+    def test_number(self):
+        with OutputCapture() as captured, mocks.local.Git(self.path) as mock, mocks.local.Svn(), MockTime:
+            contirbutors = Contributor.Mapping()
+            contirbutors.create('Jonathan Bedard', '[email protected]')
+
+            self.assertEqual(0, program.main(
+                args=('canonicalize', '--number', '3'),
+                path=self.path,
+                contributors=contirbutors,
+            ))
+
+            self.assertEqual(local.Git(self.path).commit(identifier='5@main').message, 'Patch Series\nIdentifier: 5@main')
+            self.assertEqual(local.Git(self.path).commit(identifier='4@main').message, '8th commit\nIdentifier: 4@main')
+            self.assertEqual(local.Git(self.path).commit(identifier='3@main').message, '4th commit\nIdentifier: 3@main')
+
+        self.assertEqual(
+            captured.stdout.getvalue(),
+            'Rewrite 1abe25b443e985f93b90d830e4a7e3731336af4d (1/3) (--- seconds passed, remaining --- predicted)\n'
+            'Rewrite bae5d1e90999d4f916a8a15810ccfa43f37a2fd6 (2/3) (--- seconds passed, remaining --- predicted)\n'
+            'Rewrite d8bce26fa65c6fc8f39c17927abb77f69fab82fc (3/3) (--- seconds passed, remaining --- predicted)\n'
+            '3 commits successfully canonicalized!\n',
+        )
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to