diff options
-rw-r--r-- | git/cmd.py | 20 | ||||
-rw-r--r-- | git/remote.py | 6 | ||||
-rw-r--r-- | git/util.py | 10 |
3 files changed, 19 insertions, 17 deletions
@@ -46,8 +46,8 @@ __all__ = ('Git', ) ## @{ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): - """Registers for notifications to lean that process output is ready to read, and dispatches lines to - the respective line handlers. We are able to handle carriage returns in case progress is sent by that + """Registers for notifications to lean that process output is ready to read, and dispatches lines to + the respective line handlers. We are able to handle carriage returns in case progress is sent by that mean. For performance reasons, we only apply this to stderr. This function returns once the finalizer returns :return: result of finalizer @@ -77,7 +77,7 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): def dispatch_line(fno): stream, handler, readline = fdmap[fno] # this can possibly block for a while, but since we wake-up with at least one or more lines to handle, - # we are good ... + # we are good ... line = readline(stream).decode(defenc) if line and handler: handler(line) @@ -93,13 +93,13 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): # end deplete buffer if wg: wg.done() - # end + # end - fdmap = { process.stdout.fileno() : (process.stdout, stdout_handler, read_line_fast), - process.stderr.fileno() : (process.stderr, stderr_handler, read_line_slow) } + fdmap = {process.stdout.fileno(): (process.stdout, stdout_handler, read_line_fast), + process.stderr.fileno(): (process.stderr, stderr_handler, read_line_slow)} if hasattr(select, 'poll'): - # poll is preferred, as select is limited to file handles up to 1024 ... . This could otherwise be + # poll is preferred, as select is limited to file handles up to 1024 ... . This could otherwise be # an issue for us, as it matters how many handles or own process has poll = select.poll() READ_ONLY = select.POLLIN | select.POLLPRI | select.POLLHUP | select.POLLERR @@ -137,10 +137,10 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): wg = WaitGroup() for fno in fdmap.keys(): wg.add(1) - t = threading.Thread(target = lambda: deplete_buffer(fno, wg)) + t = threading.Thread(target=lambda: deplete_buffer(fno, wg)) t.start() # end - # NOTE: Just joining threads can possibly fail as there is a gap between .start() and when it's + # NOTE: Just joining threads can possibly fail as there is a gap between .start() and when it's # actually started, which could make the wait() call to just return because the thread is not yet # active wg.wait() @@ -148,7 +148,7 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): return finalizer(process) - + def dashify(string): return string.replace('_', '-') diff --git a/git/remote.py b/git/remote.py index 85f4ebf2..87db5dd4 100644 --- a/git/remote.py +++ b/git/remote.py @@ -40,6 +40,7 @@ __all__ = ('RemoteProgress', 'PushInfo', 'FetchInfo', 'Remote') #{ Utilities + def add_progress(kwargs, git, progress): """Add the --progress flag to the given kwargs dict if supported by the git command. If the actual progress in the given progress instance is not @@ -510,6 +511,7 @@ class Remote(LazyMixin, Iterable): cmds = set(PushInfo._flag_map.keys()) & set(FetchInfo._flag_map.keys()) progress_handler = progress.new_message_handler() + def my_progress_handler(line): for pline in progress_handler(line): if line.startswith('fatal:'): @@ -520,11 +522,11 @@ class Remote(LazyMixin, Iterable): fetch_info_lines.append(line) continue # end find command code - # end for each comand code we know + # end for each comand code we know # end for each line progress didn't handle # end - # We are only interested in stderr here ... + # We are only interested in stderr here ... handle_process_output(proc, None, my_progress_handler, finalize_process) # read head information diff --git a/git/util.py b/git/util.py index e211ca41..4d1ea8d6 100644 --- a/git/util.py +++ b/git/util.py @@ -251,7 +251,7 @@ class RemoteProgress(object): return failed_lines def new_message_handler(self): - """:return: a progress handler suitable for handle_process_output(), passing lines on to this Progress + """:return: a progress handler suitable for handle_process_output(), passing lines on to this Progress handler in a suitable format""" def handler(line): return self._parse_progress_line(line.rstrip()) @@ -704,26 +704,26 @@ class Iterable(object): class WaitGroup(object): """WaitGroup is like Go sync.WaitGroup. - + Without all the useful corner cases. By Peter Teichman, taken from https://gist.github.com/pteichman/84b92ae7cef0ab98f5a8 """ def __init__(self): self.count = 0 self.cv = threading.Condition() - + def add(self, n): self.cv.acquire() self.count += n self.cv.release() - + def done(self): self.cv.acquire() self.count -= 1 if self.count == 0: self.cv.notify_all() self.cv.release() - + def wait(self): self.cv.acquire() while self.count > 0: |