git-p4: don't groom exclude path list on every commit

Currently, `cloneExclude` array is being groomed (by removing trailing "...") on every changeset. (since `extractFilesFromCommit()` is called on every imported changeset) As a micro-optimization, do it once while parsing arguments. Also, prepend "/" and remove trailing "..." at the same time. Signed-off-by: Andrey Mazo <amazo@checkvideo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mazo, Andrey committed Apr 1, 2019 at 18:02 UTC ff8c50ed0c98d9bc6aaf5fc2e93bd976c3076750
1 file changed +7 -5
git-p4.py
+7 -5
@@ -1316,7 +1316,7 @@ class Command:
1316 self.needsGit = True
1317 self.verbose = False
1318
1319 - # This is required for the "append" cloneExclude action
1319 + # This is required for the "append" update_shelve action
1320 def ensure_value(self, attr, value):
1321 if not hasattr(self, attr) or getattr(self, attr) is None:
1322 setattr(self, attr, value)
@@ -2530,6 +2530,11 @@ class View(object):
2530 die( "Error: %s is not found in client spec path" % depot_path )
2531 return ""
2532
2533 +def cloneExcludeCallback(option, opt_str, value, parser):
2534 + # prepend "/" because the first "/" was consumed as part of the option itself.
2535 + # ("-//depot/A/..." becomes "/depot/A/..." after option parsing)
2536 + parser.values.cloneExclude += ["/" + re.sub(r"\.\.\.$", "", value)]
2537 +
2538 class P4Sync(Command, P4UserMap):
2539
2540 def __init__(self):
@@ -2553,7 +2558,7 @@ class P4Sync(Command, P4UserMap):
2558 optparse.make_option("--use-client-spec", dest="useClientSpec", action='store_true',
2559 help="Only sync files that are included in the Perforce Client Spec"),
2560 optparse.make_option("-/", dest="cloneExclude",
2556 - action="append", type="string",
2561 + action="callback", callback=cloneExcludeCallback, type="string",
2562 help="exclude depot path"),
2563 ]
2564 self.description = """Imports from Perforce into a git repository.\n
@@ -2619,8 +2624,6 @@ class P4Sync(Command, P4UserMap):
2624 print("checkpoint finished: " + out)
2625
2626 def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0):
2622 - self.cloneExclude = [re.sub(r"\.\.\.$", "", path)
2623 - for path in self.cloneExclude]
2627 files = []
2628 fnum = 0
2629 while "depotFile%s" % fnum in commit:
@@ -3890,7 +3893,6 @@ class P4Clone(P4Sync):
3893 self.cloneDestination = depotPaths[-1]
3894 depotPaths = depotPaths[:-1]
3895
3893 - self.cloneExclude = ["/"+p for p in self.cloneExclude]
3896 for p in depotPaths:
3897 if not p.startswith("//"):
3898 sys.stderr.write('Depot paths must start with "//": %s\n' % p)