Skip to content

Commit

Permalink
[git-webkit] Prune remotes when fetching
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=247620
rdar://102090699

Reviewed by Elliott Williams.

* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git): Add an auto-prune option.
(Git.checkout): Add prune argument.
(Git.fetch): Add prune argument, use config default if not specified.
(Git.pull): Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/checkout.py:
(Checkout.parser): Add --prune argument.
(Checkout.main): Pass prune argument to 'checkout'.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py:
(Pull.parser): Add --prune argument.
(Pull.main): Pass prune argument to 'checkout'.

Canonical link: https://commits.webkit.org/257514@main
  • Loading branch information
JonWBedard committed Dec 7, 2022
1 parent fdb483c commit bdb212d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Tools/Scripts/libraries/webkitscmpy/setup.py
Expand Up @@ -29,7 +29,7 @@ def readme():

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

version = Version(5, 8, 3)
version = Version(5, 9, 0)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
Expand Down
32 changes: 22 additions & 10 deletions Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py
Expand Up @@ -322,6 +322,7 @@ def to_identifier(self, hash=None, revision=None, populate=True, branch=None):
'webkitscmpy.update-fork': ['true', 'false'],
'webkitscmpy.auto-check': ['true', 'false'],
'webkitscmpy.auto-create-commit': ['true', 'false'],
'webkitscmpy.auto-prune': ['only-source', 'true', 'false'],
}
CONFIG_LOCATIONS = ['global', 'repository', 'project']

Expand Down Expand Up @@ -942,7 +943,7 @@ def _to_git_ref(self, argument):
pass
return argument

def checkout(self, argument):
def checkout(self, argument, prune=None):
self._branch = None

if log.level > logging.WARNING:
Expand Down Expand Up @@ -987,7 +988,13 @@ def checkout(self, argument):
if not rc:
return self.commit()
if rc == 128:
run([self.executable(), 'fetch', name], cwd=self.root_path)
command = [self.executable(), 'fetch', name]
if prune is None:
if self.config()['webkitscmpy.auto-prune'] == 'true':
command.append('--prune')
elif name in self.source_remotes() and self.config()['webkitscmpy.auto-prune'] == 'only-source':
command.append('--prune')
run(command, cwd=self.root_path)
return None if run(
[self.executable(), 'checkout'] + ['-B', branch, '{}/{}'.format(name, branch)] + log_arg,
cwd=self.root_path,
Expand Down Expand Up @@ -1028,19 +1035,24 @@ def rebase(self, target, base=None, head='HEAD', recommit=True):
), 'refs/heads/{}...{}'.format(target, head),
], cwd=self.root_path, env={'FILTER_BRANCH_SQUELCH_WARNING': '1'}, capture_output=True).returncode

def fetch(self, branch, remote=None):
return run(
[self.executable(), 'fetch', remote or self.default_remote, '{}:{}'.format(branch, branch)],
cwd=self.root_path,
).returncode

def pull(self, rebase=None, branch=None, remote=None):
def fetch(self, branch, remote=None, prune=None):
remote = remote or self.default_remote
if prune is None and self.config()['webkitscmpy.auto-prune'] == 'true':
prune = True
elif prune is None and self.config()['webkitscmpy.auto-prune'] == 'only-source':
prune = remote in self.source_remotes()
command = [self.executable(), 'fetch', remote, '{}:{}'.format(branch, branch)]
if prune:
command.append('--prune')
return run(command, cwd=self.root_path).returncode

def pull(self, rebase=None, branch=None, remote=None, prune=None):
remote = remote or self.default_remote
commit = self.commit() if self.is_svn or branch else None

code = 0
if branch and self.branch != branch:
code = self.fetch(branch=branch, remote=remote)
code = self.fetch(branch=branch, remote=remote, prune=prune)
if not code:
command = [self.executable(), 'pull'] + ([remote, branch] if branch else [])
if rebase is True:
Expand Down
Expand Up @@ -24,6 +24,7 @@
import sys

from .command import Command
from webkitcorepy import arguments
from webkitscmpy import local, log, remote


Expand All @@ -45,6 +46,12 @@ def parser(cls, parser, loggers=None):
'--remote', dest='remote', type=str, default=None,
help='Specify remote to search for pull request from.',
)
parser.add_argument(
'--prune', '--no-prune',
dest='prune', default=None,
help='Prune deleted branches on the tracking remote when fetching',
action=arguments.NoAction,
)

@classmethod
def main(cls, args, repository, **kwargs):
Expand Down Expand Up @@ -81,7 +88,13 @@ def main(cls, args, repository, **kwargs):
return 1

try:
commit = repository.checkout(target)
if isinstance(repository, local.Git):
commit = repository.checkout(target, prune=args.prune)
elif args.prune is not None:
sys.stderr.write("'prune' arguments only valid for 'git' checkouts\n")
return 1
else:
commit = repository.checkout(target)
except (local.Scm.Exception, ValueError) as exception:
# ValueErrors and Scm exceptions usually contain enough information to be displayed
# to the user as an error
Expand Down
15 changes: 14 additions & 1 deletion Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/pull.py
Expand Up @@ -24,6 +24,7 @@

from .branch import Branch
from .command import Command
from webkitcorepy import arguments
from webkitscmpy import local


Expand All @@ -32,6 +33,15 @@ class Pull(Command):
aliases = ['up', 'update']
help = 'Update the current checkout, synchronize git-svn if configured'

@classmethod
def parser(cls, parser, loggers=None):
parser.add_argument(
'--prune', '--no-prune',
dest='prune', default=None,
help='Prune deleted branches on the tracking remote when fetching',
action=arguments.NoAction,
)

@classmethod
def main(cls, args, repository, **kwargs):
if not repository:
Expand All @@ -49,5 +59,8 @@ def main(cls, args, repository, **kwargs):
if rmt in bp_remotes:
remote = rmt
break
return repository.pull(rebase=True, branch=branch_point.branch, remote=remote)
return repository.pull(rebase=True, branch=branch_point.branch, remote=remote, prune=args.prune)
if args.prune is not None:
sys.stderr.write("'prune' arguments only valid for 'git' checkouts\n")
return 1
return repository.pull()

0 comments on commit bdb212d

Please sign in to comment.