Merge lp:~jelmer/brz-git/encodings into lp:brz-git

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 1831
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz-git/encodings
Merge into: lp:brz-git
Diff against target: 112 lines (+21/-13)
1 file modified
tree.py (+21/-13)
To merge this branch: bzr merge lp:~jelmer/brz-git/encodings
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+341076@code.launchpad.net

Commit message

Be a bit stricter about encodings.

Description of the change

Be a bit stricter about encodings.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Rubberstamp! Proposer approves of own proposal.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tree.py'
2--- tree.py 2018-03-06 23:28:35 +0000
3+++ tree.py 2018-03-08 01:53:04 +0000
4@@ -71,8 +71,8 @@
5
6 def get_file_revision(self, path, file_id=None):
7 change_scanner = self._repository._file_change_scanner
8- (path, commit_id) = change_scanner.find_last_change_revision(path,
9- self.commit_id)
10+ (path, commit_id) = change_scanner.find_last_change_revision(
11+ path.encode('utf-8'), self.commit_id)
12 return self._repository.lookup_foreign_revision_id(commit_id, self.mapping)
13
14 def get_file_mtime(self, path, file_id=None):
15@@ -88,6 +88,7 @@
16 path = self._fileid_map.lookup_path(file_id)
17 except ValueError:
18 raise errors.NoSuchId(self, file_id)
19+ path = path.decode('utf-8')
20 if self.has_filename(path):
21 return path
22 raise errors.NoSuchId(self, file_id)
23@@ -175,7 +176,7 @@
24 (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree,
25 from_dir.encode("utf-8"))
26 if mode is None: # Root
27- root_ie = self._get_dir_ie("", None)
28+ root_ie = self._get_dir_ie(b"", None)
29 else:
30 parent_path = posixpath.dirname(from_dir.encode("utf-8"))
31 parent_id = self._fileid_map.lookup_file_id(parent_path)
32@@ -202,14 +203,16 @@
33 todo.add((child_path, hexsha, ie.file_id))
34 else:
35 ie = self._get_file_ie(child_path, name, mode, hexsha, parent_id)
36- yield child_path, "V", ie.kind, ie.file_id, ie
37+ yield child_path.decode('utf-8'), "V", ie.kind, ie.file_id, ie
38
39 def _get_file_ie(self, path, name, mode, hexsha, parent_id):
40+ assert isinstance(path, bytes)
41+ assert isinstance(name, bytes)
42 kind = mode_kind(mode)
43 file_id = self._fileid_map.lookup_file_id(path)
44 ie = inventory.entry_factory[kind](file_id, name.decode("utf-8"), parent_id)
45 if kind == 'symlink':
46- ie.symlink_target = self.store[hexsha].data
47+ ie.symlink_target = self.store[hexsha].data.decode('utf-8')
48 elif kind == 'tree-reference':
49 ie.reference_revision = self.mapping.revision_id_foreign_to_bzr(hexsha)
50 else:
51@@ -217,6 +220,7 @@
52 ie.text_sha1 = osutils.sha_string(data)
53 ie.text_size = len(data)
54 ie.executable = mode_is_executable(mode)
55+ ie.revision = self.get_file_revision(path.decode('utf-8'))
56 return ie
57
58 def _get_dir_ie(self, path, parent_id):
59@@ -236,10 +240,12 @@
60 def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
61 if self.tree is None:
62 return
63- # FIXME: Support yield parents
64+ if yield_parents:
65+ # TODO(jelmer): Support yield parents
66+ raise NotImplementedError
67 if specific_file_ids is not None:
68- specific_paths = [self.id2path(file_id) for file_id in specific_file_ids]
69- if specific_paths in ([u""], []):
70+ specific_paths = [self.id2path(file_id).encode('utf-8') for file_id in specific_file_ids]
71+ if specific_paths in ([""], []):
72 specific_paths = None
73 else:
74 specific_paths = set(specific_paths)
75@@ -276,22 +282,24 @@
76
77 def get_file_verifier(self, path, file_id=None, stat_value=None):
78 (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree,
79- path)
80+ path.encode('utf-8'))
81 return ("GIT", hexsha)
82
83 def get_file_text(self, path, file_id=None):
84 """See RevisionTree.get_file_text."""
85 if self.tree is None:
86 raise errors.NoSuchFile(path)
87- (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree, path)
88+ (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree,
89+ path.encode('utf-8'))
90 if stat.S_ISREG(mode):
91 return self.store[hexsha].data
92 else:
93- return ""
94+ return b""
95
96 def get_symlink_target(self, path, file_id=None):
97 """See RevisionTree.get_symlink_target."""
98- (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree, path.encode('utf-8'))
99+ (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree,
100+ path.encode('utf-8'))
101 if stat.S_ISLNK(mode):
102 return self.store[hexsha].data.decode('utf-8')
103 else:
104@@ -305,7 +313,7 @@
105 def path_content_summary(self, path):
106 """See Tree.path_content_summary."""
107 try:
108- (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree, path)
109+ (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree, path.encode('utf-8'))
110 except KeyError:
111 return ('missing', None, None, None)
112 kind = mode_kind(mode)

Subscribers

People subscribed via source and target branches

to all changes: