chiark / gitweb /
Teach "stg import" to import patch series from tar archives
authorClark Williams <williams@redhat.com>
Fri, 24 Oct 2008 01:10:36 +0000 (03:10 +0200)
committerKarl Hasselström <kha@treskal.com>
Fri, 24 Oct 2008 01:10:36 +0000 (03:10 +0200)
Signed-off-by: Clark Williams <williams@redhat.com>
Signed-off-by: Karl Hasselström <kha@treskal.com>
12 files changed:
stgit/commands/imprt.py
t/t1800-import.sh
t/t1800-import/patches/attribution.patch [new file with mode: 0644]
t/t1800-import/patches/delete-extra-lines.patch [new file with mode: 0644]
t/t1800-import/patches/fifth-stanza.patch [new file with mode: 0644]
t/t1800-import/patches/first-stanza.patch [new file with mode: 0644]
t/t1800-import/patches/fourth-stanza.patch [new file with mode: 0644]
t/t1800-import/patches/second-stanza.patch [new file with mode: 0644]
t/t1800-import/patches/series [new file with mode: 0644]
t/t1800-import/patches/seventh-stanza.patch [new file with mode: 0644]
t/t1800-import/patches/sixth-stanza.patch [new file with mode: 0644]
t/t1800-import/patches/third-stanza.patch [new file with mode: 0644]

index de5e9a506ef7f2f416cf096c99d09df4ffceb632..3eb29ba32dc5af41634d79a5a80894caf97a56cf 100644 (file)
@@ -15,7 +15,7 @@ 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, re, email
+import sys, os, re, email, tarfile
 from mailbox import UnixMailbox
 from StringIO import StringIO
 from stgit.argparse import opt
@@ -51,7 +51,8 @@ options = [
     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',
@@ -227,6 +228,9 @@ def __import_series(filename, options):
     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:
@@ -280,6 +284,44 @@ def __import_url(url, options):
     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
     """
index 9c317411f0dc2aaead640031850d4c4b9cafb57c..ecaa5934c28eb556a3f5b255870392fe3720f5a4 100755 (executable)
@@ -133,4 +133,16 @@ test_expect_success \
     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
diff --git a/t/t1800-import/patches/attribution.patch b/t/t1800-import/patches/attribution.patch
new file mode 100644 (file)
index 0000000..2b7c8f9
--- /dev/null
@@ -0,0 +1,21 @@
+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) 
diff --git a/t/t1800-import/patches/delete-extra-lines.patch b/t/t1800-import/patches/delete-extra-lines.patch
new file mode 100644 (file)
index 0000000..e5b7a65
--- /dev/null
@@ -0,0 +1,22 @@
+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,
diff --git a/t/t1800-import/patches/fifth-stanza.patch b/t/t1800-import/patches/fifth-stanza.patch
new file mode 100644 (file)
index 0000000..4f0e77c
--- /dev/null
@@ -0,0 +1,22 @@
+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.
diff --git a/t/t1800-import/patches/first-stanza.patch b/t/t1800-import/patches/first-stanza.patch
new file mode 100644 (file)
index 0000000..ee7818f
--- /dev/null
@@ -0,0 +1,18 @@
+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.
diff --git a/t/t1800-import/patches/fourth-stanza.patch b/t/t1800-import/patches/fourth-stanza.patch
new file mode 100644 (file)
index 0000000..eb2f8f2
--- /dev/null
@@ -0,0 +1,22 @@
+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!
diff --git a/t/t1800-import/patches/second-stanza.patch b/t/t1800-import/patches/second-stanza.patch
new file mode 100644 (file)
index 0000000..bec1622
--- /dev/null
@@ -0,0 +1,22 @@
+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!"
diff --git a/t/t1800-import/patches/series b/t/t1800-import/patches/series
new file mode 100644 (file)
index 0000000..5945c98
--- /dev/null
@@ -0,0 +1,10 @@
+# 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
diff --git a/t/t1800-import/patches/seventh-stanza.patch b/t/t1800-import/patches/seventh-stanza.patch
new file mode 100644 (file)
index 0000000..555c200
--- /dev/null
@@ -0,0 +1,24 @@
+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.
diff --git a/t/t1800-import/patches/sixth-stanza.patch b/t/t1800-import/patches/sixth-stanza.patch
new file mode 100644 (file)
index 0000000..2349b7e
--- /dev/null
@@ -0,0 +1,22 @@
+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.
diff --git a/t/t1800-import/patches/third-stanza.patch b/t/t1800-import/patches/third-stanza.patch
new file mode 100644 (file)
index 0000000..d942353
--- /dev/null
@@ -0,0 +1,22 @@
+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.