@matheusbsbs / matheus-bagliano / commits / d53de8b97d
Fork 0

Teach git-p4 to ignore case in perforce filenames if configured.

When files are added to perforce, the path to that file has whichever case configuration that exists on the machine of the user who added the file. What does that mean? It means that when Alice adds a file //depot/DirA/FileA.txt ... and Bob adds: //depot/dirA/FileB.txt ... we may or may not get a problem. If a user sets the config variable git-p4.ignorecase to "true", we will consider //depot/DirA and //depot/dirA to be the same directory. Signed-off-by: Tor Arvid Lund <torarvid@gmail.com> Acked-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tor Arvid Lund committed Mar 15, 2011 at 13:08 UTC d53de8b97de9d3c037c873cd8e01041cf9d51a39
1 file changed +20 -7
contrib/fast-import/git-p4
+20 -7
@@ -456,6 +456,19 @@ def p4ChangesForPaths(depotPaths, changeRange):
456 changelist.sort()
457 return changelist
458
459 +def p4PathStartsWith(path, prefix):
460 + # This method tries to remedy a potential mixed-case issue:
461 + #
462 + # If UserA adds //depot/DirA/file1
463 + # and UserB adds //depot/dira/file2
464 + #
465 + # we may or may not have a problem. If you have core.ignorecase=true,
466 + # we treat DirA and dira as the same directory
467 + ignorecase = gitConfig("core.ignorecase", "--bool") == "true"
468 + if ignorecase:
469 + return path.lower().startswith(prefix.lower())
470 + return path.startswith(prefix)
471 +
472 class Command:
473 def __init__(self):
474 self.usage = "usage: %prog [options]"
@@ -603,7 +616,7 @@ class P4Submit(Command):
616 lastTab = path.rfind("\t")
617 if lastTab != -1:
618 path = path[:lastTab]
606 - if not path.startswith(self.depotPath):
619 + if not p4PathStartsWith(path, self.depotPath):
620 continue
621 else:
622 inFilesSection = False
@@ -941,11 +954,11 @@ class P4Sync(Command):
954 path = commit["depotFile%s" % fnum]
955
956 if [p for p in self.cloneExclude
944 - if path.startswith (p)]:
957 + if p4PathStartsWith(path, p)]:
958 found = False
959 else:
960 found = [p for p in self.depotPaths
948 - if path.startswith (p)]
961 + if p4PathStartsWith(path, p)]
962 if not found:
963 fnum = fnum + 1
964 continue
@@ -980,7 +993,7 @@ class P4Sync(Command):
993 prefixes = [re.sub("^(//[^/]+/).*", r'\1', prefixes[0])]
994
995 for p in prefixes:
983 - if path.startswith(p):
996 + if p4PathStartsWith(path, p):
997 path = path[len(p):]
998
999 return path
@@ -991,7 +1004,7 @@ class P4Sync(Command):
1004 while commit.has_key("depotFile%s" % fnum):
1005 path = commit["depotFile%s" % fnum]
1006 found = [p for p in self.depotPaths
994 - if path.startswith (p)]
1007 + if p4PathStartsWith(path, p)]
1008 if not found:
1009 fnum = fnum + 1
1010 continue
@@ -1144,7 +1157,7 @@ class P4Sync(Command):
1157 # create a commit.
1158 new_files = []
1159 for f in files:
1147 - if [p for p in branchPrefixes if f['path'].startswith(p)]:
1160 + if [p for p in branchPrefixes if p4PathStartsWith(f['path'], p)]:
1161 new_files.append (f)
1162 else:
1163 sys.stderr.write("Ignoring file outside of prefix: %s\n" % path)
@@ -1308,7 +1321,7 @@ class P4Sync(Command):
1321 source = paths[0]
1322 destination = paths[1]
1323 ## HACK
1311 - if source.startswith(self.depotPaths[0]) and destination.startswith(self.depotPaths[0]):
1324 + if p4PathStartsWith(source, self.depotPaths[0]) and p4PathStartsWith(destination, self.depotPaths[0]):
1325 source = source[len(self.depotPaths[0]):-4]
1326 destination = destination[len(self.depotPaths[0]):-4]
1327