Skip to content

Commit

Permalink
Tell _render_branch_list which dates to use explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste committed Apr 6, 2024
1 parent a3d21da commit 1300987
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/interfaces/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,30 +226,31 @@ def sectionizer(branch):

local_branches = sorted(local_branches, key=sectionizer)
return "\n{}\n".format(" " * 60).join(
self._render_branch_list(None, list(branches), descriptions, section_key)
self._render_branch_list(
None, list(branches), descriptions, human_dates=section_key != (5, 0))
for section_key, branches in groupby(local_branches, sectionizer)
)

else:
if sort_by_recent:
local_branches = sorted(local_branches, key=lambda branch: -branch.committerdate)
return self._render_branch_list(None, local_branches, descriptions, (1, 0))
return self._render_branch_list(None, local_branches, descriptions)

def _render_branch_list(self, remote_name, branches, descriptions, section_key):
# type: (Optional[str], List[Branch], Dict[str, str], Tuple) -> str
def _render_branch_list(self, remote_name, branches, descriptions, human_dates=True):
# type: (Optional[str], List[Branch], Dict[str, str], bool) -> str
remote_name_length = len(remote_name + "/") if remote_name else 0

def mangle_date(branch: Branch, previous: Optional[Branch]):
def get_date(branch):
if section_key == (5, 0):
if not human_dates:
d = branch.relative_committerdate
if d == "12 months ago":
d = "1 year ago"
return re.sub(r", \d+ months ago", " ago", d)
return branch.human_committerdate

date = get_date(branch)
if section_key != (5, 0) and previous and get_date(previous) == date:
if human_dates and previous and get_date(previous) == date:
return ""
return date

Expand Down Expand Up @@ -315,7 +316,7 @@ def render_remotes_on(self, branches, sort_by_recent, remotes):
def render(remote_name=remote_name, branches=branches) -> str:
return self.template_remote.format(
remote_name=remote_name,
remote_branch_list=self._render_branch_list(remote_name, branches, {}, (1, 0))
remote_branch_list=self._render_branch_list(remote_name, branches, {})
)

render_fns.append(render)
Expand Down

0 comments on commit 1300987

Please sign in to comment.