git-p4: decode p4 wildcard characters
There are four wildcard characters in p4. Files with these characters can be added to p4 repos using the "-f" option. They are stored in %xx notation, and when checked out, p4 converts them back to normal. This patch does the same thing when importing into git, converting the four special characters. Without this change, the files appear with literal %xx in their names. Be careful not to produce "*" in filenames on windows. That will fail. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Feb 19, 2011 at 08:18 UTC
084f6306d4b7b27a5d12236e808604220b8b3e3f
2 files changed
+40
contrib/fast-import/git-p4
+18
@@ -884,6 +884,23 @@ class P4Sync(Command):
884
if gitConfig("git-p4.syncFromOrigin") == "false":
885
self.syncWithOrigin = False
886
887
+ #
888
+ # P4 wildcards are not allowed in filenames. P4 complains
889
+ # if you simply add them, but you can force it with "-f", in
890
+ # which case it translates them into %xx encoding internally.
891
+ # Search for and fix just these four characters. Do % last so
892
+ # that fixing it does not inadvertently create new %-escapes.
893
+ #
894
+ def wildcard_decode(self, path):
895
+ # Cannot have * in a filename in windows; untested as to
896
+ # what p4 would do in such a case.
897
+ if not self.isWindows:
898
+ path = path.replace("%2A", "*")
899
+ path = path.replace("%23", "#") \
900
+ .replace("%40", "@") \
901
+ .replace("%25", "%")
902
+ return path
903
+
904
def extractFilesFromCommit(self, commit):
905
self.cloneExclude = [re.sub(r"\.\.\.$", "", path)
906
for path in self.cloneExclude]
@@ -962,6 +979,7 @@ class P4Sync(Command):
979
return
980
981
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
982
+ relPath = self.wildcard_decode(relPath)
983
if verbose:
984
sys.stderr.write("%s\n" % relPath)
985
t/t9800-git-p4.sh
+22
@@ -58,6 +58,28 @@ test_expect_success 'exit when p4 fails to produce marshaled output' '
58
test_must_fail grep -q Traceback errs
59
'
60
61
+test_expect_success 'add p4 files with wildcards in the names' '
62
+ cd "$cli" &&
63
+ echo file-wild-hash >file-wild#hash &&
64
+ echo file-wild-star >file-wild\*star &&
65
+ echo file-wild-at >file-wild@at &&
66
+ echo file-wild-percent >file-wild%percent &&
67
+ p4 add -f file-wild* &&
68
+ p4 submit -d "file wildcards" &&
69
+ cd "$TRASH_DIRECTORY"
70
+'
71
+
72
+test_expect_success 'wildcard files git-p4 clone' '
73
+ "$GITP4" clone --dest="$git" //depot &&
74
+ cd "$git" &&
75
+ test -f file-wild#hash &&
76
+ test -f file-wild\*star &&
77
+ test -f file-wild@at &&
78
+ test -f file-wild%percent &&
79
+ cd "$TRASH_DIRECTORY" &&
80
+ rm -rf "$git" && mkdir "$git"
81
+'
82
+
83
test_expect_success 'shutdown' '
84
pid=`pgrep -f p4d` &&
85
test -n "$pid" &&