pick-ui: compute .pick_status.json path only once
Signed-off-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Dylan Baker <dylan@pnwbakers.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4649>
This commit is contained in:

committed by
Marge Bot

parent
a4b36cd3dd
commit
26a26a3584
@@ -55,6 +55,8 @@ SEM = asyncio.Semaphore(50)
|
|||||||
|
|
||||||
COMMIT_LOCK = asyncio.Lock()
|
COMMIT_LOCK = asyncio.Lock()
|
||||||
|
|
||||||
|
pick_status_json = pathlib.Path(__file__).parent.parent.parent / '.pick_status.json'
|
||||||
|
|
||||||
|
|
||||||
class PickUIException(Exception):
|
class PickUIException(Exception):
|
||||||
pass
|
pass
|
||||||
@@ -80,10 +82,9 @@ class Resolution(enum.Enum):
|
|||||||
|
|
||||||
async def commit_state(*, amend: bool = False, message: str = 'Update') -> bool:
|
async def commit_state(*, amend: bool = False, message: str = 'Update') -> bool:
|
||||||
"""Commit the .pick_status.json file."""
|
"""Commit the .pick_status.json file."""
|
||||||
f = pathlib.Path(__file__).parent.parent.parent / '.pick_status.json'
|
|
||||||
async with COMMIT_LOCK:
|
async with COMMIT_LOCK:
|
||||||
p = await asyncio.create_subprocess_exec(
|
p = await asyncio.create_subprocess_exec(
|
||||||
'git', 'add', f.as_posix(),
|
'git', 'add', pick_status_json.as_posix(),
|
||||||
stdout=asyncio.subprocess.DEVNULL,
|
stdout=asyncio.subprocess.DEVNULL,
|
||||||
stderr=asyncio.subprocess.DEVNULL,
|
stderr=asyncio.subprocess.DEVNULL,
|
||||||
)
|
)
|
||||||
@@ -360,18 +361,16 @@ async def gather_commits(version: str, previous: typing.List['Commit'],
|
|||||||
|
|
||||||
|
|
||||||
def load() -> typing.List['Commit']:
|
def load() -> typing.List['Commit']:
|
||||||
p = pathlib.Path(__file__).parent.parent.parent / '.pick_status.json'
|
if not pick_status_json.exists():
|
||||||
if not p.exists():
|
|
||||||
return []
|
return []
|
||||||
with p.open('r') as f:
|
with pick_status_json.open('r') as f:
|
||||||
raw = json.load(f)
|
raw = json.load(f)
|
||||||
return [Commit.from_json(c) for c in raw]
|
return [Commit.from_json(c) for c in raw]
|
||||||
|
|
||||||
|
|
||||||
def save(commits: typing.Iterable['Commit']) -> None:
|
def save(commits: typing.Iterable['Commit']) -> None:
|
||||||
p = pathlib.Path(__file__).parent.parent.parent / '.pick_status.json'
|
|
||||||
commits = list(commits)
|
commits = list(commits)
|
||||||
with p.open('wt') as f:
|
with pick_status_json.open('wt') as f:
|
||||||
json.dump([c.to_json() for c in commits], f, indent=4)
|
json.dump([c.to_json() for c in commits], f, indent=4)
|
||||||
|
|
||||||
asyncio.ensure_future(commit_state(message=f'Update to {commits[0].sha}'))
|
asyncio.ensure_future(commit_state(message=f'Update to {commits[0].sha}'))
|
||||||
|
Reference in New Issue
Block a user