def commit_author_time_and_branch_ref(run, master_branch): get_refs = for_each_ref('refs/remotes/origin/**', format='%(refname:short) %(authordate:unix)') with run(get_refs) as program: for branch, t in columns(program.stdout): get_time = log(f"{master_branch}..{branch}", format='%at') with run(get_time) as inner_program: for author_time, in columns(inner_program.stdout): yield int(author_time), branch
from itertools import zip_longest from typing import Tuple, Iterable, List from data import columns, zip_with_tail from custom_git import for_each_ref, show from custom_git import cherry from process import proc_to_stdout TAGS_WITH_AUTHOR_DATE_CMD = for_each_ref( 'refs/tags/**', format='%(refname:short) %(taggerdate:unix)', sort='taggerdate') TAGS_WITH_COMMIT_SHA_CMD = for_each_ref( 'refs/tags/**', format='%(refname:short) %(*objectname)', ) def tags_with_author_date(run) -> Iterable[Tuple[str, int]]: proc = run(TAGS_WITH_AUTHOR_DATE_CMD) stdout = proc_to_stdout(proc) return parse_tags_with_date(stdout) def parse_tags_with_date(lines: Iterable[str]) -> Iterable[Tuple[str, int]]: return ((tag_and_maybe_date[0], int(tag_and_maybe_date[1])) for tag_and_maybe_date in columns(lines) if len(tag_and_maybe_date) > 1)
def test_for_each_ref_ref_glob(): assert for_each_ref('refs/heads/*') == [ "git", "for-each-ref", "refs/heads/*" ]
def test_for_each_ref_normal(): assert for_each_ref() == ["git", "for-each-ref"]
def test_for_each_ref_sort(): assert for_each_ref(sort='v:refname') == [ "git", "for-each-ref", "--sort=v:refname" ]
def test_for_each_ref_format(): assert for_each_ref(format='%(authordate:unix)') == [ "git", "for-each-ref", "--format=%(authordate:unix)" ]
def get_branches(run): with run(for_each_ref(format='%(refname)')) as cmd: for line in cmd.stdout: yield line.strip()