+ def convert(self):
+ """Either convert to use a separate patch directory, or
+ unconvert to place the patches in the same directory with
+ series control files
+ """
+ if self.__patch_dir == self.__series_dir:
+ print 'Converting old-style to new-style...',
+ sys.stdout.flush()
+
+ self.__patch_dir = os.path.join(self.__series_dir, 'patches')
+ os.makedirs(self.__patch_dir)
+
+ for p in self.get_applied() + self.get_unapplied():
+ src = os.path.join(self.__series_dir, p)
+ dest = os.path.join(self.__patch_dir, p)
+ os.rename(src, dest)
+
+ print 'done'
+
+ else:
+ print 'Converting new-style to old-style...',
+ sys.stdout.flush()
+
+ for p in self.get_applied() + self.get_unapplied():
+ src = os.path.join(self.__patch_dir, p)
+ dest = os.path.join(self.__series_dir, p)
+ os.rename(src, dest)
+
+ if not os.listdir(self.__patch_dir):
+ os.rmdir(self.__patch_dir)
+ print 'done'
+ else:
+ print 'Patch directory %s is not empty.' % self.__name
+
+ self.__patch_dir = self.__series_dir
+
+ def rename(self, to_name):
+ """Renames a series
+ """
+ to_stack = Series(to_name)
+
+ if to_stack.is_initialised():
+ raise StackException, '"%s" already exists' % to_stack.get_branch()
+ if os.path.exists(to_stack.__base_file):
+ os.remove(to_stack.__base_file)
+
+ git.rename_branch(self.__name, to_name)
+
+ if os.path.isdir(self.__series_dir):
+ rename(os.path.join(self.__base_dir, 'patches'),
+ self.__name, to_stack.__name)
+ if os.path.exists(self.__base_file):
+ rename(os.path.join(self.__base_dir, 'refs', 'bases'),
+ self.__name, to_stack.__name)
+ if os.path.exists(self.__refs_dir):
+ rename(os.path.join(self.__base_dir, 'refs', 'patches'),
+ self.__name, to_stack.__name)
+
+ self.__init__(to_name)
+
+ def clone(self, target_series):
+ """Clones a series
+ """
+ base = read_string(self.get_base_file())
+ Series(target_series).init(create_at = base)
+ new_series = Series(target_series)
+
+ # generate an artificial description file
+ write_string(new_series.__descr_file, 'clone of "%s"' % self.__name)
+
+ # clone self's entire series as unapplied patches
+ patches = self.get_applied() + self.get_unapplied()
+ patches.reverse()
+ for p in patches:
+ patch = self.get_patch(p)
+ new_series.new_patch(p, message = patch.get_description(),
+ can_edit = False, unapplied = True,
+ bottom = patch.get_bottom(),
+ top = patch.get_top(),
+ author_name = patch.get_authname(),
+ author_email = patch.get_authemail(),
+ author_date = patch.get_authdate())
+
+ # fast forward the cloned series to self's top
+ new_series.forward_patches(self.get_applied())
+
+ def delete(self, force = False):
+ """Deletes an stgit series
+ """
+ if self.is_initialised():
+ patches = self.get_unapplied() + self.get_applied()
+ if not force and patches:
+ raise StackException, \
+ 'Cannot delete: the series still contains patches'
+ 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):
+ os.remove(self.__unapplied_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 not os.listdir(self.__patch_dir):
+ os.rmdir(self.__patch_dir)
+ else:
+ print 'Patch directory %s is not empty.' % self.__name
+ if not os.listdir(self.__series_dir):
+ remove_dirs(os.path.join(self.__base_dir, 'patches'),
+ self.__name)
+ else:
+ print 'Series directory %s is not empty.' % self.__name
+ if not os.listdir(self.__refs_dir):
+ remove_dirs(os.path.join(self.__base_dir, 'refs', 'patches'),
+ self.__name)
+ else:
+ print 'Refs directory %s is not empty.' % self.__refs_dir
+
+ if os.path.exists(self.__base_file):
+ remove_file_and_dirs(
+ os.path.join(self.__base_dir, 'refs', 'bases'), self.__name)
+
+ def refresh_patch(self, files = None, message = None, edit = False,
+ show_patch = False,