]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - debian/scripts/misc/git-ubuntu-log
UBUNTU: [Debian] git-ubuntu-log -- prevent bug references being split
[mirror_ubuntu-zesty-kernel.git] / debian / scripts / misc / git-ubuntu-log
CommitLineData
cda0d3d5
AW
1#!/usr/bin/python3
2
3import os
4import sys
5
d603dbde 6import codecs
cda0d3d5
AW
7import urllib.request
8import json
9
731ac071
AW
10import textwrap
11
d603dbde
AW
12sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
13
cda0d3d5
AW
14# Suck up the git log output and extract the information we need.
15bugs = []
16entries = []
17entry = None
18subject_wait = False
19for line in sys.stdin:
20 if line.startswith('commit '):
21 if entry and 'ignore' not in entry:
22 entries.append(entry)
23 entry = {}
24 subject_wait = True
25
26 elif line.startswith('Author: '):
27 bits = line.strip().split(maxsplit=1)
28 entry['author'] = bits[1]
29
30 elif subject_wait and line.startswith(' '):
31 subject_wait = False
32 entry['subject'] = line.strip()
33
34 elif line.startswith(' BugLink: ') and 'launchpad.net' in line:
35 bits = line.strip().split(maxsplit=1)
36 bits = bits[1].split('/')
37 entry.setdefault('bugs', []).append(bits[-1])
38
39 # Accumulate bug numbers.
40 if bits[-1] not in bugs:
41 bugs.append(bits[-1])
42
43 elif line.startswith(' Ignore:'):
44 entry['ignore'] = True
45
46
96ba41d4
AW
47if entry and 'ignore' not in entry:
48 entries.append(entry)
49
cda0d3d5
AW
50entries.reverse()
51
52# Go through the entries and clear out authors for upstream commits.
53for entry in entries:
54 if entry['subject'].startswith('UBUNTU:'):
55 entry['subject'] = entry['subject'][7:].strip()
56 else:
57 del entry['author']
58
59# Lump everything without a bug at the bottom.
60bugs.append('__packaging__')
61bugs.append('__mainline__')
62
0eda7c2e 63emit_nl = False
cda0d3d5 64for bug in bugs:
cda0d3d5
AW
65 if bug == '__packaging__':
66 title = 'Miscellaneous Ubuntu changes'
67 elif bug == '__mainline__':
68 title = 'Miscellaneous upstream changes'
69 else:
70 bug_info = None
71
f690812d
AW
72 try:
73 #urllib.request.urlcleanup()
74 request = urllib.request.Request('https://api.launchpad.net/devel/bugs/' + bug)
75 request.add_header('Cache-Control', 'max-age=0')
76 with urllib.request.urlopen(request) as response:
77 data = response.read()
78 bug_info = json.loads(data.decode('utf-8'))
79
80 title = bug_info['title']
81 if 'description' in bug_info:
82 for line in bug_info['description'].split('\n'):
83 if line.startswith('Kernel-Description:'):
84 title = line.split(' ', 1)[1]
85
86 except urllib.error.HTTPError:
87 title = 'INVALID or PRIVATE BUG'
cda0d3d5 88
152eff9f 89 title += ' (LP###' + bug + ')'
cda0d3d5 90
0eda7c2e 91 emit_title = True
cda0d3d5
AW
92 for entry in entries:
93 if (bug == '__packaging__' and 'bugs' not in entry and 'author' in entry) or \
94 (bug == '__mainline__' and 'bugs' not in entry and 'author' not in entry) or \
95 ('bugs' in entry and bug in entry['bugs']):
0eda7c2e
AW
96 if emit_title:
97 if emit_nl:
98 print('')
99 emit_nl = True
100
731ac071 101 title_lines = textwrap.wrap(title, 76)
152eff9f 102 print(' * ' + title_lines[0].replace('LP###', 'LP: #'))
731ac071 103 for line in title_lines[1:]:
152eff9f 104 line = line.replace('LP###', 'LP: #')
731ac071
AW
105 print(' ' + line)
106
0eda7c2e 107 emit_title = False
731ac071
AW
108 title_lines = textwrap.wrap(entry['subject'], 76)
109 print(' - ' + title_lines[0])
110 for line in title_lines[1:]:
152eff9f 111 line = line.replace('LP###', 'LP: #')
731ac071 112 print(' ' + line)
cda0d3d5 113