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