##// 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 return _call_hook('post_pull', _extras_from_ui(ui), HgMessageWriter(ui))
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 def pre_push(ui, repo, node=None, **kwargs):
162 def pre_push(ui, repo, node=None, **kwargs):
151 extras = _extras_from_ui(ui)
163 extras = _extras_from_ui(ui)
152
164
153 rev_data = []
165 rev_data = []
154 if node and kwargs.get('hooktype') == 'pretxnchangegroup':
166 if node and kwargs.get('hooktype') == 'pretxnchangegroup':
155 branches = collections.defaultdict(list)
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 branches[branch].append(commit_id)
169 branches[branch].append(commit_id)
158
170
159 for branch, commits in branches.iteritems():
171 for branch, commits in branches.iteritems():
@@ -170,26 +182,28 b' def pre_push(ui, repo, node=None, **kwar'
170 return _call_hook('pre_push', extras, HgMessageWriter(ui))
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 = []
193 for commit_id, branch in _rev_range_hash(repo, node):
176 for rev in xrange(repo[node], len(repo)):
194 commit_ids.append(commit_id)
177 ctx = repo[rev]
195 if branch not in branches:
178 commit_id = mercurial.node.hex(ctx.node())
196 branches.append(branch)
179 branch = ctx.branch()
180 if with_branch:
181 commits.append((commit_id, branch))
182 else:
183 commits.append(commit_id)
184
197
185 return commits
198 if hasattr(ui, '_rc_pushkey_branches'):
186
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 extras['commit_ids'] = commit_ids
201 extras['commit_ids'] = commit_ids
202 extras['new_refs'] = {
203 'branches': branches,
204 'bookmarks': bookmarks,
205 'tags': tags
206 }
193
207
194 return _call_hook('post_push', extras, HgMessageWriter(ui))
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 # subcommand sets the PATH environment variable so that it point to the
365 # subcommand sets the PATH environment variable so that it point to the
352 # correct version of the git executable.
366 # correct version of the git executable.
353 empty_commit_id = '0' * 40
367 empty_commit_id = '0' * 40
368 branches = []
369 tags = []
354 for push_ref in rev_data:
370 for push_ref in rev_data:
355 type_ = push_ref['type']
371 type_ = push_ref['type']
372
356 if type_ == 'heads':
373 if type_ == 'heads':
357 if push_ref['old_rev'] == empty_commit_id:
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 # Fix up head revision if needed
379 # Fix up head revision if needed
360 cmd = ['git', 'show', 'HEAD']
380 cmd = ['git', 'show', 'HEAD']
@@ -378,14 +398,24 b' def git_post_receive(unused_repo_path, r'
378 # delete branch case
398 # delete branch case
379 git_revs.append('delete_branch=>%s' % push_ref['name'])
399 git_revs.append('delete_branch=>%s' % push_ref['name'])
380 else:
400 else:
401 if push_ref['name'] not in branches:
402 branches.append(push_ref['name'])
403
381 cmd = ['git', 'log',
404 cmd = ['git', 'log',
382 '{old_rev}..{new_rev}'.format(**push_ref),
405 '{old_rev}..{new_rev}'.format(**push_ref),
383 '--reverse', '--pretty=format:%H']
406 '--reverse', '--pretty=format:%H']
384 git_revs.extend(_run_command(cmd).splitlines())
407 git_revs.extend(_run_command(cmd).splitlines())
385 elif type_ == 'tags':
408 elif type_ == 'tags':
409 if push_ref['name'] not in tags:
410 tags.append(push_ref['name'])
386 git_revs.append('tag=>%s' % push_ref['name'])
411 git_revs.append('tag=>%s' % push_ref['name'])
387
412
388 extras['commit_ids'] = git_revs
413 extras['commit_ids'] = git_revs
414 extras['new_refs'] = {
415 'branches': branches,
416 'bookmarks': [],
417 'tags': tags,
418 }
389
419
390 if 'repo_size' in extras['hooks']:
420 if 'repo_size' in extras['hooks']:
391 try:
421 try:
@@ -70,7 +70,8 b' def test_git_post_receive_calls_repo_siz'
70 with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
70 with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
71 hooks.git_post_receive(
71 hooks.git_post_receive(
72 None, '', {'RC_SCM_DATA': json.dumps(extras)})
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 expected_calls = [
75 expected_calls = [
75 mock.call('repo_size', extras, mock.ANY),
76 mock.call('repo_size', extras, mock.ANY),
76 mock.call('post_push', extras, mock.ANY),
77 mock.call('post_push', extras, mock.ANY),
@@ -83,7 +84,8 b' def test_git_post_receive_does_not_call_'
83 with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
84 with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
84 hooks.git_post_receive(
85 hooks.git_post_receive(
85 None, '', {'RC_SCM_DATA': json.dumps(extras)})
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 expected_calls = [
89 expected_calls = [
88 mock.call('post_push', extras, mock.ANY)
90 mock.call('post_push', extras, mock.ANY)
89 ]
91 ]
General Comments 0
You need to be logged in to leave comments. Login now