Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: git_common.py

Issue 1851283002: Fix coloring madness in depot_tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Improve logic a bit Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « git_cl.py ('k') | git_map_branches.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. 5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly.
6 # Derived from https://gist.github.com/aljungberg/626518 6 # Derived from https://gist.github.com/aljungberg/626518
7 import multiprocessing.pool 7 import multiprocessing.pool
8 from multiprocessing.pool import IMapIterator 8 from multiprocessing.pool import IMapIterator
9 def wrapper(func): 9 def wrapper(func):
10 def wrap(self, timeout=None): 10 def wrap(self, timeout=None):
11 return func(self, timeout=timeout or 1e100) 11 return func(self, timeout=timeout or 1e100)
12 return wrap 12 return wrap
13 IMapIterator.next = wrapper(IMapIterator.next) 13 IMapIterator.next = wrapper(IMapIterator.next)
14 IMapIterator.__next__ = IMapIterator.next 14 IMapIterator.__next__ = IMapIterator.next
15 # TODO(iannucci): Monkeypatch all other 'wait' methods too. 15 # TODO(iannucci): Monkeypatch all other 'wait' methods too.
16 16
17 17
18 import binascii 18 import binascii
19 import collections 19 import collections
20 import contextlib 20 import contextlib
21 import functools 21 import functools
22 import logging 22 import logging
23 import os 23 import os
24 import re 24 import re
25 import setup_color
25 import shutil 26 import shutil
26 import signal 27 import signal
27 import sys 28 import sys
28 import tempfile 29 import tempfile
29 import textwrap 30 import textwrap
30 import threading 31 import threading
31 32
32 import subprocess2 33 import subprocess2
33 34
34 ROOT = os.path.abspath(os.path.dirname(__file__)) 35 ROOT = os.path.abspath(os.path.dirname(__file__))
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 def _inner_gen(): 275 def _inner_gen():
275 yield function() 276 yield function()
276 while True: 277 while True:
277 yield 278 yield
278 return _inner_gen().next 279 return _inner_gen().next
279 280
280 281
281 ## Git functions 282 ## Git functions
282 283
283 284
284 def blame(filename, revision=None, porcelain=False, *args): 285 def blame(filename, revision=None, porcelain=False, *_args):
285 command = ['blame'] 286 command = ['blame']
286 if porcelain: 287 if porcelain:
287 command.append('-p') 288 command.append('-p')
288 if revision is not None: 289 if revision is not None:
289 command.append(revision) 290 command.append(revision)
290 command.extend(['--', filename]) 291 command.extend(['--', filename])
291 return run(*command) 292 return run(*command)
292 293
293 294
294 def branch_config(branch, option, default=None): 295 def branch_config(branch, option, default=None):
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 return config('depot-tools.upstream', 'origin/master') 570 return config('depot-tools.upstream', 'origin/master')
570 571
571 572
572 @contextlib.contextmanager 573 @contextlib.contextmanager
573 def less(): # pragma: no cover 574 def less(): # pragma: no cover
574 """Runs 'less' as context manager yielding its stdin as a PIPE. 575 """Runs 'less' as context manager yielding its stdin as a PIPE.
575 576
576 Automatically checks if sys.stdout is a non-TTY stream. If so, it avoids 577 Automatically checks if sys.stdout is a non-TTY stream. If so, it avoids
577 running less and just yields sys.stdout. 578 running less and just yields sys.stdout.
578 """ 579 """
579 if not sys.stdout.isatty(): 580 if not setup_color.IS_TTY:
580 yield sys.stdout 581 yield sys.stdout
581 return 582 return
582 583
583 # Run with the same options that git uses (see setup_pager in git repo). 584 # Run with the same options that git uses (see setup_pager in git repo).
584 # -F: Automatically quit if the output is less than one screen. 585 # -F: Automatically quit if the output is less than one screen.
585 # -R: Don't escape ANSI color codes. 586 # -R: Don't escape ANSI color codes.
586 # -X: Don't clear the screen before starting. 587 # -X: Don't clear the screen before starting.
587 cmd = ('less', '-FRX') 588 cmd = ('less', '-FRX')
588 try: 589 try:
589 proc = subprocess2.Popen(cmd, stdin=subprocess2.PIPE) 590 proc = subprocess2.Popen(cmd, stdin=subprocess2.PIPE)
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 ['HEAD']) 904 ['HEAD'])
904 905
905 906
906 def clone_file(repository, new_workdir, link, operation): 907 def clone_file(repository, new_workdir, link, operation):
907 if not os.path.exists(os.path.join(repository, link)): 908 if not os.path.exists(os.path.join(repository, link)):
908 return 909 return
909 link_dir = os.path.dirname(os.path.join(new_workdir, link)) 910 link_dir = os.path.dirname(os.path.join(new_workdir, link))
910 if not os.path.exists(link_dir): 911 if not os.path.exists(link_dir):
911 os.makedirs(link_dir) 912 os.makedirs(link_dir)
912 operation(os.path.join(repository, link), os.path.join(new_workdir, link)) 913 operation(os.path.join(repository, link), os.path.join(new_workdir, link))
OLDNEW
« no previous file with comments | « git_cl.py ('k') | git_map_branches.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698