##// END OF EJS Templates
bugfix, repo_size crashed when broken symlinks where inside a repository.
marcink -
r675:59670f09 beta
parent child Browse files
Show More
@@ -1,99 +1,105 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 # custom hooks for application
3 # custom hooks for application
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
9 # of the License or (at your opinion) any later version of the license.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
19 # MA 02110-1301, USA.
20 """
20 """
21 Created on Aug 6, 2010
21 Created on Aug 6, 2010
22
22
23 @author: marcink
23 @author: marcink
24 """
24 """
25 from mercurial.cmdutil import revrange
25 from mercurial.cmdutil import revrange
26 from mercurial.node import nullrev
26 from mercurial.node import nullrev
27 from rhodecode.lib import helpers as h
27 from rhodecode.lib import helpers as h
28 from rhodecode.lib.utils import action_logger
28 from rhodecode.lib.utils import action_logger
29 import os
29 import os
30 import sys
30 import sys
31
31
32 def repo_size(ui, repo, hooktype=None, **kwargs):
32 def repo_size(ui, repo, hooktype=None, **kwargs):
33
33
34 if hooktype != 'changegroup':
34 if hooktype != 'changegroup':
35 return False
35 return False
36 size_hg, size_root = 0, 0
36 size_hg, size_root = 0, 0
37 for path, dirs, files in os.walk(repo.root):
37 for path, dirs, files in os.walk(repo.root):
38 if path.find('.hg') != -1:
38 if path.find('.hg') != -1:
39 for f in files:
39 for f in files:
40 try:
40 size_hg += os.path.getsize(os.path.join(path, f))
41 size_hg += os.path.getsize(os.path.join(path, f))
42 except OSError:
43 pass
41 else:
44 else:
42 for f in files:
45 for f in files:
46 try:
43 size_root += os.path.getsize(os.path.join(path, f))
47 size_root += os.path.getsize(os.path.join(path, f))
48 except OSError:
49 pass
44
50
45 size_hg_f = h.format_byte_size(size_hg)
51 size_hg_f = h.format_byte_size(size_hg)
46 size_root_f = h.format_byte_size(size_root)
52 size_root_f = h.format_byte_size(size_root)
47 size_total_f = h.format_byte_size(size_root + size_hg)
53 size_total_f = h.format_byte_size(size_root + size_hg)
48 sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \
54 sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \
49 % (size_hg_f, size_root_f, size_total_f))
55 % (size_hg_f, size_root_f, size_total_f))
50
56
51 def log_pull_action(ui, repo, **kwargs):
57 def log_pull_action(ui, repo, **kwargs):
52 """
58 """
53 Logs user last pull action
59 Logs user last pull action
54 :param ui:
60 :param ui:
55 :param repo:
61 :param repo:
56 """
62 """
57
63
58 extra_params = dict(repo.ui.configitems('rhodecode_extras'))
64 extra_params = dict(repo.ui.configitems('rhodecode_extras'))
59 username = extra_params['username']
65 username = extra_params['username']
60 repository = extra_params['repository']
66 repository = extra_params['repository']
61 action = 'pull'
67 action = 'pull'
62
68
63 action_logger(username, action, repository, extra_params['ip'])
69 action_logger(username, action, repository, extra_params['ip'])
64
70
65 return 0
71 return 0
66
72
67 def log_push_action(ui, repo, **kwargs):
73 def log_push_action(ui, repo, **kwargs):
68 """
74 """
69 Maps user last push action to new changeset id, from mercurial
75 Maps user last push action to new changeset id, from mercurial
70 :param ui:
76 :param ui:
71 :param repo:
77 :param repo:
72 """
78 """
73
79
74 extra_params = dict(repo.ui.configitems('rhodecode_extras'))
80 extra_params = dict(repo.ui.configitems('rhodecode_extras'))
75 username = extra_params['username']
81 username = extra_params['username']
76 repository = extra_params['repository']
82 repository = extra_params['repository']
77 action = 'push:%s'
83 action = 'push:%s'
78 node = kwargs['node']
84 node = kwargs['node']
79
85
80 def get_revs(repo, rev_opt):
86 def get_revs(repo, rev_opt):
81 if rev_opt:
87 if rev_opt:
82 revs = revrange(repo, rev_opt)
88 revs = revrange(repo, rev_opt)
83
89
84 if len(revs) == 0:
90 if len(revs) == 0:
85 return (nullrev, nullrev)
91 return (nullrev, nullrev)
86 return (max(revs), min(revs))
92 return (max(revs), min(revs))
87 else:
93 else:
88 return (len(repo) - 1, 0)
94 return (len(repo) - 1, 0)
89
95
90 stop, start = get_revs(repo, [node + ':'])
96 stop, start = get_revs(repo, [node + ':'])
91
97
92 revs = (str(repo[r]) for r in xrange(start, stop + 1))
98 revs = (str(repo[r]) for r in xrange(start, stop + 1))
93
99
94 action = action % ','.join(revs)
100 action = action % ','.join(revs)
95
101
96 action_logger(username, action, repository, extra_params['ip'])
102 action_logger(username, action, repository, extra_params['ip'])
97
103
98 return 0
104 return 0
99
105
General Comments 0
You need to be logged in to leave comments. Login now