hgext/churn.py
changeset 3047 dd1a142988d3
parent 3046 461573aa02ef
child 3048 7ffaf5aba4d8
equal deleted inserted replaced
3046:461573aa02ef 3047:dd1a142988d3
    68     for f in unknown:
    68     for f in unknown:
    69         lines += dirtywork(f, mmap1, mmap2)
    69         lines += dirtywork(f, mmap1, mmap2)
    70 
    70 
    71     return (who, lines)
    71     return (who, lines)
    72 
    72 
    73 def gather_stats(ui, repo, amap, revs=None):
    73 def gather_stats(ui, repo, amap, revs=None, progress=False):
    74     stats = {}
    74     stats = {}
    75     
    75     
    76     cl    = repo.changelog
    76     cl    = repo.changelog
    77 
    77 
    78     if not revs:
    78     if not revs:
    79         revs = range(0, cl.count())
    79         revs = range(0, cl.count())
    80 
    80 
       
    81     nr_revs = len(revs)
       
    82     cur_rev = 0
       
    83 
    81     for rev in revs:
    84     for rev in revs:
    82         node2    = cl.node(rev)
    85         node2    = cl.node(rev)
    83         node1    = cl.parents(node2)[0]
    86         node1    = cl.parents(node2)[0]
    84 
    87 
    85 	if cl.parents(node2)[1] != node.nullid:
    88         if cl.parents(node2)[1] != node.nullid:
    86             ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,))
    89             ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,))
    87 	    continue
    90             continue
    88 
    91 
    89         who, lines = __gather(ui, repo, node1, node2)
    92         who, lines = __gather(ui, repo, node1, node2)
    90 
    93 
    91         # remap the owner if possible
    94         # remap the owner if possible
    92         if amap.has_key(who):
    95         if amap.has_key(who):
    96         if not stats.has_key(who):
    99         if not stats.has_key(who):
    97             stats[who] = 0
   100             stats[who] = 0
    98         stats[who] += lines
   101         stats[who] += lines
    99 
   102 
   100         ui.note("rev %d: %d lines by %s\n" % (rev, lines, who))
   103         ui.note("rev %d: %d lines by %s\n" % (rev, lines, who))
       
   104 
       
   105         cur_rev += 1
       
   106         if progress:
       
   107             if int(100.0*(cur_rev - 1)/nr_revs) < int(100.0*cur_rev/nr_revs):
       
   108                 ui.write("%d%%.." % (int(100.0*cur_rev/nr_revs),))
       
   109                 sys.stdout.flush()
       
   110 
       
   111     if progress:
       
   112         ui.write("done\n")
       
   113         sys.stdout.flush()
   101 
   114 
   102     return stats
   115     return stats
   103 
   116 
   104 def churn(ui, repo, **opts):
   117 def churn(ui, repo, **opts):
   105     "Graphs the number of lines changed"
   118     "Graphs the number of lines changed"
   136         amap = get_aliases(f)
   149         amap = get_aliases(f)
   137         f.close()
   150         f.close()
   138 
   151 
   139     revs = [int(r) for r in commands.revrange(ui, repo, opts['rev'])]
   152     revs = [int(r) for r in commands.revrange(ui, repo, opts['rev'])]
   140     revs.sort()
   153     revs.sort()
   141     stats = gather_stats(ui, repo, amap, revs)
   154     stats = gather_stats(ui, repo, amap, revs, opts.get('progress'))
   142 
   155 
   143     # make a list of tuples (name, lines) and sort it in descending order
   156     # make a list of tuples (name, lines) and sort it in descending order
   144     ordered = stats.items()
   157     ordered = stats.items()
   145     ordered.sort(cmp=lambda x, y: cmp(y[1], x[1]))
   158     ordered.sort(cmp=lambda x, y: cmp(y[1], x[1]))
   146 
   159 
   157 
   170 
   158 cmdtable = {
   171 cmdtable = {
   159     "churn":
   172     "churn":
   160     (churn,
   173     (churn,
   161      [('r', 'rev', [], _('limit statistics to the specified revisions')),
   174      [('r', 'rev', [], _('limit statistics to the specified revisions')),
   162       ('', 'aliases', '', _('file with email aliases'))],
   175       ('', 'aliases', '', _('file with email aliases')),
   163     'hg churn [-r revision range] [-a file]'),
   176       ('', 'progress', None, _('show progress'))],
       
   177     'hg churn [-r revision range] [-a file] [--progress]'),
   164 }
   178 }