Project

General

Profile

Defect #3421 » size.py

Mercurial size extension c.o. Ian Cardenas - Luke Hoersten, 2009-12-19 04:20

 
1
# size.py - returns the size of the files in the 
2
#           repository without checking them out
3
#
4
# Copyright 2008 Ian P. Cardenas <ipc@srand.net>
5
#
6
# This software may be used and distributed according to the terms
7
# of the GNU General Public License, incorporated herein by reference.
8
#
9
# $Id$
10
#
11
# Setup in hgrc:
12
#
13
#   [extensions]
14
#   # enable extension
15
#   hgext.size =
16
# # Run "hg help size" to get info on configuration.  
17
'''size information in local repositories
18
'''
19

    
20
from mercurial import hg, cmdutil
21

    
22
def size(ui, repo, file1, *pats, **opts):
23
    """output the size of files
24
	returns the size of the files in a local repository
25
    """
26
    ctx = repo[opts['rev']]
27
    err = 1
28
    m = cmdutil.match(repo, (file1,) + pats, opts)
29
    for abs in ctx.walk(m):
30
        fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
31
        size = ctx[abs].size()
32
	formatted_size = "%d\n" % ( size )
33
        fp.write(formatted_size)
34
        err = 0
35
    return err
36

    
37
walkopts = [
38
    ('I', 'include', [], 'include names matching the given patterns'),
39
    ('X', 'exclude', [], 'exclude names matching the given patterns'),
40
]
41

    
42
cmdtable = {
43
    "size": (size,
44
         [('o', 'output', '', 'print output to file with formatted name'),
45
          ('r', 'rev', '', 'print the given revision'),
46
         ] + walkopts,
47
         'hg size [OPTION]... FILE...')
48
}
49

    
(2-2/4)