66
77import os ,sys
88from util import (
9- LazyMixin ,
9+ LazyMixin ,
1010stream_copy
1111 )
1212from exc import GitCommandError
1313
1414from subprocess import (
15- call ,
15+ call ,
1616Popen ,
1717PIPE
1818 )
1919
2020execute_kwargs = ('istream' ,'with_keep_cwd' ,'with_extended_output' ,
21- 'with_exceptions' ,'as_process' ,
21+ 'with_exceptions' ,'as_process' ,
2222'output_stream' )
2323
2424__all__ = ('Git' , )
@@ -40,7 +40,7 @@ class Git(LazyMixin):
4040 rval = g.ls_files() # calls 'git ls-files' program
4141
4242 ``Debugging``
43- Set the GIT_PYTHON_TRACE environment variable print each invocation
43+ Set the GIT_PYTHON_TRACE environment variable print each invocation
4444 of the command to stdout.
4545 Set its value to 'full' to see details about the returned values.
4646 """
@@ -63,7 +63,7 @@ class Git(LazyMixin):
6363
6464class AutoInterrupt (object ):
6565
66- """Kill/Interrupt the stored process instance once this instance goes out of scope. It is
66+ """Kill/Interrupt the stored process instance once this instance goes out of scope. It is
6767 used to prevent processes piling up in case iterators stop reading.
6868 Besides all attributes are wired through to the contained process object.
6969
@@ -83,7 +83,7 @@ def __del__(self):
8383if self .proc .poll ()is not None :
8484return
8585
86- # can be that nothing really exists anymore ...
86+ # can be that nothing really exists anymore ...
8787if os is None :
8888return
8989
@@ -94,34 +94,34 @@ def __del__(self):
9494except OSError :
9595pass # ignore error when process already died
9696except AttributeError :
97- # try windows
98- # for some reason, providing None for stdout/stderr still prints something. This is why
99- # we simply use the shell and redirect to nul. Its slower than CreateProcess, question
97+ # try windows
98+ # for some reason, providing None for stdout/stderr still prints something. This is why
99+ # we simply use the shell and redirect to nul. Its slower than CreateProcess, question
100100# is whether we really want to see all these messages. Its annoying no matter what.
101101call (("TASKKILL /F /T /PID %s 2>nul 1>nul" % str (self .proc .pid )),shell = True )
102- # END exception handling
102+ # END exception handling
103103
104104def __getattr__ (self ,attr ):
105105return getattr (self .proc ,attr )
106106
107107def wait (self ):
108- """Wait for the process and return its status code.
108+ """Wait for the process and return its status code.
109109
110110 :raise GitCommandError: if the return status is not 0"""
111111status = self .proc .wait ()
112112if status != 0 :
113113raise GitCommandError (self .args ,status ,self .proc .stderr .read ())
114- # END status handling
114+ # END status handling
115115return status
116116# END auto interrupt
117117
118118class CatFileContentStream (object ):
119119
120- """Object representing a sized read-only stream returning the contents of
120+ """Object representing a sized read-only stream returning the contents of
121121 an object.
122- It behaves like a stream, but counts the data read and simulates an empty
122+ It behaves like a stream, but counts the data read and simulates an empty
123123 stream once our sized content region is empty.
124- If not all data is read to the end of the objects's lifetime, we read the
124+ If not all data is read to the end of the objects's lifetime, we read the
125125 rest to assure the underlying stream continues to work"""
126126
127127__slots__ = ('_stream' ,'_nbr' ,'_size' )
@@ -131,7 +131,7 @@ def __init__(self, size, stream):
131131self ._size = size
132132self ._nbr = 0 # num bytes read
133133
134- # special case: if the object is empty, has null bytes, get the
134+ # special case: if the object is empty, has null bytes, get the
135135# final newline right away.
136136if size == 0 :
137137stream .read (1 )
@@ -220,9 +220,9 @@ def __init__(self, working_dir=None):
220220"""Initialize this instance with:
221221
222222 :param working_dir:
223- Git directory we should work in. If None, we always work in the current
223+ Git directory we should work in. If None, we always work in the current
224224 directory as returned by os.getcwd().
225- It is meant to be the working tree directory if available, or the
225+ It is meant to be the working tree directory if available, or the
226226 .git directory in case of bare repositories."""
227227super (Git ,self ).__init__ ()
228228self ._working_dir = working_dir
@@ -233,7 +233,7 @@ def __init__(self, working_dir=None):
233233self .cat_file_all = None
234234
235235def __getattr__ (self ,name ):
236- """A convenience method as it allows to call the command as if it was
236+ """A convenience method as it allows to call the command as if it was
237237 an object.
238238 :return: Callable object that will execute call _call_process with your arguments."""
239239if name [0 ]== '_' :
@@ -267,8 +267,8 @@ def execute(self, command,
267267with_keep_cwd = False ,
268268with_extended_output = False ,
269269with_exceptions = True ,
270- as_process = False ,
271- output_stream = None ,
270+ as_process = False ,
271+ output_stream = None ,
272272** subprocess_kwargs
273273 ):
274274"""Handles executing the command on the shell and consumes and returns
@@ -294,26 +294,26 @@ def execute(self, command,
294294 Whether to raise an exception when git returns a non-zero status.
295295
296296 :param as_process:
297- Whether to return the created process instance directly from which
298- streams can be read on demand. This will render with_extended_output and
299- with_exceptions ineffective - the caller will have
297+ Whether to return the created process instance directly from which
298+ streams can be read on demand. This will render with_extended_output and
299+ with_exceptions ineffective - the caller will have
300300 to deal with the details himself.
301301 It is important to note that the process will be placed into an AutoInterrupt
302- wrapper that will interrupt the process once it goes out of scope. If you
303- use the command in iterators, you should pass the whole process instance
302+ wrapper that will interrupt the process once it goes out of scope. If you
303+ use the command in iterators, you should pass the whole process instance
304304 instead of a single stream.
305305
306306 :param output_stream:
307- If set to a file-like object, data produced by the git command will be
307+ If set to a file-like object, data produced by the git command will be
308308 output to the given stream directly.
309309 This feature only has any effect if as_process is False. Processes will
310310 always be created with a pipe due to issues with subprocess.
311- This merely is a workaround as data will be copied from the
311+ This merely is a workaround as data will be copied from the
312312 output pipe to the given output stream directly.
313313
314314 :param subprocess_kwargs:
315- Keyword arguments to be passed to subprocess.Popen. Please note that
316- some of the valid kwargs are already set by this method, the ones you
315+ Keyword arguments to be passed to subprocess.Popen. Please note that
316+ some of the valid kwargs are already set by this method, the ones you
317317 specify may not be the same ones.
318318
319319 :return:
@@ -330,7 +330,7 @@ def execute(self, command,
330330 :raise GitCommandError:
331331
332332 :note:
333- If you add additional keyword arguments to the signature of this method,
333+ If you add additional keyword arguments to the signature of this method,
334334 you must update the execute_kwargs tuple housed in this module."""
335335if self .GIT_PYTHON_TRACE and not self .GIT_PYTHON_TRACE == 'full' :
336336print ' ' .join (command )
@@ -360,7 +360,7 @@ def execute(self, command,
360360stderr_value = ''
361361try :
362362if output_stream is None :
363- stdout_value ,stderr_value = proc .communicate ()
363+ stdout_value ,stderr_value = proc .communicate ()
364364# strip trailing "\n"
365365if stdout_value .endswith ("\n " ):
366366stdout_value = stdout_value [:- 1 ]
@@ -434,7 +434,7 @@ def __unpack_args(cls, arg_list):
434434outlist .extend (cls .__unpack_args (arg ))
435435elif isinstance (arg_list ,unicode ):
436436outlist .append (arg_list .encode ('utf-8' ))
437- # END recursion
437+ # END recursion
438438else :
439439outlist .append (str (arg ))
440440# END for each arg
@@ -523,7 +523,7 @@ def make_call():
523523finally :
524524import warnings
525525msg = "WARNING: Automatically switched to use git.cmd as git executable, which reduces performance by ~70%."
526- msg += "Its recommended to put git.exe into the PATH or to set the %s environment variable to the executable's location" % self ._git_exec_env_var
526+ msg += "Its recommended to put git.exe into the PATH or to set the %s environment variable to the executable's location" % self ._git_exec_env_var
527527warnings .warn (msg )
528528#END print of warning
529529#END catch first failure
@@ -541,7 +541,7 @@ def _parse_object_header(self, header_line):
541541
542542 :return: (hex_sha, type_string, size_as_int)
543543
544- :raise ValueError: if the header contains indication for an error due to
544+ :raise ValueError: if the header contains indication for an error due to
545545 incorrect input sha"""
546546tokens = header_line .split ()
547547if len (tokens )!= 3 :
@@ -553,7 +553,7 @@ def _parse_object_header(self, header_line):
553553# END error handling
554554
555555if len (tokens [0 ])!= 40 :
556- raise ValueError ("Failed to parse header: %r" % header_line )
556+ raise ValueError ("Failed to parse header: %r" % header_line )
557557return (tokens [0 ],tokens [1 ],int (tokens [2 ]))
558558
559559def __prepare_ref (self ,ref ):
@@ -581,11 +581,11 @@ def __get_object_header(self, cmd, ref):
581581return self ._parse_object_header (cmd .stdout .readline ())
582582
583583def get_object_header (self ,ref ):
584- """ Use this method to quickly examine the type and size of the object behind
585- the given ref.
584+ """ Use this method to quickly examine the type and size of the object behind
585+ the given ref.
586586
587- :note: The method will only suffer from the costs of command invocation
588- once and reuses the command in subsequent calls.
587+ :note: The method will only suffer from the costs of command invocation
588+ once and reuses the command in subsequent calls.
589589
590590 :return: (hexsha, type_string, size_as_int)"""
591591cmd = self .__get_persistent_cmd ("cat_file_header" ,"cat_file" ,batch_check = True )