Skip to content

Commit

Permalink
Speedup gita ll by using a threadpool (#238)
Browse files Browse the repository at this point in the history
Each line of 'll' output is generated from running git commands, by
using a thread pool the commands for each line can be ran in parallel.

Co-authored-by: John Beckett <[email protected]>
  • Loading branch information
johnnybeckett and john-magentium authored Apr 30, 2023
1 parent 6389470 commit aaa277f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions gita/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pathlib import Path
from typing import List, Dict, Coroutine, Union, Iterator, Tuple
from collections import Counter, defaultdict
from concurrent.futures import ThreadPoolExecutor
import multiprocessing

from . import info
from . import common
Expand Down Expand Up @@ -428,17 +430,20 @@ def describe(repos: Dict[str, Dict[str, str]], no_colors: bool = False) -> str:
Return the status of all repos
"""
if repos:
name_width = max(len(n) for n in repos) + 1
funcs = info.get_info_funcs()

get_repo_status = info.get_repo_status
if get_repo_status in funcs and no_colors:
idx = funcs.index(get_repo_status)
funcs[idx] = partial(get_repo_status, no_colors=True)

for name in sorted(repos):
info_items = " ".join(f(repos[name]) for f in funcs)
yield f"{name:<{name_width}}{info_items}"
name_width = len(max(repos, key=len)) + 1
funcs = info.get_info_funcs()

get_repo_status = info.get_repo_status
if get_repo_status in funcs and no_colors:
idx = funcs.index(get_repo_status)
funcs[idx] = partial(get_repo_status, no_colors=True)

num_threads = min(multiprocessing.cpu_count(), len(repos))
with ThreadPoolExecutor(max_workers=num_threads) as executor:
for line in executor.map(
lambda repo: f'{repo:<{name_width}}{" ".join(f(repos[repo]) for f in funcs)}',
sorted(repos)):
yield line


def get_cmds_from_files() -> Dict[str, Dict[str, str]]:
Expand Down

0 comments on commit aaa277f

Please sign in to comment.