dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00073
[PATCH 1/5] Move named file initilization to BaseRepo.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
BaseRepo now supports both getting (abstractly) putting the contents of named
files.
Change-Id: I657ddc122eca5f363b101182c34e4a222b6e072c
---
NEWS | 4 ++++
dulwich/repo.py | 32 +++++++++++++++++++++++---------
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/NEWS b/NEWS
index 394d83a..72cf790 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@
* Fix memory leak in C implementation of sorted_tree_items. (Dave Borowitz)
+ FEATURES
+
+ * Move named file initilization to BaseRepo. (Dave Borowitz)
+
TESTS
* Add tests for sorted_tree_items and C implementation. (Dave Borowitz)
diff --git a/dulwich/repo.py b/dulwich/repo.py
index 7d80fc1..ffda6d6 100644
--- a/dulwich/repo.py
+++ b/dulwich/repo.py
@@ -750,6 +750,16 @@ class BaseRepo(object):
self.object_store = object_store
self.refs = refs
+ def _init_files(self):
+ """Initialize a default set of named files."""
+ self._put_named_file('description', "Unnamed repository")
+ self._put_named_file('config', ('[core]\n'
+ 'repositoryformatversion = 0\n'
+ 'filemode = true\n'
+ 'bare = false\n'
+ 'logallrefupdates = true\n'))
+ self._put_named_file('info/exclude', '')
+
def get_named_file(self, path):
"""Get a file from the control dir with a specific name.
@@ -762,6 +772,14 @@ class BaseRepo(object):
"""
raise NotImplementedError(self.get_named_file)
+ def _put_named_file(self, path, contents):
+ """Write a file to the control dir with the given name and contents.
+
+ :param path: The path to the file, relative to the control dir.
+ :contents: A string to write to the file.
+ """
+ raise NotImplementedError(self._put_named_file)
+
def open_index(self):
"""Open the index for this repository.
@@ -1072,7 +1090,10 @@ class Repo(BaseRepo):
return self._controldir
def _put_named_file(self, path, contents):
- """Write a file from the control dir with a specific name and contents.
+ """Write a file to the control dir with the given name and contents.
+
+ :param path: The path to the file, relative to the control dir.
+ :contents: A string to write to the file.
"""
f = GitFile(os.path.join(self.controldir(), path), 'wb')
try:
@@ -1162,14 +1183,7 @@ class Repo(BaseRepo):
DiskObjectStore.init(os.path.join(path, OBJECTDIR))
ret = cls(path)
ret.refs.set_symbolic_ref("HEAD", "refs/heads/master")
- ret._put_named_file('description', "Unnamed repository")
- ret._put_named_file('config', """[core]
- repositoryformatversion = 0
- filemode = true
- bare = false
- logallrefupdates = true
-""")
- ret._put_named_file(os.path.join('info', 'exclude'), '')
+ ret._init_files()
return ret
create = init_bare
--
1.7.0.4
Follow ups