X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/e45af3d4a0faa3f7c46a0a2a9647ad09f1ba8720..ed0350be88dca8315cf7b32e88972306aae4f700:/stgit/stack.py diff --git a/stgit/stack.py b/stgit/stack.py index 93a3d4e..8fa3846 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -332,6 +332,11 @@ class Series: for patch in self.get_applied() + self.get_unapplied(): self.get_patch(patch).update_top_ref() + # trash directory + self.__trash_dir = os.path.join(self.__series_dir, 'trash') + if self.is_initialised() and not os.path.isdir(self.__trash_dir): + os.makedirs(self.__trash_dir) + def get_branch(self): """Return the branch name for the Series object """ @@ -350,9 +355,17 @@ class Series: """ return Patch(name, self.__patch_dir, self.__refs_dir) + def get_current_patch(self): + """Return a Patch object representing the topmost patch, or + None if there is no such patch.""" + crt = self.get_current() + if not crt: + return None + return Patch(crt, self.__patch_dir, self.__refs_dir) + def get_current(self): - """Return a Patch object representing the topmost patch - """ + """Return the name of the topmost patch, or None if there is + no such patch.""" if os.path.isfile(self.__current_file): name = read_string(self.__current_file) else: @@ -404,16 +417,21 @@ class Series: def __patch_is_current(self, patch): return patch.get_name() == read_string(self.__current_file) - def __patch_applied(self, name): + def patch_applied(self, name): """Return true if the patch exists in the applied list """ return name in self.get_applied() - def __patch_unapplied(self, name): + def patch_unapplied(self, name): """Return true if the patch exists in the unapplied list """ return name in self.get_unapplied() + def patch_exists(self, name): + """Return true if there is a patch with the given name, false + otherwise.""" + return self.patch_applied(name) or self.patch_unapplied(name) + def __begin_stack_check(self): """Save the current HEAD into .git/refs/heads/base if the stack is empty @@ -433,12 +451,11 @@ class Series: def head_top_equal(self): """Return true if the head and the top are the same """ - crt = self.get_current() + crt = self.get_current_patch() if not crt: # we don't care, no patches applied return True - return git.get_head() == Patch(crt, self.__patch_dir, - self.__refs_dir).get_top() + return git.get_head() == crt.get_top() def is_initialised(self): """Checks if series is already initialised @@ -568,6 +585,11 @@ class Series: for p in patches: Patch(p, self.__patch_dir, self.__refs_dir).delete() + # remove the trash directory + for fname in os.listdir(self.__trash_dir): + os.remove(fname) + os.rmdir(self.__trash_dir) + if os.path.exists(self.__applied_file): os.remove(self.__applied_file) if os.path.exists(self.__unapplied_file): @@ -688,10 +710,10 @@ class Series: top = None, bottom = None, author_name = None, author_email = None, author_date = None, committer_name = None, committer_email = None, - before_existing = False): + before_existing = False, refresh = True): """Creates a new patch """ - if self.__patch_applied(name) or self.__patch_unapplied(name): + if self.patch_applied(name) or self.patch_unapplied(name): raise StackException, 'Patch "%s" already exists' % name if not message and can_edit: @@ -741,8 +763,8 @@ class Series: else: append_string(self.__applied_file, patch.get_name()) self.__set_current(name) - - self.refresh_patch(cache_update = False, log = 'new') + if refresh: + self.refresh_patch(cache_update = False, log = 'new') def delete_patch(self, name): """Deletes a patch @@ -751,12 +773,15 @@ class Series: if self.__patch_is_current(patch): self.pop_patch(name) - elif self.__patch_applied(name): + elif self.patch_applied(name): raise StackException, 'Cannot remove an applied patch, "%s", ' \ 'which is not current' % name elif not name in self.get_unapplied(): raise StackException, 'Unknown patch "%s"' % name + # save the commit id to a trash file + write_string(os.path.join(self.__trash_dir, name), patch.get_top()) + patch.delete() unapplied = self.get_unapplied()