def new_patch(self, name, message = None, can_edit = True,
unapplied = False, show_patch = False,
- top = None, bottom = None,
+ top = None, bottom = None, commit = True,
author_name = None, author_email = None, author_date = None,
committer_name = None, committer_email = None,
- before_existing = False, refresh = True):
+ before_existing = False):
"""Creates a new patch
"""
patch = Patch(name, self.__patch_dir, self.__refs_dir)
patch.create()
- if bottom:
- patch.set_bottom(bottom)
- else:
- patch.set_bottom(head)
- if top:
- patch.set_top(top)
- else:
- patch.set_top(head)
+ if not bottom:
+ bottom = head
+ if not top:
+ top = head
+ patch.set_bottom(bottom)
+ patch.set_top(top)
patch.set_description(descr)
patch.set_authname(author_name)
patch.set_authemail(author_email)
patch.set_commname(committer_name)
patch.set_commemail(committer_email)
- if unapplied:
- self.log_patch(patch, 'new')
-
+ if before_existing:
+ insert_string(self.__applied_file, patch.get_name())
+ # no need to commit anything as the object is already
+ # present (mainly used by 'uncommit')
+ commit = False
+ elif unapplied:
patches = [patch.get_name()] + self.get_unapplied()
write_strings(self.__unapplied_file, patches)
- elif before_existing:
- self.log_patch(patch, 'new')
-
- insert_string(self.__applied_file, patch.get_name())
+ set_head = False
else:
append_string(self.__applied_file, patch.get_name())
- if refresh:
- self.refresh_patch(cache_update = False, log = 'new')
+ set_head = True
+
+ if commit:
+ # create a commit for the patch (may be empty if top == bottom);
+ # only commit on top of the current branch
+ assert(unapplied or bottom == head)
+ top_commit = git.get_commit(top)
+ commit_id = git.commit(message = descr, parents = [bottom],
+ cache_update = False,
+ tree_id = top_commit.get_tree(),
+ allowempty = True, set_head = set_head,
+ author_name = author_name,
+ author_email = author_email,
+ author_date = author_date,
+ committer_name = committer_name,
+ committer_email = committer_email)
+ # set the patch top to the new commit
+ patch.set_top(commit_id)
+
+ self.log_patch(patch, 'new')
return patch
"""Generate a log commit for a patch
"""
top = git.get_commit(patch.get_top())
- msg = '%s\t%s' % (message, top.get_id_hash())
- if notes:
- msg += '\n\n' + notes
-
old_log = patch.get_log()
- if old_log:
- parents = [old_log]
+
+ if message is None:
+ # replace the current log entry
+ if not old_log:
+ raise StackException, \
+ 'No log entry to annotate for patch "%s"' \
+ % patch.get_name()
+ replace = True
+ log_commit = git.get_commit(old_log)
+ msg = log_commit.get_log().split('\n')[0]
+ log_parent = log_commit.get_parent()
+ if log_parent:
+ parents = [log_parent]
+ else:
+ parents = []
else:
- parents = []
+ # generate a new log entry
+ replace = False
+ msg = '%s\t%s' % (message, top.get_id_hash())
+ if old_log:
+ parents = [old_log]
+ else:
+ parents = []
+
+ if notes:
+ msg += '\n\n' + notes
log = git.commit(message = msg, parents = parents,
cache_update = False, tree_id = top.get_tree(),