use cachew in my.commits
This commit is contained in:
parent
cec7cad2bf
commit
094c775480
1 changed files with 31 additions and 4 deletions
|
@ -6,7 +6,7 @@ from pathlib import Path
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import List, NamedTuple, Optional, Dict, Any, Iterator, Set
|
from typing import List, NamedTuple, Optional, Dict, Any, Iterator, Set
|
||||||
|
|
||||||
from ..common import PathIsh, LazyLogger
|
from ..common import PathIsh, LazyLogger, mcachew
|
||||||
from mycfg import commits as config
|
from mycfg import commits as config
|
||||||
|
|
||||||
# pip3 install gitpython
|
# pip3 install gitpython
|
||||||
|
@ -139,13 +139,40 @@ def repos():
|
||||||
return git_repos_in(config.roots)
|
return git_repos_in(config.roots)
|
||||||
|
|
||||||
|
|
||||||
# TODO cachew for all commits?
|
def _hashf(_repos: List[Path]):
|
||||||
def commits() -> Iterator[Commit]:
|
# TODO maybe use smth from git library? ugh..
|
||||||
for r in repos():
|
res = []
|
||||||
|
for r in _repos:
|
||||||
|
# TODO just use anything except index? ugh.
|
||||||
|
for pp in {
|
||||||
|
'.git/FETCH_HEAD',
|
||||||
|
'.git/HEAD',
|
||||||
|
'FETCH_HEAD', # bare
|
||||||
|
'HEAD', # bare
|
||||||
|
}:
|
||||||
|
ff = r / pp
|
||||||
|
if ff.exists():
|
||||||
|
updated = ff.stat().st_mtime
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise RuntimeError(r)
|
||||||
|
res.append((r, updated))
|
||||||
|
return res
|
||||||
|
|
||||||
|
# TODO per-repo cache?
|
||||||
|
# TODO set default cache path?
|
||||||
|
# TODO got similar issue as in photos with a helper method.. figure it out
|
||||||
|
@mcachew(hashf=_hashf, logger=log)
|
||||||
|
def _commits(_repos) -> Iterator[Commit]:
|
||||||
|
for r in _repos:
|
||||||
log.info('processing %s', r)
|
log.info('processing %s', r)
|
||||||
yield from repo_commits(r)
|
yield from repo_commits(r)
|
||||||
|
|
||||||
|
|
||||||
|
def commits() -> Iterator[Commit]:
|
||||||
|
return _commits(repos())
|
||||||
|
|
||||||
|
|
||||||
def print_all():
|
def print_all():
|
||||||
for c in commits():
|
for c in commits():
|
||||||
print(c)
|
print(c)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue