{"thread":{"id":"15972","subject":"[PATCH stgit] revised patch for importing series from tarball","startedAt":"2008-10-19T19:16:13Z","lastAt":"2008-10-24T02:53:09Z","messageCount":3,"participants":["Clark Williams","Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"93466","messageId":"20081019141613.05cbd93e@gmail.com","threadId":"15972","inReplyTo":null,"subject":"[PATCH stgit] revised patch for importing series from tarball","fromName":"Clark Williams","fromEmail":"clark.williams@gmail.com","sentAt":"2008-10-19T19:16:13Z","receivedAt":"2008-10-19T19:16:13Z","isPatch":true,"sender":{"key":"clark.williams@gmail.com","avatar":null},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nCatalin,\n\nAttached is my revised patch (v2 I believe) for importing a series directly from a tarball. I looked at the critique offered by Karl (pretty hard actually), but I decided in the end to keep extracting the tarball to a temp directory. It's possible that it would be desirable to extract members directly from a tarball (although as far as I can tell, you still have to extract them to a file) but I didn't judge the churn in imprt.py to be worth it for now. This version is pretty simple, in that you just detect that the input to to import_series is a tarball, call import_tarfile, then return. \n\nI added a simple test to the test harness for import as well. \n\nOh and I added '*.elc' to the .gitignore file. May not be that many folks using emacs with stgit, but hey, I am! :)\n\nClark\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v2.0.9 (GNU/Linux)\n\niEYEARECAAYFAkj7h4QACgkQqA4JVb61b9dq4ACbB9tl0FbHq5igNIPIbzALhyLf\nAw8An3weTNye7yzQ/wU2Hyt1agzCzTtC\n=7WjV\n-----END PGP SIGNATURE-----\n\n\npatch to allow importing a series from a tar archive\n\nFrom: Clark Williams <williams@redhat.com>\n\nSigned-off-by: Clark Williams <williams@redhat.com>\n---\n .gitignore                                      |    1 \n stgit/commands/imprt.py                         |   47 ++++++++++++++++++++++-\n t/t1800-import.sh                               |   12 ++++++\n t/t1800-import/patches/attribution.patch        |   21 ++++++++++\n t/t1800-import/patches/delete-extra-lines.patch |   22 +++++++++++\n t/t1800-import/patches/fifth-stanza.patch       |   22 +++++++++++\n t/t1800-import/patches/first-stanza.patch       |   18 +++++++++\n t/t1800-import/patches/fourth-stanza.patch      |   22 +++++++++++\n t/t1800-import/patches/second-stanza.patch      |   22 +++++++++++\n t/t1800-import/patches/series                   |   10 +++++\n t/t1800-import/patches/seventh-stanza.patch     |   24 ++++++++++++\n t/t1800-import/patches/sixth-stanza.patch       |   22 +++++++++++\n t/t1800-import/patches/third-stanza.patch       |   22 +++++++++++\n 13 files changed, 263 insertions(+), 2 deletions(-)\n create mode 100644 t/t1800-import/patches/attribution.patch\n create mode 100644 t/t1800-import/patches/delete-extra-lines.patch\n create mode 100644 t/t1800-import/patches/fifth-stanza.patch\n create mode 100644 t/t1800-import/patches/first-stanza.patch\n create mode 100644 t/t1800-import/patches/fourth-stanza.patch\n create mode 100644 t/t1800-import/patches/second-stanza.patch\n create mode 100644 t/t1800-import/patches/series\n create mode 100644 t/t1800-import/patches/seventh-stanza.patch\n create mode 100644 t/t1800-import/patches/sixth-stanza.patch\n create mode 100644 t/t1800-import/patches/third-stanza.patch\n\ndiff --git a/.gitignore b/.gitignore\nindex 91dbad2..f0e5d30 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -6,3 +6,4 @@ patches-*\n release.sh\n setup.cfg.rpm\n snapshot.sh\n+*.elc\ndiff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py\nindex 227743f..6860d0e 100644\n--- a/stgit/commands/imprt.py\n+++ b/stgit/commands/imprt.py\n@@ -19,6 +19,7 @@ import sys, os, re, email\n from mailbox import UnixMailbox\n from StringIO import StringIO\n from optparse import OptionParser, make_option\n+import tarfile\n \n from stgit.commands.common import *\n from stgit.utils import *\n@@ -52,7 +53,7 @@ options = [make_option('-m', '--mail',\n                        help = 'import a series of patches from an mbox file',\n                        action = 'store_true'),\n            make_option('-s', '--series',\n-                       help = 'import a series of patches',\n+                       help = 'import a series of patches from a series file or a tar archive',\n                        action = 'store_true'),\n            make_option('-u', '--url',\n                        help = 'import a patch from a URL',\n@@ -87,7 +88,7 @@ options = [make_option('-m', '--mail',\n            make_option('--commname',\n                        help = 'use COMMNAME as the committer name'),\n            make_option('--commemail',\n-                       help = 'use COMMEMAIL as the committer e-mail')\n+                       help = 'use COMMEMAIL as the committer e-mail'),\n            ] + make_sign_options()\n \n \n@@ -234,6 +235,9 @@ def __import_series(filename, options):\n     applied = crt_series.get_applied()\n \n     if filename:\n+        if tarfile.is_tarfile(filename):\n+            __import_tarfile(filename, options)\n+            return\n         f = file(filename)\n         patchdir = os.path.dirname(filename)\n     else:\n@@ -287,6 +291,45 @@ def __import_url(url, options):\n     urllib.urlretrieve(url, filename)\n     __import_file(filename, options)\n \n+def __import_tarfile(tar, options):\n+    \"\"\"Import patch series from a tar archive\n+    \"\"\"\n+    import tempfile\n+    import shutil\n+\n+    if not tarfile.is_tarfile(tar):\n+        raise CmdException, \"%s is not a tarfile!\" % tar\n+\n+\n+    t = tarfile.open(tar, 'r')\n+    names = t.getnames()\n+\n+    # verify paths in the tarfile are safe\n+    for n in names:\n+        if n.startswith('/'):\n+            raise CmdException, \"Absolute path found in %s\" % tar\n+        if n.find(\"..\") > -1:\n+            raise CmdException, \"Relative path found in %s\" % tar\n+\n+    # find the series file\n+    seriesfile = '';\n+    for m in names:\n+        if m.endswith('/series') or m == 'series':\n+            seriesfile = m\n+            break\n+    if seriesfile == '':\n+        raise CmdException, \"no 'series' file found in %s\" % tar\n+\n+    # unpack into a tmp dir\n+    tmpdir = tempfile.mkdtemp('.stg')\n+    t.extractall(tmpdir)\n+\n+    # apply the series\n+    __import_series(os.path.join(tmpdir, seriesfile), options)\n+\n+    # cleanup the tmpdir\n+    shutil.rmtree(tmpdir)\n+\n def func(parser, options, args):\n     \"\"\"Import a GNU diff file as a new patch\n     \"\"\"\ndiff --git a/t/t1800-import.sh b/t/t1800-import.sh\nindex 1352743..5a3384f 100755\n--- a/t/t1800-import.sh\n+++ b/t/t1800-import.sh\n@@ -122,4 +122,16 @@ test_expect_success \\\n     stg delete ..\n     '\n \n+test_expect_success \\\n+    'apply a series from a tarball' \\\n+    '\n+    rm -f jabberwocky.txt && touch jabberwocky.txt &&\n+    git add jabberwocky.txt && git commit -m \"empty file\" jabberwocky.txt &&\n+    (cd ../t1800-import; tar -cjf jabberwocky.tar.bz2 patches) &&\n+    stg import --series ../t1800-import/jabberwocky.tar.bz2\n+    [ $(git cat-file -p $(stg id) \\\n+        | grep -c \"tree 2c33937252a21f1550c0bf21f1de534b68f69635\") = 1 ] &&\n+    rm ../t1800-import/jabberwocky.tar.bz2\n+    '\n+    \n test_done\ndiff --git a/t/t1800-import/patches/attribution.patch b/t/t1800-import/patches/attribution.patch\nnew file mode 100644\nindex 0000000..2b7c8f9\n--- /dev/null\n+++ b/t/t1800-import/patches/attribution.patch\n@@ -0,0 +1,21 @@\n+attribution\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    4 ++++\n+ 1 files changed, 4 insertions(+), 0 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index 066d2e8..a9dd1f3 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -32,3 +32,7 @@ O frabjous day! Callooh! Callay!'\n+   Did gyre and gimble in the wabe;\n+ All mimsy were the borogoves,\n+   And the mome raths outgrabe.\n++\n++\tJABBERWOCKY\n++\tLewis Carroll\n++\t(from Through the Looking-Glass and What Alice Found There, 1872) \ndiff --git a/t/t1800-import/patches/delete-extra-lines.patch b/t/t1800-import/patches/delete-extra-lines.patch\nnew file mode 100644\nindex 0000000..e5b7a65\n--- /dev/null\n+++ b/t/t1800-import/patches/delete-extra-lines.patch\n@@ -0,0 +1,22 @@\n+delete extra lines\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    2 --\n+ 1 files changed, 0 insertions(+), 2 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index 98cb716..066d2e8 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -28,8 +28,6 @@ He left it dead, and with its head\n+ O frabjous day! Callooh! Callay!'\n+   He chortled in his joy.\n+ \n+-\n+-\n+ `Twas brillig, and the slithy toves\n+   Did gyre and gimble in the wabe;\n+ All mimsy were the borogoves,\ndiff --git a/t/t1800-import/patches/fifth-stanza.patch b/t/t1800-import/patches/fifth-stanza.patch\nnew file mode 100644\nindex 0000000..4f0e77c\n--- /dev/null\n+++ b/t/t1800-import/patches/fifth-stanza.patch\n@@ -0,0 +1,22 @@\n+fifth stanza\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    5 +++++\n+ 1 files changed, 5 insertions(+), 0 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index b1c2ad3..f1416dc 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -17,3 +17,8 @@ And, as in uffish thought he stood,\n+   The Jabberwock, with eyes of flame,\n+ Came whiffling through the tulgey wood,\n+   And burbled as it came!\n++\n++One, two! One, two! And through and through\n++  The vorpal blade went snicker-snack!\n++He left it dead, and with its head\n++  He went galumphing back.\ndiff --git a/t/t1800-import/patches/first-stanza.patch b/t/t1800-import/patches/first-stanza.patch\nnew file mode 100644\nindex 0000000..ee7818f\n--- /dev/null\n+++ b/t/t1800-import/patches/first-stanza.patch\n@@ -0,0 +1,18 @@\n+first stanza\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    4 ++++\n+ 1 files changed, 4 insertions(+), 0 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index e69de29..fba24dc 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -0,0 +1,4 @@\n++`Twas brillig, and the slithy toves\n++  Did gyre and gimble in the wabe:\n++All mimsy were the borogoves,\n++  And the mome raths outgrabe.\ndiff --git a/t/t1800-import/patches/fourth-stanza.patch b/t/t1800-import/patches/fourth-stanza.patch\nnew file mode 100644\nindex 0000000..eb2f8f2\n--- /dev/null\n+++ b/t/t1800-import/patches/fourth-stanza.patch\n@@ -0,0 +1,22 @@\n+fourth stanza\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    5 +++++\n+ 1 files changed, 5 insertions(+), 0 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index 6405f36..b1c2ad3 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -12,3 +12,8 @@ He took his vorpal sword in hand:\n+   Long time the manxome foe he sought --\n+ So rested he by the Tumtum tree,\n+   And stood awhile in thought.\n++\n++And, as in uffish thought he stood,\n++  The Jabberwock, with eyes of flame,\n++Came whiffling through the tulgey wood,\n++  And burbled as it came!\ndiff --git a/t/t1800-import/patches/second-stanza.patch b/t/t1800-import/patches/second-stanza.patch\nnew file mode 100644\nindex 0000000..bec1622\n--- /dev/null\n+++ b/t/t1800-import/patches/second-stanza.patch\n@@ -0,0 +1,22 @@\n+second stanza\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    5 +++++\n+ 1 files changed, 5 insertions(+), 0 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index fba24dc..9ed0b49 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -2,3 +2,8 @@\n+   Did gyre and gimble in the wabe:\n+ All mimsy were the borogoves,\n+   And the mome raths outgrabe.\n++\n++\"Beware the Jabberwock, my son!\n++  The jaws that bite, the claws that catch!\n++Beware the Jubjub bird, and shun\n++  The frumious Bandersnatch!\"\ndiff --git a/t/t1800-import/patches/series b/t/t1800-import/patches/series\nnew file mode 100644\nindex 0000000..5945c98\n--- /dev/null\n+++ b/t/t1800-import/patches/series\n@@ -0,0 +1,10 @@\n+# This series applies on GIT commit 6a8b6f6e2ecbcab26de7656b66b7f30eeba1ee96\n+first-stanza.patch\n+second-stanza.patch\n+third-stanza.patch\n+fourth-stanza.patch\n+fifth-stanza.patch\n+sixth-stanza.patch\n+seventh-stanza.patch\n+delete-extra-lines.patch\n+attribution.patch\ndiff --git a/t/t1800-import/patches/seventh-stanza.patch b/t/t1800-import/patches/seventh-stanza.patch\nnew file mode 100644\nindex 0000000..555c200\n--- /dev/null\n+++ b/t/t1800-import/patches/seventh-stanza.patch\n@@ -0,0 +1,24 @@\n+seventh stanza\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    7 +++++++\n+ 1 files changed, 7 insertions(+), 0 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index bf732f5..98cb716 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -27,3 +27,10 @@ He left it dead, and with its head\n+   Come to my arms, my beamish boy!\n+ O frabjous day! Callooh! Callay!'\n+   He chortled in his joy.\n++\n++\n++\n++`Twas brillig, and the slithy toves\n++  Did gyre and gimble in the wabe;\n++All mimsy were the borogoves,\n++  And the mome raths outgrabe.\ndiff --git a/t/t1800-import/patches/sixth-stanza.patch b/t/t1800-import/patches/sixth-stanza.patch\nnew file mode 100644\nindex 0000000..2349b7e\n--- /dev/null\n+++ b/t/t1800-import/patches/sixth-stanza.patch\n@@ -0,0 +1,22 @@\n+sixth stanza\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    5 +++++\n+ 1 files changed, 5 insertions(+), 0 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index f1416dc..bf732f5 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -22,3 +22,8 @@ One, two! One, two! And through and through\n+   The vorpal blade went snicker-snack!\n+ He left it dead, and with its head\n+   He went galumphing back.\n++\n++\"And, has thou slain the Jabberwock?\n++  Come to my arms, my beamish boy!\n++O frabjous day! Callooh! Callay!'\n++  He chortled in his joy.\ndiff --git a/t/t1800-import/patches/third-stanza.patch b/t/t1800-import/patches/third-stanza.patch\nnew file mode 100644\nindex 0000000..d942353\n--- /dev/null\n+++ b/t/t1800-import/patches/third-stanza.patch\n@@ -0,0 +1,22 @@\n+third stanza\n+\n+From: Clark Williams <williams@redhat.com>\n+\n+\n+---\n+ jabberwocky.txt |    5 +++++\n+ 1 files changed, 5 insertions(+), 0 deletions(-)\n+\n+diff --git a/jabberwocky.txt b/jabberwocky.txt\n+index 9ed0b49..6405f36 100644\n+--- a/jabberwocky.txt\n++++ b/jabberwocky.txt\n+@@ -7,3 +7,8 @@ All mimsy were the borogoves,\n+   The jaws that bite, the claws that catch!\n+ Beware the Jubjub bird, and shun\n+   The frumious Bandersnatch!\"\n++\n++He took his vorpal sword in hand:\n++  Long time the manxome foe he sought --\n++So rested he by the Tumtum tree,\n++  And stood awhile in thought.\n"},{"id":"93813","messageId":"20081024011708.GA20369@diana.vm.bytemark.co.uk","threadId":"15972","inReplyTo":"20081019141613.05cbd93e@gmail.com","subject":"Re: [PATCH stgit] revised patch for importing series from tarball","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-10-24T01:17:08Z","receivedAt":"2008-10-24T01:17:08Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-10-19 14:16:13 -0500, Clark Williams wrote:\n\n> I added a simple test to the test harness for import as well.\n\nGreat!\n\n> Oh and I added '*.elc' to the .gitignore file. May not be that many\n> folks using emacs with stgit, but hey, I am! :)\n\nMe too (but I have *.elc in my personal ignore file, so I never saw\nit). However, this is an unrelated change, and we don't need to ignore\n.elc files at the top level, only in contrib. I've taken the liberty\nof splitting this out to a separate commit and forging your signature\non it -- let me know if that's OK and I'll push it out.\n\n> patch to allow importing a series from a tar archive\n\nI turned this into a complete sentence, and removed \"patch\" since it's\nentirely redundant.\n\n> --- a/.gitignore\n> +++ b/.gitignore\n> @@ -6,3 +6,4 @@ patches-*\n>  release.sh\n>  setup.cfg.rpm\n>  snapshot.sh\n> +*.elc\n\nAs I said, I put this in a separate patch, and put that ignore pattern\nin contrib.gitignore instead.\n\n>             make_option('--commemail',\n> -                       help = 'use COMMEMAIL as the committer e-mail')\n> +                       help = 'use COMMEMAIL as the committer e-mail'),\n>             ] + make_sign_options()\n\nThis is just a noise change _and_ didn't apply, so I dropped it.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"93819","messageId":"20081023215309.2dc07e6e@gmail.com","threadId":"15972","inReplyTo":"20081024011708.GA20369@diana.vm.bytemark.co.uk","subject":"Re: [PATCH stgit] revised patch for importing series from tarball","fromName":"Clark Williams","fromEmail":"clark.williams@gmail.com","sentAt":"2008-10-24T02:53:09Z","receivedAt":"2008-10-24T02:53:09Z","isPatch":true,"sender":{"key":"clark.williams@gmail.com","avatar":null},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nOn Fri, 24 Oct 2008 03:17:08 +0200\nKarl Hasselström <kha@treskal.com> wrote:\n\n> On 2008-10-19 14:16:13 -0500, Clark Williams wrote:\n> \n> > I added a simple test to the test harness for import as well.\n> \n> Great!\n> \n> > Oh and I added '*.elc' to the .gitignore file. May not be that many\n> > folks using emacs with stgit, but hey, I am! :)\n> \n> Me too (but I have *.elc in my personal ignore file, so I never saw\n> it). However, this is an unrelated change, and we don't need to ignore\n> .elc files at the top level, only in contrib. I've taken the liberty\n> of splitting this out to a separate commit and forging your signature\n> on it -- let me know if that's OK and I'll push it out.\n> \n\nYes, that's fine.\n\n> > patch to allow importing a series from a tar archive\n> \n> I turned this into a complete sentence, and removed \"patch\" since it's\n> entirely redundant.\n> \n> > --- a/.gitignore\n> > +++ b/.gitignore\n> > @@ -6,3 +6,4 @@ patches-*\n> >  release.sh\n> >  setup.cfg.rpm\n> >  snapshot.sh\n> > +*.elc\n> \n> As I said, I put this in a separate patch, and put that ignore pattern\n> in contrib.gitignore instead.\n> \nThanks\n\n> >             make_option('--commemail',\n> > -                       help = 'use COMMEMAIL as the committer e-mail')\n> > +                       help = 'use COMMEMAIL as the committer e-mail'),\n> >             ] + make_sign_options()\n> \n> This is just a noise change _and_ didn't apply, so I dropped it.\n> \n\nAgreed. \n\nThanks for the update.\n\nClark\n\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v2.0.9 (GNU/Linux)\n\niEYEARECAAYFAkkBOJ0ACgkQqA4JVb61b9e6SgCeOZ0YrB/uSrvSqgLkxnLjiQp2\nAWwAoKIeIQUOWEghEOWBgODnTojA2o5q\n=B9dz\n-----END PGP SIGNATURE-----\n"}]}