/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 breezy/plugins/git/tests/__init__.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-03 03:20:44 UTC
  • mfrom: (7018.3.10 git-fixes)
  • Revision ID: breezy.the.bot@gmail.com-20180703032044-t5a5w5y0tmzrbezc
Port a few more bits of the git plugin to python 3.

Merged from https://code.launchpad.net/~jelmer/brz/git-fixes2/+merge/348803

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
class GitBranchBuilder(object):
61
61
 
62
62
    def __init__(self, stream=None):
 
63
        if not FastimportFeature.available():
 
64
            raise tests.UnavailableFeature(FastimportFeature)
63
65
        self.commit_info = []
64
66
        self.orig_stream = stream
65
67
        if stream is None:
67
69
        else:
68
70
            self.stream = stream
69
71
        self._counter = 0
70
 
        self._branch = 'refs/heads/master'
 
72
        self._branch = b'refs/heads/master'
71
73
 
72
74
    def set_branch(self, branch):
73
75
        """Set the branch we are committing."""
88
90
 
89
91
    def set_symlink(self, path, content):
90
92
        """Create or update symlink at a given path."""
91
 
        mark = self._create_blob(content)
 
93
        mark = self._create_blob(self._encode_path(content))
92
94
        mode = b'120000'
93
95
        self.commit_info.append(b'M %s :%d %s\n'
94
96
                % (mode, mark, self._encode_path(path)))
97
99
        """Create or update content at a given path."""
98
100
        mark = self._create_blob(content)
99
101
        if executable:
100
 
            mode = '100755'
 
102
            mode = b'100755'
101
103
        else:
102
 
            mode = '100644'
103
 
        self.commit_info.append('M %s :%d %s\n'
 
104
            mode = b'100644'
 
105
        self.commit_info.append(b'M %s :%d %s\n'
104
106
                                % (mode, mark, self._encode_path(path)))
105
107
 
106
 
    def set_link(self, path, link_target):
107
 
        """Create or update a link at a given path."""
108
 
        mark = self._create_blob(link_target)
109
 
        self.commit_info.append('M 120000 :%d %s\n'
110
 
                                % (mark, self._encode_path(path)))
111
 
 
112
108
    def delete_entry(self, path):
113
109
        """This will delete files or symlinks at the given location."""
114
 
        self.commit_info.append('D %s\n' % (self._encode_path(path),))
 
110
        self.commit_info.append(b'D %s\n' % (self._encode_path(path),))
115
111
 
116
112
    @staticmethod
117
113
    def _encode_path(path):
 
114
        if isinstance(path, bytes):
 
115
            return path
118
116
        if '\n' in path or path[0] == '"':
119
117
            path = path.replace('\\', '\\\\')
120
118
            path = path.replace('\n', '\\n')
142
140
            commit.
143
141
        """
144
142
        self._counter += 1
145
 
        mark = b'%d' % self._counter
 
143
        mark = b'%d' % (self._counter,)
146
144
        if timestamp is None:
147
145
            timestamp = int(time.time())
148
146
        self._write(b'commit %s\n' % (self._branch,))
149
147
        self._write(b'mark :%s\n' % (mark,))
150
 
        self._write(b'committer %s %s %s\n'
 
148
        self._write(b'committer %s %ld %s\n'
151
149
                    % (committer, timestamp, timezone))
152
 
        message = message.encode('UTF-8')
 
150
        if not isinstance(message, bytes):
 
151
            message = message.encode('UTF-8')
153
152
        self._write(b'data %d\n' % (len(message),))
154
153
        self._write(message)
155
154
        self._write(b'\n')