|
@@ -17,30 +17,53 @@
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
# MA 02110-1301, USA.
|
|
|
|
|
|
-import sys
|
|
|
+import sys, tempfile
|
|
|
from dulwich.server import Backend, TCPGitServer
|
|
|
from dulwich.repo import Repo
|
|
|
+from dulwich.pack import PackData, Pack
|
|
|
|
|
|
class GitBackend(Backend):
|
|
|
|
|
|
- def __init__(self, gitdir):
|
|
|
+ def __init__(self, gitdir=None):
|
|
|
self.gitdir = gitdir
|
|
|
- self.repository = Repo(gitdir)
|
|
|
+
|
|
|
+ if not self.gitdir:
|
|
|
+ self.gitdir = tempfile.mkdtemp()
|
|
|
+ Repo.create(self.gitdir)
|
|
|
+
|
|
|
+ self.repo = Repo(gitdir)
|
|
|
|
|
|
def get_refs(self):
|
|
|
- return [tuple(refsha) for refsha in self.repository.heads().items()]
|
|
|
+ return [('HEAD', self.repo.head())] +
|
|
|
+ [tuple(refsha) for refsha in self.repo.heads().items()]
|
|
|
|
|
|
def has_revision(self, sha):
|
|
|
return False
|
|
|
|
|
|
def apply_pack(self, refs, read):
|
|
|
- read()
|
|
|
+ # store the incoming pack in the repository
|
|
|
+ fd, name = tempfile.mkstemp(suffix='pack', prefix='', dir=self.repo.packdir())
|
|
|
+ fd.write(read())
|
|
|
+ fd.close()
|
|
|
+
|
|
|
+ # strip '.pack' off our filename
|
|
|
+ basename = name[:-5]
|
|
|
+
|
|
|
+ # generate an index for it
|
|
|
+ pd = PackData(name)
|
|
|
+ pd.create_index_v2(basename+".idx")
|
|
|
+
|
|
|
+ # FIXME: Update heads
|
|
|
|
|
|
def generate_pack(self, want, have, write, progress):
|
|
|
pass
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- backend = GitBackend(sys.argv[1])
|
|
|
+ gitdir = None
|
|
|
+ if len(sys.argv) > 1:
|
|
|
+ gitdir = sys.argv[1]
|
|
|
+
|
|
|
+ backend = GitBackend(gitdir)
|
|
|
server = TCPGitServer(backend, ('localhost', 9418))
|
|
|
server.serve_forever()
|