Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15ee5a5

Browse files
committed
fix(misc): various cleanup
Just went through all changes and adjusted them to the best of myabilities. As there are no tests to claim otherwise, I believethis is correct enough.However, it becomes evident that it's no longer possible to justmake changes without backing them with a respective test.
1 parentda86442 commit15ee5a5

File tree

4 files changed

+18
-49
lines changed

4 files changed

+18
-49
lines changed

‎git/cmd.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
fromgit.compatimport (
3737
string_types,
3838
defenc,
39+
force_bytes,
3940
PY3,
4041
bchr,
4142
# just to satisfy flake8 on py3
@@ -69,10 +70,6 @@ def _bchr(c):
6970
# Documentation
7071
## @{
7172

72-
def_drop_output_handler(line):
73-
pass
74-
75-
7673
defhandle_process_output(process,stdout_handler,stderr_handler,finalizer):
7774
"""Registers for notifications to lean that process output is ready to read, and dispatches lines to
7875
the respective line handlers. We are able to handle carriage returns in case progress is sent by that
@@ -83,13 +80,6 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer):
8380
:param stdout_handler: f(stdout_line_string), or None
8481
:param stderr_hanlder: f(stderr_line_string), or None
8582
:param finalizer: f(proc) - wait for proc to finish"""
86-
87-
log.debug('handle_process_output( process=%r, stdout_handler=%r, stderr_handler=%r, finalizer=%r'
88-
% (process,stdout_handler,stderr_handler,finalizer))
89-
90-
ifstdout_handlerisNone:
91-
stdout_handler=_drop_output_handler
92-
9383
fdmap= {process.stdout.fileno(): (stdout_handler, [b'']),
9484
process.stderr.fileno(): (stderr_handler, [b''])}
9585

@@ -130,7 +120,6 @@ def _dispatch_single_line(line, handler):
130120
# end single line helper
131121

132122
def_dispatch_lines(fno,handler,buf_list):
133-
log.debug('fno=%d, handler=%r, buf_list=%r'% (fno,handler,buf_list))
134123
lc=0
135124
forlinein_read_lines_from_fno(fno,buf_list):
136125
_dispatch_single_line(line,handler)
@@ -325,23 +314,15 @@ def wait(self, stderr=b''):
325314
:param stderr: Previously read value of stderr, in case stderr is already closed.
326315
:warn: may deadlock if output or error pipes are used and not handled separately.
327316
:raise GitCommandError: if the return status is not 0"""
328-
329-
# stderr must be a bytes object as it will
330-
# combined with more data from the process and
331-
# decoded by the caller
332317
ifstderrisNone:
333318
stderr=b''
334-
eliftype(stderr)==unicode:
335-
stderr=stderr.encode(defenc)
336-
319+
stderr=force_bytes(stderr)
320+
337321
status=self.proc.wait()
338322

339323
defread_all_from_possibly_closed_stream(stream):
340324
try:
341-
last_stderr=stream.read()
342-
iftype(last_stderr)==unicode:
343-
last_stderr=last_stderr.encode(defenc)
344-
returnstderr+last_stderr
325+
returnstderr+force_bytes(stream.read())
345326
exceptValueError:
346327
returnstderrorb''
347328

@@ -633,8 +614,8 @@ def execute(self, command,
633614
cwd=cwd,
634615
bufsize=-1,
635616
stdin=istream,
636-
stderr=PIPE,
637-
stdout=PIPE,
617+
stderr=PIPE,
618+
stdout=PIPEifwith_stdoutelseopen(os.devnull,'wb'),
638619
shell=self.USE_SHELL,
639620
close_fds=(os.name=='posix'),# unsupported on windows
640621
universal_newlines=universal_newlines,

‎git/ext/gitdb

‎git/remote.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -570,37 +570,25 @@ def _get_fetch_info_from_stderr(self, proc, progress):
570570

571571
progress_handler=progress.new_message_handler()
572572

573-
error_message=None
574573
stderr_text=None
575574

576575
forlineinproc.stderr:
577576
line=force_text(line)
578577
forplineinprogress_handler(line):
579-
ifline.startswith('fatal:')orline.startswith('error:'):
580-
error_message="Error when fetching: %s"% (line,)
581-
break
582-
583578
# END handle special messages
584579
forcmdincmds:
585580
iflen(line)>1andline[0]==' 'andline[1]==cmd:
586581
fetch_info_lines.append(line)
587582
continue
588583
# end find command code
589584
# end for each comand code we know
590-
591-
iferror_messageisnotNone:
592-
break
593585
# end for each line progress didn't handle
594-
595-
iferror_messageisnotNone:
596-
stderr_text=proc.stderr.read()
597-
598586
# end
587+
ifprogress.error_lines():
588+
stderr_text='\n'.join(progress.error_lines())
589+
599590
finalize_process(proc,stderr=stderr_text)
600591

601-
iferror_messageisnotNone:
602-
raiseGitCommandError(error_message,2,stderr=stderr_text)
603-
604592
# read head information
605593
fp=open(join(self.repo.git_dir,'FETCH_HEAD'),'rb')
606594
fetch_head_info= [l.decode(defenc)forlinfp.readlines()]
@@ -646,10 +634,6 @@ def stdout_handler(line):
646634

647635
try:
648636
handle_process_output(proc,stdout_handler,progress_handler,finalize_process)
649-
exceptGitCommandErroraserr:
650-
# convert any error from wait() into the same error with stdout lines
651-
raiseGitCommandError(err.command,err.status,progress.get_stderr())
652-
653637
exceptException:
654638
iflen(output)==0:
655639
raise

‎git/util.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,16 @@ def __init__(self):
182182
self._cur_line=None
183183
self._error_lines= []
184184

185-
defget_stderr(self):
186-
return'\n'.join(self._error_lines)
185+
deferror_lines(self):
186+
"""Returns all lines that started with error: or fatal:"""
187+
returnself._error_lines
187188

188189
def_parse_progress_line(self,line):
189190
"""Parse progress information from the given line as retrieved by git-push
190-
or git-fetch
191+
or git-fetch.
192+
193+
Lines that seem to contain an error (i.e. start with error: or fatal:) are stored
194+
separately and can be queried using `error_lines()`.
191195
192196
:return: list(line, ...) list of lines that could not be processed"""
193197
# handle
@@ -775,7 +779,7 @@ def done(self):
775779
defwait(self,stderr=b''):
776780
self.cv.acquire()
777781
whileself.count>0:
778-
self.cv.wait(strerr=stderr)
782+
self.cv.wait()
779783
self.cv.release()
780784

781785

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp