← Back to team overview

dulwich-users team mailing list archive

[PATCH 3/4] Move dul-daemon's main functionality to server.

 

From: Dave Borowitz <dborowitz@xxxxxxxxxx>

Change-Id: Ia97c5dff91257284d853434a37079f45562c985e
---
 NEWS              |    3 +++
 bin/dul-daemon    |   17 +++--------------
 dulwich/server.py |   16 ++++++++++++++++
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/NEWS b/NEWS
index 895658d..d016e42 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,9 @@
 
   * Move reference WSGI handler to web.py. (Dave Borowitz)
 
+  * Make dul-daemon a trivial wrapper around server functionality.
+    (Dave Borowitz)
+
 
 0.6.0	2010-05-22
 
diff --git a/bin/dul-daemon b/bin/dul-daemon
index dbc23ea..020ad94 100755
--- a/bin/dul-daemon
+++ b/bin/dul-daemon
@@ -17,18 +17,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
-import sys
-from dulwich.log_utils import default_logging_config
-from dulwich.repo import Repo
-from dulwich.server import DictBackend, TCPGitServer
+from dulwich.server import main
 
-if __name__ == "__main__":
-    if len(sys.argv) > 1:
-        gitdir = sys.argv[1]
-    else:
-        gitdir = "."
-
-    default_logging_config()
-    backend = DictBackend({"/": Repo(gitdir)})
-    server = TCPGitServer(backend, 'localhost')
-    server.serve_forever()
+if __name__ == '__main__':
+    main()
diff --git a/dulwich/server.py b/dulwich/server.py
index 14f78b9..524a222 100644
--- a/dulwich/server.py
+++ b/dulwich/server.py
@@ -58,6 +58,9 @@ from dulwich.protocol import (
     extract_capabilities,
     extract_want_line_capabilities,
     )
+from dulwich.repo import (
+    Repo,
+    )
 
 
 logger = log_utils.getLogger(__name__)
@@ -708,3 +711,16 @@ class TCPGitServer(SocketServer.TCPServer):
     def handle_error(self, request, client_address):
         logger.exception('Exception happened during processing of request '
                          'from %s', client_address)
+
+
+def main(argv=sys.argv):
+    """Entry point for starting a TCP git server."""
+    if len(argv) > 1:
+        gitdir = argv[1]
+    else:
+        gitdir = '.'
+
+    log_utils.default_logging_config()
+    backend = DictBackend({'/': Repo(gitdir)})
+    server = TCPGitServer(backend, 'localhost')
+    server.serve_forever()
-- 
1.7.0.4




References