]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
UBUNTU: [Packaging] git-ubuntu-log -- handle multiple bugs/cves better
authorAndy Whitcroft <apw@canonical.com>
Mon, 15 Jan 2018 13:26:19 +0000 (13:26 +0000)
committerMarcelo Henrique Cerri <marcelo.cerri@canonical.com>
Mon, 15 Jan 2018 18:45:41 +0000 (16:45 -0200)
BugLink: http://bugs.launchpad.net/bugs/1743383
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
debian/scripts/misc/git-ubuntu-log

index eee983f82354d8c9b4edf453973f31541dd9a446..e428e5727911fe84083ab576e2e3fa17d0c3c062 100755 (executable)
@@ -15,14 +15,28 @@ sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
 entries = []
 def add_entry(entry):
     if entry and 'ignore' not in entry:
-        if 'bugs' not in entry and 'cves' in entry:
-            for cve in entry['cves']:
-                if cve not in bugs:
-                    bugs.append(cve)
+        combo = []
+        for bug in entry.get('bugs', []):
+            combo.append(bug)
+        for cve in entry.get('cves', []):
+            combo.append(cve)
+        combo = sorted(combo)
+
+        if len(combo) == 0:
+            if entry.get('title', "").startswith('UBUNTU'):
+                combo = '__packaging__'
+            else:
+                combo = '__mainline__'
+        else:
+            if combo not in keys:
+                keys.append(combo)
+
+        entry['key'] = combo
         entries.append(entry)
 
+
 # Suck up the git log output and extract the information we need.
-bugs = []
+keys = []
 entry = None
 subject_wait = False
 for line in sys.stdin:
@@ -44,10 +58,6 @@ for line in sys.stdin:
         bits = bits[1].split('/')
         entry.setdefault('bugs', []).append(bits[-1])
 
-        # Accumulate bug numbers.
-        if bits[-1] not in bugs:
-            bugs.append(bits[-1])
-
     elif line.startswith('    CVE-'):
         entry.setdefault('cves', []).append(line.strip())
 
@@ -66,60 +76,64 @@ for entry in entries:
         del entry['author']
 
 # Lump everything without a bug at the bottom.
-bugs.append('__packaging__')
-bugs.append('__mainline__')
+keys.append('__packaging__')
+keys.append('__mainline__')
 
 emit_nl = False
-for bug in bugs:
-    if bug == '__packaging__':
-        title = 'Miscellaneous Ubuntu changes'
-    elif bug == '__mainline__':
-        title = 'Miscellaneous upstream changes'
-    elif bug.startswith('CVE-'):
-        title = bug
+for key in keys:
+    if key == '__packaging__':
+        title_set = [ 'Miscellaneous Ubuntu changes' ]
+    elif key == '__mainline__':
+        title_set = [ 'Miscellaneous upstream changes' ]
     else:
-        bug_info = None
-
-        try:
-            #urllib.request.urlcleanup()
-            request = urllib.request.Request('https://api.launchpad.net/devel/bugs/' + bug)
-            request.add_header('Cache-Control', 'max-age=0')
-            with urllib.request.urlopen(request) as response:
-                data = response.read()
-                bug_info = json.loads(data.decode('utf-8'))
-            
-            title = bug_info['title']
-            if 'description' in bug_info:
-                for line in bug_info['description'].split('\n'):
-                    if line.startswith('Kernel-Description:'):
-                        title = line.split(' ', 1)[1]
-
-        except urllib.error.HTTPError:
-            title = 'INVALID or PRIVATE BUG'
-
-        title += ' (LP###' + bug + ')'
+        title_set = []
+        for bug in key:
+            if bug.startswith('CVE-'):
+                title_set.append(bug)
+            else:
+                bug_info = None
+
+                try:
+                    #urllib.request.urlcleanup()
+                    request = urllib.request.Request('https://api.launchpad.net/devel/bugs/' + bug)
+                    request.add_header('Cache-Control', 'max-age=0')
+                    with urllib.request.urlopen(request) as response:
+                        data = response.read()
+                        bug_info = json.loads(data.decode('utf-8'))
+
+                    title = bug_info['title']
+                    if 'description' in bug_info:
+                        for line in bug_info['description'].split('\n'):
+                            if line.startswith('Kernel-Description:'):
+                                title = line.split(' ', 1)[1]
+
+                except urllib.error.HTTPError:
+                    title = 'INVALID or PRIVATE BUG'
+
+                title += ' (LP###' + bug + ')'
+                title_set.append(title)
+
 
     emit_title = True
     for entry in entries:
-        if (bug == '__packaging__' and 'bugs' not in entry and 'cves' not in entry and 'author' in entry) or \
-           (bug == '__mainline__' and 'bugs' not in entry and 'cves' not in entry and 'author' not in entry) or \
-           ('bugs' in entry and bug in entry['bugs']) or \
-           ('cves' in entry and bug in entry['cves']):
-            if emit_title:
-                if emit_nl:
-                    print('')
-                emit_nl = True
-
-                title_lines = textwrap.wrap(title, 76)
-                print('  * ' + title_lines[0].replace('LP###', 'LP: #'))
-                for line in title_lines[1:]:
-                    line = line.replace('LP###', 'LP: #')
-                    print('    ' + line)
-
-                emit_title = False
-            title_lines = textwrap.wrap(entry['subject'], 76)
-            print('    - ' + title_lines[0])
+        if entry['key'] != key:
+            continue
+
+        if emit_title:
+            if emit_nl:
+                print('')
+            emit_nl = True
+
+            title_lines = textwrap.wrap('#// '.join(title_set), 76)
+            print('  * ' + title_lines[0].replace('LP###', 'LP: #').replace('#//', ' //'))
             for line in title_lines[1:]:
-                line = line.replace('LP###', 'LP: #')
-                print('      ' + line)
+                line = line.replace('LP###', 'LP: #').replace('#//', ' //')
+                print('    ' + line)
+
+            emit_title = False
 
+        title_lines = textwrap.wrap(entry['subject'], 76)
+        print('    - ' + title_lines[0])
+        for line in title_lines[1:]:
+            line = line.replace('LP###', 'LP: #')
+            print('      ' + line)