{"thread":{"id":"18659","subject":"[StGit PATCH] Convert \"push\" to the lib infrastructure","startedAt":"2009-03-31T11:30:33Z","lastAt":"2009-04-01T12:06:38Z","messageCount":2,"participants":["Catalin Marinas","Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"110002","messageId":"20090331113033.2524.27502.stgit@pc1117.cambridge.arm.com","threadId":"18659","inReplyTo":null,"subject":"[StGit PATCH] Convert \"push\" to the lib infrastructure","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@arm.com","sentAt":"2009-03-31T11:30:33Z","receivedAt":"2009-03-31T11:30:33Z","isPatch":true,"sender":{"key":"catalin.marinas@arm.com","avatar":null},"body":"Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n---\n stgit/commands/push.py   |   68 ++++++++++++++++++++++++----------------------\n t/t0002-status.sh        |    2 +\n t/t1200-push-modified.sh |    2 +\n t/t1202-push-undo.sh     |    4 +--\n t/t1203-push-conflict.sh |    2 +\n t/t1205-push-subdir.sh   |    2 +\n t/t2500-clean.sh         |    2 +\n 7 files changed, 43 insertions(+), 39 deletions(-)\n\ndiff --git a/stgit/commands/push.py b/stgit/commands/push.py\nindex 818e02d..0d25a65 100644\n--- a/stgit/commands/push.py\n+++ b/stgit/commands/push.py\n@@ -16,12 +16,10 @@ along with this program; if not, write to the Free Software\n Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n \"\"\"\n \n-import sys, os\n+from stgit.commands import common\n+from stgit.lib import transaction\n+from stgit import argparse\n from stgit.argparse import opt\n-from stgit.commands.common import *\n-from stgit.utils import *\n-from stgit.out import *\n-from stgit import argparse, stack, git\n \n help = 'Push one or more patches onto the stack'\n kind = 'stack'\n@@ -45,39 +43,45 @@ options = [\n     opt('-n', '--number', type = 'int',\n         short = 'Push the specified number of patches'),\n     opt('--reverse', action = 'store_true',\n-        short = 'Push the patches in reverse order'),\n-    opt('-m', '--merged', action = 'store_true',\n-        short = 'Check for patches merged upstream')]\n+        short = 'Push the patches in reverse order')\n+    ] + argparse.keep_option() + argparse.merged_option()\n \n-directory = DirectoryGotoToplevel(log = True)\n+directory = common.DirectoryHasRepositoryLib()\n \n def func(parser, options, args):\n-    \"\"\"Pushes the given patch or all onto the series\n-    \"\"\"\n-\n-    check_local_changes()\n-    check_conflicts()\n-    check_head_top_equal(crt_series)\n-\n-    unapplied = crt_series.get_unapplied()\n-    if not unapplied:\n-        raise CmdException, 'No more patches to push'\n-\n-    if options.number:\n-        patches = unapplied[:options.number]\n-    elif options.all:\n-        patches = unapplied\n-    elif len(args) == 0:\n-        patches = [unapplied[0]]\n+    \"\"\"Pushes the given patches or the first unapplied onto the stack.\"\"\"\n+    stack = directory.repository.current_stack\n+    iw = stack.repository.default_iw\n+    clean_iw = (not options.keep and iw) or None\n+    trans = transaction.StackTransaction(stack, 'pop',\n+                                         check_clean_iw = clean_iw)\n+\n+    if not trans.unapplied:\n+        raise common.CmdException('No patches to push')\n+\n+    if options.all:\n+        patches = list(trans.unapplied)\n+    elif options.number:\n+        patches = trans.unapplied[:options.number]\n+    elif not args:\n+        patches = [trans.unapplied[0]]\n     else:\n-        patches = parse_patches(args, unapplied)\n+        patches = common.parse_patches(args, trans.unapplied)\n \n-    if patches == []:\n-        raise CmdException, 'No patches to push'\n+    if not patches:\n+        raise common.CmdException('No patches to push')\n \n     if options.reverse:\n         patches.reverse()\n \n-    push_patches(crt_series, patches, options.merged)\n-\n-    print_crt_patch(crt_series)\n+    try:\n+        if options.merged:\n+            merged = set(trans.check_merged(patches))\n+        else:\n+            merged = set()\n+        for pn in patches:\n+            trans.push_patch(pn, iw, allow_interactive = True,\n+                             already_merged = pn in merged)\n+    except transaction.TransactionHalted:\n+        pass\n+    return trans.run(iw)\ndiff --git a/t/t0002-status.sh b/t/t0002-status.sh\nindex d95a83b..ffcad77 100755\n--- a/t/t0002-status.sh\n+++ b/t/t0002-status.sh\n@@ -111,7 +111,7 @@ A fie\n C foo/bar\n EOF\n test_expect_success 'Status after conflicting push' '\n-    conflict_old stg push &&\n+    conflict stg push &&\n     stg status > output.txt &&\n     test_cmp expected.txt output.txt\n '\ndiff --git a/t/t1200-push-modified.sh b/t/t1200-push-modified.sh\nindex a591124..2077492 100755\n--- a/t/t1200-push-modified.sh\n+++ b/t/t1200-push-modified.sh\n@@ -49,7 +49,7 @@ test_expect_success \\\n \n test_expect_success \\\n     'Attempt to push the first of those patches without --merged' \\\n-    \"(cd bar && conflict_old stg push\n+    \"(cd bar && conflict stg push\n      )\n \"\n \ndiff --git a/t/t1202-push-undo.sh b/t/t1202-push-undo.sh\nindex 79439de..14a3d6d 100755\n--- a/t/t1202-push-undo.sh\n+++ b/t/t1202-push-undo.sh\n@@ -43,7 +43,7 @@ test_expect_success \\\n test_expect_success \\\n \t'Push the second patch with conflict' \\\n \t'\n-\tconflict_old stg push bar\n+\tconflict stg push bar\n \t'\n \n test_expect_success \\\n@@ -55,7 +55,7 @@ test_expect_success \\\n test_expect_success \\\n \t'Check the push after undo fails as well' \\\n \t'\n-\tconflict_old stg push bar\n+\tconflict stg push bar\n \t'\n \n test_expect_success \\\ndiff --git a/t/t1203-push-conflict.sh b/t/t1203-push-conflict.sh\nindex 96fee15..8027e6c 100755\n--- a/t/t1203-push-conflict.sh\n+++ b/t/t1203-push-conflict.sh\n@@ -38,7 +38,7 @@ test_expect_success \\\n test_expect_success \\\n \t'Push the first patch with conflict' \\\n \t'\n-\tconflict_old stg push foo\n+\tconflict stg push foo\n \t'\n \n test_expect_success \\\ndiff --git a/t/t1205-push-subdir.sh b/t/t1205-push-subdir.sh\nindex f852762..2d5918b 100755\n--- a/t/t1205-push-subdir.sh\n+++ b/t/t1205-push-subdir.sh\n@@ -47,7 +47,7 @@ test_expect_success 'Conflicting push from subdir' '\n     [ \"$(echo $(cat x.txt))\" = \"x0\" ] &&\n     [ \"$(echo $(cat foo/y.txt))\" = \"y0\" ] &&\n     cd foo &&\n-    conflict_old stg push p2 &&\n+    conflict stg push p2 &&\n     cd .. &&\n     [ \"$(echo $(stg status --conflict))\" = \"foo/y.txt x.txt\" ]\n '\ndiff --git a/t/t2500-clean.sh b/t/t2500-clean.sh\nindex 99fd29f..7f821f5 100755\n--- a/t/t2500-clean.sh\n+++ b/t/t2500-clean.sh\n@@ -32,7 +32,7 @@ test_expect_success 'Create a conflict' '\n     stg new p2 -m p2\n     echo quux > foo.txt &&\n     stg refresh &&\n-    conflict_old stg push\n+    conflict stg push\n '\n \n test_expect_success 'Make sure conflicting patches are preserved' '\n"},{"id":"110126","messageId":"20090401120638.GB30918@diana.vm.bytemark.co.uk","threadId":"18659","inReplyTo":"20090331113033.2524.27502.stgit@pc1117.cambridge.arm.com","subject":"Re: [StGit PATCH] Convert \"push\" to the lib infrastructure","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2009-04-01T12:06:38Z","receivedAt":"2009-04-01T12:06:38Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2009-03-31 12:30:33 +0100, Catalin Marinas wrote:\n\n> Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n\nAcked-by: Karl Hasselström <kha@treskal.com>\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}