Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
git-p4: use subprocess in p4CmdList
author
Scott Lamb
<slamb@slamb.org>
Mon, 16 Jul 2007 03:58:10 +0000
(20:58 -0700)
committer
Simon Hausmann
<simon@lst.de>
Tue, 17 Jul 2007 06:35:24 +0000
(08:35 +0200)
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>
contrib/fast-import/git-p4
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
a5e4079
)
diff --git
a/contrib/fast-import/git-p4
b/contrib/fast-import/git-p4
index d877150f418ab67b6e0f884bd795b990354f5613..d93e6561554a1592afdc70833d9cac51d6ad55b6 100755
(executable)
--- 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)
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)
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:
result = []
try:
while True:
- entry = marshal.load(p
ipe
)
+ entry = marshal.load(p
4.stdout
)
result.append(entry)
except EOFError:
pass
result.append(entry)
except EOFError:
pass
- exitCode = p
ipe.close
()
- if exitCode !=
None
:
+ exitCode = p
4.wait
()
+ if exitCode !=
0
:
entry = {}
entry["p4ExitCode"] = exitCode
result.append(entry)
entry = {}
entry["p4ExitCode"] = exitCode
result.append(entry)