diff --git a/commits/__init__.py b/commits/__init__.py index 098391e..4c8a2b9 100644 --- a/commits/__init__.py +++ b/commits/__init__.py @@ -41,13 +41,18 @@ def by_me(c): return False class Commit(NamedTuple): - dt: datetime + commited_dt: datetime + authored_dt: datetime message: str repo: str sha: str ref: Optional[str]=None # TODO filter so they are authored by me + @property + def dt(self) -> datetime: + return self.commited_dt + # TODO not sure, maybe a better idea to move it to timeline? def fix_datetime(dt) -> datetime: # git module got it's own tzinfo object.. and it's pretty weird @@ -62,13 +67,14 @@ from kython.ktyping import PathIsh def iter_commits(repo: PathIsh, ref=None): # TODO other branches? repo = Path(repo) - rr = repo.stem + rr = repo.name gr = git.Repo(repo) # without path might not handle pull heads properly for c in gr.iter_commits(rev=ref.path): if by_me(c): yield Commit( - dt=fix_datetime(c.committed_datetime), # TODO authored?? + commited_dt=fix_datetime(c.committed_datetime), + authored_dt=fix_datetime(c.authored_datetime), message=c.message.strip(), repo=rr, sha=c.hexsha, @@ -76,7 +82,6 @@ def iter_commits(repo: PathIsh, ref=None): ) def iter_all_ref_commits(repo: Path): - # TODO hmm, git library has got way of determining git.. gr = git.Repo(str(repo)) for r in gr.references: yield from iter_commits(repo=repo, ref=r) @@ -86,12 +91,18 @@ def is_git_repo(d: str): dotgit = join(d, '.git') return isdir(dotgit) +from git.repo.fun import is_git_dir # type: ignore def iter_all_git_repos(dd: PathIsh) -> Iterator[Path]: # TODO would that cover all repos??? dd = Path(dd) - for xx in dd.glob('**/refs/heads/'): - yield xx.parent.parent + for xx in dd.glob('**/HEAD'): # ugh + c = xx.parent + if not is_git_dir(c): + continue + if c.name == '.git': + c = c.parent + yield c # TODO is it only used in wcommits? @@ -125,3 +136,12 @@ def get_all_commits(): res[c.sha] = min(nn, c, key=lambda c: c.sha) return list(sorted(res.values(), key=lambda c: c.dt)) + + +def main(): + for c in get_all_commits(): # ('***REMOVED***'): + print(c) + + +if __name__ == '__main__': + main() diff --git a/commits/__main__.py b/commits/__main__.py deleted file mode 100644 index ee2eee1..0000000 --- a/commits/__main__.py +++ /dev/null @@ -1,5 +0,0 @@ -from commits import iter_commits, iter_all_commits, get_all_commits - -# TODO cache? -for c in get_all_commits(): # ('***REMOVED***'): - print(c) diff --git a/commits/test.py b/commits/test.py new file mode 100644 index 0000000..8d39aa0 --- /dev/null +++ b/commits/test.py @@ -0,0 +1,7 @@ +from . import get_all_commits + +# TODO shit. why can't it just be in __init__.py?? + +def test(): + commits = get_all_commits() + assert len(commits) > 10 diff --git a/run b/run deleted file mode 100755 index e60aa44..0000000 --- a/run +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -eu -python3 -m commits