2020-02-16 20:58:01 +01:00
|
|
|
#!/usr/bin/env python
|
2019-01-16 18:33:22 +01:00
|
|
|
# Copyright (c) 2014-2019, The Tor Project, Inc.
|
2014-06-16 21:00:10 +02:00
|
|
|
# See LICENSE for licensing information
|
|
|
|
|
|
|
|
"""This script sorts a bunch of changes files listed on its command
|
|
|
|
line into roughly the order in which they should appear in the
|
|
|
|
changelog.
|
|
|
|
"""
|
2014-05-29 17:21:17 +02:00
|
|
|
|
2019-12-12 06:58:51 +01:00
|
|
|
# Future imports for Python 2.7, mandatory in 3.0
|
|
|
|
from __future__ import division
|
2019-12-09 16:53:48 +01:00
|
|
|
from __future__ import print_function
|
2019-12-12 06:58:51 +01:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-05-29 17:21:17 +02:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def fetch(fn):
|
|
|
|
with open(fn) as f:
|
|
|
|
s = f.read()
|
|
|
|
s = "%s\n" % s.rstrip()
|
|
|
|
return s
|
|
|
|
|
2016-02-01 22:56:20 +01:00
|
|
|
CSR='Code simplification and refactoring'
|
|
|
|
|
|
|
|
REPLACEMENTS = {
|
|
|
|
# plurals
|
|
|
|
'Minor bugfix' : 'Minor bugfixes',
|
|
|
|
'Major bugfix' : 'Major bugfixes',
|
|
|
|
'Minor feature' : 'Minor features',
|
|
|
|
'Major feature' : 'Major features',
|
|
|
|
'Removed feature' : 'Removed features',
|
|
|
|
'Code simplification and refactorings' : CSR,
|
|
|
|
'Code simplifications and refactoring' : CSR,
|
|
|
|
'Code simplifications and refactorings' : CSR,
|
|
|
|
|
|
|
|
# wrong words
|
|
|
|
'Minor fix' : 'Minor bugfixes',
|
|
|
|
'Major fix' : 'Major bugfixes',
|
|
|
|
'Minor fixes' : 'Minor bugfixes',
|
|
|
|
'Major fixes' : 'Major bugfixes',
|
|
|
|
'Minor enhancement' : 'Minor features',
|
|
|
|
'Minor enhancements' : 'Minor features',
|
|
|
|
'Major enhancement' : 'Major features',
|
|
|
|
'Major enhancements' : 'Major features',
|
|
|
|
}
|
|
|
|
|
2014-12-22 16:00:34 +01:00
|
|
|
def score(s,fname=None):
|
2015-05-05 17:24:01 +02:00
|
|
|
m = re.match(r'^ +o ([^\n]*)\n(.*)', s, re.M|re.S)
|
2014-05-29 17:21:17 +02:00
|
|
|
if not m:
|
2019-12-09 16:53:48 +01:00
|
|
|
print("Can't score %r from %s"%(s,fname), file=sys.stderr)
|
2016-02-01 22:56:20 +01:00
|
|
|
heading = m.group(1)
|
|
|
|
heading = REPLACEMENTS.get(heading, heading)
|
2014-05-29 17:21:17 +02:00
|
|
|
lw = m.group(1).lower()
|
|
|
|
if lw.startswith("major feature"):
|
|
|
|
score = 0
|
|
|
|
elif lw.startswith("major bug"):
|
|
|
|
score = 1
|
|
|
|
elif lw.startswith("major"):
|
|
|
|
score = 2
|
|
|
|
elif lw.startswith("minor feature"):
|
|
|
|
score = 10
|
|
|
|
elif lw.startswith("minor bug"):
|
|
|
|
score = 11
|
|
|
|
elif lw.startswith("minor"):
|
|
|
|
score = 12
|
|
|
|
else:
|
|
|
|
score = 100
|
|
|
|
|
2016-02-01 22:56:20 +01:00
|
|
|
return (score, lw, heading, m.group(2))
|
2015-05-05 17:24:01 +02:00
|
|
|
|
|
|
|
def splitChanges(s):
|
|
|
|
this_entry = []
|
|
|
|
for line in s.split("\n"):
|
|
|
|
if line.strip() == "":
|
|
|
|
continue
|
|
|
|
if re.match(r" +o ", line):
|
|
|
|
if len(this_entry) > 2:
|
|
|
|
yield "".join(this_entry)
|
|
|
|
curHeader = line
|
|
|
|
this_entry = [ curHeader, "\n" ]
|
|
|
|
continue
|
|
|
|
elif re.match(r" +- ", line):
|
|
|
|
if len(this_entry) > 2:
|
|
|
|
yield "".join(this_entry)
|
|
|
|
this_entry = [ curHeader, "\n" ]
|
|
|
|
|
|
|
|
this_entry.append(line)
|
|
|
|
this_entry.append("\n")
|
2014-05-29 17:21:17 +02:00
|
|
|
|
2015-05-05 17:24:01 +02:00
|
|
|
if len(this_entry) > 2:
|
|
|
|
yield "".join(this_entry)
|
2014-05-29 17:21:17 +02:00
|
|
|
|
2015-05-05 17:24:01 +02:00
|
|
|
|
|
|
|
changes = []
|
|
|
|
|
|
|
|
for fn in sys.argv[1:]:
|
|
|
|
if fn.endswith('~'):
|
|
|
|
continue
|
|
|
|
for change in splitChanges(fetch(fn)):
|
|
|
|
changes.append(score(change,fn))
|
2014-05-29 17:21:17 +02:00
|
|
|
|
|
|
|
changes.sort()
|
|
|
|
|
2015-05-05 17:24:01 +02:00
|
|
|
last_lw = "this is not a header"
|
|
|
|
for _, lw, header, rest in changes:
|
|
|
|
if lw == last_lw:
|
2019-12-09 16:53:48 +01:00
|
|
|
print(rest, end="")
|
2015-05-05 17:24:01 +02:00
|
|
|
else:
|
2019-12-09 16:53:48 +01:00
|
|
|
print()
|
|
|
|
print(" o",header)
|
|
|
|
print(rest, end="")
|
2015-05-05 17:24:01 +02:00
|
|
|
last_lw = lw
|