##// END OF EJS Templates
hooks: expose pushed refs inside hooks....
marcink -
r223:a7b3535b default
parent child Browse files
Show More
@@ -147,13 +147,25 b' def post_pull(ui, repo, **kwargs):'
147 147 return _call_hook('post_pull', _extras_from_ui(ui), HgMessageWriter(ui))
148 148
149 149
150 def _rev_range_hash(repo, node):
151
152 commits = []
153 for rev in xrange(repo[node], len(repo)):
154 ctx = repo[rev]
155 commit_id = mercurial.node.hex(ctx.node())
156 branch = ctx.branch()
157 commits.append((commit_id, branch))
158
159 return commits
160
161
150 162 def pre_push(ui, repo, node=None, **kwargs):
151 163 extras = _extras_from_ui(ui)
152 164
153 165 rev_data = []
154 166 if node and kwargs.get('hooktype') == 'pretxnchangegroup':
155 167 branches = collections.defaultdict(list)
156 for commit_id, branch in _rev_range_hash(repo, node, with_branch=True):
168 for commit_id, branch in _rev_range_hash(repo, node):
157 169 branches[branch].append(commit_id)
158 170
159 171 for branch, commits in branches.iteritems():
@@ -170,26 +182,28 b' def pre_push(ui, repo, node=None, **kwar'
170 182 return _call_hook('pre_push', extras, HgMessageWriter(ui))
171 183
172 184
173 def _rev_range_hash(repo, node, with_branch=False):
185 def post_push(ui, repo, node, **kwargs):
186 extras = _extras_from_ui(ui)
187
188 commit_ids = []
189 branches = []
190 bookmarks = []
191 tags = []
174 192
175 commits = []
176 for rev in xrange(repo[node], len(repo)):
177 ctx = repo[rev]
178 commit_id = mercurial.node.hex(ctx.node())
179 branch = ctx.branch()
180 if with_branch:
181 commits.append((commit_id, branch))
182 else:
183 commits.append(commit_id)
193 for commit_id, branch in _rev_range_hash(repo, node):
194 commit_ids.append(commit_id)
195 if branch not in branches:
196 branches.append(branch)
184 197
185 return commits
186
198 if hasattr(ui, '_rc_pushkey_branches'):
199 bookmarks = ui._rc_pushkey_branches
187 200
188 def post_push(ui, repo, node, **kwargs):
189 commit_ids = _rev_range_hash(repo, node)
190
191 extras = _extras_from_ui(ui)
192 201 extras['commit_ids'] = commit_ids
202 extras['new_refs'] = {
203 'branches': branches,
204 'bookmarks': bookmarks,
205 'tags': tags
206 }
193 207
194 208 return _call_hook('post_push', extras, HgMessageWriter(ui))
195 209
@@ -351,10 +365,16 b' def git_post_receive(unused_repo_path, r'
351 365 # subcommand sets the PATH environment variable so that it point to the
352 366 # correct version of the git executable.
353 367 empty_commit_id = '0' * 40
368 branches = []
369 tags = []
354 370 for push_ref in rev_data:
355 371 type_ = push_ref['type']
372
356 373 if type_ == 'heads':
357 374 if push_ref['old_rev'] == empty_commit_id:
375 # starting new branch case
376 if push_ref['name'] not in branches:
377 branches.append(push_ref['name'])
358 378
359 379 # Fix up head revision if needed
360 380 cmd = ['git', 'show', 'HEAD']
@@ -378,14 +398,24 b' def git_post_receive(unused_repo_path, r'
378 398 # delete branch case
379 399 git_revs.append('delete_branch=>%s' % push_ref['name'])
380 400 else:
401 if push_ref['name'] not in branches:
402 branches.append(push_ref['name'])
403
381 404 cmd = ['git', 'log',
382 405 '{old_rev}..{new_rev}'.format(**push_ref),
383 406 '--reverse', '--pretty=format:%H']
384 407 git_revs.extend(_run_command(cmd).splitlines())
385 408 elif type_ == 'tags':
409 if push_ref['name'] not in tags:
410 tags.append(push_ref['name'])
386 411 git_revs.append('tag=>%s' % push_ref['name'])
387 412
388 413 extras['commit_ids'] = git_revs
414 extras['new_refs'] = {
415 'branches': branches,
416 'bookmarks': [],
417 'tags': tags,
418 }
389 419
390 420 if 'repo_size' in extras['hooks']:
391 421 try:
@@ -70,7 +70,8 b' def test_git_post_receive_calls_repo_siz'
70 70 with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
71 71 hooks.git_post_receive(
72 72 None, '', {'RC_SCM_DATA': json.dumps(extras)})
73 extras.update({'commit_ids': []})
73 extras.update({'commit_ids': [],
74 'new_refs': {'bookmarks': [], 'branches': [], 'tags': []}})
74 75 expected_calls = [
75 76 mock.call('repo_size', extras, mock.ANY),
76 77 mock.call('post_push', extras, mock.ANY),
@@ -83,7 +84,8 b' def test_git_post_receive_does_not_call_'
83 84 with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
84 85 hooks.git_post_receive(
85 86 None, '', {'RC_SCM_DATA': json.dumps(extras)})
86 extras.update({'commit_ids': []})
87 extras.update({'commit_ids': [],
88 'new_refs': {'bookmarks': [], 'branches': [], 'tags': []}})
87 89 expected_calls = [
88 90 mock.call('post_push', extras, mock.ANY)
89 91 ]
General Comments 0
You need to be logged in to leave comments. Login now