summaryrefslogtreecommitdiff
path: root/lib/git/cmd.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-16 11:48:20 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-16 11:48:20 +0200
commit05d2687afcc78cd192714ee3d71fdf36a37d110f (patch)
tree3e3760e5b46095458cf75446330ba2fc25fa23e5 /lib/git/cmd.py
parent6226720b0e6a5f7cb9223fc50363def487831315 (diff)
parentf2df1f56cccab13d5c92abbc6b18be725e7b4833 (diff)
downloadgitpython-05d2687afcc78cd192714ee3d71fdf36a37d110f.tar.gz
Merging latest improvements including a revamped Repo interface before more changes are to be done on the way diffing is handled
Merge branch 'improvements' * improvements: Improved archive function by allowing it to directly write to an output stream - previously it would cache everything to memory and try to provide zipping functionality itself repo: made init and clone methods less specific, previously they wanted to do it 'barely' only. New method names closely follow the default git command names repo.commit_delta_base: removed Object can now create objects of the proper type in case one attempts to create an object directly - this feature is used in several places now, allowing for additional type-checking repo: removed commits_between but added a note about how this can be achieved using the iter_commits method; reorganized methods within the type as a start for more interface changes Added Commit.iter_parents to iterate all parents repo: removed a few methods because of redundancy or because it will be obsolete once the interface overhaul is finished. This commit is just intermediate All times are not stored as time_struct, but as simple int to consume less memory
Diffstat (limited to 'lib/git/cmd.py')
-rw-r--r--lib/git/cmd.py54
1 files changed, 40 insertions, 14 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py
index 2965eb8b..500fcd93 100644
--- a/lib/git/cmd.py
+++ b/lib/git/cmd.py
@@ -13,7 +13,8 @@ from errors import GitCommandError
GIT_PYTHON_TRACE = os.environ.get("GIT_PYTHON_TRACE", False)
execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
- 'with_exceptions', 'with_raw_output', 'as_process')
+ 'with_exceptions', 'with_raw_output', 'as_process',
+ 'output_stream' )
extra = {}
if sys.platform == 'win32':
@@ -102,7 +103,8 @@ class Git(object):
with_extended_output=False,
with_exceptions=True,
with_raw_output=False,
- as_process=False
+ as_process=False,
+ output_stream=None
):
"""
Handles executing the command on the shell and consumes and returns
@@ -130,16 +132,20 @@ class Git(object):
``with_raw_output``
Whether to avoid stripping off trailing whitespace.
- ``as_process``
- Whether to return the created process instance directly from which
- streams can be read on demand. This will render with_extended_output,
- with_exceptions and with_raw_output ineffective - the caller will have
- to deal with the details himself.
- It is important to note that the process will be placed into an AutoInterrupt
- wrapper that will interrupt the process once it goes out of scope. If you
- use the command in iterators, you should pass the whole process instance
- instead of a single stream.
-
+ ``as_process``
+ Whether to return the created process instance directly from which
+ streams can be read on demand. This will render with_extended_output,
+ with_exceptions and with_raw_output ineffective - the caller will have
+ to deal with the details himself.
+ It is important to note that the process will be placed into an AutoInterrupt
+ wrapper that will interrupt the process once it goes out of scope. If you
+ use the command in iterators, you should pass the whole process instance
+ instead of a single stream.
+ ``output_stream``
+ If set to a file-like object, data produced by the git command will be
+ output to the given stream directly.
+ Otherwise a new file will be opened.
+
Returns::
str(output) # extended_output = False (Default)
@@ -160,13 +166,17 @@ class Git(object):
cwd = os.getcwd()
else:
cwd=self.git_dir
+
+ ostream = subprocess.PIPE
+ if output_stream is not None:
+ ostream = output_stream
# Start the process
proc = subprocess.Popen(command,
cwd=cwd,
stdin=istream,
stderr=subprocess.PIPE,
- stdout=subprocess.PIPE,
+ stdout=ostream,
**extra
)
@@ -223,6 +233,21 @@ class Git(object):
args.append("--%s=%s" % (dashify(k), v))
return args
+ @classmethod
+ def __unpack_args(cls, arg_list):
+ if not isinstance(arg_list, (list,tuple)):
+ return [ str(arg_list) ]
+
+ outlist = list()
+ for arg in arg_list:
+ if isinstance(arg_list, (list, tuple)):
+ outlist.extend(cls.__unpack_args( arg ))
+ # END recursion
+ else:
+ outlist.append(str(arg))
+ # END for each arg
+ return outlist
+
def _call_process(self, method, *args, **kwargs):
"""
Run the given git command with the specified arguments and return
@@ -258,7 +283,8 @@ class Git(object):
# Prepare the argument list
opt_args = self.transform_kwargs(**kwargs)
- ext_args = map(str, args)
+
+ ext_args = self.__unpack_args(args)
args = opt_args + ext_args
call = ["git", dashify(method)]