Show More
@@ -7,22 +7,22 b'' | |||||
7 |
|
7 | |||
8 | from common import NoRepo, checktool, commandline, commit, converter_source |
|
8 | from common import NoRepo, checktool, commandline, commit, converter_source | |
9 | from mercurial.i18n import _ |
|
9 | from mercurial.i18n import _ | |
10 | from mercurial import util |
|
10 | from mercurial import encoding, util | |
11 | import os, shutil, tempfile, re |
|
11 | import os, shutil, tempfile, re | |
12 |
|
12 | |||
13 | # The naming drift of ElementTree is fun! |
|
13 | # The naming drift of ElementTree is fun! | |
14 |
|
14 | |||
15 | try: |
|
15 | try: | |
16 | from xml.etree.cElementTree import ElementTree |
|
16 | from xml.etree.cElementTree import ElementTree, XMLParser | |
17 | except ImportError: |
|
17 | except ImportError: | |
18 | try: |
|
18 | try: | |
19 | from xml.etree.ElementTree import ElementTree |
|
19 | from xml.etree.ElementTree import ElementTree, XMLParser | |
20 | except ImportError: |
|
20 | except ImportError: | |
21 | try: |
|
21 | try: | |
22 | from elementtree.cElementTree import ElementTree |
|
22 | from elementtree.cElementTree import ElementTree, XMLParser | |
23 | except ImportError: |
|
23 | except ImportError: | |
24 | try: |
|
24 | try: | |
25 | from elementtree.ElementTree import ElementTree |
|
25 | from elementtree.ElementTree import ElementTree, XMLParser | |
26 | except ImportError: |
|
26 | except ImportError: | |
27 | ElementTree = None |
|
27 | ElementTree = None | |
28 |
|
28 | |||
@@ -88,12 +88,24 b' class darcs_source(converter_source, com' | |||||
88 | self.ui.debug('cleaning up %s\n' % self.tmppath) |
|
88 | self.ui.debug('cleaning up %s\n' % self.tmppath) | |
89 | shutil.rmtree(self.tmppath, ignore_errors=True) |
|
89 | shutil.rmtree(self.tmppath, ignore_errors=True) | |
90 |
|
90 | |||
|
91 | def recode(self, s, encoding=None): | |||
|
92 | if isinstance(s, unicode): | |||
|
93 | # XMLParser returns unicode objects for anything it can't | |||
|
94 | # encode into ASCII. We convert them back to str to get | |||
|
95 | # recode's normal conversion behavior. | |||
|
96 | s = s.encode('latin-1') | |||
|
97 | return super(darcs_source, self).recode(s, encoding) | |||
|
98 | ||||
91 | def xml(self, cmd, **kwargs): |
|
99 | def xml(self, cmd, **kwargs): | |
92 | # NOTE: darcs is currently encoding agnostic and will print |
|
100 | # NOTE: darcs is currently encoding agnostic and will print | |
93 | # patch metadata byte-for-byte, even in the XML changelog. |
|
101 | # patch metadata byte-for-byte, even in the XML changelog. | |
94 | etree = ElementTree() |
|
102 | etree = ElementTree() | |
|
103 | # While we are decoding the XML as latin-1 to be as liberal as | |||
|
104 | # possible, etree will still raise an exception if any | |||
|
105 | # non-printable characters are in the XML changelog. | |||
|
106 | parser = XMLParser(encoding='latin-1') | |||
95 | fp = self._run(cmd, **kwargs) |
|
107 | fp = self._run(cmd, **kwargs) | |
96 | etree.parse(fp) |
|
108 | etree.parse(fp, parser=parser) | |
97 | self.checkexit(fp.close()) |
|
109 | self.checkexit(fp.close()) | |
98 | return etree.getroot() |
|
110 | return etree.getroot() | |
99 |
|
111 |
@@ -65,9 +65,15 b' echo g > g' | |||||
65 | # darcs is encoding agnostic, so it takes whatever bytes it's given |
|
65 | # darcs is encoding agnostic, so it takes whatever bytes it's given | |
66 | darcs record -a -l -m 'p4: desc ñ' -A 'author ñ' |
|
66 | darcs record -a -l -m 'p4: desc ñ' -A 'author ñ' | |
67 |
|
67 | |||
|
68 | echo % test latin-1 commit message | |||
|
69 | echo h > h | |||
|
70 | printf "p5: desc " > ../p5 | |||
|
71 | python -c 'print "".join([chr(i) for i in range(128, 256)])' >> ../p5 | |||
|
72 | darcs record -a -l --logfile ../p5 | |||
|
73 | ||||
68 | glog() |
|
74 | glog() | |
69 | { |
|
75 | { | |
70 |
|
|
76 | hg glog --template '{rev} "{desc|firstline}" ({author}) files: {files}\n' "$@" | |
71 | } |
|
77 | } | |
72 |
|
78 | |||
73 | cd .. |
|
79 | cd .. | |
@@ -78,6 +84,7 b' hg convert darcs-repo darcs-repo-hg' | |||||
78 | # Unfortunately, non-conflicting changes, like the addition of the |
|
84 | # Unfortunately, non-conflicting changes, like the addition of the | |
79 | # "c" file in p1.1 patch are reverted too. |
|
85 | # "c" file in p1.1 patch are reverted too. | |
80 | # Just to say that manifest not listing "c" here is a bug. |
|
86 | # Just to say that manifest not listing "c" here is a bug. | |
81 | glog -R darcs-repo-hg |
|
87 | HGENCODING=latin-1 glog -R darcs-repo-hg -r 6 | "$TESTDIR"/printrepr.py | |
|
88 | HGENCODING=utf-8 glog -R darcs-repo-hg -r 0:5 | "$TESTDIR"/printrepr.py | |||
82 | hg up -q -R darcs-repo-hg |
|
89 | hg up -q -R darcs-repo-hg | |
83 | hg -R darcs-repo-hg manifest --debug |
|
90 | hg -R darcs-repo-hg manifest --debug |
@@ -16,17 +16,22 b" Finished recording patch 'p2'" | |||||
16 | Finished recording patch 'p3' |
|
16 | Finished recording patch 'p3' | |
17 | % test utf-8 commit message and author |
|
17 | % test utf-8 commit message and author | |
18 | Finished recording patch 'p4: desc ñ' |
|
18 | Finished recording patch 'p4: desc ñ' | |
|
19 | % test latin-1 commit message | |||
|
20 | Finished recording patch 'p5: desc ��������������������������������������������������������������������������������������������������������������������������������' | |||
19 | initializing destination darcs-repo-hg repository |
|
21 | initializing destination darcs-repo-hg repository | |
20 | scanning source... |
|
22 | scanning source... | |
21 | sorting... |
|
23 | sorting... | |
22 | converting... |
|
24 | converting... | |
23 |
|
|
25 | 6 p0 | |
24 |
|
|
26 | 5 p1.2 | |
25 |
|
|
27 | 4 p1.1 | |
26 |
|
|
28 | 3 p2 | |
27 |
|
|
29 | 2 p3 | |
28 |
|
|
30 | 1 p4: desc ? | |
29 | o 5 "p4: desc ñ" (author ñ) files: g |
|
31 | 0 p5: desc ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? | |
|
32 | o 6 "p5: desc \x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" (test@example.org) files: h | |||
|
33 | | | |||
|
34 | o 5 "p4: desc \xc3\xb1" (author \xc3\xb1) files: g | |||
30 | | |
|
35 | | | |
31 | o 4 "p3" (test@example.org) files: dir/d dir/d2 dir2/d f ff |
|
36 | o 4 "p3" (test@example.org) files: dir/d dir/d2 dir2/d f ff | |
32 | | |
|
37 | | | |
@@ -43,3 +48,4 b' 1e88685f5ddec574a34c70af492f95b6debc8741' | |||||
43 | 37406831adc447ec2385014019599dfec953c806 644 dir2/d |
|
48 | 37406831adc447ec2385014019599dfec953c806 644 dir2/d | |
44 | b783a337463792a5c7d548ad85a7d3253c16ba8c 644 ff |
|
49 | b783a337463792a5c7d548ad85a7d3253c16ba8c 644 ff | |
45 | 0973eb1b2ecc4de7fafe7447ce1b7462108b4848 644 g |
|
50 | 0973eb1b2ecc4de7fafe7447ce1b7462108b4848 644 g | |
|
51 | fe6f8b4f507fe3eb524c527192a84920a4288dac 644 h |
General Comments 0
You need to be logged in to leave comments.
Login now