summaryrefslogtreecommitdiffstats
path: root/repo
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-02-11 02:10:28 -0500
committerMike Frysinger <vapier@google.com>2020-02-12 19:57:42 +0000
commit8409410aa294cad68bf93679726e0a4465e1fe2b (patch)
treedc7bbeef44441043ecb43c6ca4c114ac8dc3c2f3 /repo
parentdc63181fcd3c34340e3acb5c72ae80539b5c7282 (diff)
downloadgit-repo-8409410aa294cad68bf93679726e0a4465e1fe2b.tar.gz
repo: export GIT_TRACE2_PARENT_SID
This helps with people tracing repo/git execution. We use a similar format to git, but a little simpler since we always initialize the env var setting, and we want to avoid too much overhead. Bug: https://crbug.com/gerrit/12314 Change-Id: I75675b6cc4c6f7c4f5e09f54128eba9456364d04 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254331 Reviewed-by: Josh Steadmon <steadmon@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'repo')
-rwxr-xr-xrepo47
1 files changed, 39 insertions, 8 deletions
diff --git a/repo b/repo
index 7bf48023..6ecf3921 100755
--- a/repo
+++ b/repo
@@ -10,6 +10,7 @@ copy of repo in the checkout.
10 10
11from __future__ import print_function 11from __future__ import print_function
12 12
13import datetime
13import os 14import os
14import platform 15import platform
15import subprocess 16import subprocess
@@ -478,6 +479,39 @@ def _CheckGitVersion():
478 raise CloneFailure() 479 raise CloneFailure()
479 480
480 481
482def SetGitTrace2ParentSid(env=None):
483 """Set up GIT_TRACE2_PARENT_SID for git tracing."""
484 # We roughly follow the format git itself uses in trace2/tr2_sid.c.
485 # (1) Be unique (2) be valid filename (3) be fixed length.
486 #
487 # Since we always export this variable, we try to avoid more expensive calls.
488 # e.g. We don't attempt hostname lookups or hashing the results.
489 if env is None:
490 env = os.environ
491
492 KEY = 'GIT_TRACE2_PARENT_SID'
493
494 now = datetime.datetime.utcnow()
495 value = 'repo-%s-P%08x' % (now.strftime('%Y%m%dT%H%M%SZ'), os.getpid())
496
497 # If it's already set, then append ourselves.
498 if KEY in env:
499 value = env[KEY] + '/' + value
500
501 _setenv(KEY, value, env=env)
502
503
504def _setenv(key, value, env=None):
505 """Set |key| in the OS environment |env| to |value|."""
506 if env is None:
507 env = os.environ
508 # Environment handling across systems is messy.
509 try:
510 env[key] = value
511 except UnicodeEncodeError:
512 env[key] = value.encode()
513
514
481def NeedSetupGnuPG(): 515def NeedSetupGnuPG():
482 if not os.path.isdir(home_dot_repo): 516 if not os.path.isdir(home_dot_repo):
483 return True 517 return True
@@ -514,10 +548,7 @@ def SetupGnuPG(quiet):
514 sys.exit(1) 548 sys.exit(1)
515 549
516 env = os.environ.copy() 550 env = os.environ.copy()
517 try: 551 _setenv('GNUPGHOME', gpg_dir, env)
518 env['GNUPGHOME'] = gpg_dir
519 except UnicodeEncodeError:
520 env['GNUPGHOME'] = gpg_dir.encode()
521 552
522 cmd = ['gpg', '--import'] 553 cmd = ['gpg', '--import']
523 try: 554 try:
@@ -723,10 +754,7 @@ def _Verify(cwd, branch, quiet):
723 print(file=sys.stderr) 754 print(file=sys.stderr)
724 755
725 env = os.environ.copy() 756 env = os.environ.copy()
726 try: 757 _setenv('GNUPGHOME', gpg_dir, env)
727 env['GNUPGHOME'] = gpg_dir
728 except UnicodeEncodeError:
729 env['GNUPGHOME'] = gpg_dir.encode()
730 758
731 cmd = [GIT, 'tag', '-v', cur] 759 cmd = [GIT, 'tag', '-v', cur]
732 proc = subprocess.Popen(cmd, 760 proc = subprocess.Popen(cmd,
@@ -901,6 +929,9 @@ def _SetDefaultsTo(gitdir):
901def main(orig_args): 929def main(orig_args):
902 cmd, opt, args = _ParseArguments(orig_args) 930 cmd, opt, args = _ParseArguments(orig_args)
903 931
932 # We run this early as we run some git commands ourselves.
933 SetGitTrace2ParentSid()
934
904 repo_main, rel_repo_dir = None, None 935 repo_main, rel_repo_dir = None, None
905 # Don't use the local repo copy, make sure to switch to the gitc client first. 936 # Don't use the local repo copy, make sure to switch to the gitc client first.
906 if cmd != 'gitc-init': 937 if cmd != 'gitc-init':