/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 model.py

Ultra-experimental support for "bzr pull". No test. No sanity.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
import subprocess
 
21
import tarfile
21
22
 
22
23
from bzrlib.plugins.git import errors
23
24
 
58
59
        args.append(object_id)
59
60
        return self.git_lines('cat-file', args)
60
61
 
61
 
    def rev_list(self, heads, max_count=None, header=False, parents=False):
 
62
    def rev_list(self, heads, max_count=None, header=False, parents=False,
 
63
                 topo_order=False, paths=None):
62
64
        args = []
63
65
        if max_count is not None:
64
66
            args.append('--max-count=%d' % max_count)
66
68
            args.append('--header')
67
69
        if parents:
68
70
            args.append('--parents')
 
71
        if topo_order:
 
72
            args.append('--topo-order')
69
73
        if heads is None:
70
74
            args.append('--all')
71
75
        else:
72
76
            args.extend(heads)
 
77
        if paths is not None:
 
78
            args.append('--')
 
79
            args.extend(paths)
73
80
        return self.git_lines('rev-list', args)
74
81
 
75
82
    def rev_parse(self, git_id):
92
99
            ancestors[entries[0]] = entries[1:]
93
100
        return ancestors
94
101
 
 
102
    def get_ancestry(self, revisions):
 
103
        args = ['--topo-order', '--reverse'] + revisions
 
104
        return [line[:-1] for line in self.git_lines('rev-list', args)]
 
105
 
95
106
    def ancestor_lines(self, revisions):
96
107
        revision_lines = []
97
108
        for line in self.rev_list(revisions, header=True):
114
125
                name = name[1:-1].decode('string_escape')
115
126
            name = name.decode('utf-8')
116
127
            yield permissions, type, hash, name
 
128
 
 
129
    def get_tarpipe(self, tree_id):
 
130
        cmd = self.git_command('archive', [tree_id])
 
131
        env = os.environ.copy()
 
132
        env['GIT_DIR'] = self.git_dir
 
133
        p = subprocess.Popen(cmd,
 
134
                             stdin=subprocess.PIPE,
 
135
                             stdout=subprocess.PIPE,
 
136
                             stderr=subprocess.PIPE,
 
137
                             env=env)
 
138
        p.stdin.close()
 
139
        tarpipe = TarPipe.open(mode='r|', fileobj=p.stdout)
 
140
        def close_callback():
 
141
            if p.wait() != 0:
 
142
                raise errors.GitCommandError(cmd, p.returncode,
 
143
                                             p.stderr.read().strip())
 
144
        tarpipe.set_close_callback(close_callback)
 
145
        return tarpipe
 
146
 
 
147
 
 
148
class TarPipe(tarfile.TarFile):
 
149
 
 
150
    def set_close_callback(self, close_callback):
 
151
        self.__close_callback = close_callback
 
152
 
 
153
    def close(self):
 
154
        super(TarPipe, self).close()
 
155
        self.__close_callback()