Skip to content

Commit 18fa13d

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4: catch p4 describe errors
Group the two calls to "p4 describe" into a new helper function, and try to validate the p4 results. The current behavior when p4 describe fails is to die with a python backtrace. The new behavior will print the full response. This does not solve any particular problem, but adds more checking in hopes of narrowing down odd behavior seen on at least two occasions. Based-on-patch-by: Matt Arsenault <[email protected]> Reported-by: Arthur <[email protected]> Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f7d8e3d commit 18fa13d

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

git-p4.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,29 @@ def p4_reopen(type, f):
169169
def p4_move(src, dest):
170170
p4_system(["move", "-k", wildcard_encode(src), wildcard_encode(dest)])
171171

172+
def p4_describe(change):
173+
"""Make sure it returns a valid result by checking for
174+
the presence of field "time". Return a dict of the
175+
results."""
176+
177+
ds = p4CmdList(["describe", "-s", str(change)])
178+
if len(ds) != 1:
179+
die("p4 describe -s %d did not return 1 result: %s" % (change, str(ds)))
180+
181+
d = ds[0]
182+
183+
if "p4ExitCode" in d:
184+
die("p4 describe -s %d exited with %d: %s" % (change, d["p4ExitCode"],
185+
str(d)))
186+
if "code" in d:
187+
if d["code"] == "error":
188+
die("p4 describe -s %d returned error code: %s" % (change, str(d)))
189+
190+
if "time" not in d:
191+
die("p4 describe -s %d returned no \"time\": %s" % (change, str(d)))
192+
193+
return d
194+
172195
#
173196
# Canonicalize the p4 type and return a tuple of the
174197
# base type, plus any modifiers. See "p4 help filetypes"
@@ -2543,7 +2566,7 @@ def searchParent(self, parent, branch, target):
25432566
def importChanges(self, changes):
25442567
cnt = 1
25452568
for change in changes:
2546-
description = p4Cmd(["describe", str(change)])
2569+
description = p4_describe(change)
25472570
self.updateOptionDict(description)
25482571

25492572
if not self.silent:
@@ -2667,14 +2690,8 @@ def importHeadRevision(self, revision):
26672690

26682691
# Use time from top-most change so that all git p4 clones of
26692692
# the same p4 repo have the same commit SHA1s.
2670-
res = p4CmdList("describe -s %d" % newestRevision)
2671-
newestTime = None
2672-
for r in res:
2673-
if r.has_key('time'):
2674-
newestTime = int(r['time'])
2675-
if newestTime is None:
2676-
die("\"describe -s\" on newest change %d did not give a time")
2677-
details["time"] = newestTime
2693+
res = p4_describe(newestRevision)
2694+
details["time"] = res["time"]
26782695

26792696
self.updateOptionDict(details)
26802697
try:

0 commit comments

Comments
 (0)