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 <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>

Pete Wyckoff committed Nov 23, 2012 at 17:35 UTC 18fa13d0b34b6243d3679ea78325ee33ee4d0989
1 file changed +26 -9
git-p4.py
+26 -9
@@ -169,6 +169,29 @@ def p4_reopen(type, f):
169 def p4_move(src, dest):
170 p4_system(["move", "-k", wildcard_encode(src), wildcard_encode(dest)])
171
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 +
195 #
196 # Canonicalize the p4 type and return a tuple of the
197 # base type, plus any modifiers. See "p4 help filetypes"
@@ -2543,7 +2566,7 @@ class P4Sync(Command, P4UserMap):
2566 def importChanges(self, changes):
2567 cnt = 1
2568 for change in changes:
2546 - description = p4Cmd(["describe", str(change)])
2569 + description = p4_describe(change)
2570 self.updateOptionDict(description)
2571
2572 if not self.silent:
@@ -2667,14 +2690,8 @@ class P4Sync(Command, P4UserMap):
2690
2691 # Use time from top-most change so that all git p4 clones of
2692 # 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"]
2695
2696 self.updateOptionDict(details)
2697 try: