Browse Source

Add porcelain 'daemon'.

Remove dul-daemon script, and replace with 'dulwich daemon'.
Jelmer Vernooij 10 years ago
parent
commit
a17185314e
7 changed files with 54 additions and 28 deletions
  1. 7 0
      NEWS
  2. 0 23
      bin/dul-daemon
  3. 24 0
      bin/dulwich
  4. 16 0
      dulwich/porcelain.py
  5. 3 4
      dulwich/server.py
  6. 3 0
      dulwich/tests/test_porcelain.py
  7. 1 1
      setup.py

+ 7 - 0
NEWS

@@ -25,6 +25,8 @@
 
   * Add porcelain 'status'. (Ryan Faulkner)
 
+  * Add porcelain 'daemon'. (Jelmer Vernooij)
+
   * Add `dulwich.greenthreads` module which provides support
     for concurrency of some object store operations.
     (Fabien Boucher)
@@ -46,6 +48,11 @@ API CHANGES
   * Remove deprecated `num_objects` argument to `write_pack` methods.
     (Jelmer Vernooij)
 
+ OTHER CHANGES
+
+  * The 'dul-daemon' script has been removed. The same functionality
+    is now available as 'dulwich daemon'. (Jelmer Vernooij)
+
 0.9.6	2014-04-23
 
  IMPROVEMENTS

+ 0 - 23
bin/dul-daemon

@@ -1,23 +0,0 @@
-#!/usr/bin/python
-# dul-daemon - Simple git-daemon-like server
-# Copyright (C) 2008 John Carr <john.carr@unrouted.co.uk>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; version 2
-# or (at your option) a later version of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA  02110-1301, USA.
-
-from dulwich.server import main
-
-if __name__ == '__main__':
-    main()

+ 24 - 0
bin/dulwich

@@ -29,6 +29,7 @@ a way to test Dulwich.
 import os
 import sys
 from getopt import getopt
+import optparse
 
 from dulwich import porcelain
 from dulwich.client import get_transport_and_path
@@ -245,12 +246,35 @@ def cmd_reset(args):
     porcelain.reset('.', mode=mode, *args)
 
 
+def cmd_daemon(args):
+    from dulwich import log_utils
+    from dulwich.protocol import TCP_GIT_PORT
+    parser = optparse.OptionParser()
+    parser.add_option("-l", "--listen_address", dest="listen_address",
+                      default="localhost",
+                      help="Binding IP address.")
+    parser.add_option("-p", "--port", dest="port", type=int,
+                      default=TCP_GIT_PORT,
+                      help="Binding TCP port.")
+    options, args = parser.parse_args(args)
+
+    log_utils.default_logging_config()
+    if len(args) > 1:
+        gitdir = args[1]
+    else:
+        gitdir = '.'
+    from dulwich import porcelain
+    porcelain.daemon(gitdir, address=options.listen_address,
+                     port=options.port)
+
+
 commands = {
     "add": cmd_add,
     "archive": cmd_archive,
     "clone": cmd_clone,
     "commit": cmd_commit,
     "commit-tree": cmd_commit_tree,
+    "daemon": cmd_daemon,
     "diff": cmd_diff,
     "diff-tree": cmd_diff_tree,
     "dump-pack": cmd_dump_pack,

+ 16 - 0
dulwich/porcelain.py

@@ -24,6 +24,7 @@ Currently implemented:
  * clone
  * commit
  * commit-tree
+ * daemon
  * diff-tree
  * init
  * list-tags
@@ -540,3 +541,18 @@ def get_tree_changes(repo):
         else:
             raise AssertionError('git mv ops not yet supported')
     return tracked_changes
+
+
+def daemon(path=".", address=None, port=None):
+    """Run a daemon serving Git requests over TCP/IP.
+
+    :param path: Path to the directory to serve.
+    """
+    # TODO(jelmer): Support git-daemon-export-ok and --export-all.
+    from dulwich.server import (
+        FileSystemBackend,
+        TCPGitServer,
+        )
+    backend = FileSystemBackend(path)
+    server = TCPGitServer(backend, address, port)
+    server.serve_forever()

+ 3 - 4
dulwich/server.py

@@ -884,10 +884,9 @@ def main(argv=sys.argv):
         gitdir = args[1]
     else:
         gitdir = '.'
-    backend = FileSystemBackend(gitdir)
-    server = TCPGitServer(backend, options.listen_address,
-                          port=options.port)
-    server.serve_forever()
+    from dulwich import porcelain
+    porcelain.daemon(gitdir, address=options.listen_address,
+                     port=options.port)
 
 
 def serve_command(handler_cls, argv=sys.argv, backend=None, inf=sys.stdin,

+ 3 - 0
dulwich/tests/test_porcelain.py

@@ -594,3 +594,6 @@ class StatusTests(PorcelainTestCase):
         self.assertEqual(len(changes['add']), 0)
         self.assertEqual(len(changes['modify']), 0)
         self.assertEqual(len(changes['delete']), 1)
+
+
+# TODO(jelmer): Add test for dulwich.porcelain.daemon

+ 1 - 1
setup.py

@@ -73,7 +73,7 @@ setup(name='dulwich',
       in the particular Monty Python sketch.
       """,
       packages=['dulwich', 'dulwich.tests', 'dulwich.tests.compat', 'dulwich.contrib'],
-      scripts=['bin/dulwich', 'bin/dul-daemon', 'bin/dul-web', 'bin/dul-receive-pack', 'bin/dul-upload-pack'],
+      scripts=['bin/dulwich', 'bin/dul-web', 'bin/dul-receive-pack', 'bin/dul-upload-pack'],
       ext_modules=[
           Extension('dulwich._objects', ['dulwich/_objects.c'],
                     include_dirs=include_dirs),