comparison extra/mercurial/redminehelper.py @ 3:7c48bad7d85d yuya

* Import Mercurial overhaul patches from Yuya Nishihara (see http://www.redmine.org/issues/4455)
author Chris Cannam
date Wed, 28 Jul 2010 12:40:01 +0100
parents
children
comparison
equal deleted inserted replaced
2:b940d200fbd2 3:7c48bad7d85d
1 # redminehelper: Redmine helper extension for Mercurial
2 # it's a draft to show a possible way to explore repository by the Redmine overhaul patch
3 # see: http://www.redmine.org/issues/4455
4 #
5 # Copyright 2010 Alessio Franceschelli (alefranz.net)
6 # Copyright 2010 Yuya Nishihara <yuya@tcha.org>
7 #
8 # This software may be used and distributed according to the terms of the
9 # GNU General Public License version 2 or any later version.
10
11 '''command to list revision of each file
12 '''
13
14 import re, time
15 from mercurial import cmdutil, commands, node, error
16
17 SPECIAL_TAGS = ('tip',)
18
19 def rhsummary(ui, repo, **opts):
20 """output the summary of the repository"""
21 # see mercurial/commands.py:tip
22 ui.write(':tip: rev node\n')
23 tipctx = repo[len(repo) - 1]
24 ui.write('%d %s\n' % (tipctx.rev(), tipctx))
25
26 # see mercurial/commands.py:root
27 ui.write(':root: path\n')
28 ui.write(repo.root + '\n')
29
30 # see mercurial/commands.py:tags
31 ui.write(':tags: rev node name\n')
32 for t, n in reversed(repo.tagslist()):
33 if t in SPECIAL_TAGS:
34 continue
35 try:
36 r = repo.changelog.rev(n)
37 except error.LookupError:
38 r = -1
39 ui.write('%d %s %s\n' % (r, node.short(n), t))
40
41 # see mercurial/commands.py:branches
42 def iterbranches():
43 for t, n in repo.branchtags().iteritems():
44 yield t, n, repo.changelog.rev(n)
45
46 ui.write(':branches: rev node name\n')
47 for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True):
48 if repo.lookup(r) in repo.branchheads(t, closed=False):
49 ui.write('%d %s %s\n' % (r, node.short(n), t)) # only open branch
50
51 def rhentries(ui, repo, path='', **opts):
52 """output the entries of the specified directory"""
53 rev = opts.get('rev')
54 pathprefix = (path.rstrip('/') + '/').lstrip('/')
55
56 # TODO: clean up
57 dirs, files = {}, {}
58 mf = repo[rev].manifest()
59 for f in repo[rev]:
60 if not f.startswith(pathprefix):
61 continue
62
63 name = re.sub(r'/.*', '', f[len(pathprefix):])
64 if '/' in f[len(pathprefix):]:
65 dirs[name] = (name,)
66 else:
67 try:
68 fctx = repo.filectx(f, fileid=mf[f])
69 ctx = fctx.changectx()
70 tm, tzoffset = ctx.date()
71 localtime = int(tm) + tzoffset - time.timezone
72 files[name] = (ctx.rev(), node.short(ctx.node()), localtime,
73 fctx.size(), name)
74 except LookupError: # TODO: when this occurs?
75 pass
76
77 ui.write(':dirs: name\n')
78 for n, v in sorted(dirs.iteritems(), key=lambda e: e[0]):
79 ui.write(' '.join(v) + '\n')
80
81 ui.write(':files: rev node time size name\n')
82 for n, v in sorted(files.iteritems(), key=lambda e: e[0]):
83 ui.write(' '.join(str(e) for e in v) + '\n')
84
85
86 cmdtable = {
87 'rhsummary': (rhsummary, [], 'hg rhsummary'),
88 'rhentries': (rhentries,
89 [('r', 'rev', '', 'show the specified revision')],
90 'hg rhentries [path]'),
91 }