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

[StGit PATCH 2/5] Write metadata files used by the old infrastructure

From
Karl Hasselström <kha@treskal.com>
Date
Nov 5, 2007, 03:14 UTC
Message-ID
<20071105031442.6108.19781.stgit@yoghurt>
In-Reply-To
<20071105030847.6108.44653.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 |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/stgit/lib/stack.py b/stgit/lib/stack.py
index b4d99ba..ce514d6 100644
--- a/stgit/lib/stack.py
+++ b/stgit/lib/stack.py
@@ -9,10 +9,45 @@ class Patch(object):
     name = property(lambda self: self.__name)
     def __ref(self):
         return 'refs/patches/%s/%s' % (self.__stack.name, self.__name)
+    def __log_ref(self):
+        return self.__ref() + '.log'
     @property
     def commit(self):
         return self.__stack.repository.refs.get(self.__ref())
+    def __write_compat_files(self, new_commit, msg):
+        """Write files used by the old infrastructure."""
+        fdir = os.path.join(self.__stack.directory, 'patches', self.__name)
+        def write(name, val, multiline = False):
+            fn = os.path.join(fdir, 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 set_commit(self, 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())
Previous: Karl HasselströmNext: Karl Hasselström
Message 3 of 6 in “Start the refactoring”
  1. 0/5 Start the refactoringKarl Hasselström, Nov 5, 2007
  2. 1/5 New StGit core infrastructure: repository operationsKarl Hasselström, Nov 5, 2007
  3. 2/5 Write metadata files used by the old infrastructureKarl Hasselström, Nov 5, 2007
  4. 3/5 Simple test for "stg clean"Karl Hasselström, Nov 5, 2007
  5. 4/5 Let "stg clean" use the new infrastructureKarl Hasselström, Nov 5, 2007
  6. 5/5 Add "stg coalesce"Karl Hasselström, Nov 5, 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.