File: generate_log_feature_release.py

package info (click to toggle)
gdal 3.6.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 89,664 kB
  • sloc: cpp: 1,136,033; ansic: 197,355; python: 35,910; java: 5,511; xml: 4,011; sh: 3,950; cs: 2,443; yacc: 1,047; makefile: 288
file content (62 lines) | stat: -rwxr-xr-x 1,888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python

import os
import sys

if len(sys.argv) == 1:
    VERSION = open("VERSION", "rt").read()
    VERSION = VERSION.split(".")
    last_release_branch = "%d.%d" % (int(VERSION[0]), int(VERSION[1]) - 1)
else:
    last_release_branch = sys.argv[1]

print("Generating /tmp/log.txt with changes not in %s branch" % last_release_branch)

os.system(
    f'git log --reverse -v v{last_release_branch}.0..HEAD . ":(exclude)autotest" ":(exclude)doc" ":(exclude).github" > /tmp/log_raw.txt'
)
os.system(
    f'git log --no-merges --reverse -v v{last_release_branch}.0..release/{last_release_branch} . ":(exclude)autotest" ":(exclude)doc" ":(exclude).github" > /tmp/log_bugfixes.txt'
)


class Commit(object):
    def __init__(self):
        self.metadata = ""
        self.message = ""


def get_commits(filename):
    commits = []
    commit = None
    for l in open(filename, "rt").readlines():
        if l.startswith("commit "):
            commit = Commit()
            commits.append(commit)
            commit.metadata += l
        elif commit.message == "" and l == "\n":
            commit.message += l
        elif commit.message == "":
            commit.metadata += l
        else:
            commit.message += l
    return commits


raw_commits = get_commits("/tmp/log_raw.txt")
bugfixes_commits = get_commits("/tmp/log_bugfixes.txt")
set_bugfixes_commit_messages = set()
for commit in bugfixes_commits:
    set_bugfixes_commit_messages.add(commit.message)

with open("/tmp/log.txt", "wt") as f:
    for commit in raw_commits:
        is_bugfix = False
        message = commit.message.split("\n")[1]
        for bugfix_commit_message in set_bugfixes_commit_messages:
            if message in bugfix_commit_message:
                is_bugfix = True
                break
        if not is_bugfix:
            f.write(commit.metadata)
            f.write(commit.message)