git-p4: add config git-p4.pathEncoding
Perforce keeps the encoding of a path as given by the originating OS. Git expects paths encoded as UTF-8. Add a config to tell git-p4 what encoding Perforce had used for the paths. This encoding is used to transcode the paths to UTF-8. As an example, Perforce on Windows often uses “cp1252” to encode path names. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Schneider committed
Sep 3, 2015 at 11:14 UTC
a9e38359e356de7d6397395bdde8af61440262d0
3 files changed
+76
Documentation/git-p4.txt
+7
@@ -510,6 +510,13 @@ git-p4.useClientSpec::
510
option '--use-client-spec'. See the "CLIENT SPEC" section above.
511
This variable is a boolean, not the name of a p4 client.
512
513
+git-p4.pathEncoding::
514
+ Perforce keeps the encoding of a path as given by the originating OS.
515
+ Git expects paths encoded as UTF-8. Use this config to tell git-p4
516
+ what encoding Perforce had used for the paths. This encoding is used
517
+ to transcode the paths to UTF-8. As an example, Perforce on Windows
518
+ often uses “cp1252” to encode path names.
519
+
520
Submit variables
521
~~~~~~~~~~~~~~~~
522
git-p4.detectRenames::
git-p4.py
+11
@@ -2213,6 +2213,17 @@ class P4Sync(Command, P4UserMap):
2213
text = regexp.sub(r'$\1$', text)
2214
contents = [ text ]
2215
2216
+ if gitConfig("git-p4.pathEncoding"):
2217
+ relPath = relPath.decode(gitConfig("git-p4.pathEncoding")).encode('utf8', 'replace')
2218
+ elif self.verbose:
2219
+ try:
2220
+ relPath.decode('ascii')
2221
+ except:
2222
+ print (
2223
+ "Path with Non-ASCII characters detected and no path encoding defined. "
2224
+ "Please check the encoding: %s" % relPath
2225
+ )
2226
+
2227
self.gitStream.write("M %s inline %s\n" % (git_mode, relPath))
2228
2229
# total length...
t/t9822-git-p4-path-encoding.sh
new
+58
@@ -0,0 +1,58 @@
1
+#!/bin/sh
2
+
3
+test_description='Clone repositories with non ASCII paths'
4
+
5
+. ./lib-git-p4.sh
6
+
7
+UTF8_ESCAPED="a-\303\244_o-\303\266_u-\303\274.txt"
8
+ISO8859_ESCAPED="a-\344_o-\366_u-\374.txt"
9
+
10
+test_expect_success 'start p4d' '
11
+ start_p4d
12
+'
13
+
14
+test_expect_success 'Create a repo containing iso8859-1 encoded paths' '
15
+ (
16
+ cd "$cli" &&
17
+ ISO8859="$(printf "$ISO8859_ESCAPED")" &&
18
+ echo content123 >"$ISO8859" &&
19
+ p4 add "$ISO8859" &&
20
+ p4 submit -d "test commit"
21
+ )
22
+'
23
+
24
+test_expect_failure 'Clone auto-detects depot with iso8859-1 paths' '
25
+ git p4 clone --destination="$git" //depot &&
26
+ test_when_finished cleanup_git &&
27
+ (
28
+ cd "$git" &&
29
+ UTF8="$(printf "$UTF8_ESCAPED")" &&
30
+ echo "$UTF8" >expect &&
31
+ git -c core.quotepath=false ls-files >actual &&
32
+ test_cmp expect actual
33
+ )
34
+'
35
+
36
+test_expect_success 'Clone repo containing iso8859-1 encoded paths with git-p4.pathEncoding' '
37
+ test_when_finished cleanup_git &&
38
+ (
39
+ cd "$git" &&
40
+ git init . &&
41
+ git config git-p4.pathEncoding iso8859-1 &&
42
+ git p4 clone --use-client-spec --destination="$git" //depot &&
43
+ UTF8="$(printf "$UTF8_ESCAPED")" &&
44
+ echo "$UTF8" >expect &&
45
+ git -c core.quotepath=false ls-files >actual &&
46
+ test_cmp expect actual &&
47
+
48
+ echo content123 >expect &&
49
+ cat "$UTF8" >actual &&
50
+ test_cmp expect actual
51
+ )
52
+'
53
+
54
+test_expect_success 'kill p4d' '
55
+ kill_p4d
56
+'
57
+
58
+test_done