#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  release-queue.py
#
#  Copyright 2014 Linaro Limited
#  Author: Neil Williams <neil.williams@linaro.org>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

import re
import os
import subprocess


def main():
    """
    Change the changes list to call whatever is your preferred
    viewer - however, note that the most useful method will be
    to let gerrit resolve the search into an actual review or
    review list.
    """
    try:
        chk = subprocess.check_call(["git", "log", "-n1"])
    except subprocess.CalledProcessError:
        print "Ensure this script is run from the git working copy."
        return 1
    master = []
    release = []
    pattern = re.compile("\s+Change-Id: (\w+)")
    subprocess.call(["git", "checkout", "master"])
    lines = subprocess.check_output(["git", "log"])
    for line in lines.split('\n'):
        if "Change-Id" in line:
            m = pattern.match(line)
            master.append(m.group(1))
    subprocess.call(["git", "checkout", "release"])
    lines = subprocess.check_output(["git", "log"])
    for line in lines.split('\n'):
        if "Change-Id" in line:
            m = pattern.match(line)
            release.append(m.group(1))
    diff = list(set(master) - set(release))
    changes = [
        "iceweasel",
        "-new-tab"
    ]
    for change in diff:
        changes.append("https://review.linaro.org/#/q/%s,n,z" % change)
    os.system(' '.join(changes))
    return 0

if __name__ == '__main__':
    main()

@@ -1345,16 +1345,95 @@
 (%5Cw+)%22)%0A
+    commit_pattern = re.compile(%22commit (.+)%22)%0A    # Get all commits on master%0A
     subp
@@ -1664,24 +1664,57 @@
 m.group(1))%0A
+    # Get all commits on release%0A
     subproce
@@ -1999,194 +1999,770 @@
     
-changes = %5B%0A        %22iceweasel%22,%0A        %22-new-tab%22%0A    %5D%0A    for change in diff:%0A        changes.append(%22https://review.linaro.org/#/q/%25s,n,z%22 %25 change)%0A    os.system(' '.join(changes))
+# Go back to master%0A    subprocess.call(%5B%22git%22, %22checkout%22, %22master%22%5D)%0A    lines = subprocess.check_output(%5B%22git%22, %22log%22%5D)%0A%0A    # Print each missing commit with more information%0A    current_hash = ''%0A    for change in diff:%0A        for line in lines.split('%5Cn'):%0A            # Get the commit hash%0A            if %22commit %22 in line:%0A                m = commit_pattern.match(line)%0A                if m:%0A                    current_hash = m.group(1)%0A            # Match the Change-id%0A            if %22Change-Id%22 in line:%0A                m = pattern.match(line)%0A                if change == m.group(1):%0A                    print %22%25s =%3E %25s%22 %25 (change, subprocess.check_output(%5B%22git%22, %22show%22, %22--pretty=oneline%22, current_hash%5D).split('%5Cn')%5B0%5D)%0A                    break%0A
 %0A   

Improve the release-queue script