From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGIT PATCH] Don't use patches/<branch>/current
Date: Sun, 06 May 2007 17:13:44 +0200 [thread overview]
Message-ID: <20070506150852.8985.98091.stgit@yoghurt> (raw)
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 reply other threads:[~2007-05-06 15:16 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-06 15:13 Karl Hasselström [this message]
2007-05-15 15:56 ` [StGIT PATCH] Don't use patches/<branch>/current Catalin Marinas
2007-05-15 16:21 ` Peter Oberndorfer
2007-05-15 16:50 ` Catalin Marinas
2007-05-15 18:25 ` Karl Hasselström
2007-05-15 19:38 ` [StGIT PATCH] Remove obsolete files when deleting a branch Karl Hasselström
2007-05-15 20:01 ` [StGIT PATCH] Don't use patches/<branch>/current Catalin Marinas
2007-05-16 7:11 ` Karl Hasselström
2007-05-16 12:07 ` Catalin Marinas
2007-05-16 19:40 ` Karl Hasselström
2007-05-16 20:40 ` Karl Hasselström
2007-05-17 12:43 ` Catalin Marinas
2007-05-17 14:57 ` Karl Hasselström
2007-05-17 20:51 ` Catalin Marinas
2007-05-18 6:30 ` Karl Hasselström
2007-06-10 9:54 ` [StGIT PATCH 0/6] New and improved DAG appliedness series Karl Hasselström
2007-06-10 9:54 ` [StGIT PATCH 1/6] Verify patch status during the test Karl Hasselström
2007-06-10 9:55 ` [StGIT PATCH 2/6] Make use of the get_patch() utility function Karl Hasselström
2007-06-10 9:55 ` [StGIT PATCH 3/6] Compute patch appliedness from commit DAG Karl Hasselström
2007-06-10 9:55 ` [StGIT PATCH 4/6] Test the new DAG appliedness machinery Karl Hasselström
2007-06-10 9:55 ` [StGIT PATCH 5/6] Fix bash completion after the DAG appliedness patch Karl Hasselström
2007-06-10 9:55 ` [StGIT PATCH 6/6] Speed up the appliedness test Karl Hasselström
2007-06-30 19:54 ` [StGIT PATCH 0/6] New and improved DAG appliedness series Yann Dirson
2007-07-01 14:35 ` Karl Hasselström
2007-05-15 21:08 ` [StGIT PATCH] Don't use patches/<branch>/current Yann Dirson
2007-05-15 21:36 ` Catalin Marinas
2007-05-15 21:49 ` Yann Dirson
2007-05-16 6:27 ` Karl Hasselström
2007-05-19 0:09 ` [StGIT PATCH 0/5] Metadata format versioning Karl Hasselström
2007-05-19 0:09 ` [StGIT PATCH 1/5] Fix config caching so that get, set, get works Karl Hasselström
2007-05-19 0:09 ` [StGIT PATCH 2/5] Have only a single command in each test_expect_failure Karl Hasselström
2007-05-19 0:10 ` [StGIT PATCH 3/5] Upgrade old StGIT branches to new-format metadata Karl Hasselström
2007-05-19 0:10 ` [StGIT PATCH 4/5] Test the format version upgrade code Karl Hasselström
2007-05-19 0:10 ` [StGIT PATCH 5/5] Add --binary flag to commands that generate diffs Karl Hasselström
2007-05-22 12:15 ` Catalin Marinas
2007-05-22 13:31 ` Karl Hasselström
2007-05-20 20:03 ` [StGit PATCH 0/2] Bash prompt updates Robin Rosenberg
2007-05-20 20:04 ` [StGit PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current' Robin Rosenberg
2007-05-20 20:46 ` Yann Dirson
2007-05-20 21:22 ` [PATCH " Robin Rosenberg
2007-05-21 7:48 ` Karl Hasselström
2007-05-21 9:31 ` Catalin Marinas
2007-05-21 10:15 ` Karl Hasselström
2007-05-21 11:39 ` Karl Hasselström
2007-05-21 15:17 ` Catalin Marinas
2007-05-21 15:39 ` Karl Hasselström
2007-05-22 12:11 ` Catalin Marinas
2007-05-22 13:29 ` Karl Hasselström
2007-05-21 18:57 ` Yann Dirson
2007-05-20 21:24 ` [PATCH 2/2] Don't use / as separatar since it is common i branch names Robin Rosenberg
2007-05-20 20:04 ` [StGit PATCH " Robin Rosenberg
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=20070506150852.8985.98091.stgit@yoghurt \
--to=kha@treskal.com \
--cc=catalin.marinas@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).