Git development
 help / color / mirror / Atom feed
From: Yann Dirson <ydirson@altern.org>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGIT PATCH 8/9] Add a constructor to PatchSet.
Date: Sun, 17 Jun 2007 00:01:10 +0200	[thread overview]
Message-ID: <20070616220110.14941.24888.stgit@gandelf.nowhere.earth> (raw)
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

  parent reply	other threads:[~2007-06-16 22:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-16 22:00 [StGIT PATCH 0/9] Refactoring of command handling Yann Dirson
2007-06-16 22:00 ` [StGIT PATCH 1/9] Fix contrib/stg-whatchanged way of identifying a conflict Yann Dirson
2007-06-16 22:00 ` [StGIT PATCH 2/9] Revert part of the reverted commit that we want to keep Yann Dirson
2007-06-16 22:00 ` [StGIT PATCH 4/9] Fixed thinko in error message Yann Dirson
2007-06-16 22:00 ` [StGIT PATCH 5/9] Promote more common functions to Command methods Yann Dirson
2007-06-16 22:01 ` [StGIT PATCH 6/9] Changed sync not to use -b which has other semantics Yann Dirson
2007-06-16 22:01 ` [StGIT PATCH 7/9] Replace crt_series uses with a method call Yann Dirson
2007-06-16 22:01 ` Yann Dirson [this message]
2007-06-16 22:01 ` [StGIT PATCH 9/9] Cleanup the use of the Series class Yann Dirson
2007-06-19 22:41 ` [StGIT PATCH 0/9] Refactoring of command handling Yann Dirson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070616220110.14941.24888.stgit@gandelf.nowhere.earth \
    --to=ydirson@altern.org \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox