annotate .svn/pristine/9d/9dc877e22163cfba0e0ecab2db123574b64de75c.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # redminehelper: Redmine helper extension for Mercurial
Chris@909 2 #
Chris@909 3 # Copyright 2010 Alessio Franceschelli (alefranz.net)
Chris@909 4 # Copyright 2010-2011 Yuya Nishihara <yuya@tcha.org>
Chris@909 5 #
Chris@909 6 # This software may be used and distributed according to the terms of the
Chris@909 7 # GNU General Public License version 2 or any later version.
Chris@909 8 """helper commands for Redmine to reduce the number of hg calls
Chris@909 9
Chris@909 10 To test this extension, please try::
Chris@909 11
Chris@909 12 $ hg --config extensions.redminehelper=redminehelper.py rhsummary
Chris@909 13
Chris@909 14 I/O encoding:
Chris@909 15
Chris@909 16 :file path: urlencoded, raw string
Chris@909 17 :tag name: utf-8
Chris@909 18 :branch name: utf-8
Chris@909 19 :node: 12-digits (short) hex string
Chris@909 20
Chris@909 21 Output example of rhsummary::
Chris@909 22
Chris@909 23 <?xml version="1.0"?>
Chris@909 24 <rhsummary>
Chris@909 25 <repository root="/foo/bar">
Chris@909 26 <tip revision="1234" node="abcdef0123..."/>
Chris@909 27 <tag revision="123" node="34567abc..." name="1.1.1"/>
Chris@909 28 <branch .../>
Chris@909 29 ...
Chris@909 30 </repository>
Chris@909 31 </rhsummary>
Chris@909 32
Chris@909 33 Output example of rhmanifest::
Chris@909 34
Chris@909 35 <?xml version="1.0"?>
Chris@909 36 <rhmanifest>
Chris@909 37 <repository root="/foo/bar">
Chris@909 38 <manifest revision="1234" path="lib">
Chris@909 39 <file name="diff.rb" revision="123" node="34567abc..." time="12345"
Chris@909 40 size="100"/>
Chris@909 41 ...
Chris@909 42 <dir name="redmine"/>
Chris@909 43 ...
Chris@909 44 </manifest>
Chris@909 45 </repository>
Chris@909 46 </rhmanifest>
Chris@909 47 """
Chris@909 48 import re, time, cgi, urllib
Chris@909 49 from mercurial import cmdutil, commands, node, error, hg
Chris@909 50
Chris@909 51 _x = cgi.escape
Chris@909 52 _u = lambda s: cgi.escape(urllib.quote(s))
Chris@909 53
Chris@909 54 def _tip(ui, repo):
Chris@909 55 # see mercurial/commands.py:tip
Chris@909 56 def tiprev():
Chris@909 57 try:
Chris@909 58 return len(repo) - 1
Chris@909 59 except TypeError: # Mercurial < 1.1
Chris@909 60 return repo.changelog.count() - 1
Chris@909 61 tipctx = repo.changectx(tiprev())
Chris@909 62 ui.write('<tip revision="%d" node="%s"/>\n'
Chris@909 63 % (tipctx.rev(), _x(node.short(tipctx.node()))))
Chris@909 64
Chris@909 65 _SPECIAL_TAGS = ('tip',)
Chris@909 66
Chris@909 67 def _tags(ui, repo):
Chris@909 68 # see mercurial/commands.py:tags
Chris@909 69 for t, n in reversed(repo.tagslist()):
Chris@909 70 if t in _SPECIAL_TAGS:
Chris@909 71 continue
Chris@909 72 try:
Chris@909 73 r = repo.changelog.rev(n)
Chris@909 74 except error.LookupError:
Chris@909 75 continue
Chris@909 76 ui.write('<tag revision="%d" node="%s" name="%s"/>\n'
Chris@909 77 % (r, _x(node.short(n)), _x(t)))
Chris@909 78
Chris@909 79 def _branches(ui, repo):
Chris@909 80 # see mercurial/commands.py:branches
Chris@909 81 def iterbranches():
Chris@909 82 for t, n in repo.branchtags().iteritems():
Chris@909 83 yield t, n, repo.changelog.rev(n)
Chris@909 84 def branchheads(branch):
Chris@909 85 try:
Chris@909 86 return repo.branchheads(branch, closed=False)
Chris@909 87 except TypeError: # Mercurial < 1.2
Chris@909 88 return repo.branchheads(branch)
Chris@909 89 for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True):
Chris@909 90 if repo.lookup(r) in branchheads(t):
Chris@909 91 ui.write('<branch revision="%d" node="%s" name="%s"/>\n'
Chris@909 92 % (r, _x(node.short(n)), _x(t)))
Chris@909 93
Chris@909 94 def _manifest(ui, repo, path, rev):
Chris@909 95 ctx = repo.changectx(rev)
Chris@909 96 ui.write('<manifest revision="%d" path="%s">\n'
Chris@909 97 % (ctx.rev(), _u(path)))
Chris@909 98
Chris@909 99 known = set()
Chris@909 100 pathprefix = (path.rstrip('/') + '/').lstrip('/')
Chris@909 101 for f, n in sorted(ctx.manifest().iteritems(), key=lambda e: e[0]):
Chris@909 102 if not f.startswith(pathprefix):
Chris@909 103 continue
Chris@909 104 name = re.sub(r'/.*', '/', f[len(pathprefix):])
Chris@909 105 if name in known:
Chris@909 106 continue
Chris@909 107 known.add(name)
Chris@909 108
Chris@909 109 if name.endswith('/'):
Chris@909 110 ui.write('<dir name="%s"/>\n'
Chris@909 111 % _x(urllib.quote(name[:-1])))
Chris@909 112 else:
Chris@909 113 fctx = repo.filectx(f, fileid=n)
Chris@909 114 tm, tzoffset = fctx.date()
Chris@909 115 ui.write('<file name="%s" revision="%d" node="%s" '
Chris@909 116 'time="%d" size="%d"/>\n'
Chris@909 117 % (_u(name), fctx.rev(), _x(node.short(fctx.node())),
Chris@909 118 tm, fctx.size(), ))
Chris@909 119
Chris@909 120 ui.write('</manifest>\n')
Chris@909 121
Chris@909 122 def rhannotate(ui, repo, *pats, **opts):
Chris@909 123 rev = urllib.unquote_plus(opts.pop('rev', None))
Chris@909 124 opts['rev'] = rev
Chris@909 125 return commands.annotate(ui, repo, *map(urllib.unquote_plus, pats), **opts)
Chris@909 126
Chris@909 127 def rhcat(ui, repo, file1, *pats, **opts):
Chris@909 128 rev = urllib.unquote_plus(opts.pop('rev', None))
Chris@909 129 opts['rev'] = rev
Chris@909 130 return commands.cat(ui, repo, urllib.unquote_plus(file1), *map(urllib.unquote_plus, pats), **opts)
Chris@909 131
Chris@909 132 def rhdiff(ui, repo, *pats, **opts):
Chris@909 133 """diff repository (or selected files)"""
Chris@909 134 change = opts.pop('change', None)
Chris@909 135 if change: # add -c option for Mercurial<1.1
Chris@909 136 base = repo.changectx(change).parents()[0].rev()
Chris@909 137 opts['rev'] = [str(base), change]
Chris@909 138 opts['nodates'] = True
Chris@909 139 return commands.diff(ui, repo, *map(urllib.unquote_plus, pats), **opts)
Chris@909 140
Chris@909 141 def rhlog(ui, repo, *pats, **opts):
Chris@909 142 rev = opts.pop('rev')
Chris@909 143 bra0 = opts.pop('branch')
Chris@909 144 from_rev = urllib.unquote_plus(opts.pop('from', None))
Chris@909 145 to_rev = urllib.unquote_plus(opts.pop('to' , None))
Chris@909 146 bra = urllib.unquote_plus(opts.pop('rhbranch', None))
Chris@909 147 from_rev = from_rev.replace('"', '\\"')
Chris@909 148 to_rev = to_rev.replace('"', '\\"')
Chris@909 149 if hg.util.version() >= '1.6':
Chris@909 150 opts['rev'] = ['"%s":"%s"' % (from_rev, to_rev)]
Chris@909 151 else:
Chris@909 152 opts['rev'] = ['%s:%s' % (from_rev, to_rev)]
Chris@909 153 opts['branch'] = [bra]
Chris@909 154 return commands.log(ui, repo, *map(urllib.unquote_plus, pats), **opts)
Chris@909 155
Chris@909 156 def rhmanifest(ui, repo, path='', **opts):
Chris@909 157 """output the sub-manifest of the specified directory"""
Chris@909 158 ui.write('<?xml version="1.0"?>\n')
Chris@909 159 ui.write('<rhmanifest>\n')
Chris@909 160 ui.write('<repository root="%s">\n' % _u(repo.root))
Chris@909 161 try:
Chris@909 162 _manifest(ui, repo, urllib.unquote_plus(path), urllib.unquote_plus(opts.get('rev')))
Chris@909 163 finally:
Chris@909 164 ui.write('</repository>\n')
Chris@909 165 ui.write('</rhmanifest>\n')
Chris@909 166
Chris@909 167 def rhsummary(ui, repo, **opts):
Chris@909 168 """output the summary of the repository"""
Chris@909 169 ui.write('<?xml version="1.0"?>\n')
Chris@909 170 ui.write('<rhsummary>\n')
Chris@909 171 ui.write('<repository root="%s">\n' % _u(repo.root))
Chris@909 172 try:
Chris@909 173 _tip(ui, repo)
Chris@909 174 _tags(ui, repo)
Chris@909 175 _branches(ui, repo)
Chris@909 176 # TODO: bookmarks in core (Mercurial>=1.8)
Chris@909 177 finally:
Chris@909 178 ui.write('</repository>\n')
Chris@909 179 ui.write('</rhsummary>\n')
Chris@909 180
Chris@909 181 # This extension should be compatible with Mercurial 0.9.5.
Chris@909 182 # Note that Mercurial 0.9.5 doesn't have extensions.wrapfunction().
Chris@909 183 cmdtable = {
Chris@909 184 'rhannotate': (rhannotate,
Chris@909 185 [('r', 'rev', '', 'revision'),
Chris@909 186 ('u', 'user', None, 'list the author (long with -v)'),
Chris@909 187 ('n', 'number', None, 'list the revision number (default)'),
Chris@909 188 ('c', 'changeset', None, 'list the changeset'),
Chris@909 189 ],
Chris@909 190 'hg rhannotate [-r REV] [-u] [-n] [-c] FILE...'),
Chris@909 191 'rhcat': (rhcat,
Chris@909 192 [('r', 'rev', '', 'revision')],
Chris@909 193 'hg rhcat ([-r REV] ...) FILE...'),
Chris@909 194 'rhdiff': (rhdiff,
Chris@909 195 [('r', 'rev', [], 'revision'),
Chris@909 196 ('c', 'change', '', 'change made by revision')],
Chris@909 197 'hg rhdiff ([-c REV] | [-r REV] ...) [FILE]...'),
Chris@909 198 'rhlog': (rhlog,
Chris@909 199 [
Chris@909 200 ('r', 'rev', [], 'show the specified revision'),
Chris@909 201 ('b', 'branch', [],
Chris@909 202 'show changesets within the given named branch'),
Chris@909 203 ('l', 'limit', '',
Chris@909 204 'limit number of changes displayed'),
Chris@909 205 ('d', 'date', '',
Chris@909 206 'show revisions matching date spec'),
Chris@909 207 ('u', 'user', [],
Chris@909 208 'revisions committed by user'),
Chris@909 209 ('', 'from', '',
Chris@909 210 ''),
Chris@909 211 ('', 'to', '',
Chris@909 212 ''),
Chris@909 213 ('', 'rhbranch', '',
Chris@909 214 ''),
Chris@909 215 ('', 'template', '',
Chris@909 216 'display with template')],
Chris@909 217 'hg rhlog [OPTION]... [FILE]'),
Chris@909 218 'rhmanifest': (rhmanifest,
Chris@909 219 [('r', 'rev', '', 'show the specified revision')],
Chris@909 220 'hg rhmanifest [-r REV] [PATH]'),
Chris@909 221 'rhsummary': (rhsummary, [], 'hg rhsummary'),
Chris@909 222 }