← Back to team overview

dulwich-users team mailing list archive

[PATCH] web: change '/' only if repo is physical

 

Such replacements don't make sense for in-memory repos, only
physical/disk-based ones.

While doing so, refactor out some code into _url_to_path, renaming it
too.

This fixes test_get_idx_file and test_get_pack_file in
test_web.DumbHandlersTestCase on Windows.
---
 dulwich/web.py |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/dulwich/web.py b/dulwich/web.py
index 3f354db..ad8b768 100644
--- a/dulwich/web.py
+++ b/dulwich/web.py
@@ -112,16 +112,20 @@ def send_file(req, f, content_type):
         raise
 
 
-def _url_to_path(url):
-    return url.replace('/', os.path.sep)
+def _contents_and_path_for_url(backend, mat):
+    repo = get_repo(backend, mat)
+    path = mat.group()
+    # os-specific separator for paths only make sense for physical repos
+    if isinstance(repo, Repo):
+        path = path.replace('/', os.path.sep)
+    return repo.get_named_file(path), path
 
 
 def get_text_file(req, backend, mat):
     req.nocache()
-    path = _url_to_path(mat.group())
+    contents, path = _contents_and_path_for_url(backend, mat)
     logger.info('Sending plain text file %s', path)
-    return send_file(req, get_repo(backend, mat).get_named_file(path),
-                     'text/plain')
+    return send_file(req, contents, 'text/plain')
 
 
 def get_loose_object(req, backend, mat):
@@ -143,17 +147,17 @@ def get_loose_object(req, backend, mat):
 
 def get_pack_file(req, backend, mat):
     req.cache_forever()
-    path = _url_to_path(mat.group())
+    contents, path = _contents_and_path_for_url(backend, mat)
     logger.info('Sending pack file %s', path)
-    return send_file(req, get_repo(backend, mat).get_named_file(path),
+    return send_file(req, contents,
                      'application/x-git-packed-objects')
 
 
 def get_idx_file(req, backend, mat):
     req.cache_forever()
-    path = _url_to_path(mat.group())
+    contents, path = _contents_and_path_for_url(backend, mat)
     logger.info('Sending pack file %s', path)
-    return send_file(req, get_repo(backend, mat).get_named_file(path),
+    return send_file(req, contents,
                      'application/x-git-packed-objects-toc')
 
 
-- 
1.7.3.2.msysgit.0




Follow ups