Skip to content

status: add warning on slow status call #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions scmrepo/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import logging
import os
import re
import threading
from collections.abc import Mapping
from contextlib import contextmanager
from functools import partialmethod
from typing import Dict, Iterable, Optional, Tuple, Type, Union
from typing import Any, Dict, Iterable, Optional, Tuple, Type, Union

from funcy import cached_property, first
from pathspec.patterns import GitWildMatchPattern
Expand Down Expand Up @@ -318,7 +319,6 @@ def add_commit(
diff = partialmethod(_backend_func, "diff")
reset = partialmethod(_backend_func, "reset")
checkout_index = partialmethod(_backend_func, "checkout_index")
status = partialmethod(_backend_func, "status")
merge = partialmethod(_backend_func, "merge")
validate_git_remote = partialmethod(_backend_func, "validate_git_remote")
check_ref_format = partialmethod(_backend_func, "check_ref_format")
Expand Down Expand Up @@ -412,3 +412,38 @@ def describe(
):
return self.get_ref("HEAD", follow=False)
return self._describe(rev, base, match, exclude)

def status(self, *args, **kwargs):

event = threading.Event()
status_result: Union[Any, Exception, None] = None

def worker():
nonlocal status_result
try:
status_result = self._backend_func("status", *args, **kwargs)
except Exception as exc: # pylint: disable=broad-except
status_result = exc
event.set()

thread = threading.Thread(target=worker, name="scm-status")
thread.start()

counter = 0
while True:
if event.wait(1):
break
counter += 1
if counter == 5:
logger.warning("Getting git status..")
elif counter == 10:
msg = (
"This is taking a while. If there's any large untracked"
+ "directories, you can try adding these to .gitignore."
)
logger.warning(msg)

if isinstance(status_result, Exception):
raise status_result # pylint: disable=raising-bad-type

return status_result