aboutsummaryrefslogtreecommitdiffstats
path: root/git-p4.py
diff options
context:
space:
mode:
authorLuke Diamand <luke@diamand.org>2018-06-08 21:32:46 +0100
committerJunio C Hamano <gitster@pobox.com>2018-06-12 14:46:09 -0700
commit55bb3e3611c7b3f7bbbaf8d9ce98a4ed4196c3eb (patch)
treea1f2183a0c9c1b7e3778055e5771ae391c58396d /git-p4.py
parent0ef67acdd784852ee8e86dcdb653cc290c1a77a3 (diff)
downloadgit-55bb3e3611c7b3f7bbbaf8d9ce98a4ed4196c3eb.tar.gz
git-p4: raise exceptions from p4CmdList based on error from p4 server
This change lays some groundwork for better handling of rowcount errors from the server, where it fails to send us results because we requested too many. It adds an option to p4CmdList() to return errors as a Python exception. The exceptions are derived from P4Exception (something went wrong), P4ServerException (the server sent us an error code) and P4RequestSizeException (we requested too many rows/results from the server database). This makes the code that handles the errors a bit easier. The default behavior is unchanged; the new code is enabled with a flag. Signed-off-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-p4.py')
-rwxr-xr-xgit-p4.py44
1 files changed, 40 insertions, 4 deletions
diff --git a/git-p4.py b/git-p4.py
index cbb6619737..90377263fe 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -561,10 +561,30 @@ def isModeExec(mode):
# otherwise False.
return mode[-3:] == "755"
+class P4Exception(Exception):
+ """ Base class for exceptions from the p4 client """
+ def __init__(self, exit_code):
+ self.p4ExitCode = exit_code
+
+class P4ServerException(P4Exception):
+ """ Base class for exceptions where we get some kind of marshalled up result from the server """
+ def __init__(self, exit_code, p4_result):
+ super(P4ServerException, self).__init__(exit_code)
+ self.p4_result = p4_result
+ self.code = p4_result[0]['code']
+ self.data = p4_result[0]['data']
+
+class P4RequestSizeException(P4ServerException):
+ """ One of the maxresults or maxscanrows errors """
+ def __init__(self, exit_code, p4_result, limit):
+ super(P4RequestSizeException, self).__init__(exit_code, p4_result)
+ self.limit = limit
+
def isModeExecChanged(src_mode, dst_mode):
return isModeExec(src_mode) != isModeExec(dst_mode)
-def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False):
+def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
+ errors_as_exceptions=False):
if isinstance(cmd,basestring):
cmd = "-G " + cmd
@@ -611,9 +631,25 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False):
pass
exitCode = p4.wait()
if exitCode != 0:
- entry = {}
- entry["p4ExitCode"] = exitCode
- result.append(entry)
+ if errors_as_exceptions:
+ if len(result) > 0:
+ data = result[0].get('data')
+ if data:
+ m = re.search('Too many rows scanned \(over (\d+)\)', data)
+ if not m:
+ m = re.search('Request too large \(over (\d+)\)', data)
+
+ if m:
+ limit = int(m.group(1))
+ raise P4RequestSizeException(exitCode, result, limit)
+
+ raise P4ServerException(exitCode, result)
+ else:
+ raise P4Exception(exitCode)
+ else:
+ entry = {}
+ entry["p4ExitCode"] = exitCode
+ result.append(entry)
return result