annotate .svn/pristine/a2/a228c3d0b7910e4eb07f95e583bb22e9efe2f4c4.svn-base @ 1295:622f24f53b42 redmine-2.3

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