Skip to content

Commit

Permalink
git p4: catch p4 describe errors
Browse files Browse the repository at this point in the history
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 <arsenm2@gmail.com>
Reported-by: Arthur <a.foulon@amesys.fr>
Signed-off-by: Pete Wyckoff <pw@padd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Pete Wyckoff authored and Junio C Hamano committed Nov 26, 2012
1 parent f7d8e3d commit 18fa13d
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,29 @@ def p4_reopen(type, f):
def p4_move(src, dest):
p4_system(["move", "-k", wildcard_encode(src), wildcard_encode(dest)])

def p4_describe(change):
"""Make sure it returns a valid result by checking for
the presence of field "time". Return a dict of the
results."""

ds = p4CmdList(["describe", "-s", str(change)])
if len(ds) != 1:
die("p4 describe -s %d did not return 1 result: %s" % (change, str(ds)))

d = ds[0]

if "p4ExitCode" in d:
die("p4 describe -s %d exited with %d: %s" % (change, d["p4ExitCode"],
str(d)))
if "code" in d:
if d["code"] == "error":
die("p4 describe -s %d returned error code: %s" % (change, str(d)))

if "time" not in d:
die("p4 describe -s %d returned no \"time\": %s" % (change, str(d)))

return d

#
# Canonicalize the p4 type and return a tuple of the
# base type, plus any modifiers. See "p4 help filetypes"
Expand Down Expand Up @@ -2543,7 +2566,7 @@ def searchParent(self, parent, branch, target):
def importChanges(self, changes):
cnt = 1
for change in changes:
description = p4Cmd(["describe", str(change)])
description = p4_describe(change)
self.updateOptionDict(description)

if not self.silent:
Expand Down Expand Up @@ -2667,14 +2690,8 @@ def importHeadRevision(self, revision):

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

self.updateOptionDict(details)
try:
Expand Down

0 comments on commit 18fa13d

Please sign in to comment.