Merge lp:~jelmer/dulwich/httprepo into lp:~vcs-imports/dulwich/trunk

Proposed by Jelmer Vernooij
Status: Rejected
Rejected by: Jelmer Vernooij
Proposed branch: lp:~jelmer/dulwich/httprepo
Merge into: lp:~vcs-imports/dulwich/trunk
Diff against target: 131 lines (+127/-0)
1 file modified
dulwich/httprepo.py (+127/-0)
To merge this branch: bzr merge lp:~jelmer/dulwich/httprepo
Reviewer Review Type Date Requested Status
VCS imports Pending
Review via email: mp+22424@code.launchpad.net

Description of the change

HTTP Dumb access support

To post a comment you must log in.
lp:~jelmer/dulwich/httprepo updated
462. By Jelmer Vernooij

merge trunk

Unmerged revisions

462. By Jelmer Vernooij

merge trunk

461. By Jelmer Vernooij

Add basic dumb HTTP repository implementation.

460. By Jelmer Vernooij

Remove one-line function, only used in one place.

459. By Jelmer Vernooij

Remove put_named_file from public API

458. By Jelmer Vernooij

Fix PackData._get_size().

457. By Jelmer Vernooij

Delay checking size until it's actually used.

456. By Jelmer Vernooij

Add convenience function for parsing info/refs file.

455. By Jelmer Vernooij

Extend DictRefsContainer.

454. By Jelmer Vernooij

Mark current version as 0.5.0

453. By Jelmer Vernooij

merge support for use with in-memory packs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'dulwich/httprepo.py'
2--- dulwich/httprepo.py 1970-01-01 00:00:00 +0000
3+++ dulwich/httprepo.py 2010-06-08 19:26:25 +0000
4@@ -0,0 +1,127 @@
5+# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
6+#
7+# This program is free software; you can redistribute it and/or modify
8+# it under the terms of the GNU General Public License as published by
9+# the Free Software Foundation; either version 2 of the License, or
10+# (at your option) any later version.
11+#
12+# This program is distributed in the hope that it will be useful,
13+# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+# GNU General Public License for more details.
16+#
17+# You should have received a copy of the GNU General Public License
18+# along with this program; if not, write to the Free Software
19+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20+
21+"""(dumb) HTTP repository access."""
22+
23+import urllib
24+
25+from dulwich.errors import (
26+ NotGitRepository,
27+ NoIndexPresent,
28+ )
29+from dulwich.objects import (
30+ ShaFile,
31+ )
32+from dulwich.object_store import (
33+ PackBasedObjectStore,
34+ PACKDIR,
35+ )
36+from dulwich.pack import (
37+ PackData,
38+ Pack,
39+ load_pack_index_file,
40+ )
41+from dulwich.repo import (
42+ BaseRepo,
43+ DictRefsContainer,
44+ OBJECTDIR,
45+ read_info_refs,
46+ )
47+
48+
49+class HTTPRepo(BaseRepo):
50+
51+ def __init__(self, baseurl):
52+ self._opener = urllib.URLopener()
53+ self.baseurl = baseurl.rstrip("/") + "/"
54+ refsf = self.get_named_file(".git/info/refs")
55+ if refsf:
56+ self.bare = False
57+ self._controlurl = urllib.basejoin(self.baseurl, '.git')
58+ else:
59+ refsf = self.get_named_file("info/refs")
60+ if refsf is None:
61+ raise NotGitRepository(self.baseurl)
62+ self.bare = True
63+ self._controlurl = self.baseurl
64+ object_store = HTTPObjectStore(self._opener,
65+ urllib.basejoin(self.baseurl, OBJECTDIR))
66+ refs = read_info_refs(refsf)
67+ refs["HEAD"] = self.get_named_file("HEAD").read().rstrip("\n")
68+ super(HTTPRepo, self).__init__(object_store,
69+ DictRefsContainer(refs))
70+
71+ def get_named_file(self, path):
72+ """Get a file from the control dir with a specific name.
73+
74+ Although the filename should be interpreted as a filename relative to
75+ the control dir in a disk-baked Repo, the object returned need not be
76+ pointing to a file in that location.
77+
78+ :param path: The path to the file, relative to the control dir.
79+ :return: An open file object, or None if the file does not exist.
80+ """
81+ try:
82+ return self._opener.open(urllib.basejoin(self.baseurl, path.lstrip('/')))
83+ except IOError:
84+ # FIXME: Be more specific than *any* IOError?
85+ return None
86+
87+ def open_index(self):
88+ """Open the index for this repository."""
89+ raise NoIndexPresent()
90+
91+ def __repr__(self):
92+ return "<HTTPRepo for %r>" % self.baseurl
93+
94+
95+class HTTPObjectStore(PackBasedObjectStore):
96+ """Git-style object store that exists on disk."""
97+
98+ def __init__(self, opener, url):
99+ """Open an object store.
100+
101+ """
102+ super(HTTPObjectStore, self).__init__()
103+ self._opener = opener
104+ self.url = url.rstrip("/") + "/"
105+ self.pack_url = urllib.basejoin(self.url, PACKDIR).rstrip("/")+"/"
106+
107+ def _load_packs(self):
108+ ret = []
109+ packs_index = urllib.basejoin(self.url, 'info/packs')
110+ for line in self._opener.open(packs_index).readlines():
111+ line = line.rstrip("\n")
112+ if not line:
113+ continue
114+ (kind, name) = line.split(" ", 1)
115+ if kind != "P":
116+ continue
117+ if name.startswith("pack-") and name.endswith(".pack"):
118+ pack_url = urllib.basejoin(self.pack_url, name)
119+ pd = PackData(name, self._opener.open(pack_url))
120+ idxname = name.replace(".pack", ".idx")
121+ index_url = urllib.basejoin(self.pack_url, idxname)
122+ idx = load_pack_index_file(idxname, self._opener.open(index_url))
123+ ret.append(Pack.from_objects(pd, idx))
124+ return ret
125+
126+ def _split_loose_object(self, sha):
127+ return (sha[:2], sha[2:])
128+
129+ def _get_loose_object(self, sha):
130+ path = '%s/%s' % self._split_loose_object(sha)
131+ return ShaFile._parse_file(self._opener.open(urllib.basejoin(self.url, path)).read())

Subscribers

People subscribed via source and target branches