Skip to content

Commit

Permalink
Merge pull request #1033 from kaste/optimize-status-interface
Browse files Browse the repository at this point in the history
Optimize status interface
  • Loading branch information
asfaltboy committed Nov 21, 2018
2 parents a55c585 + 0c2dd28 commit 57b00b1
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 53 deletions.
1 change: 1 addition & 0 deletions common/commands/view_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def run(self, edit):
if savvy_settings.get("vintageous_friendly", False) is True:
self.view.settings().set("git_savvy.vintageous_friendly", True)
if savvy_settings.get("vintageous_enter_insert_mode", False) is True:
self.view.settings().set("vintageous_reset_mode_when_switching_tabs", False)
self.view.run_command("_enter_insert_mode")


Expand Down
23 changes: 14 additions & 9 deletions core/git_mixins/active_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_current_branch_name(self):
except StopIteration:
return None

def _get_branch_status_components(self):
def _get_branch_status_components(self, lines):
"""
Return a tuple of:
Expand All @@ -28,9 +28,8 @@ def _get_branch_status_components(self):
6) # commits behind of remote
7) boolean indicating whether the remote branch is gone
"""
stdout = self.git("status", "-b", "--porcelain").strip()

first_line, *addl_lines = stdout.split("\n", 2)
first_line, *addl_lines = lines
# Any additional lines will mean files have changed or are untracked.
clean = len(addl_lines) == 0

Expand Down Expand Up @@ -67,8 +66,12 @@ def get_branch_status(self, delim=None):
If a delimeter is provided, join tuple components with it, and return
that value.
"""
detached, initial, branch, remote, clean, ahead, behind, gone = \
self._get_branch_status_components()
lines = self._get_status()
branch_status = self._get_branch_status_components(lines)
return self._format_branch_status(branch_status, delim)

def _format_branch_status(self, branch_status, delim=None):
detached, initial, branch, remote, clean, ahead, behind, gone = branch_status

secondary = []

Expand Down Expand Up @@ -102,14 +105,15 @@ def get_branch_status(self, delim=None):
return status, secondary

def get_branch_status_short(self):

if self.in_rebase():
return "(no branch, rebasing {})".format(self.rebase_branch_name())

merge_head = self.merge_head() if self.in_merge() else ""
lines = self._get_status()
branch_status = self._get_branch_status_components(lines)
return self._format_branch_status_short(branch_status)

detached, initial, branch, remote, clean, ahead, behind, gone = \
self._get_branch_status_components()
def _format_branch_status_short(self, branch_status):
detached, initial, branch, remote, clean, ahead, behind, gone = branch_status

dirty = "" if clean else "*"

Expand All @@ -123,6 +127,7 @@ def get_branch_status_short(self):
if behind:
output += "-" + behind

merge_head = self.merge_head() if self.in_merge() else ""
return output if not merge_head else output + " (merging {})".format(merge_head)

def get_commit_hash_for_head(self):
Expand Down
24 changes: 15 additions & 9 deletions core/git_mixins/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@

class StatusMixin():

def get_status(self):
"""
Return a list of FileStatus objects. These objects correspond
to all files that are 1) staged, 2) modified, 3) new, 4) deleted,
5) renamed, or 6) copied as well as additional status information that can
occur mid-merge.
"""
stdout = self.git("status", "--porcelain", "-z")
def _get_status(self):
return self.git("status", "--porcelain", "-z", "-b").rstrip("\x00").split("\x00")

porcelain_entries = stdout.split("\x00").__iter__()
def _parse_status_for_file_statuses(self, lines):
porcelain_entries = lines[1:].__iter__()
entries = []

for entry in porcelain_entries:
Expand All @@ -42,6 +37,17 @@ def get_status(self):

return entries

def get_status(self):
"""
Return a list of FileStatus objects. These objects correspond
to all files that are 1) staged, 2) modified, 3) new, 4) deleted,
5) renamed, or 6) copied as well as additional status information that can
occur mid-merge.
"""

lines = self._get_status()
return self._parse_status_for_file_statuses(lines)

def _get_indexed_entry(self, raw_entry):
"""
Parse a diff-index entry into an IndexEntry object. Each input entry
Expand Down
Loading

0 comments on commit 57b00b1

Please sign in to comment.