/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: John Carr
  • Date: 2008-12-30 22:10:38 UTC
  • mto: (0.217.35 git-serve)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: john.carr@unrouted.co.uk-20081230221038-wkjk7e99ro3cpo18
Don't bother using InterRepo, use import_git_objects directly. Don't need a full repository (just operating on a pack and index)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib.bzrdir import BzrDir
18
 
from bzrlib.repository import Repository, InterRepository
 
18
from bzrlib.repository import Repository
19
19
 
 
20
from bzrlib.plugins.git.fetch import import_git_objects
20
21
from bzrlib.plugins.git.mapping import default_mapping
21
22
 
22
23
from dulwich.server import Backend
23
 
from dulwich.repo import Repo
 
24
from dulwich.pack import Pack, PackData, write_pack_index_v2
 
25
from dulwich.objects import ShaFile
24
26
 
25
 
#FIXME: Shouldnt need these imports
26
 
import tempfile
 
27
import os, tempfile
27
28
 
28
29
class BzrBackend(Backend):
29
30
 
38
39
    def apply_pack(self, refs, read):
39
40
        """ apply pack from client to current repository """
40
41
 
41
 
        # FIXME: Until we have a VirtualGitRepository, lets just stash it on disk
42
 
        source_path = tempfile.mkdtemp()
43
 
        Repo.init_bare(source_path)
44
 
        repo = Repo(source_path)
45
 
        f, commit = repo.object_store.add_pack()
 
42
        fd, path = tempfile.mkstemp(suffix=".pack")
 
43
        f = os.fdopen(fd, 'w')
46
44
        f.write(read())
47
45
        f.close()
48
 
        commit()
49
 
        for oldsha, sha, ref in refs:
50
 
            repo.set_ref(ref, sha)
51
 
        source_repos = Repository.open(source_path)
52
 
        # END FIXME
53
 
 
54
 
        target_repos = Repository.open(self.directory)
55
 
 
56
 
        source_repos.lock_read()
 
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()
57
59
        try:
58
 
            inter = InterRepository.get(source_repos, target_repos)
59
 
            inter.fetch()
 
60
            target.start_write_group()
 
61
            try:
 
62
                import_git_objects(target, self.mapping, iter(get_objects()))
 
63
            finally:
 
64
                target.commit_write_group()
60
65
        finally:
61
 
            source_repos.unlock()
 
66
            target.unlock()
62
67
 
63
68
        for oldsha, sha, ref in refs:
64
69
            if ref[:11] == 'refs/heads/':