git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org, "David Kågedal" <davidk@lysator.liu.se>
Subject: [StGit PATCH 5/5] stg repair: Patchify non-patch commits between patches
Date: Sun, 11 Nov 2007 20:44:04 +0100	[thread overview]
Message-ID: <20071111194404.18868.44443.stgit@yoghurt> (raw)
In-Reply-To: <20071111193545.18868.62490.stgit@yoghurt>

This teaches "stg repair" to find non-patch commits that sit between
patches, and turn them into patches. This situation can happen e.g.
like this:

  stg new -m A && stg new -m B && stg new -m C
  stg pop A B C
  stg push B
  echo foo > foo && git add foo && stg refresh
  git reset --hard $(stg id C)

The old "stg repair" would at this point simply conclude that A and C
are applied, and B unapplied. However, B's old commit is still between
them even though it's not a patch, which will cause problems later --
StGit generally assumes that the applied patches are a consecutive
string of commits. The new "stg repair", on the other hand, will find
B's old commit, and create a new patch for it.

One downside of this change is that we can no longer conclude that all
is well just because head == top, so no-op runs of "stg repair" just
got more expensive.

Signed-off-by: Karl Hasselström <kha@treskal.com>

---

 stgit/commands/repair.py |   19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)


diff --git a/stgit/commands/repair.py b/stgit/commands/repair.py
index f8fe624..4787f72 100644
--- a/stgit/commands/repair.py
+++ b/stgit/commands/repair.py
@@ -101,33 +101,28 @@ def read_commit_dag(branch):
 def func(parser, options, args):
     """Repair inconsistencies in StGit metadata."""
 
-    def nothing_to_do():
-        out.info('Nothing to repair')
-
     orig_applied = crt_series.get_applied()
     orig_unapplied = crt_series.get_unapplied()
 
-    # If head == top, we're done.
-    head = git.get_commit(git.get_head()).get_id_hash()
-    top = crt_series.get_current_patch()
-    if top and head == top.get_top():
-        return nothing_to_do()
-
     if crt_series.get_protected():
         raise CmdException(
             'This branch is protected. Modification is not permitted.')
 
     # Find commits that aren't patches, and applied patches.
+    head = git.get_commit(git.get_head()).get_id_hash()
     commits, patches = read_commit_dag(crt_series.get_name())
     c = commits[head]
-    patchify = []
+    patchify = []       # commits to definitely patchify
+    maybe_patchify = [] # commits to patchify if we find a patch below them
     applied = []
     while len(c.parents) == 1:
         parent, = c.parents
         if c.patch:
             applied.append(c)
-        elif not applied:
-            patchify.append(c)
+            patchify.extend(maybe_patchify)
+            maybe_patchify = []
+        else:
+            maybe_patchify.append(c)
         c = parent
     applied.reverse()
     patchify.reverse()

  parent reply	other threads:[~2007-11-11 19:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-11 19:43 [StGit PATCH 0/5] A few small fixes Karl Hasselström
2007-11-11 19:43 ` [StGit PATCH 1/5] Simple test for "stg clean" Karl Hasselström
2007-11-11 19:43 ` [StGit PATCH 2/5] Cogito is deprecated, so don't point to it Karl Hasselström
2007-11-11 19:43 ` [StGit PATCH 3/5] Let some commands work with detached HEAD Karl Hasselström
2007-11-11 19:43 ` [StGit PATCH 4/5] Rename "stg assimilate" to "stg repair" Karl Hasselström
2007-11-11 19:44 ` Karl Hasselström [this message]
2007-11-12 11:02 ` [StGit PATCH 0/5] A few small fixes Catalin Marinas
2007-11-12 13:01   ` Karl Hasselström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071111194404.18868.44443.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@gmail.com \
    --cc=davidk@lysator.liu.se \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).