Mercurial > hg
comparison mercurial/subrepo.py @ 41494:fa7d4e6a0c98
subrepo: clean up lingering bytes/str issues in svn support
Path encoding is a little suspect in here, but it's not worse than it
was when we were on Python 2 only.
Subversion subrepo tests now pass in Python 3.
Differential Revision: https://phab.mercurial-scm.org/D5774
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 30 Jan 2019 19:18:20 -0500 |
parents | 46ab0c6b28dc |
children | d65519e5dd04 |
comparison
equal
deleted
inserted
replaced
41493:97ab4cbb342e | 41494:fa7d4e6a0c98 |
---|---|
959 bufsize=-1, close_fds=procutil.closefds, | 959 bufsize=-1, close_fds=procutil.closefds, |
960 stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 960 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
961 universal_newlines=True, | 961 universal_newlines=True, |
962 env=procutil.tonativeenv(env), **extrakw) | 962 env=procutil.tonativeenv(env), **extrakw) |
963 stdout, stderr = p.communicate() | 963 stdout, stderr = p.communicate() |
964 stdout, stderr = pycompat.fsencode(stdout), pycompat.fsencode(stderr) | |
964 stderr = stderr.strip() | 965 stderr = stderr.strip() |
965 if not failok: | 966 if not failok: |
966 if p.returncode: | 967 if p.returncode: |
967 raise error.Abort(stderr or 'exited with code %d' | 968 raise error.Abort(stderr or 'exited with code %d' |
968 % p.returncode) | 969 % p.returncode) |
985 # Get the working directory revision as well as the last | 986 # Get the working directory revision as well as the last |
986 # commit revision so we can compare the subrepo state with | 987 # commit revision so we can compare the subrepo state with |
987 # both. We used to store the working directory one. | 988 # both. We used to store the working directory one. |
988 output, err = self._svncommand(['info', '--xml']) | 989 output, err = self._svncommand(['info', '--xml']) |
989 doc = xml.dom.minidom.parseString(output) | 990 doc = xml.dom.minidom.parseString(output) |
990 entries = doc.getElementsByTagName('entry') | 991 entries = doc.getElementsByTagName(r'entry') |
991 lastrev, rev = '0', '0' | 992 lastrev, rev = '0', '0' |
992 if entries: | 993 if entries: |
993 rev = str(entries[0].getAttribute('revision')) or '0' | 994 rev = pycompat.bytestr(entries[0].getAttribute(r'revision')) or '0' |
994 commits = entries[0].getElementsByTagName('commit') | 995 commits = entries[0].getElementsByTagName(r'commit') |
995 if commits: | 996 if commits: |
996 lastrev = str(commits[0].getAttribute('revision')) or '0' | 997 lastrev = pycompat.bytestr( |
998 commits[0].getAttribute(r'revision')) or '0' | |
997 return (lastrev, rev) | 999 return (lastrev, rev) |
998 | 1000 |
999 def _wcrev(self): | 1001 def _wcrev(self): |
1000 return self._wcrevs()[0] | 1002 return self._wcrevs()[0] |
1001 | 1003 |
1006 is True if any change is a missing entry. | 1008 is True if any change is a missing entry. |
1007 """ | 1009 """ |
1008 output, err = self._svncommand(['status', '--xml']) | 1010 output, err = self._svncommand(['status', '--xml']) |
1009 externals, changes, missing = [], [], [] | 1011 externals, changes, missing = [], [], [] |
1010 doc = xml.dom.minidom.parseString(output) | 1012 doc = xml.dom.minidom.parseString(output) |
1011 for e in doc.getElementsByTagName('entry'): | 1013 for e in doc.getElementsByTagName(r'entry'): |
1012 s = e.getElementsByTagName('wc-status') | 1014 s = e.getElementsByTagName(r'wc-status') |
1013 if not s: | 1015 if not s: |
1014 continue | 1016 continue |
1015 item = s[0].getAttribute('item') | 1017 item = s[0].getAttribute(r'item') |
1016 props = s[0].getAttribute('props') | 1018 props = s[0].getAttribute(r'props') |
1017 path = e.getAttribute('path') | 1019 path = e.getAttribute(r'path').encode('utf8') |
1018 if item == 'external': | 1020 if item == r'external': |
1019 externals.append(path) | 1021 externals.append(path) |
1020 elif item == 'missing': | 1022 elif item == r'missing': |
1021 missing.append(path) | 1023 missing.append(path) |
1022 if (item not in ('', 'normal', 'unversioned', 'external') | 1024 if (item not in (r'', r'normal', r'unversioned', r'external') |
1023 or props not in ('', 'none', 'normal')): | 1025 or props not in (r'', r'none', r'normal')): |
1024 changes.append(path) | 1026 changes.append(path) |
1025 for path in changes: | 1027 for path in changes: |
1026 for ext in externals: | 1028 for ext in externals: |
1027 if path == ext or path.startswith(ext + pycompat.ossep): | 1029 if path == ext or path.startswith(ext + pycompat.ossep): |
1028 return True, True, bool(missing) | 1030 return True, True, bool(missing) |
1139 @annotatesubrepoerror | 1141 @annotatesubrepoerror |
1140 def files(self): | 1142 def files(self): |
1141 output = self._svncommand(['list', '--recursive', '--xml'])[0] | 1143 output = self._svncommand(['list', '--recursive', '--xml'])[0] |
1142 doc = xml.dom.minidom.parseString(output) | 1144 doc = xml.dom.minidom.parseString(output) |
1143 paths = [] | 1145 paths = [] |
1144 for e in doc.getElementsByTagName('entry'): | 1146 for e in doc.getElementsByTagName(r'entry'): |
1145 kind = pycompat.bytestr(e.getAttribute('kind')) | 1147 kind = pycompat.bytestr(e.getAttribute(r'kind')) |
1146 if kind != 'file': | 1148 if kind != 'file': |
1147 continue | 1149 continue |
1148 name = ''.join(c.data for c | 1150 name = r''.join(c.data for c |
1149 in e.getElementsByTagName('name')[0].childNodes | 1151 in e.getElementsByTagName(r'name')[0].childNodes |
1150 if c.nodeType == c.TEXT_NODE) | 1152 if c.nodeType == c.TEXT_NODE) |
1151 paths.append(name.encode('utf-8')) | 1153 paths.append(name.encode('utf8')) |
1152 return paths | 1154 return paths |
1153 | 1155 |
1154 def filedata(self, name, decode): | 1156 def filedata(self, name, decode): |
1155 return self._svncommand(['cat'], name)[0] | 1157 return self._svncommand(['cat'], name)[0] |
1156 | 1158 |