Skip to content

Commit

Permalink
[gitstatus.py] Use --porcelain to make faster in using python
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jun 28, 2015
1 parent 7d480a9 commit 8cb257a
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions gitstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@

branch = branch.decode("utf-8").strip()[11:]

res, err = Popen(['git','diff','--name-status'], stdout=PIPE, stderr=PIPE).communicate()
# Get git status (staged, change, conflicts and untracked)
res, err = Popen(['git', 'status', '--porcelain'], stdout=PIPE, stderr=PIPE).communicate()
err_string = err.decode('utf-8')
if 'fatal' in err_string:
sys.exit(0)
changed_files = [namestat[0] for namestat in res.decode("utf-8").splitlines()]
staged_files = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()]
nb_changed = len(changed_files) - changed_files.count('U')
nb_U = staged_files.count('U')
nb_staged = len(staged_files) - nb_U
staged = str(nb_staged)
conflicts = str(nb_U)
changed = str(nb_changed)
nb_untracked = len([0 for status in Popen(['git','status','--porcelain',],stdout=PIPE).communicate()[0].decode("utf-8").splitlines() if status.startswith('??')])
untracked = str(nb_untracked)
status = [(st[0], st[1], st[2:]) for st in res.splitlines()]
tracked, untracked = [], []
for st in status:
if st[0] == '?' and st[1] == '?':
untracked.append(st)
else:
tracked.append(st)
staged = filter(lambda x: x[0] != ' ' and x[0] != 'U', tracked)
changed = filter(lambda x: x[1] == 'M', tracked)
conflicts = filter(lambda x: x[0] == 'U', tracked)
n_staged = len(staged)
n_changed = len(changed)
n_conflicts = len(conflicts)
n_untracked = len(untracked)

ahead, behind = 0,0

Expand All @@ -56,10 +61,10 @@
branch,
str(ahead),
str(behind),
staged,
conflicts,
changed,
untracked,
str(n_staged),
str(n_conflicts),
str(n_changed),
str(n_untracked),
])
print(out, end='')

0 comments on commit 8cb257a

Please sign in to comment.