Skip to content

Commit ff8c50e

Browse files
Mazo, Andreygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2768cb commit ff8c50e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

git-p4.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ def __init__(self):
13161316
self.needsGit = True
13171317
self.verbose = False
13181318

1319-
# This is required for the "append" cloneExclude action
1319+
# This is required for the "append" update_shelve action
13201320
def ensure_value(self, attr, value):
13211321
if not hasattr(self, attr) or getattr(self, attr) is None:
13221322
setattr(self, attr, value)
@@ -2530,6 +2530,11 @@ def map_in_client(self, depot_path):
25302530
die( "Error: %s is not found in client spec path" % depot_path )
25312531
return ""
25322532

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+
25332538
class P4Sync(Command, P4UserMap):
25342539

25352540
def __init__(self):
@@ -2553,7 +2558,7 @@ def __init__(self):
25532558
optparse.make_option("--use-client-spec", dest="useClientSpec", action='store_true',
25542559
help="Only sync files that are included in the Perforce Client Spec"),
25552560
optparse.make_option("-/", dest="cloneExclude",
2556-
action="append", type="string",
2561+
action="callback", callback=cloneExcludeCallback, type="string",
25572562
help="exclude depot path"),
25582563
]
25592564
self.description = """Imports from Perforce into a git repository.\n
@@ -2619,8 +2624,6 @@ def checkpoint(self):
26192624
print("checkpoint finished: " + out)
26202625

26212626
def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0):
2622-
self.cloneExclude = [re.sub(r"\.\.\.$", "", path)
2623-
for path in self.cloneExclude]
26242627
files = []
26252628
fnum = 0
26262629
while "depotFile%s" % fnum in commit:
@@ -3890,7 +3893,6 @@ def run(self, args):
38903893
self.cloneDestination = depotPaths[-1]
38913894
depotPaths = depotPaths[:-1]
38923895

3893-
self.cloneExclude = ["/"+p for p in self.cloneExclude]
38943896
for p in depotPaths:
38953897
if not p.startswith("//"):
38963898
sys.stderr.write('Depot paths must start with "//": %s\n' % p)

0 commit comments

Comments
 (0)