Skip to content

Commit

Permalink
Move code and flip conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste committed Apr 6, 2024
1 parent 6cbf5ee commit c7f6a00
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions core/interfaces/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,25 @@ def sectionizer(branch):

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 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)
def get_date(branch):
if human_dates:
return branch.human_committerdate

d = branch.relative_committerdate
if d == "12 months ago":
d = "1 year ago"
# Shorten relative dates with months e.g. "1 year, 1 month ago"
# to just "1 year ago".
return re.sub(r", \d+ months? ago", " ago", d)

def mangle_date(branch: Branch, previous: Optional[Branch]):
date = get_date(branch)
if human_dates and previous and get_date(previous) == date:
return ""
return date

remote_name_length = len(remote_name + "/") if remote_name else 0
paired_with_previous: Iterable[Tuple[Optional[Branch], Branch]] = \
pairwise(chain([None], branches)) # type: ignore[list-item]
return "\n".join(
Expand Down

0 comments on commit c7f6a00

Please sign in to comment.