+ self.set_parent(parent_remote, parent_branch)
+
+ self.create_empty_field('applied')
+ self.create_empty_field('unapplied')
+ self.create_empty_field('description')
+ os.makedirs(os.path.join(self._dir(), 'patches'))
+ os.makedirs(self.__refs_dir)
+ self._set_field('orig-base', git.get_head())
+
+ 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._dir():
+ print 'Converting old-style to new-style...',
+ sys.stdout.flush()
+
+ self.__patch_dir = os.path.join(self._dir(), 'patches')
+ os.makedirs(self.__patch_dir)
+
+ for p in self.get_applied() + self.get_unapplied():
+ src = os.path.join(self._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._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.__patch_dir
+
+ self.__patch_dir = self._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()
+
+ git.rename_branch(self.__name, to_name)
+
+ if os.path.isdir(self._dir()):
+ rename(os.path.join(self.__base_dir, 'patches'),
+ 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)
+
+ # Rename the config section
+ config.rename_section("branch.%s" % self.__name,
+ "branch.%s" % to_name)
+
+ self.__init__(to_name)
+
+ def clone(self, target_series):
+ """Clones a series
+ """
+ try:
+ # allow cloning of branches not under StGIT control
+ base = self.get_base()
+ except:
+ base = git.get_head()
+ Series(target_series).init(create_at = base)
+ new_series = Series(target_series)
+
+ # generate an artificial description file
+ new_series.set_description('clone of "%s"' % self.__name)
+
+ # clone self's entire series as unapplied patches
+ try:
+ # allow cloning of branches not under StGIT control
+ applied = self.get_applied()
+ unapplied = self.get_unapplied()
+ patches = applied + unapplied
+ patches.reverse()
+ except:
+ patches = applied = unapplied = []
+ for p in patches:
+ patch = self.get_patch(p)
+ newpatch = 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())
+ if patch.get_log():
+ print "setting log to %s" % patch.get_log()
+ newpatch.set_log(patch.get_log())
+ else:
+ print "no log for %s" % patchname
+
+ # fast forward the cloned series to self's top
+ new_series.forward_patches(applied)
+
+ # Clone parent informations
+ value = config.get('branch.%s.remote' % self.__name)
+ if value:
+ config.set('branch.%s.remote' % target_series, value)