Skip to content

Commit

Permalink
[git-webkit] Support —oneline in log command
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=238209
<rdar://problem/90660142>

Reviewed by Dewei Zhu.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py:
(FilteredCommand): Header lines don't always start with 'commit'
(FilteredCommand.main): Handle --online output
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/log.py:
(Log):
(Log.parser): Add various `git log` options.
(Log.main): Forward `git log` options.


Canonical link: https://commits.webkit.org/248944@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291987 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Mar 28, 2022
1 parent a309ccc commit b1079a1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 13 deletions.
18 changes: 18 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,21 @@
2022-03-28 Jonathan Bedard <jbedard@apple.com>

[git-webkit] Support —oneline in log command
https://bugs.webkit.org/show_bug.cgi?id=238209
<rdar://problem/90660142>

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py:
(FilteredCommand): Header lines don't always start with 'commit'
(FilteredCommand.main): Handle --online output
* Scripts/libraries/webkitscmpy/webkitscmpy/program/log.py:
(Log):
(Log.parser): Add various `git log` options.
(Log.main): Forward `git log` options.

2022-03-28 Devin Rousso <drousso@apple.com>

[iOS] Add `WKWebView` API to control CSS "small viewport" `sv*` and "large viewport" `lv*` units
Expand Down
2 changes: 1 addition & 1 deletion Tools/Scripts/libraries/webkitscmpy/setup.py
Expand Up @@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='4.5.1',
version='4.6.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(4, 5, 1)
version = Version(4, 6, 0)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
Expand Down
37 changes: 27 additions & 10 deletions Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/command.py
Expand Up @@ -54,7 +54,7 @@ class FilteredCommand(Command):
HASH = 'hash'
REVISION = 'revision'

GIT_HEADER_RE = re.compile(r'^commit (?P<hash>[a-f0-9A-F]+)')
GIT_HEADER_RE = re.compile(r'^(commit )?(?P<hash>[a-f0-9A-F]+)')
SVN_HEADER_RE = re.compile(r'^(?P<revision>r/d+) | ')

REVISION_RES = (re.compile(r'^(?P<revision>\d+)\s'), re.compile(r'(?P<revision>[rR]\d+)'))
Expand Down Expand Up @@ -211,9 +211,9 @@ def replace_line(match, mode=cls.APPEND_MODE, **kwargs):
if representation == 'hash':
reference = reference[:Commit.HASH_LABEL_SIZE]
if mode == cls.APPEND_MODE:
reference = '{} ({})'.format(match.group(1), reference)
reference = '{} ({})'.format(match.groups()[-1], reference)
if mode == cls.HEADER_MODE:
alternates = [] if match.group(1).startswith(reference) else [match.group(1)]
alternates = [] if match.groups()[-1].startswith(reference) else [match.groups()[-1]]
for repr in {'revision', 'hash', 'identifier'} - {'hash' if repository.is_git else 'revision', representation}:
if repr in kwargs:
continue
Expand All @@ -224,7 +224,7 @@ def replace_line(match, mode=cls.APPEND_MODE, **kwargs):
other = other[:Commit.HASH_LABEL_SIZE]
alternates.append('r{}'.format(other) if isinstance(other, int) else other)
reference = '{} ({})'.format(reference, ', '.join(alternates))
return match.group(0).replace(match.group(1), reference)
return match.group(0).replace(match.groups()[-1], reference)
return match.group(0)

res = {}
Expand All @@ -241,23 +241,40 @@ def replace_line(match, mode=cls.APPEND_MODE, **kwargs):
line = log_output.stdout.readline()
while line:
header = header_re.sub(
lambda match: replace_line(match, mode=cls.HEADER_MODE, **{'hash' if repository.is_git else 'revision': match.group(1)}),
lambda match: replace_line(match, mode=cls.HEADER_MODE, **{'hash' if repository.is_git else 'revision': match.groups()[-1]}),
line,
)
if header != line:
index = 2 if header.startswith('commit') else 1
header = header.split(' ')
with Terminal.Style(color=Terminal.Text.yellow, style=Terminal.Text.bold).apply(sys.stdout):
sys.stdout.write(' '.join(header.split(' ')[:2]))

sys.stdout.write(' ')
sys.stdout.write(' '.join(header[:index]))

if index < len(header):
sys.stdout.write(' ')
in_red = index
while in_red < len(header):
if len(header[in_red]) < 2:
break
if header[in_red][-1] == ',':
in_red += 1
continue
if header[in_red][-1] == ')' or header[in_red][-2] == ')':
in_red += 1
break
with Terminal.Style(color=Terminal.Text.red).apply(sys.stdout):
sys.stdout.write(' '.join(header.split(' ')[2:]))
sys.stdout.write(' '.join(header[index:in_red]))

if in_red < len(header):
sys.stdout.write(' ')
sys.stdout.write(' '.join(header[in_red:]))

line = log_output.stdout.readline()
continue

for repr, regexs in res.items():
line = regexs[0].sub(
lambda match: replace_line(match, mode=cls.REPLACE_MODE, **{repr: match.group(1)}),
lambda match: replace_line(match, mode=cls.REPLACE_MODE, **{repr: match.group()[-1]}),
line,
)

Expand Down
64 changes: 63 additions & 1 deletion Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/log.py
Expand Up @@ -24,7 +24,7 @@

import sys

from webkitcorepy import Terminal
from webkitcorepy import arguments, Terminal
from webkitscmpy import local
from webkitscmpy.program.command import FilteredCommand

Expand All @@ -33,10 +33,72 @@ class Log(FilteredCommand):
name = 'log'
help = "Filter raw output of 'git log' or 'svn log' to replace native commit representation with identifiers"

@classmethod
def parser(cls, parser, loggers=None):
FilteredCommand.parser(parser, loggers=loggers)
parser.add_argument(
'--max-count', '-n', type=int,
help='Limit the number of commits to output.',
dest='max_count',
default=None,
)
parser.add_argument(
'--skip', type=int,
help='Skip number commits before starting to show the commit output.',
dest='skip',
default=None,
)
parser.add_argument(
'--pretty', '--format', type=str,
help='Pretty-print the contents of the commit logs in a given format, where <format> can be\n'
'one of oneline, short, medium, full, fuller, reference, email, raw, format:<string> and\n'
'tformat:<string>. When <format> is none of the above, and has %%placeholder in it, it\n'
'acts as if --pretty=tformat:<format> were given.\n\n'
'See the "PRETTY FORMATS" section for some additional details for each format. When\n'
'=<format> part is omitted, it defaults to medium.\n\n'
'Note: you can specify the default pretty format in the repository configuration (see\n'
'git-config(1)).',
dest='pretty',
default=None,
)
parser.add_argument(
'--abbrev-commit', '--no-abbrev-commit',
help='Instead of showing the full 40-byte hexadecimal commit object name, show a prefix that\n'
'names the object uniquely. "--abbrev=<n>" (which also modifies diff output, if it is\n'
'displayed) option can be used to specify the minimum length of the prefix.',
action=arguments.NoAction,
dest='abbrev_commit',
default=None,
)
parser.add_argument(
'--oneline',
help='This is a shorthand for "--pretty=oneline --abbrev-commit" used together.',
action='store_true',
dest='oneline',
default=None,
)

@classmethod
def main(cls, args, repository, **kwargs):
config = getattr(repository, 'config', lambda: {})()
Terminal.colors = config.get('color.diff', config.get('color.ui', 'auto')) != 'false'

max_count = getattr(args, 'max_count', None)
if max_count:
args.args.insert(0, '--max-count={}'.format(max_count))
skip = getattr(args, 'skip', None)
if skip:
args.args.insert(0, '--skip={}'.format(skip))
pretty = getattr(args, 'pretty', None)
if pretty:
args.args.insert(0, '--pretty={}'.format(pretty))
abbrev_commit = getattr(args, 'abbrev_commit', None)
if abbrev_commit is not None:
args.args.insert(0, '--abbrev-commit' if abbrev_commit else '--no-abbrev-commit')
oneline = getattr(args, 'oneline', None)
if oneline is not None:
args.args.insert(0, '--oneline')

return cls.pager(args, repository, file=__file__, **kwargs)


Expand Down

0 comments on commit b1079a1

Please sign in to comment.