Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chg: dev: Refactored code as per suggestions from Vaab. split_regex is
Browse files Browse the repository at this point in the history
now named split_event_regex and defaults to None leaving default
behaviour as upstream.
HackingM committed Apr 28, 2015

Verified

This commit was signed with the committer’s verified signature. The key has expired.
jadolg Jorge Alberto Díaz Orozco (Akiel)
1 parent d383d5e commit d40870f
Showing 2 changed files with 27 additions and 31 deletions.
53 changes: 24 additions & 29 deletions gitchangelog.py
Original file line number Diff line number Diff line change
@@ -814,7 +814,7 @@ def makotemplate(template_name):
##

def changelog(repository,
split_regex=r'(?s)(.+?)(?=[Cc]hg|[Ff]ix|[Nn]ew|$)',
split_event_regex=None,
ignore_regexps=[],
section_regexps=[(None,'')],
unreleased_version_label="unreleased",
@@ -883,42 +883,37 @@ def changelog(repository,
## Loop through all the commits
for commit in commits:

## Split the combined subject and body if using a split_regex otherwise just
## Split the subject if using a split_event_regex otherwise just
## use the subject
if (len(strip(split_regex)) > 0):
events = re.split(split_regex, commit.subject + '\n\n' + commit.body)
if split_event_regex:
events = re.split(split_event_regex, commit.subject)
else:
events = commit.subject
events = [commit.subject]

## Loop through the resulting event list
for event in events:

## Check that the event is not just an empty string (presumably the split
## regex is not perfect)
if (len(strip(event)) > 0):
event = strip(event)
if not event:
continue

## If this event matches an ignore regex then skip it
if any(re.search(pattern, event) is not None
for pattern in ignore_regexps):
continue

## Find the first matching section (not sure why this is certain to work
## or what happens if it fails)
matched_section = first_matching(section_regexps, event)

## Finally store the commit in the matching section
if (len(strip(split_regex)) > 0):
sections[matched_section].append({
"author": commit.author_name,
"subject": subject_process(event),
"body": '',
})
else:
sections[matched_section].append({
"author": commit.author_name,
"subject": subject_process(event),
"body": body_process(commit.body),
})
## If this event matches an ignore regex then skip it
if any(re.search(pattern, event) is not None
for pattern in ignore_regexps):
continue

## Find the first matching section (not sure why this is certain to work
## or what happens if it fails)
matched_section = first_matching(section_regexps, event)

## Finally store the commit in the matching section
sections[matched_section].append({
"author": commit.author_name,
"subject": subject_process(event),
"body": '' if split_event_regex else body_process(commit.body),
})

## Flush current version
current_version["sections"] = [{"label": k, "commits": sections[k]}
@@ -1050,7 +1045,7 @@ def main():

content = changelog(
repository,
split_regex=config['split_regex'],
split_event_regex=config['split_event_regex'],
ignore_regexps=config['ignore_regexps'],
section_regexps=config['section_regexps'],
unreleased_version_label=config['unreleased_version_label'],
5 changes: 3 additions & 2 deletions gitchangelog.rc.reference
Original file line number Diff line number Diff line change
@@ -50,11 +50,12 @@
## message will be displayed in the changelog without reformatting.

##
## ``split_regex`` is a regex
## ``split_event_regex`` is a regex
##
## It is used to split a commit log entry into events before processing each event.
##
split_regex = r'(?s)(.+?)(?=[Cc]hg|[Ff]ix|[Nn]ew|$)'
#split_event_regex = r'(?s)(.+?)(?=(?:[Cc]hg|[Ff]ix|[Nn]ew)\s*:|\s*$)'
split_event_regex = None


##

0 comments on commit d40870f

Please sign in to comment.