summaryrefslogtreecommitdiff
path: root/contrib/fast-import
diff options
context:
space:
mode:
authorScott Lamb <slamb@slamb.org>2007-07-16 03:58:10 (GMT)
committerSimon Hausmann <simon@lst.de>2007-07-17 06:35:24 (GMT)
commit9f90c7335e223c26d19f3c01a6d89e6c0cd8b827 (patch)
tree25f50c8a3cadec5e0cb86148ad9f057271bcb8f9 /contrib/fast-import
parenta5e407988b35b7353bd03c770afc647670c25981 (diff)
downloadgit-9f90c7335e223c26d19f3c01a6d89e6c0cd8b827.zip
git-9f90c7335e223c26d19f3c01a6d89e6c0cd8b827.tar.gz
git-9f90c7335e223c26d19f3c01a6d89e6c0cd8b827.tar.bz2
git-p4: use subprocess in p4CmdList
This allows bidirectional piping - useful for "-x -" to avoid commandline arguments - and is a step toward bypassing the shell. Signed-off-by: Scott Lamb <slamb@slamb.org> Signed-off-by: Simon Hausmann <simon@lst.de>
Diffstat (limited to 'contrib/fast-import')
-rwxr-xr-xcontrib/fast-import/git-p423
1 files changed, 18 insertions, 5 deletions
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index d877150..d93e656 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -63,21 +63,34 @@ def system(cmd):
if os.system(cmd) != 0:
die("command failed: %s" % cmd)
-def p4CmdList(cmd):
+def p4CmdList(cmd, stdin=None, stdin_mode='w+b'):
cmd = "p4 -G %s" % cmd
if verbose:
sys.stderr.write("Opening pipe: %s\n" % cmd)
- pipe = os.popen(cmd, "rb")
+
+ # Use a temporary file to avoid deadlocks without
+ # subprocess.communicate(), which would put another copy
+ # of stdout into memory.
+ stdin_file = None
+ if stdin is not None:
+ stdin_file = tempfile.TemporaryFile(prefix='p4-stdin', mode=stdin_mode)
+ stdin_file.write(stdin)
+ stdin_file.flush()
+ stdin_file.seek(0)
+
+ p4 = subprocess.Popen(cmd, shell=True,
+ stdin=stdin_file,
+ stdout=subprocess.PIPE)
result = []
try:
while True:
- entry = marshal.load(pipe)
+ entry = marshal.load(p4.stdout)
result.append(entry)
except EOFError:
pass
- exitCode = pipe.close()
- if exitCode != None:
+ exitCode = p4.wait()
+ if exitCode != 0:
entry = {}
entry["p4ExitCode"] = exitCode
result.append(entry)