Move named file initilization to BaseRepo.
authorDave Borowitz <dborowitz@google.com>
Thu, 13 May 2010 00:44:05 +0000 (17:44 -0700)
committerDave Borowitz <dborowitz@google.com>
Tue, 1 Jun 2010 22:28:00 +0000 (15:28 -0700)
BaseRepo now supports both getting (abstractly) putting the contents of named
files.

Change-Id: I657ddc122eca5f363b101182c34e4a222b6e072c

NEWS
dulwich/repo.py

diff --git a/NEWS b/NEWS
index 394d83ae1b1beb41e26539b24ab1827d23c01d37..72cf790553857439b4e9b5fa616edf532a1df734 100644 (file)
--- 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)
index 7d80fc114d0d9fa35bec072e8167804dd202fa18..ffda6d63094a500667f36bab343e02e0577a9ef6 100644 (file)
@@ -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