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 <ggibbons@perforce.com> Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gary Gibbons committed Jan 2, 2012 at 18:05 UTC e3e68643b5c2adec097ba26230e0fcb641febacb
2 files changed +21 -10
contrib/fast-import/git-p4
+20 -9
@@ -1217,6 +1217,7 @@ class P4Sync(Command, P4UserMap):
1217 self.cloneExclude = []
1218 self.useClientSpec = False
1219 self.clientSpecDirs = []
1220 + self.haveSingleFileClientViews = False
1221
1222 if gitConfig("git-p4.syncFromOrigin") == "false":
1223 self.syncWithOrigin = False
@@ -1274,6 +1275,16 @@ class P4Sync(Command, P4UserMap):
1275 # will end up putting all foo/branch files into
1276 # branch/foo/
1277 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 +
1288 if path.startswith(val[0]):
1289 # replace the depot path with the client path
1290 path = path.replace(val[0], val[1][1])
@@ -1905,19 +1916,19 @@ class P4Sync(Command, P4UserMap):
1916 # save the "client view"; i.e the RHS of the view
1917 # line that tells the client where to put the
1918 # files for this view.
1908 - cv = v[index+3:].strip() # +3 to remove previous '...'
1919
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]
1929
1930 # now save the view; +index means included, -index
1931 # means it should be filtered out.
1920 - v = v[start:index]
1932 if v.startswith("-"):
1933 v = v[1:]
1934 include = -len(v)
t/t9809-git-p4-client-view.sh
+1 -1
@@ -191,7 +191,7 @@ test_expect_success 'exclusion wildcard, client rhs different (normal)' '
191 git_verify $files
192 '
193
194 -test_expect_failure 'exclusion single file' '
194 +test_expect_success 'exclusion single file' '
195 client_view "//depot/... //client/..." \
196 "-//depot/dir2/file22 //client/file22" &&
197 files="dir1/file11 dir1/file12 dir2/file21" &&