Subject: [StGIT PATCH] Store branch description in the config file

From: Karl Hasselström <[email-masked]>
Date: Mon, 14 May 2007 21:28:10 +0200

Instead of storing the branch description in an StGIT-specific file,
store it in the git config file, where tools other than StGIT can read
and write it.

Signed-off-by: Karl Hasselström <[email-masked]>
---

On 2007-05-12 12:27:49 -0700, Junio C Hamano wrote:

> Will it be something like
>
>       [branch "master"]
>               description = "My primary development line"

This was easier to do than I'd thought. I don't get quotes around the
description, though; do I have to insert them manually? And what
purpose do they serve?

 stgit/stack.py |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/stgit/stack.py b/stgit/stack.py
index c105b21..7048af7 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -451,7 +451,6 @@ class Series(StgitObject):
                                        self.__name)
 
         self.__hidden_file = os.path.join(self._dir(), 'hidden')
-        self.__descr_file = os.path.join(self._dir(), 'description')
 
         # where this series keeps its patches
         self.__patch_dir = os.path.join(self._dir(), 'patches')
@@ -550,11 +549,23 @@ class Series(StgitObject):
         if os.path.isfile(protect_file):
             os.remove(protect_file)
 
+    def __branch_descr(self):
+        return 'branch.%s.description' % self.get_branch()
+
     def get_description(self):
-        return self._get_field('description') or ''
+        # Fall back to the .git/patches/<branch>/description file if
+        # the config variable is unset.
+        return (config.get(self.__branch_descr())
+                or self._get_field('description') or '')
 
     def set_description(self, line):
-        self._set_field('description', line)
+        if line:
+            config.set(self.__branch_descr(), line)
+        else:
+            config.unset(self.__branch_descr())
+        # Delete the old .git/patches/<branch>/description file if it
+        # exists.
+        self._set_field('description', None)
 
     def get_parent_remote(self):
         value = config.get('branch.%s.remote' % self.__name)
@@ -787,8 +798,6 @@ class Series(StgitObject):
             # (move functionality to StgitObject ?)
             if os.path.exists(self.__hidden_file):
                 os.remove(self.__hidden_file)
-            if os.path.exists(self.__descr_file):
-                os.remove(self.__descr_file)
             if os.path.exists(self._dir()+'/orig-base'):
                 os.remove(self._dir()+'/orig-base')