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

  • Committer: Jelmer Vernooij
  • Date: 2009-01-14 18:24:38 UTC
  • mto: (0.222.3 dulwich)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090114182438-c0tn5eczyupi4ztn
Fix download url, add version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
# This program is free software; you can redistribute it and/or
5
5
# modify it under the terms of the GNU General Public License
6
6
# as published by the Free Software Foundation; version 2
7
 
# of the License.
 
7
# or (at your option) any later version of the License.
8
8
#
9
9
# This program is distributed in the hope that it will be useful,
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
19
import SocketServer
20
20
from dulwich.protocol import Protocol, ProtocolFile, TCP_GIT_PORT, extract_capabilities
21
21
from dulwich.repo import Repo
22
 
from dulwich.pack import PackData, Pack, write_pack_data
23
 
import os, sha, tempfile
 
22
from dulwich.pack import write_pack_data
 
23
import tempfile
24
24
 
25
25
class Backend(object):
26
26
 
40
40
        """
41
41
        raise NotImplementedError
42
42
 
43
 
    def fetch_objects(self, determine_wants, graph_waker, progress):
 
43
    def fetch_objects(self, determine_wants, graph_walker, progress):
44
44
        """
45
45
        Yield the objects required for a list of commits.
46
46
 
59
59
            Repo.create(self.gitdir)
60
60
 
61
61
        self.repo = Repo(self.gitdir)
62
 
 
63
 
    def get_refs(self):
64
 
        return self.repo.get_refs()
 
62
        self.fetch_objects = self.repo.fetch_objects
 
63
        self.get_refs = self.repo.get_refs
65
64
 
66
65
    def apply_pack(self, refs, read):
67
 
        # store the incoming pack in the repository
68
 
        fd, name = tempfile.mkstemp(suffix='.pack', prefix='pack-', dir=self.repo.pack_dir())
69
 
        os.write(fd, read())
70
 
        os.close(fd)
71
 
 
72
 
        # strip '.pack' off our filename
73
 
        basename = name[:-5]
74
 
 
75
 
        # generate an index for it
76
 
        pd = PackData(name)
77
 
        pd.create_index_v2(basename+".idx")
 
66
        fd, commit = self.repo.object_store.add_pack()
 
67
        fd.write(read())
 
68
        fd.close()
 
69
        commit()
78
70
 
79
71
        for oldsha, sha, ref in refs:
80
72
            if ref == "0" * 40:
104
96
        def determine_wants(heads):
105
97
            keys = heads.keys()
106
98
            if keys:
107
 
                self.proto.write_pkt_line("%s %s\x00%s\n" % (keys[0], heads[keys[0]], self.capabilities()))
 
99
                self.proto.write_pkt_line("%s %s\x00%s\n" % ( heads[keys[0]], keys[0], self.capabilities()))
108
100
                for k in keys[1:]:
109
 
                    self.proto.write_pkt_line("%s %s\n" % (k, heads[k]))
 
101
                    self.proto.write_pkt_line("%s %s\n" % (heads[k], k))
110
102
 
111
103
            # i'm done..
112
104
            self.proto.write("0000")
121
113
 
122
114
            want_revs = []
123
115
            while want and want[:4] == 'want':
124
 
                want_rev = want[5:45]
125
 
                # FIXME: This check probably isnt needed?
126
 
                want_revs.append(want_rev)
 
116
                want_revs.append(want[5:45])
127
117
                want = self.proto.read_pkt_line()
128
118
            return want_revs
129
119
 
130
120
        progress = lambda x: self.proto.write_sideband(2, x)
 
121
        write = lambda x: self.proto.write_sideband(1, x)
131
122
 
132
123
        class ProtocolGraphWalker(object):
133
124
 
134
 
            def __init__(self):
 
125
            def __init__(self, proto):
 
126
                self.proto = proto
135
127
                self._last_sha = None
136
128
 
137
129
            def ack(self, have_ref):
142
134
                if have[:4] == 'have':
143
135
                    return have[5:45]
144
136
 
145
 
                if have[:4] == 'done':
146
 
                    return None
 
137
                #if have[:4] == 'done':
 
138
                #    return None
147
139
 
148
140
                if self._last_sha:
149
141
                    # Oddness: Git seems to resend the last ACK, without the "continue" statement
152
144
                # The exchange finishes with a NAK
153
145
                self.proto.write_pkt_line("NAK\n")
154
146
 
 
147
        graph_walker = ProtocolGraphWalker(self.proto)
155
148
        objects = list(self.backend.fetch_objects(determine_wants, graph_walker, progress))
156
149
        progress("dul-daemon says what\n")
157
150
        progress("counting objects: %d, done.\n" % len(objects))