implement git blacklist

This commit is contained in:
Martinez 2015-12-26 16:29:08 +01:00
parent 83c5127414
commit e6930e3642

View file

@ -325,48 +325,54 @@ 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()
if branch_name:
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")
modified = command("git diff --name-only").count("\n")
staged = command("git diff --name-only --staged").count("\n")
if count_to_pull:
self.fragments.append("%d " %(count_to_pull))
if count_to_push:
self.fragments.append("%d " %(count_to_push))
if merging:
self.fragments.append(style_color(COLOR_GIT_MERGE))
self.fragments.append(style_bold())
self.fragments.append("")
elif modified or staged:
self.fragments.append(style_color(COLOR_GIT_DIRTY))
else:
self.fragments.append(style_color(COLOR_GIT_CLEAN))
if deep_parse:
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")
modified = command("git diff --name-only").count("\n")
staged = command("git diff --name-only --staged").count("\n")
if count_to_pull:
self.fragments.append("%d " %(count_to_pull))
if count_to_push:
self.fragments.append("%d " %(count_to_push))
if merging:
self.fragments.append(style_color(COLOR_GIT_MERGE))
self.fragments.append(style_bold())
self.fragments.append("")
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 untracked:
self.fragments.append(style_color(COLOR_GIT_UNTRACKED))
self.fragments.append(" ?%d" %(untracked))
if modified:
self.fragments.append(style_color(COLOR_GIT_MODIFIED))
self.fragments.append("%d" %(modified))
if staged:
self.fragments.append(style_color(COLOR_GIT_STAGED))
self.fragments.append("%d" %(staged))
if deep_parse:
if untracked:
self.fragments.append(style_color(COLOR_GIT_UNTRACKED))
self.fragments.append(" ?%d" %(untracked))
if modified:
self.fragments.append(style_color(COLOR_GIT_MODIFIED))
self.fragments.append("%d" %(modified))
if staged:
self.fragments.append(style_color(COLOR_GIT_STAGED))
self.fragments.append("%d" %(staged))
self.fragments.append(style_reset())