git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
CWClark Williams <clark.williams@gmail.com>
Date
Sep 7, 2008, 03:47 UTC
Message-ID
<48C34EC7.9040102@gmail.com>
-----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@redhat.com>
Signed-off-by: Clark Williams <williams@redhat.com>
---
 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)
 
Next: Karl Hasselström
Message 1 of 10 in “add option to import series directly from a tar archive”
  1. add option to import series directly from a tar archiveClark Williams, Sep 7, 2008
  2. Karl HasselströmSep 8, 2008
  3. Clark WilliamsSep 8, 2008
  4. Karl HasselströmSep 8, 2008
  5. Samuel TardieuSep 12, 2008
  6. Clark WilliamsSep 12, 2008
  7. Samuel TardieuSep 12, 2008
  8. Karl HasselströmSep 12, 2008
  9. Karl HasselströmSep 12, 2008
  10. Karl HasselströmSep 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.