Skip to content
Permalink
Browse files
[git-webkit] Use --date=unix in log commands
https://bugs.webkit.org/show_bug.cgi?id=240537
<rdar://93464544>

Reviewed by Stephanie Lewis.

Override any local configuration for git log's date format,
use a simpler date format.

* Tools/Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git.Cache.populate): Use --date=unix.
(Git.commit): Ditto.
(Git._args_from_content): Parse --date=unix.
(Git.commits): Use --date=unix.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py:
(TestGit.test_log):

Canonical link: https://commits.webkit.org/250767@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294510 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed May 19, 2022
1 parent e8621c0 commit 72a02b7c2c8d74067d679d30835bba9767206ee3
Showing 5 changed files with 19 additions and 26 deletions.
@@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='4.14.3',
version='4.14.4',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
@@ -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, 14, 3)
version = Version(4, 14, 4)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
@@ -30,7 +30,6 @@
import sys
import time

from datetime import datetime, timedelta
from collections import defaultdict

from webkitcorepy import run, decorators, NestedFuzzyDict
@@ -130,7 +129,7 @@ def _append(branch, hash, revision=None):
kwargs = dict(encoding='utf-8')
self._last_populated[branch] = time.time()
log = subprocess.Popen(
[self.repo.executable(), 'log', branch, '--no-decorate'],
[self.repo.executable(), 'log', branch, '--no-decorate', '--date=unix'],
cwd=self.repo.root_path,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
@@ -555,7 +554,7 @@ def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=Non

default_branch = self.default_branch
parsed_branch_point = None
log_format = ['-1', '--no-decorate'] if include_log else ['-1', '--no-decorate', '--format=short']
log_format = ['-1', '--no-decorate', '--date=unix'] if include_log else ['-1', '--no-decorate', '--date=unix', '--format=short']

# Determine the `git log` output and branch for a given identifier
if identifier is not None:
@@ -712,13 +711,7 @@ def _args_from_content(self, content, include_log=True):
if split[0] == 'Author':
author = Contributor.from_scm_log(line.lstrip(), self.contributors)
elif split[0] == 'CommitDate':
tz_diff = line.split(' ')[-1]
date = datetime.strptime(split[1].lstrip()[:-len(tz_diff)], '%a %b %d %H:%M:%S %Y ')
date += timedelta(
hours=int(tz_diff[1:3]),
minutes=int(tz_diff[3:5]),
) * (1 if tz_diff[0] == '-' else -1)
timestamp = int(calendar.timegm(date.timetuple())) - time.timezone
timestamp = int(line.split(' ')[-1])

message = ''
for line in content.splitlines()[5:]:
@@ -738,7 +731,7 @@ def commits(self, begin=None, end=None, include_log=True, include_identifier=Tru
try:
log = None
log = subprocess.Popen(
[self.executable(), 'log', '--format=fuller', '--no-decorate', '{}...{}'.format(end.hash, begin.hash)],
[self.executable(), 'log', '--format=fuller', '--no-decorate', '--date=unix', '{}...{}'.format(end.hash, begin.hash)],
cwd=self.root_path,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
@@ -271,7 +271,7 @@ def __init__(
stdout='{}\n'.format(self.find(args[2]).hash),
) if self.find(args[2]) else mocks.ProcessCompletion(returncode=128)
), mocks.Subprocess.Route(
self.executable, 'log', re.compile(r'.+'), '-1', '--no-decorate',
self.executable, 'log', re.compile(r'.+'), '-1', '--no-decorate', '--date=unix',
cwd=self.path,
generator=lambda *args, **kwargs: mocks.ProcessCompletion(
returncode=0,
@@ -284,7 +284,7 @@ def __init__(
branch=self.branch,
author=self.find(args[2]).author.name,
email=self.find(args[2]).author.email,
date=datetime.utcfromtimestamp(self.find(args[2]).timestamp + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
date=self.find(args[2]).timestamp,
log='\n'.join([
(' ' + line) if line else '' for line in self.find(args[2]).message.splitlines()
] + ([' git-svn-id: https://svn.{}/repository/{}/trunk@{} 268f45cc-cd09-0410-ab3c-d52691b4dbfc'.format(
@@ -296,7 +296,7 @@ def __init__(
),
) if self.find(args[2]) else mocks.ProcessCompletion(returncode=128),
), mocks.Subprocess.Route(
self.executable, 'log', '--format=fuller', '--no-decorate', re.compile(r'.+\.\.\..+'),
self.executable, 'log', '--format=fuller', '--no-decorate', '--date=unix', re.compile(r'.+\.\.\..+'),
cwd=self.path,
generator=lambda *args, **kwargs: mocks.ProcessCompletion(
returncode=0,
@@ -310,7 +310,7 @@ def __init__(
hash=commit.hash,
author=commit.author.name,
email=commit.author.email,
date=datetime.utcfromtimestamp(commit.timestamp + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
date=commit.timestamp,
log='\n'.join([
(' ' + line) if line else '' for line in commit.message.splitlines()
] + ([
@@ -319,7 +319,7 @@ def __init__(
os.path.basename(path),
commit.revision,
)] if git_svn else []),
)) for commit in list(self.commits_in_range(args[4].split('...')[-1], args[4].split('...')[0]))[:-1]
)) for commit in list(self.commits_in_range(args[5].split('...')[-1], args[5].split('...')[0]))[:-1]
])
)
), mocks.Subprocess.Route(
@@ -335,7 +335,7 @@ def __init__(
hash=commit.hash,
author=commit.author.name,
email=commit.author.email,
date=datetime.utcfromtimestamp(commit.timestamp + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
date=commit.timestamp if '--date=unix' in args else datetime.utcfromtimestamp(commit.timestamp + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
log='\n'.join([
(' ' + line) if line else '' for line in commit.message.splitlines()
] + ([
@@ -317,7 +317,7 @@ def test_log(self):
with mocks.local.Git(self.path, git_svn=True):
self.assertEqual(
run([
local.Git.executable(), 'log', '--format=fuller', '--no-decorate', 'remotes/origin/main...1abe25b4',
local.Git.executable(), 'log', '--format=fuller', '--no-decorate', '--date=unix', 'remotes/origin/main...1abe25b4',
], cwd=self.path, capture_output=True, encoding='utf-8').stdout,
'''commit d8bce26fa65c6fc8f39c17927abb77f69fab82fc
Author: Jonathan Bedard <jbedard@apple.com>
@@ -337,15 +337,15 @@ def test_log(self):
8th commit
git-svn-id: https://svn.example.org/repository/repository/trunk@8 268f45cc-cd09-0410-ab3c-d52691b4dbfc
'''.format(
time_a=datetime.utcfromtimestamp(1601668000 + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
time_b=datetime.utcfromtimestamp(1601663000 + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
time_a=1601668000,
time_b=1601663000,
))

def test_branch_log(self):
with mocks.local.Git(self.path, git_svn=True):
self.assertEqual(
run([
local.Git.executable(), 'log', '--format=fuller', '--no-decorate', 'branch-b...main',
local.Git.executable(), 'log', '--format=fuller', '--no-decorate', '--date=unix', 'branch-b...main',
], cwd=self.path, capture_output=True, encoding='utf-8').stdout,
'''commit 790725a6d79e28db2ecdde29548d2262c0bd059d
Author: Jonathan Bedard <jbedard@apple.com>
@@ -367,9 +367,9 @@ def test_branch_log(self):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@6 268f45cc-cd09-0410-ab3c-d52691b4dbfc
git-svn-id: https://svn.example.org/repository/repository/trunk@5 268f45cc-cd09-0410-ab3c-d52691b4dbfc
'''.format(
time_a=datetime.utcfromtimestamp(1601667000 + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
time_b=datetime.utcfromtimestamp(1601664000 + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
time_c=datetime.utcfromtimestamp(1601662000 + time.timezone).strftime('%a %b %d %H:%M:%S %Y +0000'),
time_a=1601667000,
time_b=1601664000,
time_c=1601662000,
))

def test_cache(self):

0 comments on commit 72a02b7

Please sign in to comment.