X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/0f4eba6a37c1a5454560b097873e5a22bfcde908..8866fedad702f33cbeaf83d18ab120f3a76922f5:/stgit/stack.py diff --git a/stgit/stack.py b/stgit/stack.py index 2ae4dd5..dbdda01 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -92,8 +92,9 @@ def edit_file(series, line, comment, show_patch = True): f.close() # the editor - if config.has_option('stgit', 'editor'): - editor = config.get('stgit', 'editor') + editor = config.get('stgit.editor') + if editor: + pass elif 'EDITOR' in os.environ: editor = os.environ['EDITOR'] else: @@ -307,6 +308,7 @@ 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') @@ -374,6 +376,14 @@ class Series(StgitObject): f.close() return names + def get_hidden(self): + if not os.path.isfile(self.__hidden_file): + return [] + f = file(self.__hidden_file) + names = [line.strip() for line in f.readlines()] + f.close() + return names + def get_base_file(self): self.__begin_stack_check() return self.__base_file @@ -397,6 +407,32 @@ class Series(StgitObject): def set_description(self, line): self._set_field('description', line) + def get_parent_remote(self): + return config.get('branch.%s.remote' % self.__name) or 'origin' + + def __set_parent_remote(self, remote): + value = config.set('branch.%s.remote' % self.__name, remote) + + def get_parent_branch(self): + value = config.get('branch.%s.merge' % self.__name) + if value: + return value + elif git.rev_parse('heads/origin'): + return 'heads/origin' + else: + raise StackException, 'Cannot find a parent branch for "%s"' % self.__name + + def __set_parent_branch(self, name): + config.set('branch.%s.merge' % self.__name, name) + + def set_parent(self, remote, localbranch): + if localbranch: + self.__set_parent_branch(localbranch) + if remote: + self.__set_parent_remote(remote) + elif remote: + raise StackException, 'Remote "%s" without a branch cannot be used as parent' % remote + def __patch_is_current(self, patch): return patch.get_name() == self.get_current() @@ -410,6 +446,11 @@ class Series(StgitObject): """ return name in self.get_unapplied() + def patch_hidden(self, name): + """Return true if the patch is hidden. + """ + return name in self.get_hidden() + def patch_exists(self, name): """Return true if there is a patch with the given name, false otherwise.""" @@ -445,7 +486,7 @@ class Series(StgitObject): """ return os.path.isdir(self.__patch_dir) - def init(self, create_at=False): + def init(self, create_at=False, parent_remote=None, parent_branch=None): """Initialises the stgit series """ bases_dir = os.path.join(self.__base_dir, 'refs', 'bases') @@ -462,6 +503,8 @@ class Series(StgitObject): os.makedirs(self.__patch_dir) + self.set_parent(parent_remote, parent_branch) + create_dirs(bases_dir) self.create_empty_field('applied') @@ -589,6 +632,8 @@ class Series(StgitObject): os.remove(self.__applied_file) if os.path.exists(self.__unapplied_file): 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): @@ -784,6 +829,10 @@ class Series(StgitObject): f = file(self.__unapplied_file, 'w+') f.writelines([line + '\n' for line in unapplied]) f.close() + + if self.patch_hidden(name): + self.unhide_patch(name) + self.__begin_stack_check() def forward_patches(self, names): @@ -1057,6 +1106,10 @@ class Series(StgitObject): if newname in applied or newname in unapplied: raise StackException, 'Patch "%s" already exists' % newname + if self.patch_hidden(oldname): + self.unhide_patch(oldname) + self.hide_patch(newname) + if oldname in unapplied: Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname) unapplied[unapplied.index(oldname)] = newname @@ -1093,3 +1146,28 @@ class Series(StgitObject): cache_update = False, tree_id = top.get_tree(), allowempty = True) patch.set_log(log) + + def hide_patch(self, name): + """Add the patch to the hidden list. + """ + if not self.patch_exists(name): + raise StackException, 'Unknown patch "%s"' % name + elif self.patch_hidden(name): + raise StackException, 'Patch "%s" already hidden' % name + + append_string(self.__hidden_file, name) + + def unhide_patch(self, name): + """Add the patch to the hidden list. + """ + if not self.patch_exists(name): + raise StackException, 'Unknown patch "%s"' % name + hidden = self.get_hidden() + if not name in hidden: + raise StackException, 'Patch "%s" not hidden' % name + + hidden.remove(name) + + f = file(self.__hidden_file, 'w+') + f.writelines([line + '\n' for line in hidden]) + f.close()