Skip to content

Commit e3e6864

Browse files
ggibbonsgitster
authored andcommitted
git-p4: support single file p4 client view maps
Perforce client views can map individual files, mapping one //depot file path to one //client file path. These mappings contain no meta/masking characters. This patch add support for these file maps to the currently supported '...' view mappings. [pw: one test now suceeds] Signed-off-by: Gary Gibbons <[email protected]> Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent df5ed90 commit e3e6864

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

contrib/fast-import/git-p4

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ class P4Sync(Command, P4UserMap):
12171217
self.cloneExclude = []
12181218
self.useClientSpec = False
12191219
self.clientSpecDirs = []
1220+
self.haveSingleFileClientViews = False
12201221

12211222
if gitConfig("git-p4.syncFromOrigin") == "false":
12221223
self.syncWithOrigin = False
@@ -1274,6 +1275,16 @@ class P4Sync(Command, P4UserMap):
12741275
# will end up putting all foo/branch files into
12751276
# branch/foo/
12761277
for val in self.clientSpecDirs:
1278+
if self.haveSingleFileClientViews and len(path) == abs(val[1][0]) and path == val[0]:
1279+
# since 'path' is a depot file path, if it matches the LeftMap,
1280+
# then the View is a single file mapping, so use the entire rightMap
1281+
# first two tests above avoid the last == test for common cases
1282+
path = val[1][1]
1283+
# now strip out the client (//client/...)
1284+
path = re.sub("^(//[^/]+/)", '', path)
1285+
# the rest is local client path
1286+
return path
1287+
12771288
if path.startswith(val[0]):
12781289
# replace the depot path with the client path
12791290
path = path.replace(val[0], val[1][1])
@@ -1905,19 +1916,19 @@ class P4Sync(Command, P4UserMap):
19051916
# save the "client view"; i.e the RHS of the view
19061917
# line that tells the client where to put the
19071918
# files for this view.
1908-
cv = v[index+3:].strip() # +3 to remove previous '...'
19091919

1910-
# if the client view doesn't end with a
1911-
# ... wildcard, then we're going to mess up the
1912-
# output directory, so fail gracefully.
1913-
if not cv.endswith('...'):
1914-
print 'Sorry, client view in "%s" needs to end with wildcard' % (k)
1915-
sys.exit(1)
1916-
cv=cv[:-3]
1920+
# check for individual file mappings - those which have no '...'
1921+
if index < 0 :
1922+
v,cv = v.strip().split()
1923+
v = v[start:]
1924+
self.haveSingleFileClientViews = True
1925+
else:
1926+
cv = v[index+3:].strip() # +3 to remove previous '...'
1927+
cv=cv[:-3]
1928+
v = v[start:index]
19171929

19181930
# now save the view; +index means included, -index
19191931
# means it should be filtered out.
1920-
v = v[start:index]
19211932
if v.startswith("-"):
19221933
v = v[1:]
19231934
include = -len(v)

t/t9809-git-p4-client-view.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ test_expect_success 'exclusion wildcard, client rhs different (normal)' '
191191
git_verify $files
192192
'
193193

194-
test_expect_failure 'exclusion single file' '
194+
test_expect_success 'exclusion single file' '
195195
client_view "//depot/... //client/..." \
196196
"-//depot/dir2/file22 //client/file22" &&
197197
files="dir1/file11 dir1/file12 dir2/file21" &&

0 commit comments

Comments
 (0)