git-p4: do not pass '-r 0' to p4 commands

git-p4 crashes when used with a very old p4 client version that does not support the '-r <number>' option in its commands. Allow making git-p4 work with old p4 clients by setting git-p4.retries to 0. Alternatively git-p4.retries could be made opt-in. But since only very old, barely maintained p4 versions don't support the '-r' option, the setting-retries-to-0 workaround would do. The "-r retries" option is present in Perforce 2012.2 Command Reference, but absent from Perforce 2012.1 Command Reference. Signed-off-by: Igor Kushnir <igorkuo@gmail.com> Acked-by: Lars Schneider <larsxschneider@gmail.com> Reviewed-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Igor Kushnir committed Dec 29, 2016 at 12:22 UTC bc233524c96518c04650d297ad81a9c948fc2e41
2 files changed +5 -1
Documentation/git-p4.txt
+2
@@ -470,6 +470,8 @@ git-p4.client::
470 git-p4.retries::
471 Specifies the number of times to retry a p4 command (notably,
472 'p4 sync') if the network times out. The default value is 3.
473 + Set the value to 0 to disable retries or if your p4 version
474 + does not support retries (pre 2012.2).
475
476 Clone and sync variables
477 ~~~~~~~~~~~~~~~~~~~~~~~~
git-p4.py
+3 -1
@@ -82,7 +82,9 @@ def p4_build_cmd(cmd):
82 if retries is None:
83 # Perform 3 retries by default
84 retries = 3
85 - real_cmd += ["-r", str(retries)]
85 + if retries > 0:
86 + # Provide a way to not pass this option by setting git-p4.retries to 0
87 + real_cmd += ["-r", str(retries)]
88
89 if isinstance(cmd,basestring):
90 real_cmd = ' '.join(real_cmd) + ' ' + cmd