/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/__init__.py

GitBranchBuilder now handles file names with newlines correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
        else:
128
128
            mode = '100644'
129
129
        self.commit_info.append('M %s :%d %s\n'
130
 
                                % (mode, mark, path.encode('utf-8')))
 
130
                                % (mode, mark, self._encode_path(path)))
131
131
 
132
132
    def set_link(self, path, link_target):
133
133
        """Create or update a link at a given path."""
134
134
        mark = self._create_blob(link_target)
135
135
        self.commit_info.append('M 120000 :%d %s\n'
136
 
                                % (mark, path.encode('utf-8')))
 
136
                                % (mark, self._encode_path(path)))
137
137
 
138
138
    def delete_entry(self, path):
139
139
        """This will delete files or symlinks at the given location."""
140
 
        self.commit_info.append('D %s\n' % (path.encode('utf-8'),))
 
140
        self.commit_info.append('D %s\n' % (self._encode_path(path),))
 
141
 
 
142
    @staticmethod
 
143
    def _encode_path(path):
 
144
        if '\n' in path or path[0] == '"':
 
145
            path = path.replace('\\', '\\\\')
 
146
            path = path.replace('\n', '\\n')
 
147
            path = path.replace('"', '\\"')
 
148
            path = '"' + path + '"'
 
149
        return path.encode('utf-8')
141
150
 
142
151
    # TODO: Author
143
152
    # TODO: Author timestamp+timezone