Skip to content

Commit

Permalink
gitlog2changelog.py: sync to releasebranch_8_4 (fixes invalid escape …
Browse files Browse the repository at this point in the history
…sequence)
  • Loading branch information
neteler committed Sep 29, 2024
1 parent 4421e8a commit db68d02
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions tools/gitlog2changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@
# Minor changes for NUT by Charles Lepple
# Distributed under the terms of the GNU General Public License v2 or later

import string, re, os
import re
from textwrap import TextWrapper
import sys
import subprocess

rev_range = ''
rev_range = ""


# Define the git command and its arguments as a list
git_command = [
"git",
"log",
"--summary",
"--stat",
"--no-merges",
"--date=short",
]

if len(sys.argv) > 1:
base = sys.argv[1]
rev_range = '%s..HEAD' % base
rev_range = "%s..HEAD" % base
git_command.append(rev_range)

# Execute git log with the desired command line options.
fin = os.popen('git log --summary --stat --no-merges --date=short %s' % rev_range, 'r')
process = subprocess.Popen(git_command, stdout=subprocess.PIPE, encoding="utf8")
fin = process.stdout

# Create a ChangeLog file in the current directory.
fout = open('ChangeLog', 'w')
fout = open("ChangeLog", "w")

# Set up the loop variables in order to locate the blocks we want
authorFound = False
Expand All @@ -33,7 +48,7 @@
# The main part of the loop
for line in fin:
# The commit line marks the start of a new commit object.
if line.startswith('commit'):
if line.startswith("commit"):
# Start all over again...
authorFound = False
dateFound = False
Expand All @@ -45,32 +60,32 @@
continue
# Match the author line and extract the part we want
# (Don't use startswith to allow Author override inside commit message.)
elif 'Author:' in line:
authorList = re.split(': ', line, 1)
elif "Author:" in line:
authorList = re.split(": ", line, 1)
try:
author = authorList[1]
author = author[0:len(author)-1]
author = author[0 : len(author) - 1]
authorFound = True
except:
print ("Could not parse authorList = '%s'" % (line))
print("Could not parse authorList = '%s'" % (line))

# Match the date line
elif line.startswith('Date:'):
dateList = re.split(': ', line, 1)
elif line.startswith("Date:"):
dateList = re.split(": ", line, 1)
try:
date = dateList[1]
date = date[0:len(date)-1]
date = date[0 : len(date) - 1]
dateFound = True
except:
print ("Could not parse dateList = '%s'" % (line))
print("Could not parse dateList = '%s'" % (line))
# The Fossil-IDs are ignored:
elif line.startswith(' Fossil-ID:') or line.startswith(' [[SVN:'):
elif line.startswith(" Fossil-ID:") or line.startswith(" [[SVN:"):
continue
# The svn-id lines are ignored
elif ' git-svn-id:' in line:
elif " git-svn-id:" in line:
continue
# The sign off line is ignored too
elif 'Signed-off-by' in line:
elif "Signed-off-by" in line:
continue
# Extract the actual commit message for this commit
elif authorFound & dateFound & messageFound == False:
Expand All @@ -88,12 +103,12 @@
else:
message = message + " " + line.strip()
# If this line is hit all of the files have been stored for this commit
elif re.search('files? changed', line):
elif re.search("files? changed", line):
filesFound = True
continue
# Collect the files for this commit. FIXME: Still need to add +/- to files
elif authorFound & dateFound & messageFound:
fileList = re.split(' \| ', line, 2)
fileList = re.split(r" \| ", line, 2)
if len(fileList) > 1:
if len(files) > 0:
files = files + ", " + fileList[0].strip()
Expand All @@ -118,7 +133,7 @@
# Write out the commit line
fout.write(wrapper.fill(commitLine) + "\n")

#Now reset all the variables ready for a new commit block.
# Now reset all the variables ready for a new commit block.
authorFound = False
dateFound = False
messageFound = False
Expand Down

0 comments on commit db68d02

Please sign in to comment.