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): def __init__(self):
Part.__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 name-rev --name-only --no-undefined --always HEAD").strip()
if branch_name: if branch_name:
self.fragments.append("") self.fragments.append("")
count_to_pull = command("git log --oneline ..@{u}").count("\n") if deep_parse:
count_to_push = command("git log --oneline @{u}..").count("\n") count_to_pull = command("git log --oneline ..@{u}").count("\n")
git_dir = command("git rev-parse --git-dir").strip() count_to_push = command("git log --oneline @{u}..").count("\n")
merging = os.path.exists(os.path.join(git_dir, "MERGE_HEAD")) git_dir = command("git rev-parse --git-dir").strip()
untracked = command("git ls-files --other --exclude-standard").count("\n") merging = os.path.exists(os.path.join(git_dir, "MERGE_HEAD"))
modified = command("git diff --name-only").count("\n") untracked = command("git ls-files --other --exclude-standard").count("\n")
staged = command("git diff --name-only --staged").count("\n") modified = command("git diff --name-only").count("\n")
staged = command("git diff --name-only --staged").count("\n")
if count_to_pull: if count_to_pull:
self.fragments.append("%d " %(count_to_pull)) self.fragments.append("%d " %(count_to_pull))
if count_to_push: if count_to_push:
self.fragments.append("%d " %(count_to_push)) self.fragments.append("%d " %(count_to_push))
if merging: if merging:
self.fragments.append(style_color(COLOR_GIT_MERGE)) self.fragments.append(style_color(COLOR_GIT_MERGE))
self.fragments.append(style_bold()) self.fragments.append(style_bold())
self.fragments.append("") self.fragments.append("")
elif modified or staged: elif modified or staged:
self.fragments.append(style_color(COLOR_GIT_DIRTY)) self.fragments.append(style_color(COLOR_GIT_DIRTY))
else: else:
self.fragments.append(style_color(COLOR_GIT_CLEAN)) self.fragments.append(style_color(COLOR_GIT_CLEAN))
self.fragments.append(branch_name) self.fragments.append(branch_name)
self.fragments.append(style_reset()) self.fragments.append(style_reset())
if untracked: if deep_parse:
self.fragments.append(style_color(COLOR_GIT_UNTRACKED)) if untracked:
self.fragments.append(" ?%d" %(untracked)) self.fragments.append(style_color(COLOR_GIT_UNTRACKED))
self.fragments.append(" ?%d" %(untracked))
if modified: if modified:
self.fragments.append(style_color(COLOR_GIT_MODIFIED)) self.fragments.append(style_color(COLOR_GIT_MODIFIED))
self.fragments.append("%d" %(modified)) self.fragments.append("%d" %(modified))
if staged: if staged:
self.fragments.append(style_color(COLOR_GIT_STAGED)) self.fragments.append(style_color(COLOR_GIT_STAGED))
self.fragments.append("%d" %(staged)) self.fragments.append("%d" %(staged))
self.fragments.append(style_reset()) self.fragments.append(style_reset())