annotate .svn/pristine/a2/a228c3d0b7910e4eb07f95e583bb22e9efe2f4c4.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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