[StGit PATCH] add option to import series directly from a tar archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Catalin/Karl,

Attached is my first cut at adding the ability to import a patch series by specifying
the tarball. For example, the following command:

	$ stg import --tarfile patch-2.6.26.3-rt6.bz2

will apply the latest -rt patch series to your current kernel tree.

No Karl, I haven't developed a test for it (yet).  I wanted to see what you guys
thought first :)

Clark
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkjDTscACgkQqA4JVb61b9dNRgCZAW+tOCgz5Y+A0IdomcOA4X7v
u8MAnRvFWMXRJ0Kxv1rAnBRnheq6Iidi
=W7Dl
-----END PGP SIGNATURE-----
patch to allow importing a series from a tar archive

From: Clark Williams <williams@xxxxxxxxxx>

Signed-off-by: Clark Williams <williams@xxxxxxxxxx>
---
 stgit/commands/imprt.py |   46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index 227743f..0e9bb73 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -87,7 +87,10 @@ options = [make_option('-m', '--mail',
            make_option('--commname',
                        help = 'use COMMNAME as the committer name'),
            make_option('--commemail',
-                       help = 'use COMMEMAIL as the committer e-mail')
+                       help = 'use COMMEMAIL as the committer e-mail'),
+           make_option('--tarfile',
+                       help = 'import a series from a tar archive',
+                       action = "store_true"),
            ] + make_sign_options()
 
 
@@ -287,6 +290,45 @@ 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 tarfile
+    import tempfile
+
+    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.startswith("../"):
+            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
+    os.system('rm -rf %s' % tmpdir)
+
 def func(parser, options, args):
     """Import a GNU diff file as a new patch
     """
@@ -308,6 +350,8 @@ def func(parser, options, args):
         __import_mbox(filename, options)
     elif options.url:
         __import_url(filename, options)
+    elif options.tarfile:
+        __import_tarfile(filename, options)
     else:
         __import_file(filename, options)
 

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux