chiark / gitweb /
Do not call 'refresh' when creating a patch (bug #8872)
authorCatalin Marinas <catalin.marinas@gmail.com>
Mon, 16 Jul 2007 22:48:30 +0000 (23:48 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Mon, 16 Jul 2007 22:48:30 +0000 (23:48 +0100)
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 <catalin.marinas@gmail.com>
stgit/commands/assimilate.py
stgit/git.py
stgit/stack.py

index e5ebb5537417efdf1e144046ee28a3ded93ac829..5134e343cc4bff62bbc39b5153986c11141e9959 100644 (file)
@@ -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,
index 1f574818a7b810436c0455a58b8663a567fdf4d9..72bf889206bdaf5fc80100c76caf2a179edb3687 100644 (file)
@@ -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
index 3c43aa39370728a7db063df1c40c441e66bb50e4..b03fdc062d996a9a86784b97c83e4ef397157d58 100644 (file)
@@ -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