Chris@3: # redminehelper: Redmine helper extension for Mercurial Chris@3: # it's a draft to show a possible way to explore repository by the Redmine overhaul patch Chris@3: # see: http://www.redmine.org/issues/4455 Chris@3: # Chris@3: # Copyright 2010 Alessio Franceschelli (alefranz.net) Chris@3: # Copyright 2010 Yuya Nishihara Chris@3: # Chris@3: # This software may be used and distributed according to the terms of the Chris@3: # GNU General Public License version 2 or any later version. Chris@3: Chris@3: '''command to list revision of each file Chris@3: ''' Chris@3: Chris@3: import re, time Chris@3: from mercurial import cmdutil, commands, node, error Chris@3: Chris@3: SPECIAL_TAGS = ('tip',) Chris@3: Chris@3: def rhsummary(ui, repo, **opts): Chris@3: """output the summary of the repository""" Chris@3: # see mercurial/commands.py:tip Chris@3: ui.write(':tip: rev node\n') Chris@3: tipctx = repo[len(repo) - 1] Chris@3: ui.write('%d %s\n' % (tipctx.rev(), tipctx)) Chris@3: Chris@3: # see mercurial/commands.py:root Chris@3: ui.write(':root: path\n') Chris@3: ui.write(repo.root + '\n') Chris@3: Chris@3: # see mercurial/commands.py:tags Chris@3: ui.write(':tags: rev node name\n') Chris@3: for t, n in reversed(repo.tagslist()): Chris@3: if t in SPECIAL_TAGS: Chris@3: continue Chris@3: try: Chris@3: r = repo.changelog.rev(n) Chris@3: except error.LookupError: Chris@3: r = -1 Chris@3: ui.write('%d %s %s\n' % (r, node.short(n), t)) Chris@3: Chris@3: # see mercurial/commands.py:branches Chris@3: def iterbranches(): Chris@3: for t, n in repo.branchtags().iteritems(): Chris@3: yield t, n, repo.changelog.rev(n) Chris@3: Chris@3: ui.write(':branches: rev node name\n') Chris@3: for t, n, r in sorted(iterbranches(), key=lambda e: e[2], reverse=True): Chris@3: if repo.lookup(r) in repo.branchheads(t, closed=False): Chris@3: ui.write('%d %s %s\n' % (r, node.short(n), t)) # only open branch Chris@3: Chris@3: def rhentries(ui, repo, path='', **opts): Chris@3: """output the entries of the specified directory""" Chris@3: rev = opts.get('rev') Chris@3: pathprefix = (path.rstrip('/') + '/').lstrip('/') Chris@3: Chris@3: # TODO: clean up Chris@3: dirs, files = {}, {} Chris@3: mf = repo[rev].manifest() Chris@3: for f in repo[rev]: Chris@3: if not f.startswith(pathprefix): Chris@3: continue Chris@3: Chris@3: name = re.sub(r'/.*', '', f[len(pathprefix):]) Chris@3: if '/' in f[len(pathprefix):]: Chris@3: dirs[name] = (name,) Chris@3: else: Chris@3: try: Chris@3: fctx = repo.filectx(f, fileid=mf[f]) Chris@3: ctx = fctx.changectx() Chris@3: tm, tzoffset = ctx.date() Chris@3: localtime = int(tm) + tzoffset - time.timezone Chris@3: files[name] = (ctx.rev(), node.short(ctx.node()), localtime, Chris@3: fctx.size(), name) Chris@3: except LookupError: # TODO: when this occurs? Chris@3: pass Chris@3: Chris@3: ui.write(':dirs: name\n') Chris@3: for n, v in sorted(dirs.iteritems(), key=lambda e: e[0]): Chris@3: ui.write(' '.join(v) + '\n') Chris@3: Chris@3: ui.write(':files: rev node time size name\n') Chris@3: for n, v in sorted(files.iteritems(), key=lambda e: e[0]): Chris@3: ui.write(' '.join(str(e) for e in v) + '\n') Chris@3: Chris@3: Chris@3: cmdtable = { Chris@3: 'rhsummary': (rhsummary, [], 'hg rhsummary'), Chris@3: 'rhentries': (rhentries, Chris@3: [('r', 'rev', '', 'show the specified revision')], Chris@3: 'hg rhentries [path]'), Chris@3: }