##// END OF EJS Templates
hooks: expose few extra variables from hook calls
marcink -
r557:47d2196a default
parent child Browse files
Show More
@@ -214,6 +214,30 b' def _check_heads(repo, start, end, commi'
214 return []
214 return []
215
215
216
216
217 def _get_git_env():
218 env = {}
219 for k, v in os.environ.items():
220 if k.startswith('GIT'):
221 env[k] = v
222
223 # serialized version
224 return [(k, v) for k, v in env.items()]
225
226
227 def _get_hg_env(old_rev, new_rev, txnid, repo_path):
228 env = {}
229 for k, v in os.environ.items():
230 if k.startswith('HG'):
231 env[k] = v
232
233 env['HG_NODE'] = old_rev
234 env['HG_NODE_LAST'] = new_rev
235 env['HG_TXNID'] = txnid
236 env['HG_PENDING'] = repo_path
237
238 return [(k, v) for k, v in env.items()]
239
240
217 def repo_size(ui, repo, **kwargs):
241 def repo_size(ui, repo, **kwargs):
218 extras = _extras_from_ui(ui)
242 extras = _extras_from_ui(ui)
219 return _call_hook('repo_size', extras, HgMessageWriter(ui))
243 return _call_hook('repo_size', extras, HgMessageWriter(ui))
@@ -260,6 +284,7 b' def pre_push(ui, repo, node=None, **kwar'
260 for branch, commits in branches.items():
284 for branch, commits in branches.items():
261 old_rev = kwargs.get('node_last') or commits[0]
285 old_rev = kwargs.get('node_last') or commits[0]
262 rev_data.append({
286 rev_data.append({
287 'total_commits': len(commits),
263 'old_rev': old_rev,
288 'old_rev': old_rev,
264 'new_rev': commits[-1],
289 'new_rev': commits[-1],
265 'ref': '',
290 'ref': '',
@@ -270,8 +295,16 b' def pre_push(ui, repo, node=None, **kwar'
270 for push_ref in rev_data:
295 for push_ref in rev_data:
271 push_ref['multiple_heads'] = _heads
296 push_ref['multiple_heads'] = _heads
272
297
298 repo_path = os.path.join(
299 extras.get('repo_store', ''), extras.get('repository', ''))
300 push_ref['hg_env'] = _get_hg_env(
301 old_rev=push_ref['old_rev'],
302 new_rev=push_ref['new_rev'], txnid=kwargs.get('txnid'),
303 repo_path=repo_path)
304
273 extras['hook_type'] = kwargs.get('hooktype', 'pre_push')
305 extras['hook_type'] = kwargs.get('hooktype', 'pre_push')
274 extras['commit_ids'] = rev_data
306 extras['commit_ids'] = rev_data
307
275 return _call_hook('pre_push', extras, HgMessageWriter(ui))
308 return _call_hook('pre_push', extras, HgMessageWriter(ui))
276
309
277
310
@@ -428,6 +461,10 b' def _parse_git_ref_lines(revision_lines)'
428 ref_data = ref.split('/', 2)
461 ref_data = ref.split('/', 2)
429 if ref_data[1] in ('tags', 'heads'):
462 if ref_data[1] in ('tags', 'heads'):
430 rev_data.append({
463 rev_data.append({
464 # NOTE(marcink):
465 # we're unable to tell total_commits for git at this point
466 # but we set the variable for consistency with GIT
467 'total_commits': -1,
431 'old_rev': old_rev,
468 'old_rev': old_rev,
432 'new_rev': new_rev,
469 'new_rev': new_rev,
433 'ref': ref,
470 'ref': ref,
@@ -457,8 +494,7 b' def git_pre_receive(unused_repo_path, re'
457
494
458 for push_ref in rev_data:
495 for push_ref in rev_data:
459 # store our git-env which holds the temp store
496 # store our git-env which holds the temp store
460 push_ref['git_env'] = [
497 push_ref['git_env'] = _get_git_env()
461 (k, v) for k, v in os.environ.items() if k.startswith('GIT')]
462 push_ref['pruned_sha'] = ''
498 push_ref['pruned_sha'] = ''
463 if not detect_force_push:
499 if not detect_force_push:
464 # don't check for forced-push when we don't need to
500 # don't check for forced-push when we don't need to
@@ -590,6 +626,21 b' def _get_extras_from_txn_id(path, txn_id'
590 return extras
626 return extras
591
627
592
628
629 def _get_extras_from_commit_id(commit_id, path):
630 extras = {}
631 try:
632 cmd = ['svnlook', 'pget',
633 '-r', commit_id,
634 '--revprop', path, 'rc-scm-extras']
635 stdout, stderr = subprocessio.run_command(
636 cmd, env=os.environ.copy())
637 extras = json.loads(base64.urlsafe_b64decode(stdout))
638 except Exception:
639 log.exception('Failed to extract extras info from commit_id')
640
641 return extras
642
643
593 def svn_pre_commit(repo_path, commit_data, env):
644 def svn_pre_commit(repo_path, commit_data, env):
594 path, txn_id = commit_data
645 path, txn_id = commit_data
595 branches = []
646 branches = []
@@ -606,6 +657,7 b' def svn_pre_commit(repo_path, commit_dat'
606 extras['commit_ids'] = []
657 extras['commit_ids'] = []
607 extras['txn_id'] = txn_id
658 extras['txn_id'] = txn_id
608 extras['new_refs'] = {
659 extras['new_refs'] = {
660 'total_commits': 1,
609 'branches': branches,
661 'branches': branches,
610 'bookmarks': [],
662 'bookmarks': [],
611 'tags': tags,
663 'tags': tags,
@@ -614,21 +666,6 b' def svn_pre_commit(repo_path, commit_dat'
614 return _call_hook('pre_push', extras, SvnMessageWriter())
666 return _call_hook('pre_push', extras, SvnMessageWriter())
615
667
616
668
617 def _get_extras_from_commit_id(commit_id, path):
618 extras = {}
619 try:
620 cmd = ['svnlook', 'pget',
621 '-r', commit_id,
622 '--revprop', path, 'rc-scm-extras']
623 stdout, stderr = subprocessio.run_command(
624 cmd, env=os.environ.copy())
625 extras = json.loads(base64.urlsafe_b64decode(stdout))
626 except Exception:
627 log.exception('Failed to extract extras info from commit_id')
628
629 return extras
630
631
632 def svn_post_commit(repo_path, commit_data, env):
669 def svn_post_commit(repo_path, commit_data, env):
633 """
670 """
634 commit_data is path, rev, txn_id
671 commit_data is path, rev, txn_id
@@ -651,6 +688,7 b' def svn_post_commit(repo_path, commit_da'
651 'branches': branches,
688 'branches': branches,
652 'bookmarks': [],
689 'bookmarks': [],
653 'tags': tags,
690 'tags': tags,
691 'total_commits': 1,
654 }
692 }
655
693
656 if 'repo_size' in extras['hooks']:
694 if 'repo_size' in extras['hooks']:
General Comments 0
You need to be logged in to leave comments. Login now