|
17 | 17 | print("ERROR: GitPython is not installed. Install it with: pip install GitPython") |
18 | 18 | sys.exit(1) |
19 | 19 |
|
20 | | -from ciq_helpers import last_git_tag |
| 20 | +from ciq_helpers import get_git_user, last_git_tag, parse_kernel_tag, replace_spec_changelog |
21 | 21 |
|
22 | 22 |
|
23 | | -def calculate_lt_rebase_versions(upstream_tag, distlocalversion, dist): |
| 23 | +def calculate_lt_rebase_versions(kernel_version, distlocalversion, dist): |
24 | 24 | """Calculate version strings for LT rebase. |
25 | 25 |
|
26 | 26 | Arguments: |
27 | | - upstream_tag: Git tag from git describe (e.g., 'v6.12.74') |
| 27 | + kernel_version: Kernel version string (e.g., '6.12.74') |
28 | 28 | distlocalversion: DISTLOCALVERSION string (e.g., '.1.0.0') |
29 | 29 | dist: DIST string (e.g., '.el9_clk') |
30 | 30 |
|
31 | 31 | Returns: |
32 | 32 | Tuple of (full_kernel_version, tag_version, spectarfile_release, new_tag, major_version) |
33 | 33 | """ |
34 | | - # Remove 'v' prefix if present |
35 | | - full_kernel_version = upstream_tag.lstrip("v") |
36 | | - tag_version = f"{full_kernel_version}-1" |
| 34 | + tag_version = f"{kernel_version}-1" |
37 | 35 | spectarfile_release = f"{tag_version}{distlocalversion}{dist}" |
38 | 36 | new_tag = f"ciq_kernel-{tag_version}" |
39 | | - major_version = full_kernel_version.split(".")[0] |
| 37 | + major_version = kernel_version.split(".")[0] |
40 | 38 |
|
41 | | - return full_kernel_version, tag_version, spectarfile_release, new_tag, major_version |
| 39 | + return kernel_version, tag_version, spectarfile_release, new_tag, major_version |
42 | 40 |
|
43 | 41 |
|
44 | 42 | def update_spec_file( |
@@ -77,75 +75,49 @@ def update_spec_file( |
77 | 75 |
|
78 | 76 | # Get git user info, checking both repo-level and global config |
79 | 77 | try: |
80 | | - name = srcgit.git.config("user.name") |
81 | | - email = srcgit.git.config("user.email") |
| 78 | + name, email = get_git_user(srcgit) |
82 | 79 | except git.exc.GitCommandError as e: |
83 | 80 | print("ERROR: Failed to read git config. Please ensure user.name and user.email are configured.") |
84 | 81 | print(' Run: git config --global user.name "Your Name"') |
85 | 82 | print(' Run: git config --global user.email "your.email@example.com"') |
86 | 83 | print(f" Error details: {e}") |
87 | 84 | sys.exit(1) |
88 | 85 |
|
89 | | - new_spec = [] |
| 86 | + # Update version variables |
| 87 | + updated_spec = [] |
90 | 88 | for line in spec: |
91 | | - # Update version variables |
92 | 89 | if line.startswith("%define specrpmversion"): |
93 | 90 | line = f"%define specrpmversion {full_kernel_version}" |
94 | | - new_spec.append(line) |
95 | | - continue |
96 | | - |
97 | | - if line.startswith("%define specversion"): |
| 91 | + elif line.startswith("%define specversion"): |
98 | 92 | line = f"%define specversion {full_kernel_version}" |
99 | | - new_spec.append(line) |
100 | | - continue |
101 | | - |
102 | | - if line.startswith("%define tarfile_release"): |
| 93 | + elif line.startswith("%define tarfile_release"): |
103 | 94 | line = f"%define tarfile_release {spectarfile_release}" |
104 | | - new_spec.append(line) |
105 | | - continue |
106 | | - |
107 | | - # Replace changelog |
108 | | - if line.startswith("%changelog"): |
109 | | - new_spec.append(line) |
110 | | - |
111 | | - # Generate changelog header |
112 | | - changelog_date = time.strftime("%a %b %d %Y") |
113 | | - changelog_header = f"* {changelog_date} {name} <{email}> - {lt_tag_version}{distlocalversion}{dist}" |
114 | | - new_spec.append(changelog_header) |
115 | | - new_spec.append( |
116 | | - f"-- Rebased changes for Linux {full_kernel_version} (https://github.com/ctrliq/kernel-src-tree/releases/tag/{lt_new_tag})" |
117 | | - ) |
118 | | - |
119 | | - # Add all commits from upstream tag to HEAD |
120 | | - try: |
121 | | - commit_logs = srcgit.git.log("--no-merges", "--pretty=format:-- %s (%an)", f"{upstream_tag}..HEAD") |
122 | | - for log_line in commit_logs.split("\n"): |
123 | | - if log_line.strip(): |
124 | | - new_spec.append(log_line) |
125 | | - except git.exc.GitCommandError as e: |
126 | | - print(f"ERROR: Failed to get git log from {upstream_tag}..HEAD: {e}") |
127 | | - sys.exit(1) |
| 95 | + updated_spec.append(line) |
128 | 96 |
|
129 | | - new_spec.append("") |
130 | | - new_spec.append( |
131 | | - f"-- Linux {full_kernel_version} (https://cdn.kernel.org/pub/linux/kernel/v{lt_major_version}.x/ChangeLog-{full_kernel_version})" |
132 | | - ) |
133 | | - new_spec.append("") |
134 | | - new_spec.append("") |
| 97 | + # Build changelog entry lines |
| 98 | + changelog_date = time.strftime("%a %b %d %Y") |
| 99 | + changelog_lines = [ |
| 100 | + f"* {changelog_date} {name} <{email}> - {lt_tag_version}{distlocalversion}{dist}", |
| 101 | + f"-- Rebased changes for Linux {full_kernel_version} (https://github.com/ctrliq/kernel-src-tree/releases/tag/{lt_new_tag})", |
| 102 | + ] |
135 | 103 |
|
136 | | - # Preserve trailing comments from original spec file |
137 | | - in_changelog = False |
138 | | - for orig_line in spec: |
139 | | - if orig_line.startswith("%changelog"): |
140 | | - in_changelog = True |
141 | | - continue |
142 | | - if in_changelog and (orig_line.startswith("#") or orig_line.startswith("###")): |
143 | | - new_spec.append(orig_line) |
| 104 | + try: |
| 105 | + commit_logs = srcgit.git.log("--no-merges", "--pretty=format:-- %s (%an)", f"{upstream_tag}..HEAD") |
| 106 | + for log_line in commit_logs.split("\n"): |
| 107 | + if log_line.strip(): |
| 108 | + changelog_lines.append(log_line) |
| 109 | + except git.exc.GitCommandError as e: |
| 110 | + print(f"ERROR: Failed to get git log from {upstream_tag}..HEAD: {e}") |
| 111 | + sys.exit(1) |
144 | 112 |
|
145 | | - # Skip the rest of the original changelog |
146 | | - break |
| 113 | + changelog_lines += [ |
| 114 | + "", |
| 115 | + f"-- Linux {full_kernel_version} (https://cdn.kernel.org/pub/linux/kernel/v{lt_major_version}.x/ChangeLog-{full_kernel_version})", |
| 116 | + "", |
| 117 | + "", |
| 118 | + ] |
147 | 119 |
|
148 | | - new_spec.append(line) |
| 120 | + new_spec = replace_spec_changelog(updated_spec, changelog_lines) |
149 | 121 |
|
150 | 122 | # Write the updated spec file |
151 | 123 | try: |
@@ -189,25 +161,15 @@ def update_spec_file( |
189 | 161 | print(f"Using last tag: {upstream_tag}") |
190 | 162 |
|
191 | 163 | # Validate tag format (should be like 'v6.12.74' or '6.12.74') |
192 | | - tag_without_v = upstream_tag.lstrip("v") |
193 | | - tag_parts = tag_without_v.split(".") |
194 | | - if len(tag_parts) != 3: |
195 | | - print(f"ERROR: Invalid tag format: {upstream_tag}") |
196 | | - print(" Expected format: vX.Y.Z or X.Y.Z (e.g., v6.12.74)") |
197 | | - sys.exit(1) |
198 | | - |
199 | | - # Validate that parts are numeric |
200 | 164 | try: |
201 | | - for part in tag_parts: |
202 | | - int(part) |
203 | | - except ValueError: |
204 | | - print(f"ERROR: Invalid tag format: {upstream_tag}") |
205 | | - print(" Tag version parts must be numeric") |
| 165 | + kernel_version = parse_kernel_tag(upstream_tag) |
| 166 | + except ValueError as e: |
| 167 | + print(f"ERROR: {e}") |
206 | 168 | sys.exit(1) |
207 | 169 |
|
208 | 170 | # Calculate version strings |
209 | 171 | full_kernel_version, tag_version, spectarfile_release, new_tag, major_version = calculate_lt_rebase_versions( |
210 | | - upstream_tag, args.distlocalversion, args.dist |
| 172 | + kernel_version, args.distlocalversion, args.dist |
211 | 173 | ) |
212 | 174 |
|
213 | 175 | print("\nLT Rebase Version Information:") |
|
0 commit comments