X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/2b4b9c29d1bc5d98eafdfdc82b99b57ebd4298d0..edf4f599dcc78b741df36bf835cc14a1e0bafedb:/stgit/stack.py diff --git a/stgit/stack.py b/stgit/stack.py index 9ccbb1e..165b5a7 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -629,7 +629,8 @@ class Series: unapplied = False, show_patch = False, top = None, bottom = None, author_name = None, author_email = None, author_date = None, - committer_name = None, committer_email = None): + committer_name = None, committer_email = None, + before_existing = False): """Creates a new patch """ if self.__patch_applied(name) or self.__patch_unapplied(name): @@ -672,8 +673,13 @@ class Series: f.writelines([line + '\n' for line in patches]) f.close() else: - append_string(self.__applied_file, patch.get_name()) - self.__set_current(name) + if before_existing: + 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) def delete_patch(self, name): """Deletes a patch @@ -774,7 +780,27 @@ class Series: return forwarded - def push_patch(self, name): + def merged_patches(self, names): + """Test which patches were merged upstream by reverse-applying + them in reverse order. The function returns the list of + patches detected to have been applied. The state of the tree + is restored to the original one + """ + patches = [Patch(name, self.__patch_dir, self.__refs_dir) + for name in names] + patches.reverse() + + merged = [] + for p in patches: + if git.apply_diff(p.get_top(), p.get_bottom(), False): + merged.append(p.get_name()) + merged.reverse() + + git.reset() + + return merged + + def push_patch(self, name, empty = False): """Pushes a patch on the stack """ unapplied = self.get_unapplied() @@ -792,7 +818,15 @@ class Series: modified = False # top != bottom always since we have a commit for each patch - if head == bottom: + if empty: + # just make an empty patch (top = bottom = HEAD). This + # option is useful to allow undoing already merged + # patches. The top is updated by refresh_patch since we + # need an empty commit + patch.set_bottom(head, backup = True) + patch.set_top(head, backup = True) + modified = True + elif head == bottom: # reset the backup information patch.set_bottom(bottom, backup = True) patch.set_top(top, backup = True) @@ -829,7 +863,7 @@ class Series: self.__set_current(name) # head == bottom case doesn't need to refresh the patch - if head != bottom: + if empty or head != bottom: if not ex: # if the merge was OK and no conflicts, just refresh the patch # The GIT cache was already updated by the merge operation