/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

  • Committer: Jelmer Vernooij
  • Date: 2009-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

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
48
46
    PackData,
49
47
    write_pack_index_v2,
50
48
    )
51
 
from dulwich.objects import (
52
 
    ShaFile,
53
 
    sha_to_hex,
54
 
    hex_to_sha,
55
 
    )
 
49
 
56
50
 
57
51
class BzrBackend(Backend):
58
52
 
80
74
        return ret
81
75
 
82
76
    def apply_pack(self, refs, read):
83
 
        """apply pack from client to current repository"""
 
77
        """ apply pack from client to current repository """
84
78
 
85
79
        fd, path = tempfile.mkstemp(suffix=".pack")
86
80
        f = os.fdopen(fd, 'w')
89
83
 
90
84
        p = PackData(path)
91
85
        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
86
        write_pack_index_v2(path[:-5]+".idx", entries, p.calculate_checksum())
100
87
 
101
 
        repo_dir = BzrDir.open_from_transport(self.transport)
102
 
        target = repo_dir.find_repository()
 
88
        def get_objects():
 
89
            pack = Pack(path[:-5])
 
90
            for obj in pack.iterobjects():
 
91
                yield obj
103
92
 
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
 
93
        target = Repository.open_from_transport(self.transport)
110
94
 
111
95
        target.lock_write()
112
96
        try:
113
97
            target.start_write_group()
114
98
            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:
 
99
                import_git_objects(target, self.mapping, iter(get_objects()))
 
100
            finally:
122
101
                target.commit_write_group()
123
102
        finally:
124
103
            target.unlock()