Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-import sys, os, re, email
+import sys, os, re, email, tarfile
from mailbox import UnixMailbox
from StringIO import StringIO
from stgit.argparse import opt
opt('-M', '--mbox', action = 'store_true',
short = 'Import a series of patches from an mbox file'),
opt('-s', '--series', action = 'store_true',
- short = 'Import a series of patches'),
+ short = 'Import a series of patches', long = """
+ Import a series of patches from a series file or a tar archive."""),
opt('-u', '--url', action = 'store_true',
short = 'Import a patch from a URL'),
opt('-n', '--name',
applied = crt_series.get_applied()
if filename:
+ if tarfile.is_tarfile(filename):
+ __import_tarfile(filename, options)
+ return
f = file(filename)
patchdir = os.path.dirname(filename)
else:
urllib.urlretrieve(url, filename)
__import_file(filename, options)
+def __import_tarfile(tar, options):
+ """Import patch series from a tar archive
+ """
+ import tempfile
+ import shutil
+
+ if not tarfile.is_tarfile(tar):
+ raise CmdException, "%s is not a tarfile!" % tar
+
+ t = tarfile.open(tar, 'r')
+ names = t.getnames()
+
+ # verify paths in the tarfile are safe
+ for n in names:
+ if n.startswith('/'):
+ raise CmdException, "Absolute path found in %s" % tar
+ if n.find("..") > -1:
+ raise CmdException, "Relative path found in %s" % tar
+
+ # find the series file
+ seriesfile = '';
+ for m in names:
+ if m.endswith('/series') or m == 'series':
+ seriesfile = m
+ break
+ if seriesfile == '':
+ raise CmdException, "no 'series' file found in %s" % tar
+
+ # unpack into a tmp dir
+ tmpdir = tempfile.mkdtemp('.stg')
+ t.extractall(tmpdir)
+
+ # apply the series
+ __import_series(os.path.join(tmpdir, seriesfile), options)
+
+ # cleanup the tmpdir
+ shutil.rmtree(tmpdir)
+
def func(parser, options, args):
"""Import a GNU diff file as a new patch
"""
stg delete ..
'
+test_expect_success \
+ 'apply a series from a tarball' \
+ '
+ rm -f jabberwocky.txt && touch jabberwocky.txt &&
+ git add jabberwocky.txt && git commit -m "empty file" jabberwocky.txt &&
+ (cd ../t1800-import; tar -cjf jabberwocky.tar.bz2 patches) &&
+ stg import --series ../t1800-import/jabberwocky.tar.bz2
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree 2c33937252a21f1550c0bf21f1de534b68f69635") = 1 ] &&
+ rm ../t1800-import/jabberwocky.tar.bz2
+ '
+
test_done
--- /dev/null
+attribution
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 4 ++++
+ 1 files changed, 4 insertions(+), 0 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index 066d2e8..a9dd1f3 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -32,3 +32,7 @@ O frabjous day! Callooh! Callay!'
+ Did gyre and gimble in the wabe;
+ All mimsy were the borogoves,
+ And the mome raths outgrabe.
++
++ JABBERWOCKY
++ Lewis Carroll
++ (from Through the Looking-Glass and What Alice Found There, 1872)
--- /dev/null
+delete extra lines
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 2 --
+ 1 files changed, 0 insertions(+), 2 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index 98cb716..066d2e8 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -28,8 +28,6 @@ He left it dead, and with its head
+ O frabjous day! Callooh! Callay!'
+ He chortled in his joy.
+
+-
+-
+ `Twas brillig, and the slithy toves
+ Did gyre and gimble in the wabe;
+ All mimsy were the borogoves,
--- /dev/null
+fifth stanza
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 5 +++++
+ 1 files changed, 5 insertions(+), 0 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index b1c2ad3..f1416dc 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -17,3 +17,8 @@ And, as in uffish thought he stood,
+ The Jabberwock, with eyes of flame,
+ Came whiffling through the tulgey wood,
+ And burbled as it came!
++
++One, two! One, two! And through and through
++ The vorpal blade went snicker-snack!
++He left it dead, and with its head
++ He went galumphing back.
--- /dev/null
+first stanza
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 4 ++++
+ 1 files changed, 4 insertions(+), 0 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index e69de29..fba24dc 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -0,0 +1,4 @@
++`Twas brillig, and the slithy toves
++ Did gyre and gimble in the wabe:
++All mimsy were the borogoves,
++ And the mome raths outgrabe.
--- /dev/null
+fourth stanza
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 5 +++++
+ 1 files changed, 5 insertions(+), 0 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index 6405f36..b1c2ad3 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -12,3 +12,8 @@ He took his vorpal sword in hand:
+ Long time the manxome foe he sought --
+ So rested he by the Tumtum tree,
+ And stood awhile in thought.
++
++And, as in uffish thought he stood,
++ The Jabberwock, with eyes of flame,
++Came whiffling through the tulgey wood,
++ And burbled as it came!
--- /dev/null
+second stanza
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 5 +++++
+ 1 files changed, 5 insertions(+), 0 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index fba24dc..9ed0b49 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -2,3 +2,8 @@
+ Did gyre and gimble in the wabe:
+ All mimsy were the borogoves,
+ And the mome raths outgrabe.
++
++"Beware the Jabberwock, my son!
++ The jaws that bite, the claws that catch!
++Beware the Jubjub bird, and shun
++ The frumious Bandersnatch!"
--- /dev/null
+# This series applies on GIT commit 6a8b6f6e2ecbcab26de7656b66b7f30eeba1ee96
+first-stanza.patch
+second-stanza.patch
+third-stanza.patch
+fourth-stanza.patch
+fifth-stanza.patch
+sixth-stanza.patch
+seventh-stanza.patch
+delete-extra-lines.patch
+attribution.patch
--- /dev/null
+seventh stanza
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 7 +++++++
+ 1 files changed, 7 insertions(+), 0 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index bf732f5..98cb716 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -27,3 +27,10 @@ He left it dead, and with its head
+ Come to my arms, my beamish boy!
+ O frabjous day! Callooh! Callay!'
+ He chortled in his joy.
++
++
++
++`Twas brillig, and the slithy toves
++ Did gyre and gimble in the wabe;
++All mimsy were the borogoves,
++ And the mome raths outgrabe.
--- /dev/null
+sixth stanza
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 5 +++++
+ 1 files changed, 5 insertions(+), 0 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index f1416dc..bf732f5 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -22,3 +22,8 @@ One, two! One, two! And through and through
+ The vorpal blade went snicker-snack!
+ He left it dead, and with its head
+ He went galumphing back.
++
++"And, has thou slain the Jabberwock?
++ Come to my arms, my beamish boy!
++O frabjous day! Callooh! Callay!'
++ He chortled in his joy.
--- /dev/null
+third stanza
+
+From: Clark Williams <williams@redhat.com>
+
+
+---
+ jabberwocky.txt | 5 +++++
+ 1 files changed, 5 insertions(+), 0 deletions(-)
+
+diff --git a/jabberwocky.txt b/jabberwocky.txt
+index 9ed0b49..6405f36 100644
+--- a/jabberwocky.txt
++++ b/jabberwocky.txt
+@@ -7,3 +7,8 @@ All mimsy were the borogoves,
+ The jaws that bite, the claws that catch!
+ Beware the Jubjub bird, and shun
+ The frumious Bandersnatch!"
++
++He took his vorpal sword in hand:
++ Long time the manxome foe he sought --
++So rested he by the Tumtum tree,
++ And stood awhile in thought.