git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGit PATCH 09/10] Let "stg goto" use the new infrastructure

From
Karl Hasselström <kha@treskal.com>
Date
Nov 25, 2007, 20:51 UTC
Message-ID
<20071125205152.7823.70589.stgit@yoghurt>
In-Reply-To
<20071125203717.7823.70046.stgit@yoghurt>

In the process, it loses the --keep option, since the new infrastructure always keeps local changes (and aborts cleanly if they are in the way).

Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 stgit/commands/clean.py |    2 +-
 stgit/commands/goto.py  |   52 ++++++++++++++++-------------------------------
 2 files changed, 19 insertions(+), 35 deletions(-)
diff --git a/stgit/commands/clean.py b/stgit/commands/clean.py
index cfcc004..55ab858 100644
--- a/stgit/commands/clean.py
+++ b/stgit/commands/clean.py
@@ -37,7 +37,7 @@ options = [make_option('-a', '--applied',
 
 
 def _clean(stack, clean_applied, clean_unapplied):
-    trans = transaction.StackTransaction(stack, 'clean')
+    trans = transaction.StackTransaction(stack, 'stg clean')
     def del_patch(pn):
         if pn in stack.patchorder.applied:
             return clean_applied and trans.patches[pn].data.is_empty()
diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py
index 84b840b..3ea69dd 100644
--- a/stgit/commands/goto.py
+++ b/stgit/commands/goto.py
@@ -15,13 +15,9 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os
 from optparse import OptionParser, make_option
-
-from stgit.commands.common import *
-from stgit.utils import *
-from stgit import stack, git
-
+from stgit.commands import common
+from stgit.lib import transaction
 
 help = 'push or pop patches to the given one'
 usage = """%prog [options] <name>
@@ -30,38 +26,26 @@ Push/pop patches to/from the stack until the one given on the command
 line becomes current. There is no '--undo' option for 'goto'. Use the
 'push --undo' command for this."""
 
-directory = DirectoryGotoToplevel()
-options = [make_option('-k', '--keep',
-                       help = 'keep the local changes when popping patches',
-                       action = 'store_true')]
-
+directory = common.DirectoryHasRepositoryLib()
+options = []
 
 def func(parser, options, args):
-    """Pushes the given patch or all onto the series
-    """
     if len(args) != 1:
         parser.error('incorrect number of arguments')
-
-    check_conflicts()
-    check_head_top_equal(crt_series)
-
-    if not options.keep:
-        check_local_changes()
-
-    applied = crt_series.get_applied()
-    unapplied = crt_series.get_unapplied()
     patch = args[0]
 
-    if patch in applied:
-        applied.reverse()
-        patches = applied[:applied.index(patch)]
-        pop_patches(crt_series, patches, options.keep)
-    elif patch in unapplied:
-        if options.keep:
-            raise CmdException, 'Cannot use --keep with patch pushing'
-        patches = unapplied[:unapplied.index(patch)+1]
-        push_patches(crt_series, patches)
+    stack = directory.repository.current_stack
+    iw = stack.repository.default_iw()
+    trans = transaction.StackTransaction(stack, 'stg goto')
+    if patch in trans.applied:
+        to_pop = set(trans.applied[trans.applied.index(patch)+1:])
+        assert not trans.pop_patches(lambda pn: pn in to_pop)
+    elif patch in trans.unapplied:
+        try:
+            for pn in trans.unapplied[:trans.unapplied.index(patch)+1]:
+                trans.push_patch(pn, iw)
+        except transaction.TransactionHalted:
+            pass
     else:
-        raise CmdException, 'Patch "%s" does not exist' % patch
-
-    print_crt_patch(crt_series)
+        raise CmdException('Patch "%s" does not exist' % patch)
+    trans.run(iw)
Previous: Karl HasselströmNext: Karl Hasselström
Message 13 of 14 in “Infrastructure rewrite series”
  1. 00/10 Infrastructure rewrite seriesKarl Hasselström, Nov 25, 2007
  2. 01/10 New StGit core infrastructure: repository operationsKarl Hasselström, Nov 25, 2007
  3. 02/10 Write metadata files used by the old infrastructureKarl Hasselström, Nov 25, 2007
  4. 03/10 Upgrade older stacks to newest versionKarl Hasselström, Nov 25, 2007
  5. 04/10 Let "stg clean" use the new infrastructureKarl Hasselström, Nov 25, 2007
  6. 05/10 Add "stg coalesce"Karl Hasselström, Nov 25, 2007
  7. 06/10 Let "stg applied" and "stg unapplied" use the new infrastructureKarl Hasselström, Nov 25, 2007
  8. 07/10 Teach the new infrastructure about the index and worktreeKarl Hasselström, Nov 25, 2007
  9. Karl HasselströmNov 26, 2007
  10. David KågedalNov 26, 2007
  11. Karl HasselströmNov 26, 2007
  12. 08/10 Let "stg clean" use the new transaction primitivesKarl Hasselström, Nov 25, 2007
  13. 09/10 Let "stg goto" use the new infrastructureKarl Hasselström, Nov 25, 2007
  14. 10/10 Convert "stg uncommit" to the new infrastructureKarl Hasselström, Nov 25, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.