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

[StGIT PATCH] Don't use patches/<branch>/current

From
Karl Hasselström <kha@treskal.com>
Date
May 6, 2007, 15:13 UTC
Message-ID
<20070506150852.8985.98091.stgit@yoghurt>

The name of the current patch, if any, is always the last line of patches/<branch>/applied (and there is no current patch if and only if the "applied" file is empty). So use that instead, and stop having to worry about keeping the redundant "current" file up-to-date.

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

This is another remove-redundant-metadata cleanup patch. Not only does it remove more code than it adds, the removed code (mostly calls to __set_current) is the kind that one easily forgets to insert in the proper places when writing new code.

 stgit/stack.py |   35 +++++++++--------------------------
 1 files changed, 9 insertions(+), 26 deletions(-)
diff --git a/stgit/stack.py b/stgit/stack.py
index 2477ac6..3e9fc4f 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -295,7 +295,6 @@ class Series(StgitObject):
         self.__applied_file = os.path.join(self._dir(), 'applied')
         self.__unapplied_file = os.path.join(self._dir(), 'unapplied')
         self.__hidden_file = os.path.join(self._dir(), 'hidden')
-        self.__current_file = os.path.join(self._dir(), 'current')
         self.__descr_file = os.path.join(self._dir(), 'description')
 
         # where this series keeps its patches
@@ -325,11 +324,6 @@ class Series(StgitObject):
         """
         return self.__name
 
-    def __set_current(self, name):
-        """Sets the topmost patch
-        """
-        self._set_field('current', name)
-
     def get_patch(self, name):
         """Return a Patch object for the given name
         """
@@ -346,11 +340,16 @@ class Series(StgitObject):
     def get_current(self):
         """Return the name of the topmost patch, or None if there is
         no such patch."""
-        name = self._get_field('current')
-        if name == '':
+        try:
+            applied = self.get_applied()
+        except StackException:
+            # No "applied" file: branch is not initialized.
+            return None
+        try:
+            return applied[-1]
+        except IndexError:
+            # No patches applied.
             return None
-        else:
-            return name
 
     def get_applied(self):
         if not os.path.isfile(self.__applied_file):
@@ -650,8 +649,6 @@ class Series(StgitObject):
                 os.remove(self.__unapplied_file)
             if os.path.exists(self.__hidden_file):
                 os.remove(self.__hidden_file)
-            if os.path.exists(self.__current_file):
-                os.remove(self.__current_file)
             if os.path.exists(self.__descr_file):
                 os.remove(self.__descr_file)
             if os.path.exists(self._dir()+'/orig-base'):
@@ -825,11 +822,8 @@ class Series(StgitObject):
             self.log_patch(patch, 'new')
 
             insert_string(self.__applied_file, patch.get_name())
-            if not self.get_current():
-                self.__set_current(name)
         else:
             append_string(self.__applied_file, patch.get_name())
-            self.__set_current(name)
             if refresh:
                 self.refresh_patch(cache_update = False, log = 'new')
 
@@ -936,8 +930,6 @@ class Series(StgitObject):
         f.writelines([line + '\n' for line in unapplied])
         f.close()
 
-        self.__set_current(name)
-
         return forwarded
 
     def merged_patches(self, names):
@@ -1019,8 +1011,6 @@ class Series(StgitObject):
         f.writelines([line + '\n' for line in unapplied])
         f.close()
 
-        self.__set_current(name)
-
         # head == bottom case doesn't need to refresh the patch
         if empty or head != bottom:
             if not ex:
@@ -1098,11 +1088,6 @@ class Series(StgitObject):
         f.writelines([line + '\n' for line in applied])
         f.close()
 
-        if applied == []:
-            self.__set_current(None)
-        else:
-            self.__set_current(applied[-1])
-
     def empty_patch(self, name):
         """Returns True if the patch is empty
         """
@@ -1144,8 +1129,6 @@ class Series(StgitObject):
             f.close()
         elif oldname in applied:
             Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname)
-            if oldname == self.get_current():
-                self.__set_current(newname)
 
             applied[applied.index(oldname)] = newname
 
Next: Catalin Marinas
Message 1 of 36 in “Don't use patches/<branch>/current”
  1. Don't use patches/<branch>/currentKarl Hasselström, May 6, 2007
  2. Catalin MarinasMay 15, 2007
  3. Peter OberndorferMay 15, 2007
  4. Catalin MarinasMay 15, 2007
  5. Karl HasselströmMay 15, 2007
  6. Remove obsolete files when deleting a branchKarl Hasselström, May 15, 2007
  7. Catalin MarinasMay 15, 2007
  8. Karl HasselströmMay 16, 2007
  9. Catalin MarinasMay 16, 2007
  10. Karl HasselströmMay 16, 2007
  11. Karl HasselströmMay 16, 2007
  12. Catalin MarinasMay 17, 2007
  13. Karl HasselströmMay 17, 2007
  14. Catalin MarinasMay 17, 2007
  15. Karl HasselströmMay 18, 2007
  16. 0/6 New and improved DAG appliedness seriesKarl Hasselström, Jun 10, 2007
  17. 1/6 Verify patch status during the testKarl Hasselström, Jun 10, 2007
  18. 2/6 Make use of the get_patch() utility functionKarl Hasselström, Jun 10, 2007
  19. 3/6 Compute patch appliedness from commit DAGKarl Hasselström, Jun 10, 2007
  20. 4/6 Test the new DAG appliedness machineryKarl Hasselström, Jun 10, 2007
  21. 5/6 Fix bash completion after the DAG appliedness patchKarl Hasselström, Jun 10, 2007
  22. 6/6 Speed up the appliedness testKarl Hasselström, Jun 10, 2007
  23. Yann DirsonJun 30, 2007
  24. Karl HasselströmJul 1, 2007
  25. Yann DirsonMay 15, 2007
  26. Catalin MarinasMay 15, 2007
  27. Yann DirsonMay 15, 2007
  28. Karl HasselströmMay 16, 2007
  29. 0/5 Metadata format versioningKarl Hasselström, May 19, 2007
  30. 1/5 Fix config caching so that get, set, get worksKarl Hasselström, May 19, 2007
  31. 2/5 Have only a single command in each test_expect_failureKarl Hasselström, May 19, 2007
  32. 3/5 Upgrade old StGIT branches to new-format metadataKarl Hasselström, May 19, 2007
  33. 4/5 Test the format version upgrade codeKarl Hasselström, May 19, 2007
  34. 5/5 Add --binary flag to commands that generate diffsKarl Hasselström, May 19, 2007
  35. Catalin MarinasMay 22, 2007
  36. Karl HasselströmMay 22, 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.