From 74178ab9b6d5248aed093cd48fa2b10ddcdb7366 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Fri, 12 Jul 2019 14:47:15 +0200 Subject: [PATCH] Show refs in the log panel --- core/git_mixins/history.py | 7 +++--- core/ui_mixins/quick_panel.py | 43 ++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/core/git_mixins/history.py b/core/git_mixins/history.py index 3db6b9487..daaf83644 100644 --- a/core/git_mixins/history.py +++ b/core/git_mixins/history.py @@ -6,6 +6,7 @@ LogEntry = namedtuple("LogEntry", ( "short_hash", "long_hash", + "ref", "summary", "raw_body", "author", @@ -37,7 +38,7 @@ def log(self, author=None, branch=None, file_path=None, start_end=None, cherry=N "--max-count={}".format(limit) if limit else None, "--skip={}".format(skip) if skip else None, "--reverse" if reverse else None, - '--format=%h%n%H%n%s%n%an%n%ae%n%at%x00%B%x00%x00%n', + '--format=%h%n%H%n%D%n%s%n%an%n%ae%n%at%x00%B%x00%x00%n', "--author={}".format(author) if author else None, "--grep={}".format(msg_regexp) if msg_regexp else None, "--cherry" if cherry else None, @@ -62,8 +63,8 @@ def log(self, author=None, branch=None, file_path=None, start_end=None, cherry=N continue entry, raw_body = entry.split("\x00") - short_hash, long_hash, summary, author, email, datetime = entry.split("\n") - entries.append(LogEntry(short_hash, long_hash, summary, raw_body, author, email, datetime)) + short_hash, long_hash, ref, summary, author, email, datetime = entry.split("\n") + entries.append(LogEntry(short_hash, long_hash, ref, summary, raw_body, author, email, datetime)) return entries diff --git a/core/ui_mixins/quick_panel.py b/core/ui_mixins/quick_panel.py index 51ba79c46..139951d23 100644 --- a/core/ui_mixins/quick_panel.py +++ b/core/ui_mixins/quick_panel.py @@ -1,3 +1,4 @@ +from functools import partial import itertools import sublime from ...common import util @@ -498,12 +499,48 @@ def show_log_panel(entries, on_done, **kwargs): return lp +def short_ref(ref): + def simplify(r): + if r.startswith('HEAD -> '): + return '{}*'.format(r[8:]) + + if r.startswith('tag: '): + return r[5:] + + return r + + def remote_diverged_from_local(refs, r): + try: + a, b = r.split('/', 1) + except ValueError: + return True + else: + return False if b in refs else True + + if not ref: + return '' + + refs = ref.split(', ') + refs = [simplify(r) for r in refs] + refs = [r for r in refs if remote_diverged_from_local(refs, r)] + refs = ["|{}|".format(r) for r in refs] + + return ' '.join(refs) + + +filter_ = partial(filter, None) + + class LogPanel(PaginatedPanel): def format_item(self, entry): - return ([entry.short_hash + " " + entry.summary, - entry.author + ", " + util.dates.fuzzy(entry.datetime)], - entry.long_hash) + return ( + [ + " ".join(filter_((entry.short_hash, short_ref(entry.ref), entry.summary))), + ", ".join(filter_((entry.author, util.dates.fuzzy(entry.datetime)))), + ], + entry.long_hash + ) @property def next_page_message(self):