Skip to content

Commit

Permalink
Fix for problem comparing on Linux with case sensitivity mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
rcowham committed Oct 17, 2024
1 parent e2c2992 commit 7c7f7b2
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions CompareRepos.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
python3 CompareRepos.py -h
The script requires a config file as for P4Transfer.py
The config file provides the Perforce connection information for both servers,
The config file provides the Perforce connection information for both servers,
and source/target client workspace names.
For full documentation/usage, see project doc:
Expand All @@ -56,14 +56,16 @@
import re
import argparse
import textwrap
from pathlib import Path
import shutil
from ruamel.yaml import YAML
yaml = YAML()


# This is updated based on the value in the config file - used in comparisons below
caseSensitiveOS = (platform.system() == "Linux")
caseSensitiveServer = True # default - adjusted below in config file
inconsistentCase = False # Combo of the above, eg. true => case insensitive servers, but case sensitive OS!
caseSensitiveServer = True # default - adjusted below in config file
inconsistentCase = False # Combo of the above, eg. true => case insensitive servers, but case sensitive OS!
alreadyEscaped = re.compile(r"%25|%23|%40|%2A")


Expand Down Expand Up @@ -167,6 +169,16 @@ def getFiles(self, fstat):
localFiles[fname] = f['clientFile']
return depotFiles, localFiles

def copyLocalFile(self, src, targ):
# Copy a file if there is a case path issue - where it might fail an add or edit
source_path = Path(src)
target_path = Path(targ)
target_path.parent.mkdir(parents=True, exist_ok=True)
if target_path.exists():
target_path.chmod(0o644)
shutil.copy(source_path, target_path)
print(f"Fixed case issue: copied {src} to {targ}")

def run(self):
srcDepotFiles = {}
targDepotFiles = {}
Expand All @@ -187,7 +199,7 @@ def run(self):
with self.srcp4.at_exception_level(P4.P4.RAISE_NONE):
haveList = self.srcp4.run('have', srcPath)
for f in haveList:
if inconsistentCase: # Use the case from source server and don't care about target which is also caseinsensitiveß
if inconsistentCase: # Use the case from source server and don't care about target which is also caseinsensitive
k = f['depotFile']
else:
k = f['depotFile'].lower()
Expand Down Expand Up @@ -218,6 +230,8 @@ def run(self):
if self.options.fix:
print("deleted: %s; %s" % (k, v.depotFile))
print(self.srcp4.run_sync('-f', "%s#%s" % (escapeWildcards(srcLocalFiles[k]), v.rev)))
if inconsistentCase and srcLocalFiles[k] != targLocalFiles[k]:
self.copyLocalFile(srcLocalFiles[k], targLocalFiles[k])
print(self.targp4.run_add('-ft', v.type, srcLocalFiles[k]))
if 'delete' not in v.action and v.action != 'purge':
if k in targDepotFiles and 'delete' not in targDepotFiles[k].action and v.digest != targDepotFiles[k].digest:
Expand All @@ -227,6 +241,8 @@ def run(self):
with self.targp4.at_exception_level(P4.P4.RAISE_NONE):
print(self.targp4.run_sync("-k", targLocalFiles[k]))
print(self.srcp4.run_sync('-f', "%s#%s" % (escapeWildcards(srcLocalFiles[k]), v.rev)))
if inconsistentCase and srcLocalFiles[k] != targLocalFiles[k]:
self.copyLocalFile(srcLocalFiles[k], targLocalFiles[k])
print(self.targp4.run_edit('-t', v.type, escapeWildcards(srcLocalFiles[k])))
for k, v in targDepotFiles.items():
if 'delete' not in v.action:
Expand Down Expand Up @@ -266,6 +282,7 @@ def run(self):
Sum Total: %d
""" % (missingCount, deletedCount, extrasCount, differentCount, missingCount + deletedCount + extrasCount + differentCount))


if __name__ == '__main__':
obj = CompareRepos()
obj.run()

0 comments on commit 7c7f7b2

Please sign in to comment.