git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGIT PATCH 8/9] Add a constructor to PatchSet.

From
Yann Dirson <ydirson@altern.org>
Date
Jun 16, 2007, 22:01 UTC
Message-ID
<20070616220110.14941.24888.stgit@gandelf.nowhere.earth>
In-Reply-To
<20070616213615.14941.31187.stgit@gandelf.nowhere.earth>
Move __base_dir up into PatchSet as well, and add an accessor.
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
 stgit/stack.py |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/stgit/stack.py b/stgit/stack.py
index 634588d..e33fe62 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -277,11 +277,26 @@ class Patch(StgitObject):
 FORMAT_VERSION = 2
 
 class PatchSet(StgitObject):
+    def __init__(self, name = None):
+        try:
+            if name:
+                self.set_name (name)
+            else:
+                self.set_name (git.get_head_file())
+            self.__base_dir = basedir.get()
+        except git.GitException, ex:
+            raise StackException, 'GIT tree not initialised: %s' % ex
+
+        self._set_dir(os.path.join(self.__base_dir, 'patches', self.get_name()))
+
     def get_name(self):
         return self.__name
     def set_name(self, name):
         self.__name = name
 
+    def _basedir(self):
+        return self.__base_dir
+
     def get_head(self):
         """Return the head of the branch
         """
@@ -337,22 +352,13 @@ class Series(PatchSet):
     def __init__(self, name = None):
         """Takes a series name as the parameter.
         """
-        try:
-            if name:
-                self.set_name (name)
-            else:
-                self.set_name (git.get_head_file())
-            self.__base_dir = basedir.get()
-        except git.GitException, ex:
-            raise StackException, 'GIT tree not initialised: %s' % ex
-
-        self._set_dir(os.path.join(self.__base_dir, 'patches', self.get_name()))
+        PatchSet.__init__(self, name)
 
         # Update the branch to the latest format version if it is
         # initialized, but don't touch it if it isn't.
         self.update_to_current_format_version()
 
-        self.__refs_dir = os.path.join(self.__base_dir, 'refs', 'patches',
+        self.__refs_dir = os.path.join(self._basedir(), 'refs', 'patches',
                                        self.get_name())
 
         self.__applied_file = os.path.join(self._dir(), 'applied')
@@ -374,7 +380,7 @@ class Series(PatchSet):
         possible on external functions that may change during a format
         version bump, since it must remain able to process older formats."""
 
-        branch_dir = os.path.join(self.__base_dir, 'patches', self.get_name())
+        branch_dir = os.path.join(self._basedir(), 'patches', self.get_name())
         def get_format_version():
             """Return the integer format version number, or None if the
             branch doesn't have any StGIT metadata at all, of any version."""
@@ -416,7 +422,7 @@ class Series(PatchSet):
             mkdir(os.path.join(branch_dir, 'trash'))
             patch_dir = os.path.join(branch_dir, 'patches')
             mkdir(patch_dir)
-            refs_dir = os.path.join(self.__base_dir, 'refs', 'patches', self.get_name())
+            refs_dir = os.path.join(self._basedir(), 'refs', 'patches', self.get_name())
             mkdir(refs_dir)
             for patch in (file(os.path.join(branch_dir, 'unapplied')).readlines()
                           + file(os.path.join(branch_dir, 'applied')).readlines()):
@@ -435,7 +441,7 @@ class Series(PatchSet):
                     config.set('branch.%s.description' % self.get_name(), desc)
                 rm(desc_file)
             rm(os.path.join(branch_dir, 'current'))
-            rm(os.path.join(self.__base_dir, 'refs', 'bases', self.get_name()))
+            rm(os.path.join(self._basedir(), 'refs', 'bases', self.get_name()))
             set_format_version(2)
 
         # Make sure we're at the latest version.
@@ -603,10 +609,10 @@ class Series(PatchSet):
         git.rename_branch(self.get_name(), to_name)
 
         if os.path.isdir(self._dir()):
-            rename(os.path.join(self.__base_dir, 'patches'),
+            rename(os.path.join(self._basedir(), 'patches'),
                    self.get_name(), to_stack.get_name())
         if os.path.exists(self.__refs_dir):
-            rename(os.path.join(self.__base_dir, 'refs', 'patches'),
+            rename(os.path.join(self._basedir(), 'refs', 'patches'),
                    self.get_name(), to_stack.get_name())
 
         # Rename the config section
Previous: Yann DirsonNext: Yann Dirson
Message 8 of 10 in “Refactoring of command handling”
  1. 0/9 Refactoring of command handlingYann Dirson, Jun 16, 2007
  2. 1/9 Fix contrib/stg-whatchanged way of identifying a conflict.Yann Dirson, Jun 16, 2007
  3. 2/9 Revert part of the reverted commit that we want to keep.Yann Dirson, Jun 16, 2007
  4. 4/9 Fixed thinko in error message.Yann Dirson, Jun 16, 2007
  5. 5/9 Promote more common functions to Command methods.Yann Dirson, Jun 16, 2007
  6. 6/9 Changed sync not to use -b which has other semantics.Yann Dirson, Jun 16, 2007
  7. 7/9 Replace crt_series uses with a method call.Yann Dirson, Jun 16, 2007
  8. 8/9 Add a constructor to PatchSet.Yann Dirson, Jun 16, 2007
  9. 9/9 Cleanup the use of the Series class.Yann Dirson, Jun 16, 2007
  10. Yann DirsonJun 19, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.