From: Catalin Marinas <catalin.marinas@gmail.com>
To: git@vger.kernel.org
Cc: kha@treskal.com
Subject: [StGIT PATCH 4/5] Add stack creation and initialisation support to lib.Stack
Date: Wed, 04 Jun 2008 22:13:43 +0100 [thread overview]
Message-ID: <20080604211343.32531.41429.stgit@localhost.localdomain> (raw)
In-Reply-To: <20080604210655.32531.82580.stgit@localhost.localdomain>
This patch adds the create and initialise Stack classmethods to handle
the initialisation of StGIT patch series on a Git branch.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
stgit/lib/stack.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/stgit/lib/stack.py b/stgit/lib/stack.py
index aca7a36..7375d41 100644
--- a/stgit/lib/stack.py
+++ b/stgit/lib/stack.py
@@ -3,6 +3,10 @@
import os.path
from stgit import exception, utils
from stgit.lib import git, stackupgrade
+from stgit.config import config
+
+class StackException(exception.StgException):
+ """Exception raised by stack objects."""
class Patch(object):
"""Represents an StGit patch. This class is mainly concerned with
@@ -105,6 +109,14 @@ class PatchOrder(object):
all = property(lambda self: self.applied + self.unapplied + self.hidden)
all_visible = property(lambda self: self.applied + self.unapplied)
+ @staticmethod
+ def create(stackdir):
+ """Create the PatchOrder specific files
+ """
+ utils.create_empty_file(os.path.join(stackdir, 'applied'))
+ utils.create_empty_file(os.path.join(stackdir, 'unapplied'))
+ utils.create_empty_file(os.path.join(stackdir, 'hidden'))
+
class Patches(object):
"""Creates L{Patch} objects. Makes sure there is only one such object
per patch."""
@@ -133,12 +145,14 @@ class Patches(object):
class Stack(git.Branch):
"""Represents an StGit stack (that is, a git branch with some extra
metadata)."""
+ __repo_subdir = 'patches'
+
def __init__(self, repository, name):
git.Branch.__init__(self, repository, name)
self.__patchorder = PatchOrder(self)
self.__patches = Patches(self)
if not stackupgrade.update_to_current_format_version(repository, name):
- raise exception.StgException('%s: branch not initialized' % name)
+ raise StackException('%s: branch not initialized' % name)
patchorder = property(lambda self: self.__patchorder)
patches = property(lambda self: self.__patches)
@property
@@ -156,6 +170,45 @@ class Stack(git.Branch):
return True
return self.head == self.patches.get(self.patchorder.applied[-1]).commit
+ def set_parents(self, remote, localbranch):
+ if not localbranch:
+ return
+ if remote:
+ self.set_parent_remote(remote)
+ self.set_parent_branch(localbranch)
+ config.set('branch.%s.stgit.parentbranch' % self._name, localbranch)
+
+ @classmethod
+ def initialise(cls, repository, name = None):
+ """Initialise a Git branch to handle patch series."""
+ if not name:
+ name = repository.current_branch_name
+ # make sure that the corresponding Git branch exists
+ git.Branch(repository, name)
+
+ dir = os.path.join(repository.directory, cls.__repo_subdir, name)
+ compat_dir = os.path.join(dir, 'patches')
+ if os.path.exists(dir):
+ raise StackException('%s: branch already initialized' % name)
+
+ # create the stack directory and files
+ utils.create_dirs(dir)
+ utils.create_dirs(compat_dir)
+ PatchOrder.create(dir)
+ config.set(stackupgrade.format_version_key(name),
+ str(stackupgrade.FORMAT_VERSION))
+
+ return repository.get_stack(name)
+
+ @classmethod
+ def create(cls, repository, name,
+ create_at = None, parent_remote = None, parent_branch = None):
+ """Create and initialise a Git branch returning the L{Stack} object."""
+ git.Branch.create(repository, name, create_at = create_at)
+ stack = cls.initialise(repository, name)
+ stack.set_parents(parent_remote, parent_branch)
+ return stack
+
class Repository(git.Repository):
"""A git L{Repository<git.Repository>} with some added StGit-specific
operations."""
next prev parent reply other threads:[~2008-06-04 21:30 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-04 21:13 [StGIT PATCH 0/5] Various updates to the new infrastructure Catalin Marinas
2008-06-04 21:13 ` [StGIT PATCH 1/5] Allow stack.patchorder.all to return hidden patches Catalin Marinas
2008-06-05 6:41 ` Karl Hasselström
2008-06-05 11:46 ` Catalin Marinas
2008-06-04 21:13 ` [StGIT PATCH 2/5] Rename Repository.head to Repository.head_ref Catalin Marinas
2008-06-05 6:46 ` Karl Hasselström
2008-06-05 11:49 ` Catalin Marinas
2008-06-05 11:58 ` Karl Hasselström
2008-06-05 12:06 ` Catalin Marinas
2008-06-05 12:46 ` Karl Hasselström
2008-06-04 21:13 ` [StGIT PATCH 3/5] Create a git.Branch class as ancestor of stack.Stack Catalin Marinas
2008-06-05 7:01 ` Karl Hasselström
2008-06-05 12:03 ` Catalin Marinas
2008-06-05 13:04 ` Karl Hasselström
2008-06-06 8:44 ` Catalin Marinas
2008-06-07 9:06 ` Karl Hasselström
2008-06-08 22:16 ` Catalin Marinas
2008-06-09 0:07 ` David Aguilar
2008-06-09 0:46 ` Sverre Rabbelier
2008-06-09 7:07 ` Karl Hasselström
2008-06-04 21:13 ` Catalin Marinas [this message]
2008-06-05 7:28 ` [StGIT PATCH 4/5] Add stack creation and initialisation support to lib.Stack Karl Hasselström
2008-06-05 12:42 ` Catalin Marinas
2008-06-07 8:59 ` Karl Hasselström
2008-06-04 21:13 ` [StGIT PATCH 5/5] Add stack creation and deletion support to the new infrastructure Catalin Marinas
2008-06-05 7:34 ` Karl Hasselström
2008-06-05 9:43 ` Catalin Marinas
2008-06-05 7:38 ` [StGIT PATCH 0/5] Various updates " Karl Hasselström
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=20080604211343.32531.41429.stgit@localhost.localdomain \
--to=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
--cc=kha@treskal.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.