From 3348844bc45b4204619f77949d09a4ecebc402f3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 17 Mar 2022 10:30:57 -0700 Subject: [PATCH] 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. --- bin/pick/core.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bin/pick/core.py b/bin/pick/core.py index e10f7416580..fe5af9d8db2 100644 --- a/bin/pick/core.py +++ b/bin/pick/core.py @@ -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 []