Skip to content

Commit

Permalink
Merge branch 'master' into randy3k/rebase_check
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed May 5, 2017
2 parents ef89be4 + cb09c15 commit e395e04
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
12 changes: 11 additions & 1 deletion common/util/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pprint as _pprint

import sublime

from contextlib import contextmanager

_log = []
enabled = False
Expand All @@ -21,6 +21,16 @@ def stop_logging():
enabled = False


@contextmanager
def disable_logging():
global enabled
enabled = False
try:
yield
finally:
enabled = True


def get_log():
return json.dumps(_log, indent=2)

Expand Down
2 changes: 1 addition & 1 deletion core/commands/show_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def run(self, commit_hash):
view.settings().set("git_savvy.show_commit_view.show_word_diff", False)
view.settings().set("word_wrap", False)
view.settings().set("line_numbers", False)
view.set_name(SHOW_COMMIT_TITLE.format(commit_hash[:7]))
view.set_name(SHOW_COMMIT_TITLE.format(self.get_short_hash(commit_hash)))
view.set_scratch(True)
view.run_command("gs_show_commit_refresh")
view.run_command("gs_diff_navigate")
Expand Down
2 changes: 1 addition & 1 deletion core/commands/show_file_at_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run_async(self, commit_hash, filepath, lineno=1, lang=None):
view.settings().set("git_savvy.file_path", filepath)
view.settings().set("git_savvy.show_file_at_commit_view.lineno", lineno)
view.settings().set("git_savvy.repo_path", repo_path)
view.set_name(SHOW_COMMIT_TITLE.format(commit_hash[:7], self.get_rel_path(filepath)))
view.set_name(SHOW_COMMIT_TITLE.format(self.get_short_hash(commit_hash), self.get_rel_path(filepath)))
sublime.set_timeout_async(lambda: self.render_text(view), 0)

def render_text(self, view):
Expand Down
4 changes: 3 additions & 1 deletion core/commands/status_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sublime_plugin import TextCommand, EventListener

from ..git_command import GitCommand
from ...common.util import debug


class GsStatusBarEventListener(EventListener):
Expand Down Expand Up @@ -57,7 +58,8 @@ def run_async(self):
self.view.erase_status("gitsavvy-repo-status")
return

short_status = self.get_branch_status_short()
with debug.disable_logging():
short_status = self.get_branch_status_short()
self.view.set_status("gitsavvy-repo-status", short_status)

global update_status_bar_soon
Expand Down
3 changes: 3 additions & 0 deletions core/git_mixins/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ def commit_parents(self, commit_hash):
def commit_is_merge(self, commit_hash):
sha = self.git("rev-list", "--merges", "-1", "{0}~1..{0}".format(commit_hash)).strip()
return sha is not ""

def get_short_hash(self, commit_hash):
return self.git("rev-parse", "--short", commit_hash).strip()
25 changes: 18 additions & 7 deletions core/interfaces/rebase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re

import sublime
from sublime_plugin import WindowCommand, TextCommand
Expand All @@ -12,6 +13,11 @@
from ..ui_mixins.quick_panel import show_log_panel


COMMIT_NODE_CHAR = "●"
COMMIT_NODE_CHAR_OPTIONS = "●*"
COMMIT_LINE = re.compile("\s*[%s]\s*([a-z0-9]{3,})" % COMMIT_NODE_CHAR_OPTIONS)


def filter_quick_panel(fn):
return lambda idx: fn(idx) if idx != -1 else None

Expand Down Expand Up @@ -152,7 +158,7 @@ def render_base_ref(self):

@ui.partial("base_commit")
def render_base_commit(self):
return self.base_commit()[:7]
return self.get_short_hash(self.base_commit())

@ui.partial("status")
def render_status(self):
Expand Down Expand Up @@ -231,7 +237,7 @@ def _get_diverged_in_rebase(self):
for entry in self.entries:
conflicts = ""
was_rewritten = entry.long_hash in rewritten
new_hash = rewritten[entry.long_hash][:7] if was_rewritten else None
new_hash = rewritten[entry.long_hash] if was_rewritten else None
is_merge = self.commit_is_merge(entry.long_hash)
if self.in_rebase_merge() and is_merge:
is_conflict = conflict_commit in self.commits_of_merge(entry.long_hash)
Expand Down Expand Up @@ -264,7 +270,7 @@ def _get_diverged_in_rebase(self):
"status": (self.SUCCESS if was_rewritten else
self.CONFLICT if is_conflict else
self.UNKNOWN),
"commit_hash": new_hash if was_rewritten else entry.short_hash,
"commit_hash": self.get_short_hash(new_hash) if was_rewritten else entry.short_hash,
"commit_summary": ("(was {}) {}".format(entry.short_hash, entry.summary)
if was_rewritten else
entry.summary),
Expand Down Expand Up @@ -485,7 +491,9 @@ def get_selected_short_hash(self):

line = self.view.line(sels[0])
line_str = self.view.substr(line)
return line_str[7:14]
m = COMMIT_LINE.match(line_str)
if m:
return m.group(1)

def get_idx_entry_and_prev(self, short_hash):
entry_before_selected = None
Expand Down Expand Up @@ -556,7 +564,8 @@ def run_async(self):
def do_action(self, target_commit):

squash_idx, squash_entry, _ = self.get_idx_entry_and_prev(self.squash_entry.short_hash)
target_idx, target_entry, before_target = self.get_idx_entry_and_prev(target_commit[:7])
target_idx, target_entry, before_target = \
self.get_idx_entry_and_prev(self.get_short_hash(target_commit))

if self.commit_is_merge(target_entry.long_hash):
sublime.message_dialog("Unable to squash a merge.")
Expand Down Expand Up @@ -691,7 +700,8 @@ def run_async(self):
def do_action(self, target_commit):

move_idx, move_entry, _ = self.get_idx_entry_and_prev(self.move_entry.short_hash)
target_idx, target_entry, before_target = self.get_idx_entry_and_prev(target_commit[:7])
target_idx, target_entry, before_target = \
self.get_idx_entry_and_prev(self.get_short_hash(target_commit))
idx = move_idx - target_idx

commit_chain = self.perpare_rewrites(self.interface.entries[target_idx:])
Expand Down Expand Up @@ -737,7 +747,8 @@ def run_async(self):
def do_action(self, target_commit):

move_idx, move_entry, before_move = self.get_idx_entry_and_prev(self.move_entry.short_hash)
target_idx, target_entry, _ = self.get_idx_entry_and_prev(target_commit[:7])
target_idx, target_entry, _ = \
self.get_idx_entry_and_prev(self.get_short_hash(target_commit))
idx = target_idx - move_idx

commit_chain = self.perpare_rewrites(self.interface.entries[move_idx:])
Expand Down
4 changes: 2 additions & 2 deletions core/interfaces/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def render_local_tags(self):
return NO_LOCAL_TAGS_MESSAGE

return "\n".join(
" {} {}".format(tag.sha[:7], tag.tag)
" {} {}".format(self.get_short_hash(tag.sha), tag.tag)
for tag in self.local_tags
)

Expand Down Expand Up @@ -148,7 +148,7 @@ def get_remote_tags_list(self, remote, remote_name):
if "tags" in remote:
if remote["tags"]:
msg = "\n".join(
" {} {}".format(tag.sha[:7], tag.tag)
" {} {}".format(self.get_short_hash(tag.sha), tag.tag)
for tag in remote["tags"] if tag.tag[-3:] != "^{}"
)
else:
Expand Down

0 comments on commit e395e04

Please sign in to comment.