1 |
Use skel.ChangeLog from the repo to create the header of a new ChangeLog |
2 |
file. Else, we just retain the original header of the ChangeLog. When |
3 |
no skel.ChangeLog file exists, and this is a new ChangeLog, no header is |
4 |
used. |
5 |
|
6 |
diff --git a/bin/repoman b/bin/repoman |
7 |
--- a/bin/repoman |
8 |
+++ b/bin/repoman |
9 |
@@ -2450,7 +2450,7 @@ |
10 |
new_changelog = utilities.UpdateChangeLog(checkdir_relative, \ |
11 |
catdir, pkgdir, \ |
12 |
clnew, clremoved, clchanged, \ |
13 |
- changelog_msg, options.pretend) |
14 |
+ changelog_msg, options.pretend, repodir) |
15 |
if new_changelog is None: |
16 |
writemsg_level("!!! Updating the ChangeLog failed\n", \ |
17 |
level=logging.ERROR, noiselevel=-1) |
18 |
diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py |
19 |
--- a/pym/repoman/utilities.py |
20 |
+++ b/pym/repoman/utilities.py |
21 |
@@ -523,7 +523,8 @@ |
22 |
|
23 |
return outvcs |
24 |
|
25 |
-def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, pretend): |
26 |
+def UpdateChangeLog(pkgdir, category, package, new, removed, changed, \ |
27 |
+ msg, pretend, repodir): |
28 |
""" Write an entry to an existing ChangeLog, or create a new one. """ |
29 |
|
30 |
# figure out who to write as |
31 |
@@ -550,7 +551,6 @@ |
32 |
cl_path = os.path.join(pkgdir, 'ChangeLog') |
33 |
clold_lines = [] |
34 |
clnew_lines = [] |
35 |
- old_header_lines = [] |
36 |
header_lines = [] |
37 |
|
38 |
try: |
39 |
@@ -559,41 +559,50 @@ |
40 |
mode='r', encoding=_encodings['repo.content'], errors='replace') |
41 |
except EnvironmentError: |
42 |
clold_file = None |
43 |
+ |
44 |
+ clskel_file = None |
45 |
+ if clold_file is None: |
46 |
+ # we will only need the ChangeLog skeleton if there is no |
47 |
+ # ChangeLog yet |
48 |
+ try: |
49 |
+ clskel_path = os.path.join(repodir, 'skel.ChangeLog') |
50 |
+ clskel_file = io.open(_unicode_encode(clskel_path, |
51 |
+ encoding=_encodings['fs'], errors='strict'), |
52 |
+ mode='r', encoding=_encodings['repo.content'], |
53 |
+ errors='replace') |
54 |
+ except EnvironmentError: |
55 |
+ pass |
56 |
|
57 |
f, clnew_path = mkstemp() |
58 |
|
59 |
- # create an empty ChangeLog.new with correct header first |
60 |
+ # construct correct header first |
61 |
try: |
62 |
- f = io.open(f, mode='w', encoding=_encodings['repo.content'], |
63 |
- errors='backslashreplace') |
64 |
- |
65 |
- if clold_file is None: |
66 |
- header_lines.append(_unicode_decode('# ChangeLog for %s/%s\n' % |
67 |
- (category, package))) |
68 |
- year = time.strftime('%Y') |
69 |
- header_lines.append(_unicode_decode('# Copyright 1999-' |
70 |
- '%s Gentoo Foundation; Distributed under the GPL v2\n' % year)) |
71 |
- header_lines.append(_unicode_decode('# $Header: $\n')) |
72 |
- header_lines.append(_unicode_decode('\n')) |
73 |
- else: |
74 |
+ if clold_file is not None: |
75 |
+ # retain header from old ChangeLog |
76 |
for line in clold_file: |
77 |
- line_strip = line.strip() |
78 |
- if line_strip and line[:1] != "#": |
79 |
- clold_lines.append(line) |
80 |
+ line_strip = line.strip() |
81 |
+ clold_lines.append(line) |
82 |
+ if line_strip[:1] != '#': |
83 |
break |
84 |
- header_lines.append(line) |
85 |
+ if clskel_file is None: |
86 |
+ clnew_lines.append(line) |
87 |
if not line_strip: |
88 |
break |
89 |
- |
90 |
- # update the copyright year |
91 |
- old_header_lines = header_lines[:] |
92 |
- if len(header_lines) >= 2: |
93 |
- header_lines[1] = re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ', |
94 |
- r'\1-%s ' % time.strftime('%Y'), header_lines[1]) |
95 |
+ elif clskel_file is not None: |
96 |
+ # read skel.ChangeLog up to first empty line |
97 |
+ for line in clskel_file: |
98 |
+ line_strip = line.strip() |
99 |
+ if not line_strip: |
100 |
+ break |
101 |
+ line = line.replace('<CATEGORY>', category) |
102 |
+ line = line.replace('<PACKAGE_NAME>', package) |
103 |
+ line = re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ', |
104 |
+ r'\1-%s ' % time.strftime('%Y'), line) |
105 |
+ clnew_lines.append(line) |
106 |
+ clnew_lines.append(_unicode_decode('\n')) |
107 |
+ clskel_file.close() |
108 |
|
109 |
# write new ChangeLog entry |
110 |
- clnew_lines.extend(header_lines) |
111 |
- date = time.strftime('%d %b %Y') |
112 |
newebuild = False |
113 |
for fn in new: |
114 |
if not fn.endswith('.ebuild'): |
115 |
@@ -632,20 +641,18 @@ |
116 |
clnew_lines.append(_unicode_decode('%s\n' % line)) |
117 |
clnew_lines.append(_unicode_decode('\n')) |
118 |
|
119 |
+ f = io.open(f, mode='w', encoding=_encodings['repo.content'], |
120 |
+ errors='backslashreplace') |
121 |
+ |
122 |
for line in clnew_lines: |
123 |
f.write(line) |
124 |
|
125 |
# append stuff from old ChangeLog |
126 |
if clold_file is not None: |
127 |
- # If the old ChangeLog didn't have a header, then |
128 |
# clold_lines may contain a saved non-header line |
129 |
# that we want to write first. |
130 |
- for line in clold_lines: |
131 |
- f.write(line) |
132 |
- |
133 |
- # Now prepend old_header_lines to clold_lines, for use |
134 |
- # in the unified_diff call below. |
135 |
- clold_lines = old_header_lines + clold_lines |
136 |
+ if clold_lines[-1].strip(): |
137 |
+ f.write(clold_lines[-1]) |
138 |
|
139 |
for line in clold_file: |
140 |
f.write(line) |
141 |
@@ -655,7 +662,7 @@ |
142 |
# show diff (do we want to keep on doing this, or only when |
143 |
# pretend?) |
144 |
for line in difflib.unified_diff(clold_lines, clnew_lines, |
145 |
- fromfile=cl_path, tofile=cl_path + '.new', n=0): |
146 |
+ fromfile=cl_path, tofile=cl_path, n=0): |
147 |
util.writemsg_stdout(line, noiselevel=-1) |
148 |
util.writemsg_stdout("\n", noiselevel=-1) |
149 |
|
150 |
@@ -663,7 +670,7 @@ |
151 |
# remove what we've done |
152 |
os.remove(clnew_path) |
153 |
else: |
154 |
- # rename ChangeLog.new to ChangeLog, and set permissions |
155 |
+ # rename to ChangeLog, and set permissions |
156 |
try: |
157 |
clold_stat = os.stat(cl_path) |
158 |
except OSError: |