/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

Fix branch cloning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib.bzrdir import BzrDir
18
 
from bzrlib.repository import Repository
19
 
 
20
 
from bzrlib.plugins.git.fetch import import_git_objects
21
 
from bzrlib.plugins.git.mapping import default_mapping
22
 
 
23
17
from dulwich.server import Backend
24
 
from dulwich.pack import Pack, PackData, write_pack_index_v2
25
 
from dulwich.objects import ShaFile
26
 
 
27
 
import os, tempfile
28
18
 
29
19
class BzrBackend(Backend):
30
20
 
31
21
    def __init__(self, directory):
32
22
        self.directory = directory
33
 
        self.mapping = default_mapping
34
23
 
35
24
    def get_refs(self):
36
25
        """ return a dict of all tags and branches in repository (and shas) """
38
27
 
39
28
    def apply_pack(self, refs, read):
40
29
        """ apply pack from client to current repository """
41
 
 
42
 
        fd, path = tempfile.mkstemp(suffix=".pack")
43
 
        f = os.fdopen(fd, 'w')
44
 
        f.write(read())
45
 
        f.close()
46
 
 
47
 
        p = PackData(path)
48
 
        entries = p.sorted_entries()
49
 
        write_pack_index_v2(path[:-5]+".idx", entries, p.calculate_checksum())
50
 
 
51
 
        def get_objects():
52
 
            pack = Pack(path[:-5])
53
 
            for obj in pack.iterobjects():
54
 
                yield obj
55
 
 
56
 
        target = Repository.open(self.directory)
57
 
 
58
 
        target.lock_write()
59
 
        try:
60
 
            target.start_write_group()
61
 
            try:
62
 
                import_git_objects(target, self.mapping, iter(get_objects()))
63
 
            finally:
64
 
                target.commit_write_group()
65
 
        finally:
66
 
            target.unlock()
67
 
 
68
 
        for oldsha, sha, ref in refs:
69
 
            if ref[:11] == 'refs/heads/':
70
 
                branch_nick = ref[11:]
71
 
 
72
 
                try:
73
 
                    target_dir = BzrDir.open(self.directory + "/" + branch_nick)
74
 
                except:
75
 
                    target_dir = BzrDir.create(self.directory + "/" + branch_nick)
76
 
 
77
 
                try:
78
 
                    target_branch = target_dir.open_branch()
79
 
                except:
80
 
                    target_branch = target_dir.create_branch()
81
 
               
82
 
                rev_id = self.mapping.revision_id_foreign_to_bzr(sha)
83
 
                target_branch.generate_revision_history(rev_id) 
 
30
        self.read()
84
31
 
85
32
    def fetch_objects(self, determine_wants, graph_walker, progress):
86
33
        """ yield git objects to send to client """