add --verbose to all commands.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Han-Wen Nienhuys committed
May 23, 2007 at 18:49 UTC
4addad229169ece62f36c6c17cc15bdf532a60bc
1 file changed
+18
-14
contrib/fast-import/git-p4
+18
-14
@@ -15,47 +15,47 @@ import re
15
from sets import Set;
16
17
gitdir = os.environ.get("GIT_DIR", "")
18
-silent = True
18
+verbose = False
19
20
def write_pipe(c, str):
21
- if not silent:
21
+ if verbose:
22
sys.stderr.write('writing pipe: %s\n' % c)
23
24
pipe = os.popen(c, 'w')
25
val = pipe.write(str)
26
if pipe.close():
27
- sys.stderr.write('Command failed')
27
+ sys.stderr.write('Command %s failed\n' % c)
28
sys.exit(1)
29
30
return val
31
32
-def read_pipe(c):
33
- if not silent:
32
+def read_pipe(c, ignore_error=False):
33
+ if verbose:
34
sys.stderr.write('reading pipe: %s\n' % c)
35
36
pipe = os.popen(c, 'rb')
37
val = pipe.read()
38
- if pipe.close():
39
- sys.stderr.write('Command failed')
38
+ if pipe.close() and not ignore_error:
39
+ sys.stderr.write('Command %s failed\n' % c)
40
sys.exit(1)
41
42
return val
43
44
45
def read_pipe_lines(c):
46
- if not silent:
46
+ if verbose:
47
sys.stderr.write('reading pipe: %s\n' % c)
48
## todo: check return status
49
pipe = os.popen(c, 'rb')
50
val = pipe.readlines()
51
if pipe.close():
52
- sys.stderr.write('Command failed')
52
+ sys.stderr.write('Command %s failed\n' % c)
53
sys.exit(1)
54
55
return val
56
57
def system(cmd):
58
- if not silent:
58
+ if verbose:
59
sys.stderr.write("executing %s" % cmd)
60
if os.system(cmd) != 0:
61
die("command failed: %s" % cmd)
@@ -157,7 +157,7 @@ def gitBranchExists(branch):
157
return proc.wait() == 0;
158
159
def gitConfig(key):
160
- return mypopen("git config %s" % key).read()[:-1]
160
+ return read_pipe("git config %s" % key, ignore_error=True).strip()
161
162
class Command:
163
def __init__(self):
@@ -168,7 +168,8 @@ class P4Debug(Command):
168
def __init__(self):
169
Command.__init__(self)
170
self.options = [
171
- ]
171
+ optparse.make_option("--verbose", dest="verbose", action="store_true"),
172
+ ]
173
self.description = "A tool to debug the output of p4 -G."
174
self.needsGit = False
175
@@ -234,6 +235,7 @@ class P4Submit(Command):
235
Command.__init__(self)
236
self.options = [
237
optparse.make_option("--continue", action="store_false", dest="firstTime"),
238
+ optparse.make_option("--verbose", dest="verbose", action="store_true"),
239
optparse.make_option("--origin", dest="origin"),
240
optparse.make_option("--reset", action="store_true", dest="reset"),
241
optparse.make_option("--log-substitutions", dest="substFile"),
@@ -861,11 +863,12 @@ class P4Sync(Command):
863
if not self.silent:
864
print "Creating/updating branch(es) in %s based on origin branch(es)" % self.refPrefix
865
864
- for line in mypopen("git rev-parse --symbolic --remotes"):
866
+ for line in read_pipe_lines("git rev-parse --symbolic --remotes"):
867
+ line = line.strip()
868
if (not line.startswith("origin/")) or line.endswith("HEAD\n"):
869
continue
870
868
- headName = line[len("origin/"):-1]
871
+ headName = line[len("origin/")]
872
remoteHead = self.refPrefix + headName
873
originHead = "origin/" + headName
874
@@ -1292,6 +1295,7 @@ if len(options) > 0:
1295
1296
(cmd, args) = parser.parse_args(sys.argv[2:], cmd);
1297
1298
+verbose = cmd.verbose
1299
if cmd.needsGit:
1300
gitdir = cmd.gitdir
1301
if len(gitdir) == 0: