prompt: remove git blacklist, use timeout instead

This commit is contained in:
Martinez 2018-03-17 15:43:58 +01:00
parent 6691f43ab6
commit 4850e142aa

View file

@ -47,8 +47,6 @@ COLOR_ERROR = 196
MOUNT_IGNORE_FS = ["iso9660", "tmpfs", "rootfs"]
MOUNT_IGNORE_DIR = ["/dev", "/proc", "/sys"]
GIT_BLACKLIST = ["/var/paludis/repositories"]
def get_username():
return pwd.getpwuid(os.geteuid())[0]
@ -321,7 +319,7 @@ class PathPart(Part):
self.fragments.append(str(dir))
def command(cmd):
def command(cmd, timeout=0.5):
"""
Executes a command, returns stdout, suppresses stderr."
"""
@ -330,7 +328,7 @@ def command(cmd):
cmd = cmd.split()
s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
s.wait()
s.wait(timeout)
return s.stdout.read().decode("utf-8")
@ -414,13 +412,13 @@ class WineprefixPart(Part):
class GitPart(Part):
"""
2 4 master ?11 6 10
2 4 M master ?11 6 10
- 2 commits are available for pulling (remote is ahead)
- 4 commits are available for pushing (local is ahead)
- we're merging
- branch name is master
- 11 untracked filed
- 11 untracked files
- 6 modified files
- 10 modified and staged files
@ -430,22 +428,17 @@ class GitPart(Part):
def __init__(self):
Part.__init__(self)
# avoid expensive parsing if blacklisted
cwd = os.getcwd()
deep_parse = not any([cwd.startswith(d) for d in GIT_BLACKLIST])
branch_name = command("git name-rev --name-only --no-undefined --always HEAD").strip()
#branch_name = command("git symbolic-ref HEAD").strip()#.remove("refs/heads/")
if branch_name:
self.fragments.append("")
if deep_parse:
try:
self.fragments.append("")
count_to_pull = command("git log --oneline ..@{u}").count("\n")
count_to_push = command("git log --oneline @{u}..").count("\n")
git_dir = command("git rev-parse --git-dir").strip()
merging = os.path.exists(os.path.join(git_dir, "MERGE_HEAD"))
untracked = command("git ls-files --other --exclude-standard").count("\n")
untracked = command("git ls-files --other --exclude-standard", timeout=0.2).count("\n")
modified = command("git diff --name-only").count("\n")
staged = command("git diff --name-only --staged").count("\n")
@ -458,16 +451,15 @@ class GitPart(Part):
if merging:
self.fragments.append(style_color(COLOR_GIT_MERGE))
self.fragments.append(style_bold())
self.fragments.append("")
self.fragments.append("M ")
elif modified or staged:
self.fragments.append(style_color(COLOR_GIT_DIRTY))
else:
self.fragments.append(style_color(COLOR_GIT_CLEAN))
self.fragments.append(branch_name)
self.fragments.append(style_reset())
if deep_parse:
self.fragments.append(branch_name)
self.fragments.append(style_reset())
if untracked:
self.fragments.append(style_color(COLOR_GIT_UNTRACKED))
self.fragments.append(" ?%d" %(untracked))
@ -479,8 +471,13 @@ class GitPart(Part):
if staged:
self.fragments.append(style_color(COLOR_GIT_STAGED))
self.fragments.append("%d" %(staged))
self.fragments.append(style_reset())
self.fragments.append(style_reset())
except subprocess.TimeoutExpired:
self.fragments = []
self.fragments.append(style_color(COLOR_GIT_DIRTY))
self.fragments.append("⚠ git timeout ⚠")
self.fragments.append(style_reset())
class Padding(Part):
def __init__(self, term_width):