Skip to content
Permalink
Browse files
[git-webkit] Use --git-common-dir over hard-coded .git
https://bugs.webkit.org/show_bug.cgi?id=240732
<rdar://93676555>

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/local/git.py:
(Git.Cache.path): Use common_directory instead of .git.
(Git.is_svn): Ditto.
(Git.common_directory): Attempt to determine path to .git directory with
`git rev-parse --git-common-dir`.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py:
(Scm.common_directory): Added.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
(Svn.Cache.path): Use common_directory instead of .svn.
(Svn.common_directory): Added.
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/setup.py:
(Setup.git): Use common_directory instead of .git.

Canonical link: https://commits.webkit.org/251023@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294900 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed May 26, 2022
1 parent 6773d7a commit 6989de10781efa0ecfa754de7b6519a9a8442c0c
Showing 7 changed files with 29 additions and 6 deletions.
@@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='4.15.0',
version='4.15.1',
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, 15, 0)
version = Version(4, 15, 1)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
@@ -70,7 +70,7 @@ def load(self):

@property
def path(self):
return os.path.join(self.repo.root_path, '.git', 'identifiers.json')
return os.path.join(self.repo.common_directory, 'identifiers.json')

def _fill(self, branch):
default_branch = self.repo.default_branch
@@ -396,7 +396,7 @@ def info(self):
@property
@decorators.Memoize()
def is_svn(self):
config = os.path.join(self.root_path, '.git/config')
config = os.path.join(self.common_directory, 'config')
if not os.path.isfile(config):
return False

@@ -418,6 +418,14 @@ def root_path(self):
return None
return result.stdout.rstrip()

@property
@decorators.Memoize()
def common_directory(self):
result = run([self.executable(), 'rev-parse', '--git-common-dir'], cwd=self.path, capture_output=True, encoding='utf-8')
if result.returncode:
return os.path.join(self.root_path, '.git')
return os.path.join(self.root_path, result.stdout.rstrip())

@property
@decorators.Memoize()
def default_branch(self):
@@ -106,6 +106,10 @@ def metadata(self):
def root_path(self):
raise NotImplementedError()

@property
def common_directory(self):
raise NotImplementedError()

@property
def branch(self):
raise NotImplementedError()
@@ -59,7 +59,7 @@ def __init__(self, repo, guranteed_for=10):

@property
def path(self):
return os.path.join(self.repo.root_path, '.svn', 'webkitscmpy-cache.json')
return os.path.join(self.repo.common_directory, 'webkitscmpy-cache.json')

def populate(self, branch=None):
branch = branch or self.repo.default_branch
@@ -255,6 +255,10 @@ def is_svn(self):
def root_path(self):
return self._root_path

@property
def common_directory(self):
return os.path.join(self.root_path, '.svn')

@property
def default_branch(self):
return 'trunk'
@@ -209,6 +209,13 @@ def __init__(
returncode=0,
stdout='{}\n'.format(self.path),
),
), mocks.Subprocess.Route(
self.executable, 'rev-parse', '--git-common-dir',
cwd=self.path,
completion=mocks.ProcessCompletion(
returncode=0,
stdout='.git\n',
),
), mocks.Subprocess.Route(
self.executable, 'rev-parse', '--abbrev-ref', 'HEAD',
cwd=self.path,
@@ -284,7 +284,7 @@ def git(cls, args, repository, additional_setup=None, hooks=None, **kwargs):
python=os.path.basename(sys.executable),
)

target = os.path.join(repository.root_path, '.git', 'hooks', hook)
target = os.path.join(repository.common_directory, 'hooks', hook)
if not os.path.exists(os.path.dirname(target)):
os.makedirs(os.path.dirname(target))
with open(target, 'w') as f:

0 comments on commit 6989de1

Please sign in to comment.