From: Catalin Marinas Date: Mon, 16 Jul 2007 22:48:30 +0000 (+0100) Subject: Do not call 'refresh' when creating a patch (bug #8872) X-Git-Tag: v0.13~9 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/0ec93bfd95feee9d786e7eb73f9d49af07c5cb29 Do not call 'refresh' when creating a patch (bug #8872) The Series.new_patch function was calling refresh_patch which led to checking in the pending adds in the index. This patch adds the creation of a commit without writing the index. Signed-off-by: Catalin Marinas --- diff --git a/stgit/commands/assimilate.py b/stgit/commands/assimilate.py index e5ebb55..5134e34 100644 --- a/stgit/commands/assimilate.py +++ b/stgit/commands/assimilate.py @@ -85,7 +85,7 @@ def func(parser, options, args): cname, cmail, cdate = name_email_date(victim.get_committer()) crt_series.new_patch( patch2name[victim], - can_edit = False, before_existing = False, refresh = False, + can_edit = False, before_existing = False, commit = False, top = victim.get_id_hash(), bottom = victim.get_parent(), message = victim.get_log(), author_name = aname, author_email = amail, author_date = adate, diff --git a/stgit/git.py b/stgit/git.py index 1f57481..72bf889 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -593,7 +593,7 @@ def update_cache(files = None, force = False): return True def commit(message, files = None, parents = None, allowempty = False, - cache_update = True, tree_id = None, + cache_update = True, tree_id = None, set_head = False, author_name = None, author_email = None, author_date = None, committer_name = None, committer_email = None): """Commit the current tree to repository @@ -615,12 +615,10 @@ def commit(message, files = None, parents = None, allowempty = False, elif message[-1:] != '\n': message += '\n' - must_switch = True # write the index to repository if tree_id == None: tree_id = _output_one_line(['git-write-tree']) - else: - must_switch = False + set_head = True # the commit cmd = ['env'] @@ -641,7 +639,7 @@ def commit(message, files = None, parents = None, allowempty = False, cmd += ['-p', p] commit_id = _output_one_line(cmd, message) - if must_switch: + if set_head: __set_head(commit_id) return commit_id diff --git a/stgit/stack.py b/stgit/stack.py index 3c43aa3..b03fdc0 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -823,10 +823,10 @@ class Series(PatchSet): 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 """ @@ -851,15 +851,13 @@ class Series(PatchSet): 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) @@ -867,19 +865,37 @@ class Series(PatchSet): 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(commit and 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