Skip to content

Commit 3952710

Browse files
Ian Wienandgitster
authored andcommitted
Obey p4 views when using client spec
When using the p4 client spec, this attempts to obey the client's output preferences. For example, a view like //depot/foo/branch/... //client/branch/foo/... //depot/bar/branch/... //client/branch/bar/... will result in a directory layout in the git tree of branch/ branch/foo branch/bar p4 can do various other reordering that this change doesn't support, but we should detect it and at least fail nicely. Signed-off-by: Ian Wienand <[email protected]> Acked-by: Pete Wyckoff <[email protected]> Acked-by: Tor Arvid Lund <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbef0db commit 3952710

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

contrib/fast-import/git-p4

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,22 @@ class P4Sync(Command):
910910
return files
911911

912912
def stripRepoPath(self, path, prefixes):
913+
if self.useClientSpec:
914+
915+
# if using the client spec, we use the output directory
916+
# specified in the client. For example, a view
917+
# //depot/foo/branch/... //client/branch/foo/...
918+
# will end up putting all foo/branch files into
919+
# branch/foo/
920+
for val in self.clientSpecDirs:
921+
if path.startswith(val[0]):
922+
# replace the depot path with the client path
923+
path = path.replace(val[0], val[1][1])
924+
# now strip out the client (//client/...)
925+
path = re.sub("^(//[^/]+/)", '', path)
926+
# the rest is all path
927+
return path
928+
913929
if self.keepRepoPath:
914930
prefixes = [re.sub("^(//[^/]+/).*", r'\1', prefixes[0])]
915931

@@ -1032,7 +1048,7 @@ class P4Sync(Command):
10321048
includeFile = True
10331049
for val in self.clientSpecDirs:
10341050
if f['path'].startswith(val[0]):
1035-
if val[1] <= 0:
1051+
if val[1][0] <= 0:
10361052
includeFile = False
10371053
break
10381054

@@ -1475,19 +1491,45 @@ class P4Sync(Command):
14751491
for entry in specList:
14761492
for k,v in entry.iteritems():
14771493
if k.startswith("View"):
1494+
1495+
# p4 has these %%1 to %%9 arguments in specs to
1496+
# reorder paths; which we can't handle (yet :)
1497+
if re.match('%%\d', v) != None:
1498+
print "Sorry, can't handle %%n arguments in client specs"
1499+
sys.exit(1)
1500+
14781501
if v.startswith('"'):
14791502
start = 1
14801503
else:
14811504
start = 0
14821505
index = v.find("...")
1506+
1507+
# save the "client view"; i.e the RHS of the view
1508+
# line that tells the client where to put the
1509+
# files for this view.
1510+
cv = v[index+3:].strip() # +3 to remove previous '...'
1511+
1512+
# if the client view doesn't end with a
1513+
# ... wildcard, then we're going to mess up the
1514+
# output directory, so fail gracefully.
1515+
if not cv.endswith('...'):
1516+
print 'Sorry, client view in "%s" needs to end with wildcard' % (k)
1517+
sys.exit(1)
1518+
cv=cv[:-3]
1519+
1520+
# now save the view; +index means included, -index
1521+
# means it should be filtered out.
14831522
v = v[start:index]
14841523
if v.startswith("-"):
14851524
v = v[1:]
1486-
temp[v] = -len(v)
1525+
include = -len(v)
14871526
else:
1488-
temp[v] = len(v)
1527+
include = len(v)
1528+
1529+
temp[v] = (include, cv)
1530+
14891531
self.clientSpecDirs = temp.items()
1490-
self.clientSpecDirs.sort( lambda x, y: abs( y[1] ) - abs( x[1] ) )
1532+
self.clientSpecDirs.sort( lambda x, y: abs( y[1][0] ) - abs( x[1][0] ) )
14911533

14921534
def run(self, args):
14931535
self.depotPaths = []

contrib/fast-import/git-p4.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ git-p4.useclientspec
191191

192192
git config [--global] git-p4.useclientspec false
193193

194+
The P4CLIENT environment variable should be correctly set for p4 to be
195+
able to find the relevant client. This client spec will be used to
196+
both filter the files cloned by git and set the directory layout as
197+
specified in the client (this implies --keep-path style semantics).
198+
194199
Implementation Details...
195200
=========================
196201

0 commit comments

Comments
 (0)