git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #94999 from StijnDW/redmine

nixos/redmine: patch mercurial integration

commit8e63d1268c711721b20da2763b189dc9e290fa48 authorAaron Andersen <aaron@fosslib.net> dateTue 11 Aug 2020, 20:56 (6 years ago) parentbf47b8264fde26
2 files changed+279
pkgs/applications/version-management/redmine/0001-python3.patch+275 pkgs/applications/version-management/redmine/default.nix+4
pkgs/applications/version-management/redmine/0001-python3.patchnew file+275
@@ -0,0 +1,275 @@
1+--- a/lib/redmine/scm/adapters/mercurial/redminehelper.py
2++++ b/lib/redmine/scm/adapters/mercurial/redminehelper.py
3+@@ -45,17 +45,20 @@ Output example of rhmanifest::
4+ </repository>
5+ </rhmanifest>
6+ """
7+-import re, time, cgi, urllib
8++import re, time, html, urllib
9+ from mercurial import cmdutil, commands, node, error, hg, registrar
10+
11+ cmdtable = {}
12+ command = registrar.command(cmdtable) if hasattr(registrar, 'command') else cmdutil.command(cmdtable)
13+
14+-_x = cgi.escape
15+-_u = lambda s: cgi.escape(urllib.quote(s))
16++_x = lambda s: html.escape(s.decode('utf-8')).encode('utf-8')
17++_u = lambda s: html.escape(urllib.parse.quote(s)).encode('utf-8')
18++
19++def unquoteplus(*args, **kwargs):
20++ return urllib.parse.unquote_to_bytes(*args, **kwargs).replace(b'+', b' ')
21+
22+ def _changectx(repo, rev):
23+- if isinstance(rev, str):
24++ if isinstance(rev, bytes):
25+ rev = repo.lookup(rev)
26+ if hasattr(repo, 'changectx'):
27+ return repo.changectx(rev)
28+@@ -70,10 +73,10 @@ def _tip(ui, repo):
29+ except TypeError: # Mercurial < 1.1
30+ return repo.changelog.count() - 1
31+ tipctx = _changectx(repo, tiprev())
32+- ui.write('<tip revision="%d" node="%s"/>\n'
33++ ui.write(b'<tip revision="%d" node="%s"/>\n'
34+ % (tipctx.rev(), _x(node.hex(tipctx.node()))))
35+
36+-_SPECIAL_TAGS = ('tip',)
37++_SPECIAL_TAGS = (b'tip',)
38+
39+ def _tags(ui, repo):
40+ # see mercurial/commands.py:tags
41+@@ -84,7 +87,7 @@ def _tags(ui, repo):
42+ r = repo.changelog.rev(n)
43+ except error.LookupError:
44+ continue
45+- ui.write('<tag revision="%d" node="%s" name="%s"/>\n'
46++ ui.write(b'<tag revision="%d" node="%s" name="%s"/>\n'
47+ % (r, _x(node.hex(n)), _x(t)))
48+
49+ def _branches(ui, repo):
50+@@ -104,136 +107,148 @@ def _branches(ui, repo):
51+ return repo.branchheads(branch)
52+ def lookup(rev, n):
53+ try:
54+- return repo.lookup(rev)
55++ return repo.lookup(str(rev).encode('utf-8'))
56+ except RuntimeError:
57+ return n
58+ for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True):
59+ if lookup(r, n) in branchheads(t):
60+- ui.write('<branch revision="%d" node="%s" name="%s"/>\n'
61++ ui.write(b'<branch revision="%d" node="%s" name="%s"/>\n'
62+ % (r, _x(node.hex(n)), _x(t)))
63+
64+ def _manifest(ui, repo, path, rev):
65+ ctx = _changectx(repo, rev)
66+- ui.write('<manifest revision="%d" path="%s">\n'
67++ ui.write(b'<manifest revision="%d" path="%s">\n'
68+ % (ctx.rev(), _u(path)))
69+
70+ known = set()
71+- pathprefix = (path.rstrip('/') + '/').lstrip('/')
72++ pathprefix = (path.decode('utf-8').rstrip('/') + '/').lstrip('/')
73+ for f, n in sorted(ctx.manifest().iteritems(), key=lambda e: e[0]):
74+- if not f.startswith(pathprefix):
75++ fstr = f.decode('utf-8')
76++ if not fstr.startswith(pathprefix):
77+ continue
78+- name = re.sub(r'/.*', '/', f[len(pathprefix):])
79++ name = re.sub(r'/.*', '/', fstr[len(pathprefix):])
80+ if name in known:
81+ continue
82+ known.add(name)
83+
84+ if name.endswith('/'):
85+- ui.write('<dir name="%s"/>\n'
86++ ui.write(b'<dir name="%s"/>\n'
87+ % _x(urllib.quote(name[:-1])))
88+ else:
89+ fctx = repo.filectx(f, fileid=n)
90+ tm, tzoffset = fctx.date()
91+- ui.write('<file name="%s" revision="%d" node="%s" '
92+- 'time="%d" size="%d"/>\n'
93++ ui.write(b'<file name="%s" revision="%d" node="%s" '
94++ b'time="%d" size="%d"/>\n'
95+ % (_u(name), fctx.rev(), _x(node.hex(fctx.node())),
96+ tm, fctx.size(), ))
97+
98+- ui.write('</manifest>\n')
99++ ui.write(b'</manifest>\n')
100+
101+-@command('rhannotate',
102+- [('r', 'rev', '', 'revision'),
103+- ('u', 'user', None, 'list the author (long with -v)'),
104+- ('n', 'number', None, 'list the revision number (default)'),
105+- ('c', 'changeset', None, 'list the changeset'),
106++@command(b'rhannotate',
107++ [(b'r', b'rev', b'', b'revision'),
108++ (b'u', b'user', None, b'list the author (long with -v)'),
109++ (b'n', b'number', None, b'list the revision number (default)'),
110++ (b'c', b'changeset', None, b'list the changeset'),
111+ ],
112+- 'hg rhannotate [-r REV] [-u] [-n] [-c] FILE...')
113++ b'hg rhannotate [-r REV] [-u] [-n] [-c] FILE...')
114+ def rhannotate(ui, repo, *pats, **opts):
115+- rev = urllib.unquote_plus(opts.pop('rev', None))
116++ rev = unquoteplus(opts.pop('rev', b''))
117+ opts['rev'] = rev
118+- return commands.annotate(ui, repo, *map(urllib.unquote_plus, pats), **opts)
119++ return commands.annotate(ui, repo, *map(unquoteplus, pats), **opts)
120+
121+-@command('rhcat',
122+- [('r', 'rev', '', 'revision')],
123+- 'hg rhcat ([-r REV] ...) FILE...')
124++@command(b'rhcat',
125++ [(b'r', b'rev', b'', b'revision')],
126++ b'hg rhcat ([-r REV] ...) FILE...')
127+ def rhcat(ui, repo, file1, *pats, **opts):
128+- rev = urllib.unquote_plus(opts.pop('rev', None))
129++ rev = unquoteplus(opts.pop('rev', b''))
130+ opts['rev'] = rev
131+- return commands.cat(ui, repo, urllib.unquote_plus(file1), *map(urllib.unquote_plus, pats), **opts)
132++ return commands.cat(ui, repo, unquoteplus(file1), *map(unquoteplus, pats), **opts)
133+
134+-@command('rhdiff',
135+- [('r', 'rev', [], 'revision'),
136+- ('c', 'change', '', 'change made by revision')],
137+- 'hg rhdiff ([-c REV] | [-r REV] ...) [FILE]...')
138++@command(b'rhdiff',
139++ [(b'r', b'rev', [], b'revision'),
140++ (b'c', b'change', b'', b'change made by revision')],
141++ b'hg rhdiff ([-c REV] | [-r REV] ...) [FILE]...')
142+ def rhdiff(ui, repo, *pats, **opts):
143+ """diff repository (or selected files)"""
144+ change = opts.pop('change', None)
145+ if change: # add -c option for Mercurial<1.1
146+ base = _changectx(repo, change).parents()[0].rev()
147+- opts['rev'] = [str(base), change]
148++ opts['rev'] = [base, change]
149+ opts['nodates'] = True
150+- return commands.diff(ui, repo, *map(urllib.unquote_plus, pats), **opts)
151+-
152+-@command('rhlog',
153+- [
154+- ('r', 'rev', [], 'show the specified revision'),
155+- ('b', 'branch', [],
156+- 'show changesets within the given named branch'),
157+- ('l', 'limit', '',
158+- 'limit number of changes displayed'),
159+- ('d', 'date', '',
160+- 'show revisions matching date spec'),
161+- ('u', 'user', [],
162+- 'revisions committed by user'),
163+- ('', 'from', '',
164+- ''),
165+- ('', 'to', '',
166+- ''),
167+- ('', 'rhbranch', '',
168+- ''),
169+- ('', 'template', '',
170+- 'display with template')],
171+- 'hg rhlog [OPTION]... [FILE]')
172++ return commands.diff(ui, repo, *map(unquoteplus, pats), **opts)
173++
174++@command(b'rhlog',
175++ [
176++ (b'r', b'rev', [], b'show the specified revision'),
177++ (b'b', b'branch', [],
178++ b'show changesets within the given named branch'),
179++ (b'l', b'limit', b'',
180++ b'limit number of changes displayed'),
181++ (b'd', b'date', b'',
182++ b'show revisions matching date spec'),
183++ (b'u', b'user', [],
184++ b'revisions committed by user'),
185++ (b'', b'from', b'',
186++ b''),
187++ (b'', b'to', b'',
188++ b''),
189++ (b'', b'rhbranch', b'',
190++ b''),
191++ (b'', b'template', b'',
192++ b'display with template')],
193++ b'hg rhlog [OPTION]... [FILE]')
194++
195+ def rhlog(ui, repo, *pats, **opts):
196+ rev = opts.pop('rev')
197+ bra0 = opts.pop('branch')
198+- from_rev = urllib.unquote_plus(opts.pop('from', None))
199+- to_rev = urllib.unquote_plus(opts.pop('to' , None))
200+- bra = urllib.unquote_plus(opts.pop('rhbranch', None))
201+- from_rev = from_rev.replace('"', '\\"')
202+- to_rev = to_rev.replace('"', '\\"')
203+- if hg.util.version() >= '1.6':
204+- opts['rev'] = ['"%s":"%s"' % (from_rev, to_rev)]
205++ from_rev = unquoteplus(opts.pop('from', b''))
206++ to_rev = unquoteplus(opts.pop('to' , b''))
207++ bra = unquoteplus(opts.pop('rhbranch', b''))
208++ from_rev = from_rev.replace(b'"', b'\\"')
209++ to_rev = to_rev.replace(b'"', b'\\"')
210++ if (from_rev != b'') or (to_rev != b''):
211++ if from_rev != b'':
212++ quotefrom = b'"%s"' % (from_rev)
213++ else:
214++ quotefrom = from_rev
215++ if to_rev != b'':
216++ quoteto = b'"%s"' % (to_rev)
217++ else:
218++ quoteto = to_rev
219++ opts['rev'] = [b'%s:%s' % (quotefrom, quoteto)]
220+ else:
221+- opts['rev'] = ['%s:%s' % (from_rev, to_rev)]
222+- opts['branch'] = [bra]
223+- return commands.log(ui, repo, *map(urllib.unquote_plus, pats), **opts)
224+-
225+-@command('rhmanifest',
226+- [('r', 'rev', '', 'show the specified revision')],
227+- 'hg rhmanifest [-r REV] [PATH]')
228+-def rhmanifest(ui, repo, path='', **opts):
229++ opts['rev'] = rev
230++ if (bra != b''):
231++ opts['branch'] = [bra]
232++ return commands.log(ui, repo, *map(unquoteplus, pats), **opts)
233++
234++
235++@command(b'rhmanifest',
236++ [(b'r', b'rev', b'', b'show the specified revision')],
237++ b'hg rhmanifest -r REV [PATH]')
238++def rhmanifest(ui, repo, path=b'', **opts):
239+ """output the sub-manifest of the specified directory"""
240+- ui.write('<?xml version="1.0"?>\n')
241+- ui.write('<rhmanifest>\n')
242+- ui.write('<repository root="%s">\n' % _u(repo.root))
243++ ui.write(b'<?xml version="1.0"?>\n')
244++ ui.write(b'<rhmanifest>\n')
245++ ui.write(b'<repository root="%s">\n' % _u(repo.root))
246+ try:
247+- _manifest(ui, repo, urllib.unquote_plus(path), urllib.unquote_plus(opts.get('rev')))
248++ _manifest(ui, repo, unquoteplus(path), unquoteplus(opts.get('rev')))
249+ finally:
250+- ui.write('</repository>\n')
251+- ui.write('</rhmanifest>\n')
252++ ui.write(b'</repository>\n')
253++ ui.write(b'</rhmanifest>\n')
254+
255+-@command('rhsummary',[], 'hg rhsummary')
256++@command(b'rhsummary',[], b'hg rhsummary')
257+ def rhsummary(ui, repo, **opts):
258+ """output the summary of the repository"""
259+- ui.write('<?xml version="1.0"?>\n')
260+- ui.write('<rhsummary>\n')
261+- ui.write('<repository root="%s">\n' % _u(repo.root))
262++ ui.write(b'<?xml version="1.0"?>\n')
263++ ui.write(b'<rhsummary>\n')
264++ ui.write(b'<repository root="%s">\n' % _u(repo.root))
265+ try:
266+ _tip(ui, repo)
267+ _tags(ui, repo)
268+ _branches(ui, repo)
269+ # TODO: bookmarks in core (Mercurial>=1.8)
270+ finally:
271+- ui.write('</repository>\n')
272+- ui.write('</rhsummary>\n')
273++ ui.write(b'</repository>\n')
274++ ui.write(b'</rhsummary>\n')
275+
pkgs/applications/version-management/redmine/default.nix+4
@@ -21,6 +21,10 @@ in
2121
2222 buildInputs = [ rubyEnv rubyEnv.wrappedRuby rubyEnv.bundler ];
2323
24+ # taken from https://www.redmine.org/issues/33784
25+ # can be dropped when the upstream bug is closed and the fix is present in the upstream release
26+ patches = [ ./0001-python3.patch ];
27+
2428 buildPhase = ''
2529 mv config config.dist
2630 mv public/themes public/themes.dist