Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master-1, master-0, and 0.9.4

New method ``update_server_info`` which generates data
for dumb server access.

Changeset e7ec4dc01b4b

Parent 493ed46a2b8f

by Jelmer Vernooij

Changes to 5 files · Browse files at e7ec4dc01b4b Showing diff from parent 493ed46a2b8f Diff from another changeset...

Change 1 of 1 Show Entire File NEWS Stacked
 
19
20
21
 
 
 
22
23
24
 
19
20
21
22
23
24
25
26
27
@@ -19,6 +19,9 @@
    * Add support for retrieving tarballs from remote servers.   (Jelmer Vernooij, #379087) + + * New method ``update_server_info`` which generates data + for dumb server access. (Jelmer Vernooij, #731235)    0.8.1 2011-10-31  
Change 1 of 3 Show Entire File bin/​dulwich Stacked
 
35
36
37
 
38
39
40
 
174
175
176
 
 
 
 
 
177
178
179
 
183
184
185
 
186
187
188
 
35
36
37
38
39
40
41
 
175
176
177
178
179
180
181
182
183
184
185
 
189
190
191
192
193
194
195
@@ -35,6 +35,7 @@
 from dulwich.index import Index  from dulwich.pack import Pack, sha_to_hex  from dulwich.repo import Repo +from dulwich.server import update_server_info      def cmd_archive(args): @@ -174,6 +175,11 @@
  r.do_commit(committer=committer, author=author, message=opts["--message"])     +def cmd_update_server_info(args): + r = Repo(".") + update_server_info(r) + +  commands = {   "commit": cmd_commit,   "fetch-pack": cmd_fetch_pack, @@ -183,6 +189,7 @@
  "log": cmd_log,   "clone": cmd_clone,   "archive": cmd_archive, + "update-server-info": cmd_update_server_info,   }    if len(sys.argv) < 2:
Change 1 of 2 Show Entire File dulwich/​server.py Stacked
 
27
28
29
 
30
31
32
 
787
788
789
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
28
29
30
31
32
33
 
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
@@ -27,6 +27,7 @@
     import collections +import os  import socket  import SocketServer  import sys @@ -787,3 +788,40 @@
  # FIXME: Catch exceptions and write a single-line summary to outf.   handler.handle()   return 0 + + +def generate_info_refs(repo): + """Generate an info refs file.""" + refs = repo.get_refs() + for name in sorted(refs.iterkeys()): + # get_refs() includes HEAD as a special case, but we don't want to + # advertise it + if name == 'HEAD': + continue + sha = refs[name] + o = repo[sha] + if not o: + continue + yield '%s\t%s\n' % (sha, name) + peeled_sha = repo.get_peeled(name) + if peeled_sha != sha: + yield '%s\t%s^{}\n' % (peeled_sha, name) + + +def generate_objects_info_packs(repo): + """Generate an index for for packs.""" + for pack in repo.object_store.packs: + yield 'P pack-%s.pack\n' % pack.name() + + +def update_server_info(repo): + """Generate server info for dumb file access. + + This generates info/refs and objects/info/packs, + similar to "git update-server-info". + """ + repo._put_named_file(os.path.join('info', 'refs'), + "".join(generate_info_refs(repo))) + + repo._put_named_file(os.path.join('objects', 'info', 'packs'), + "".join(generate_objects_info_packs(repo)))
 
44
45
46
 
47
48
49
 
689
690
691
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
45
46
47
48
49
50
 
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
@@ -44,6 +44,7 @@
  ReceivePackHandler,   SingleAckGraphWalkerImpl,   UploadPackHandler, + update_server_info,   )  from dulwich.tests import TestCase  from dulwich.tests.utils import ( @@ -689,3 +690,30 @@
  outlines[0][4:].split("\x00")[0])   self.assertEquals("0000", outlines[-1])   self.assertEquals(0, exitcode) + + +class UpdateServerInfoTests(TestCase): + """Tests for update_server_info.""" + + def setUp(self): + super(UpdateServerInfoTests, self).setUp() + self.path = tempfile.mkdtemp() + self.repo = Repo.init(self.path) + + def test_empty(self): + update_server_info(self.repo) + self.assertEquals("", + open(os.path.join(self.path, ".git", "info", "refs"), 'r').read()) + self.assertEquals("", + open(os.path.join(self.path, ".git", "objects", "info", "packs"), 'r').read()) + + def test_simple(self): + commit_id = self.repo.do_commit( + message="foo", + committer="Joe Example <joe@example.com>", + ref="refs/heads/foo") + update_server_info(self.repo) + ref_text = open(os.path.join(self.path, ".git", "info", "refs"), 'r').read() + self.assertEquals(ref_text, "%s\trefs/heads/foo\n" % commit_id) + packs_text = open(os.path.join(self.path, ".git", "objects", "info", "packs"), 'r').read() + self.assertEquals(packs_text, "")
Change 1 of 3 Show Entire File dulwich/​web.py Stacked
 
29
30
31
 
32
33
34
 
38
39
40
 
 
41
42
43
 
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
 
 
197
198
199
200
201
202
203
204
 
205
206
207
 
29
30
31
32
33
34
35
 
39
40
41
42
43
44
45
46
 
183
184
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
187
188
189
190
191
192
193
 
 
194
195
196
197
@@ -29,6 +29,7 @@
 except ImportError:   from dulwich._compat import parse_qs  from dulwich import log_utils +from dulwich.gzip import GzipConsumer  from dulwich.protocol import (   ReceivableProtocol,   ) @@ -38,6 +39,8 @@
 from dulwich.server import (   DictBackend,   DEFAULT_HANDLERS, + generate_info_refs, + generate_objects_info_packs,   )     @@ -180,28 +183,15 @@
  req.respond(HTTP_OK, 'text/plain')   logger.info('Emulating dumb info/refs')   repo = get_repo(backend, mat) - refs = repo.get_refs() - for name in sorted(refs.iterkeys()): - # get_refs() includes HEAD as a special case, but we don't want to - # advertise it - if name == 'HEAD': - continue - sha = refs[name] - o = repo[sha] - if not o: - continue - yield '%s\t%s\n' % (sha, name) - peeled_sha = repo.get_peeled(name) - if peeled_sha != sha: - yield '%s\t%s^{}\n' % (peeled_sha, name) + for text in generate_info_refs(repo): + yield text      def get_info_packs(req, backend, mat):   req.nocache()   req.respond(HTTP_OK, 'text/plain')   logger.info('Emulating dumb info/packs') - for pack in get_repo(backend, mat).object_store.packs: - yield 'P pack-%s.pack\n' % pack.name() + return generate_objects_info_packs(get_repo(backend, mat))      class _LengthLimitedFile(object):