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

Properly set InventoryEntry revision when changing symlink targets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Jelmer Vernooij
2
 
# Copyright (C) 2008 John Carr
3
1
# Copyright (C) 2008 Canonical Ltd
4
2
#
5
3
# This program is free software; you can redistribute it and/or modify
20
18
import tempfile
21
19
 
22
20
from dulwich.server import TCPGitServer
 
21
import os
23
22
 
24
23
from bzrlib.bzrdir import (
25
24
    BzrDir,
48
47
    PackData,
49
48
    write_pack_index_v2,
50
49
    )
51
 
from dulwich.objects import (
52
 
    ShaFile,
53
 
    sha_to_hex,
54
 
    hex_to_sha,
55
 
    )
 
50
 
56
51
 
57
52
class BzrBackend(Backend):
58
53
 
80
75
        return ret
81
76
 
82
77
    def apply_pack(self, refs, read):
83
 
        """apply pack from client to current repository"""
 
78
        """ apply pack from client to current repository """
84
79
 
85
80
        fd, path = tempfile.mkstemp(suffix=".pack")
86
81
        f = os.fdopen(fd, 'w')
89
84
 
90
85
        p = PackData(path)
91
86
        entries = p.sorted_entries()
92
 
        heads = []
93
 
        for e in entries:
94
 
            sha = e[0]
95
 
            offset = e[1]
96
 
            t, o = p.get_object_at (offset)
97
 
            if t == 1 or t == 4:
98
 
                heads.append(sha)
99
87
        write_pack_index_v2(path[:-5]+".idx", entries, p.calculate_checksum())
100
88
 
101
 
        repo_dir = BzrDir.open_from_transport(self.transport)
102
 
        target = repo_dir.find_repository()
 
89
        def get_objects():
 
90
            pack = Pack(path[:-5])
 
91
            for obj in pack.iterobjects():
 
92
                yield obj
103
93
 
104
 
        objects = {}
105
 
        for tup in p.iterobjects():
106
 
            obj_type, obj = p.get_object_at (tup[0])
107
 
            if obj_type in range(1, 4):
108
 
                sf = ShaFile.from_raw_string (obj_type, obj)
109
 
                objects[hex_to_sha(sf.id)] = sf
 
94
        target = Repository.open_from_transport(self.transport)
110
95
 
111
96
        target.lock_write()
112
97
        try:
113
98
            target.start_write_group()
114
99
            try:
115
 
                import_git_objects(target, self.mapping, objects,
116
 
                                   BazaarObjectStore (target, self.mapping),
117
 
                                   heads)
118
 
            except:
119
 
                target.abort_write_group()
120
 
                raise
121
 
            else:
 
100
                import_git_objects(target, self.mapping, iter(get_objects()))
 
101
            finally:
122
102
                target.commit_write_group()
123
103
        finally:
124
104
            target.unlock()
152
132
            return repo.fetch_objects(determine_wants, graph_walker, None, progress)
153
133
 
154
134
        wants = determine_wants(self.get_refs())
155
 
        graph_walker.reset()
156
135
        repo.lock_read()
157
136
        store = BazaarObjectStore(repo)
158
137
        have = store.find_common_revisions(graph_walker)