Mercurial > kallithea
annotate rhodecode/lib/hooks.py @ 3340:f1491bad8339 beta
unified RhodeCode paster commands
- moved them to commont paster_commands package
- re-use sqlalchemy session initializaiton
- some docs updates
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 09 Feb 2013 22:21:31 +0100 |
parents | c2bf0fa7b3cb |
children | 796738bb697c |
rev | line source |
---|---|
913
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
1 # -*- coding: utf-8 -*- |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
2 """ |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
3 rhodecode.lib.hooks |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~ |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
5 |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
6 Hooks runned by rhodecode |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
7 |
913
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
8 :created_on: Aug 6, 2010 |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
9 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1814
diff
changeset
|
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
913
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
12 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
16 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
17 # |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
22 # |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
913
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
25 import os |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
26 import sys |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
27 import time |
2324
1dbf07735af4
save full raw id in push log data for much faster revision lookup
Marcin Kuzminski <marcin@python-works.com>
parents:
2236
diff
changeset
|
28 import binascii |
1dbf07735af4
save full raw id in push log data for much faster revision lookup
Marcin Kuzminski <marcin@python-works.com>
parents:
2236
diff
changeset
|
29 from inspect import isfunction |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 |
1415
677408ee9355
fixed hooks for mercurial 1.9
Marcin Kuzminski <marcin@python-works.com>
parents:
1307
diff
changeset
|
31 from mercurial.scmutil import revrange |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
32 from mercurial.node import nullrev |
2324
1dbf07735af4
save full raw id in push log data for much faster revision lookup
Marcin Kuzminski <marcin@python-works.com>
parents:
2236
diff
changeset
|
33 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
34 from rhodecode.lib import helpers as h |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
35 from rhodecode.lib.utils import action_logger |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2402
diff
changeset
|
36 from rhodecode.lib.vcs.backends.base import EmptyChangeset |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
37 from rhodecode.lib.compat import json |
2818
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
38 from rhodecode.lib.exceptions import HTTPLockedRC |
2958
c0a6a2e6bb2e
Use lightweight revisions in journal by default
Marcin Kuzminski <marcin@python-works.com>
parents:
2904
diff
changeset
|
39 from rhodecode.lib.utils2 import safe_str, datetime_to_time |
2818
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
40 from rhodecode.model.db import Repository, User |
1307 | 41 |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
42 |
2196
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
43 def _get_scm_size(alias, root_path): |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
44 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
45 if not alias.startswith('.'): |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
46 alias += '.' |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
47 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
48 size_scm, size_root = 0, 0 |
2963
742d1b8ca263
use str() on os.walk passing unicode can lead to UnicodeDecode errors when iterating
Marcin Kuzminski <marcin@python-works.com>
parents:
2958
diff
changeset
|
49 for path, dirs, files in os.walk(safe_str(root_path)): |
2196
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
50 if path.find(alias) != -1: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
51 for f in files: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
52 try: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
53 size_scm += os.path.getsize(os.path.join(path, f)) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
54 except OSError: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
55 pass |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
56 else: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
57 for f in files: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
58 try: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
59 size_root += os.path.getsize(os.path.join(path, f)) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
60 except OSError: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
61 pass |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
62 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
63 size_scm_f = h.format_byte_size(size_scm) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
64 size_root_f = h.format_byte_size(size_root) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
65 size_total_f = h.format_byte_size(size_root + size_scm) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
66 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
67 return size_scm_f, size_root_f, size_total_f |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
68 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
69 |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 def repo_size(ui, repo, hooktype=None, **kwargs): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
71 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
72 Presents size of repository after push |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
73 |
913
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
74 :param ui: |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
75 :param repo: |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
76 :param hooktype: |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
77 """ |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 |
2196
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
79 size_hg_f, size_root_f, size_total_f = _get_scm_size('.hg', repo.root) |
1814
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
80 |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
81 last_cs = repo[len(repo) - 1] |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
82 |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
83 msg = ('Repository size .hg:%s repo:%s total:%s\n' |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
84 'Last revision is now r%s:%s\n') % ( |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
85 size_hg_f, size_root_f, size_total_f, last_cs.rev(), last_cs.hex()[:12] |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
86 ) |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
87 |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
88 sys.stdout.write(msg) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
89 |
1307 | 90 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
91 def pre_push(ui, repo, **kwargs): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
92 # pre push function, currently used to ban pushing when |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
93 # repository is locked |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
94 try: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
95 rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}")) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
96 except: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
97 rc_extras = {} |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
98 extras = dict(repo.ui.configitems('rhodecode_extras')) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
99 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
100 if 'username' in extras: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
101 username = extras['username'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
102 repository = extras['repository'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
103 scm = extras['scm'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
104 locked_by = extras['locked_by'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
105 elif 'username' in rc_extras: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
106 username = rc_extras['username'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
107 repository = rc_extras['repository'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
108 scm = rc_extras['scm'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
109 locked_by = rc_extras['locked_by'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
110 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
111 raise Exception('Missing data in repo.ui and os.environ') |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
112 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
113 usr = User.get_by_username(username) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
114 if locked_by[0] and usr.user_id != int(locked_by[0]): |
2750
30cafecb2630
Fixed issue with mixed locking notification and bad username
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
115 locked_by = User.get(locked_by[0]).username |
30cafecb2630
Fixed issue with mixed locking notification and bad username
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
116 raise HTTPLockedRC(repository, locked_by) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
117 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
118 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
119 def pre_pull(ui, repo, **kwargs): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
120 # pre push function, currently used to ban pushing when |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
121 # repository is locked |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
122 try: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
123 rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}")) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
124 except: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
125 rc_extras = {} |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
126 extras = dict(repo.ui.configitems('rhodecode_extras')) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
127 if 'username' in extras: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
128 username = extras['username'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
129 repository = extras['repository'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
130 scm = extras['scm'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
131 locked_by = extras['locked_by'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
132 elif 'username' in rc_extras: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
133 username = rc_extras['username'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
134 repository = rc_extras['repository'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
135 scm = rc_extras['scm'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
136 locked_by = rc_extras['locked_by'] |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
137 else: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
138 raise Exception('Missing data in repo.ui and os.environ') |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
139 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
140 if locked_by[0]: |
2750
30cafecb2630
Fixed issue with mixed locking notification and bad username
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
141 locked_by = User.get(locked_by[0]).username |
30cafecb2630
Fixed issue with mixed locking notification and bad username
Marcin Kuzminski <marcin@python-works.com>
parents:
2726
diff
changeset
|
142 raise HTTPLockedRC(repository, locked_by) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
143 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
144 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
145 def log_pull_action(ui, repo, **kwargs): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
146 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
147 Logs user last pull action |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
148 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
149 :param ui: |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
150 :param repo: |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
151 """ |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
152 try: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
153 rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}")) |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
154 except: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
155 rc_extras = {} |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
156 extras = dict(repo.ui.configitems('rhodecode_extras')) |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
157 if 'username' in extras: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
158 username = extras['username'] |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
159 repository = extras['repository'] |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
160 scm = extras['scm'] |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
161 make_lock = extras['make_lock'] |
3097
db1b7125cdaf
fixed issue with passing IP address to log action logger for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2998
diff
changeset
|
162 ip = extras['ip'] |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
163 elif 'username' in rc_extras: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
164 username = rc_extras['username'] |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
165 repository = rc_extras['repository'] |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
166 scm = rc_extras['scm'] |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
167 make_lock = rc_extras['make_lock'] |
3097
db1b7125cdaf
fixed issue with passing IP address to log action logger for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2998
diff
changeset
|
168 ip = rc_extras['ip'] |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
169 else: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
170 raise Exception('Missing data in repo.ui and os.environ') |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
171 user = User.get_by_username(username) |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
172 action = 'pull' |
3097
db1b7125cdaf
fixed issue with passing IP address to log action logger for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2998
diff
changeset
|
173 action_logger(user, action, repository, ip, commit=True) |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
174 # extension hook call |
2406
7be31af5bc78
changed scope of calling EXTENSIONS from rhodecode for githooks to be able to execute them
Marcin Kuzminski <marcin@python-works.com>
parents:
2404
diff
changeset
|
175 from rhodecode import EXTENSIONS |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
176 callback = getattr(EXTENSIONS, 'PULL_HOOK', None) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
177 |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
178 if isfunction(callback): |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
179 kw = {} |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
180 kw.update(extras) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
181 callback(**kw) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
182 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
183 if make_lock is True: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
184 Repository.lock(Repository.get_by_repo_name(repository), user.user_id) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
185 #msg = 'Made lock on repo `%s`' % repository |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
186 #sys.stdout.write(msg) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
187 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
188 return 0 |
503
3d6d548ad3cc
Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
189 |
1307 | 190 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
191 def log_push_action(ui, repo, **kwargs): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
192 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
193 Maps user last push action to new changeset id, from mercurial |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
194 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
195 :param ui: |
2236
37c143aa8616
fixes issue #436 git push error
Marcin Kuzminski <marcin@python-works.com>
parents:
2203
diff
changeset
|
196 :param repo: repo object containing the `ui` object |
503
3d6d548ad3cc
Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
197 """ |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
198 |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
199 try: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
200 rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}")) |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
201 except: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
202 rc_extras = {} |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
203 |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
204 extras = dict(repo.ui.configitems('rhodecode_extras')) |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
205 if 'username' in extras: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
206 username = extras['username'] |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
207 repository = extras['repository'] |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
208 scm = extras['scm'] |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
209 make_lock = extras['make_lock'] |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
210 elif 'username' in rc_extras: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
211 username = rc_extras['username'] |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
212 repository = rc_extras['repository'] |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
213 scm = rc_extras['scm'] |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
214 make_lock = rc_extras['make_lock'] |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
215 else: |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
216 raise Exception('Missing data in repo.ui and os.environ') |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
217 |
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
218 action = 'push' + ':%s' |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
219 |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
220 if scm == 'hg': |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
221 node = kwargs['node'] |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
222 |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
223 def get_revs(repo, rev_opt): |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
224 if rev_opt: |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
225 revs = revrange(repo, rev_opt) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
226 |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
227 if len(revs) == 0: |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
228 return (nullrev, nullrev) |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
229 return (max(revs), min(revs)) |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
230 else: |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
231 return (len(repo) - 1, 0) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
232 |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
233 stop, start = get_revs(repo, [node + ':']) |
2324
1dbf07735af4
save full raw id in push log data for much faster revision lookup
Marcin Kuzminski <marcin@python-works.com>
parents:
2236
diff
changeset
|
234 h = binascii.hexlify |
2407
8a68e0292232
Change git & hg hooks to post. They shouldn't block as they are used just for logging actions. Futhermore post hooks have access to changesets, so it's much better flexible
Marcin Kuzminski <marcin@python-works.com>
parents:
2406
diff
changeset
|
235 revs = [h(repo[r].node()) for r in xrange(start, stop + 1)] |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
236 elif scm == 'git': |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
237 revs = kwargs.get('_git_revs', []) |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
238 if '_git_revs' in kwargs: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
239 kwargs.pop('_git_revs') |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
240 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
241 action = action % ','.join(revs) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
242 |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
243 action_logger(username, action, repository, extras['ip'], commit=True) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
244 |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
245 # extension hook call |
2406
7be31af5bc78
changed scope of calling EXTENSIONS from rhodecode for githooks to be able to execute them
Marcin Kuzminski <marcin@python-works.com>
parents:
2404
diff
changeset
|
246 from rhodecode import EXTENSIONS |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
247 callback = getattr(EXTENSIONS, 'PUSH_HOOK', None) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
248 if isfunction(callback): |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
249 kw = {'pushed_revs': revs} |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
250 kw.update(extras) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
251 callback(**kw) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
252 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
253 if make_lock is False: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
254 Repository.unlock(Repository.get_by_repo_name(repository)) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
255 msg = 'Released lock on repo `%s`\n' % repository |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
256 sys.stdout.write(msg) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
257 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
258 return 0 |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
259 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
260 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
261 def log_create_repository(repository_dict, created_by, **kwargs): |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
262 """ |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
263 Post create repository Hook. This is a dummy function for admins to re-use |
2109 | 264 if needed. It's taken from rhodecode-extensions module and executed |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
265 if present |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
266 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
267 :param repository: dict dump of repository object |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
268 :param created_by: username who created repository |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
269 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
270 available keys of repository_dict: |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
271 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
272 'repo_type', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
273 'description', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
274 'private', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
275 'created_on', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
276 'enable_downloads', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
277 'repo_id', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
278 'user_id', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
279 'enable_statistics', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
280 'clone_uri', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
281 'fork_id', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
282 'group_id', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
283 'repo_name' |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
284 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
285 """ |
2406
7be31af5bc78
changed scope of calling EXTENSIONS from rhodecode for githooks to be able to execute them
Marcin Kuzminski <marcin@python-works.com>
parents:
2404
diff
changeset
|
286 from rhodecode import EXTENSIONS |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
287 callback = getattr(EXTENSIONS, 'CREATE_REPO_HOOK', None) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
288 if isfunction(callback): |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
289 kw = {} |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
290 kw.update(repository_dict) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
291 kw.update({'created_by': created_by}) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
292 kw.update(kwargs) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
293 return callback(**kw) |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
294 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
295 return 0 |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
296 |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
297 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
298 def log_delete_repository(repository_dict, deleted_by, **kwargs): |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
299 """ |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
300 Post delete repository Hook. This is a dummy function for admins to re-use |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
301 if needed. It's taken from rhodecode-extensions module and executed |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
302 if present |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
303 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
304 :param repository: dict dump of repository object |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
305 :param deleted_by: username who deleted the repository |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
306 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
307 available keys of repository_dict: |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
308 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
309 'repo_type', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
310 'description', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
311 'private', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
312 'created_on', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
313 'enable_downloads', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
314 'repo_id', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
315 'user_id', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
316 'enable_statistics', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
317 'clone_uri', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
318 'fork_id', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
319 'group_id', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
320 'repo_name' |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
321 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
322 """ |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
323 from rhodecode import EXTENSIONS |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
324 callback = getattr(EXTENSIONS, 'DELETE_REPO_HOOK', None) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
325 if isfunction(callback): |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
326 kw = {} |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
327 kw.update(repository_dict) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
328 kw.update({'deleted_by': deleted_by, |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
329 'deleted_on': time.time()}) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
330 kw.update(kwargs) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
331 return callback(**kw) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
332 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
333 return 0 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
334 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
335 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
336 handle_git_pre_receive = (lambda repo_path, revs, env: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
337 handle_git_receive(repo_path, revs, env, hook_type='pre')) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
338 handle_git_post_receive = (lambda repo_path, revs, env: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
339 handle_git_receive(repo_path, revs, env, hook_type='post')) |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
340 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
341 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
342 def handle_git_receive(repo_path, revs, env, hook_type='post'): |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
343 """ |
2407
8a68e0292232
Change git & hg hooks to post. They shouldn't block as they are used just for logging actions. Futhermore post hooks have access to changesets, so it's much better flexible
Marcin Kuzminski <marcin@python-works.com>
parents:
2406
diff
changeset
|
344 A really hacky method that is runned by git post-receive hook and logs |
2409
761e00380370
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2408
diff
changeset
|
345 an push action together with pushed revisions. It's executed by subprocess |
761e00380370
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2408
diff
changeset
|
346 thus needs all info to be able to create a on the fly pylons enviroment, |
761e00380370
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2408
diff
changeset
|
347 connect to database and run the logging code. Hacky as sh*t but works. |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
348 |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
349 :param repo_path: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
350 :type repo_path: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
351 :param revs: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
352 :type revs: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
353 :param env: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
354 :type env: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
355 """ |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
356 from paste.deploy import appconfig |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
357 from sqlalchemy import engine_from_config |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
358 from rhodecode.config.environment import load_environment |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
359 from rhodecode.model import init_model |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
360 from rhodecode.model.db import RhodeCodeUi |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
361 from rhodecode.lib.utils import make_ui |
2870
cbf0775ff6b4
There's no need to use special env variable for config file, it's already passed in in extras now
Marcin Kuzminski <marcin@python-works.com>
parents:
2818
diff
changeset
|
362 extras = json.loads(env['RHODECODE_EXTRAS']) |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
363 |
2870
cbf0775ff6b4
There's no need to use special env variable for config file, it's already passed in in extras now
Marcin Kuzminski <marcin@python-works.com>
parents:
2818
diff
changeset
|
364 path, ini_name = os.path.split(extras['config']) |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
365 conf = appconfig('config:%s' % ini_name, relative_to=path) |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
366 load_environment(conf.global_conf, conf.local_conf) |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
367 |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
368 engine = engine_from_config(conf, 'sqlalchemy.db1.') |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
369 init_model(engine) |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
370 |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
371 baseui = make_ui('db') |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
372 # fix if it's not a bare repo |
2872
17556a81ec6f
Make detecting bare Git repositories more robust
Stefan Engel <mail@engel-stefan.de>
parents:
2870
diff
changeset
|
373 if repo_path.endswith(os.sep + '.git'): |
17556a81ec6f
Make detecting bare Git repositories more robust
Stefan Engel <mail@engel-stefan.de>
parents:
2870
diff
changeset
|
374 repo_path = repo_path[:-5] |
2818
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
375 |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
376 repo = Repository.get_by_full_path(repo_path) |
2818
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
377 if not repo: |
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
378 raise OSError('Repository %s not found in database' |
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
379 % (safe_str(repo_path))) |
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
380 |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
381 _hooks = dict(baseui.configitems('hooks')) or {} |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
382 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
383 for k, v in extras.items(): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
384 baseui.setconfig('rhodecode_extras', k, v) |
3278
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
385 if hook_type == 'pre': |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
386 repo = repo.scm_instance |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
387 else: |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
388 #post push shouldn't use the cached instance never |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
389 repo = repo.scm_instance_no_cache |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
390 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
391 repo.ui = baseui |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
392 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
393 if hook_type == 'pre': |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
394 pre_push(baseui, repo) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
395 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
396 # if push hook is enabled via web interface |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
397 elif hook_type == 'post' and _hooks.get(RhodeCodeUi.HOOK_PUSH): |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
398 |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
399 rev_data = [] |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
400 for l in revs: |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
401 old_rev, new_rev, ref = l.split(' ') |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
402 _ref_data = ref.split('/') |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
403 if _ref_data[1] in ['tags', 'heads']: |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
404 rev_data.append({'old_rev': old_rev, |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
405 'new_rev': new_rev, |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
406 'ref': ref, |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
407 'type': _ref_data[1], |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
408 'name': _ref_data[2].strip()}) |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
409 |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
410 git_revs = [] |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
411 for push_ref in rev_data: |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
412 _type = push_ref['type'] |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
413 if _type == 'heads': |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
414 if push_ref['old_rev'] == EmptyChangeset().raw_id: |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
415 cmd = "for-each-ref --format='%(refname)' 'refs/heads/*'" |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
416 heads = repo.run_git_command(cmd)[0] |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
417 heads = heads.replace(push_ref['ref'], '') |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
418 heads = ' '.join(map(lambda c: c.strip('\n').strip(), |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
419 heads.splitlines())) |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
420 cmd = (('log %(new_rev)s' % push_ref) + |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
421 ' --reverse --pretty=format:"%H" --not ' + heads) |
2998
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
422 git_revs += repo.run_git_command(cmd)[0].splitlines() |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
423 |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
424 elif push_ref['new_rev'] == EmptyChangeset().raw_id: |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
425 #delete branch case |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
426 git_revs += ['delete_branch=>%s' % push_ref['name']] |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
427 else: |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
428 cmd = (('log %(old_rev)s..%(new_rev)s' % push_ref) + |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
429 ' --reverse --pretty=format:"%H"') |
2998
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
430 git_revs += repo.run_git_command(cmd)[0].splitlines() |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
431 |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
432 elif _type == 'tags': |
2998
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
433 git_revs += ['tag=>%s' % push_ref['name']] |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
434 |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
435 log_push_action(baseui, repo, _git_revs=git_revs) |