(fp, repo)
| 67 | |
| 68 | |
| 69 | def page(fp, repo): |
| 70 | if not sys.stdout.isatty(): # we are being piped or redirected |
| 71 | if sys.platform != 'win32': |
| 72 | # Prevent Python from throwing exceptions on SIGPIPE |
| 73 | from signal import signal, SIGPIPE, SIG_DFL |
| 74 | signal(SIGPIPE, SIG_DFL) |
| 75 | # memory-friendly way to output contents of file to stdout |
| 76 | with open(fp, 'r') as f: |
| 77 | shutil.copyfileobj(f, sys.stdout) |
| 78 | return |
| 79 | |
| 80 | # On Windows, we need to call 'more' through cmd.exe (with 'cmd'). The /C is |
| 81 | # so that the command window gets closed after 'more' finishes |
| 82 | default_pager = 'less' if sys.platform != 'win32' else 'cmd /C more' |
| 83 | try: |
| 84 | pager = repo.config['core.pager'] |
| 85 | except KeyError: |
| 86 | pager = '' # empty string will evaluate to False below |
| 87 | pager = pager or os.environ.get('PAGER', None) or default_pager |
| 88 | cmd = shlex.split(pager) # split into constituents |
| 89 | if os.path.basename(cmd[0]) == 'less': |
| 90 | cmd.extend(['-r', '-f']) # append arguments |
| 91 | |
| 92 | cmd.append(fp) # add file name to page command |
| 93 | try: |
| 94 | ret = subprocess.call(cmd, stdin=sys.stdin, stdout=sys.stdout) |
| 95 | if ret != 0: |
| 96 | pprint.err('Call to pager {0} failed'.format(pager)) |
| 97 | except OSError: |
| 98 | pprint.err('Couldn\'t launch pager {0}'.format(pager)) |
| 99 | pprint.err_exp('change the value of git\'s core.pager setting') |
| 100 | |
| 101 | |
| 102 | class PathProcessor(argparse.Action): |
nothing calls this directly
no outgoing calls
no test coverage detected