pick/core: Add a method for updating commits

This is almost the same as the one in the ui, but without the UI
elements. It would be nice to share code between them, but I'm not sure
how to do that yet.
This commit is contained in:
Dylan Baker 2022-03-17 10:30:57 -07:00
parent 29960e0b4a
commit 3348844bc4

View file

@ -22,6 +22,7 @@
import asyncio
import enum
import itertools
import json
import pathlib
import re
@ -372,6 +373,25 @@ async def gather_commits(version: str, previous: typing.List['Commit'],
return commits
async def update_commits() -> None:
"""Gather all new commits and update the on-disk cache.
"""
commits = load()
with open('VERSION', 'r') as f:
version = '.'.join(f.read().split('.')[:2])
if commits:
sha = commits[0].sha
else:
sha = f'{version}-branchpoint'
if new := await get_new_commits(sha):
collected_commits = await gather_commits(version, commits, new)
else:
collected_commits = []
save(itertools.chain(collected_commits, commits))
def load() -> typing.List['Commit']:
if not pick_status_json.exists():
return []