133
subprocess.check_call(real_cmd, shell=expand)
134
135
def p4_integrate(src, dest):
136
- p4_system(["integrate", "-Dt", src, dest])
136
+ p4_system(["integrate", "-Dt", wildcard_encode(src), wildcard_encode(dest)])
137
138
def p4_sync(f, *options):
139
- p4_system(["sync"] + list(options) + [f])
139
+ p4_system(["sync"] + list(options) + [wildcard_encode(f)])
140
141
def p4_add(f):
142
- p4_system(["add", f])
142
+ # forcibly add file names with wildcards
143
+ if wildcard_present(f):
144
+ p4_system(["add", "-f", f])
145
+ else:
146
+ p4_system(["add", f])
147
148
def p4_delete(f):
145
- p4_system(["delete", f])
149
+ p4_system(["delete", wildcard_encode(f)])
150
151
def p4_edit(f):
148
- p4_system(["edit", f])
152
+ p4_system(["edit", wildcard_encode(f)])
153
154
def p4_revert(f):
151
- p4_system(["revert", f])
155
+ p4_system(["revert", wildcard_encode(f)])
156
153
-def p4_reopen(type, file):
154
- p4_system(["reopen", "-t", type, file])
157
+def p4_reopen(type, f):
158
+ p4_system(["reopen", "-t", type, wildcard_encode(f)])
159
160
#
161
# Canonicalize the p4 type and return a tuple of the
252
def getP4OpenedType(file):
253
# Returns the perforce file type for the given file.
254
251
- result = p4_read_pipe(["opened", file])
255
+ result = p4_read_pipe(["opened", wildcard_encode(file)])
256
match = re.match(".*\((.+)\)\r?$", result)
257
if match:
258
return match.group(1)
662
663
return entry["Root"]
664
665
+#
666
+# P4 wildcards are not allowed in filenames. P4 complains
667
+# if you simply add them, but you can force it with "-f", in
668
+# which case it translates them into %xx encoding internally.
669
+#
670
+def wildcard_decode(path):
671
+ # Search for and fix just these four characters. Do % last so
672
+ # that fixing it does not inadvertently create new %-escapes.
673
+ # Cannot have * in a filename in windows; untested as to
674
+ # what p4 would do in such a case.
675
+ if not platform.system() == "Windows":
676
+ path = path.replace("%2A", "*")
677
+ path = path.replace("%23", "#") \
678
+ .replace("%40", "@") \
679
+ .replace("%25", "%")
680
+ return path
681
+
682
+def wildcard_encode(path):
683
+ # do % first to avoid double-encoding the %s introduced here
684
+ path = path.replace("%", "%25") \
685
+ .replace("*", "%2A") \
686
+ .replace("#", "%23") \
687
+ .replace("@", "%40")
688
+ return path
689
+
690
+def wildcard_present(path):
691
+ return path.translate(None, "*#@%") != path
692
+
693
class Command:
694
def __init__(self):
695
self.usage = "usage: %prog [options]"
1219
del(os.environ["P4DIFF"])
1220
diff = ""
1221
for editedFile in editedFiles:
1190
- diff += p4_read_pipe(['diff', '-du', editedFile])
1222
+ diff += p4_read_pipe(['diff', '-du',
1223
+ wildcard_encode(editedFile)])
1224
1225
newdiff = ""
1226
for newFile in filesToAdd:
1730
if gitConfig("git-p4.syncFromOrigin") == "false":
1731
self.syncWithOrigin = False
1732
1700
- #
1701
- # P4 wildcards are not allowed in filenames. P4 complains
1702
- # if you simply add them, but you can force it with "-f", in
1703
- # which case it translates them into %xx encoding internally.
1704
- # Search for and fix just these four characters. Do % last so
1705
- # that fixing it does not inadvertently create new %-escapes.
1706
- #
1707
- def wildcard_decode(self, path):
1708
- # Cannot have * in a filename in windows; untested as to
1709
- # what p4 would do in such a case.
1710
- if not self.isWindows:
1711
- path = path.replace("%2A", "*")
1712
- path = path.replace("%23", "#") \
1713
- .replace("%40", "@") \
1714
- .replace("%25", "%")
1715
- return path
1716
-
1733
# Force a checkpoint in fast-import and wait for it to finish
1734
def checkpoint(self):
1735
self.gitStream.write("checkpoint\n\n")
1797
fnum = fnum + 1
1798
1799
relPath = self.stripRepoPath(path, self.depotPaths)
1800
+ relPath = wildcard_decode(relPath)
1801
1802
for branch in self.knownBranches.keys():
1803
1815
1816
def streamOneP4File(self, file, contents):
1817
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
1801
- relPath = self.wildcard_decode(relPath)
1818
+ relPath = wildcard_decode(relPath)
1819
if verbose:
1820
sys.stderr.write("%s\n" % relPath)
1821
1884
1885
def streamOneP4Deletion(self, file):
1886
relPath = self.stripRepoPath(file['path'], self.branchPrefixes)
1887
+ relPath = wildcard_decode(relPath)
1888
if verbose:
1889
sys.stderr.write("delete %s\n" % relPath)
1890
self.gitStream.write("D %s\n" % relPath)