All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org, "David Kågedal" <davidk@lysator.liu.se>
Subject: [StGit PATCH 02/10] Write metadata files used by the old infrastructure
Date: Sun, 25 Nov 2007 21:51:06 +0100	[thread overview]
Message-ID: <20071125205105.7823.50417.stgit@yoghurt> (raw)
In-Reply-To: <20071125203717.7823.70046.stgit@yoghurt>

The new infrastructure doesn't use them, but they're needed to support
the old infrastructure during the transition when both of them are in
use.

Signed-off-by: Karl Hasselström <kha@treskal.com>

---

 stgit/lib/stack.py |   52 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 49 insertions(+), 3 deletions(-)


diff --git a/stgit/lib/stack.py b/stgit/lib/stack.py
index d5bd488..5a34592 100644
--- a/stgit/lib/stack.py
+++ b/stgit/lib/stack.py
@@ -7,15 +7,61 @@ class Patch(object):
         self.__stack = stack
         self.__name = name
     name = property(lambda self: self.__name)
+    @property
     def __ref(self):
         return 'refs/patches/%s/%s' % (self.__stack.name, self.__name)
     @property
+    def __log_ref(self):
+        return self.__ref + '.log'
+    @property
     def commit(self):
-        return self.__stack.repository.refs.get(self.__ref())
+        return self.__stack.repository.refs.get(self.__ref)
+    @property
+    def __compat_dir(self):
+        return os.path.join(self.__stack.directory, 'patches', self.__name)
+    def __write_compat_files(self, new_commit, msg):
+        """Write files used by the old infrastructure."""
+        def write(name, val, multiline = False):
+            fn = os.path.join(self.__compat_dir, name)
+            if val:
+                utils.write_string(fn, val, multiline)
+            elif os.path.isfile(fn):
+                os.remove(fn)
+        def write_patchlog():
+            try:
+                old_log = [self.__stack.repository.refs.get(self.__log_ref)]
+            except KeyError:
+                old_log = []
+            cd = git.Commitdata(tree = new_commit.data.tree, parents = old_log,
+                                message = '%s\t%s' % (msg, new_commit.sha1))
+            c = self.__stack.repository.commit(cd)
+            self.__stack.repository.refs.set(self.__log_ref, c, msg)
+            return c
+        d = new_commit.data
+        write('authname', d.author.name)
+        write('authemail', d.author.email)
+        write('authdate', d.author.date)
+        write('commname', d.committer.name)
+        write('commemail', d.committer.email)
+        write('description', d.message)
+        write('log', write_patchlog().sha1)
+        try:
+            old_commit_sha1 = self.commit
+        except KeyError:
+            old_commit_sha1 = None
+        write('top.old', old_commit_sha1)
+    def __delete_compat_files(self):
+        if os.path.isdir(self.__compat_dir):
+            for f in os.listdir(self.__compat_dir):
+                os.remove(os.path.join(self.__compat_dir, f))
+            os.rmdir(self.__compat_dir)
+        self.__stack.repository.refs.delete(self.__log_ref)
     def set_commit(self, commit, msg):
-        self.__stack.repository.refs.set(self.__ref(), commit, msg)
+        self.__write_compat_files(commit, msg)
+        self.__stack.repository.refs.set(self.__ref, commit, msg)
     def delete(self):
-        self.__stack.repository.refs.delete(self.__ref())
+        self.__delete_compat_files()
+        self.__stack.repository.refs.delete(self.__ref)
     def is_applied(self):
         return self.name in self.__stack.patchorder.applied
     def is_empty(self):

  parent reply	other threads:[~2007-11-25 20:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-25 20:50 [StGit PATCH 00/10] Infrastructure rewrite series Karl Hasselström
2007-11-25 20:51 ` [StGit PATCH 01/10] New StGit core infrastructure: repository operations Karl Hasselström
2007-11-25 20:51 ` Karl Hasselström [this message]
2007-11-25 20:51 ` [StGit PATCH 03/10] Upgrade older stacks to newest version Karl Hasselström
2007-11-25 20:51 ` [StGit PATCH 04/10] Let "stg clean" use the new infrastructure Karl Hasselström
2007-11-25 20:51 ` [StGit PATCH 05/10] Add "stg coalesce" Karl Hasselström
2007-11-25 20:51 ` [StGit PATCH 06/10] Let "stg applied" and "stg unapplied" use the new infrastructure Karl Hasselström
2007-11-25 20:51 ` [StGit PATCH 07/10] Teach the new infrastructure about the index and worktree Karl Hasselström
2007-11-26  8:31   ` Karl Hasselström
2007-11-26  8:56   ` David Kågedal
2007-11-26 10:44     ` Karl Hasselström
2007-11-25 20:51 ` [StGit PATCH 08/10] Let "stg clean" use the new transaction primitives Karl Hasselström
2007-11-25 20:51 ` [StGit PATCH 09/10] Let "stg goto" use the new infrastructure Karl Hasselström
2007-11-25 20:51 ` [StGit PATCH 10/10] Convert "stg uncommit" to " 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=20071125205105.7823.50417.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@gmail.com \
    --cc=davidk@lysator.liu.se \
    --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 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.