Skip to content

Commit 084f630

Browse files
Pete Wyckoffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e32e00d commit 084f630

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

contrib/fast-import/git-p4

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,23 @@ class P4Sync(Command):
884884
if gitConfig("git-p4.syncFromOrigin") == "false":
885885
self.syncWithOrigin = False
886886

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+
887904
def extractFilesFromCommit(self, commit):
888905
self.cloneExclude = [re.sub(r"\.\.\.$", "", path)
889906
for path in self.cloneExclude]
@@ -962,6 +979,7 @@ class P4Sync(Command):
962979
return
963980

964981
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
982+
relPath = self.wildcard_decode(relPath)
965983
if verbose:
966984
sys.stderr.write("%s\n" % relPath)
967985

t/t9800-git-p4.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ test_expect_success 'exit when p4 fails to produce marshaled output' '
5858
test_must_fail grep -q Traceback errs
5959
'
6060

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+
6183
test_expect_success 'shutdown' '
6284
pid=`pgrep -f p4d` &&
6385
test -n "$pid" &&

0 commit comments

Comments
 (0)