annotate extra/mercurial/redminehelper.py @ 1628:9c5f8e24dadc live tip

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