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

Re: Adding files to a git-archive when it is generated, and whats the best way to find out what branch a commit is on?

From
Jeff Epler <jepler@unpythonic.net>
Date
Jul 29, 2009, 16:12 UTC
Message-ID
<20090729161202.GA2443@unpythonic.net>
In-Reply-To
<9b18b3110907290115v1f30eeat748631bb09f92517@mail.gmail.com>

When I wanted to add extra files to a tar produced by git-archive, I used python's tarfile module. This assumes the tar will fit comfortably in memory. The specifics probably don't apply in your case, but maybe it will be useful anyhow.

You could also use tar's -r or gnu tar's -A modes to add to the
git-archive tar once it's been created:
    git-archive ... > temp.tar
    tar -rf temp.tar additional-file
(unfortunately, -r and -A don't operate on pipes)
def main(args):
    if len(args) == 1:
        version = args[0]
    elif len(args) > 1:
        raise SystemExit, "Usage: %s [version]" % sys.argv[0]
    else:
        status, gitversion = commands.getstatusoutput("git-describe --tags")
        version = highest_version()
        if status != 0 or version != gitversion:
            raise SystemExit, """\
Highest version %r doesn't match description %r.
Specify version number explicitly if this is what you want""" % (
                    version, gitversion)
    version = version.lstrip("v")
    DIRNAME = "%(p)s-%(v)s" % {'p': PACKAGE_NAME, 'v': version}
    TARNAME = DIRNAME + '.tar.gz'
    verstream = StringIO.StringIO("%s\n" % version)
    verinfo = tarfile.TarInfo(DIRNAME + "/VERSION")
    verinfo.mode = 0660
    verinfo.size = len(verstream.getvalue())
    verinfo.mtime = time.time()
    tardata = os.popen("git-archive --prefix=%(p)s/ v%(v)s"
                            % {'p': DIRNAME, 'v': version}).read()
    tarstream = StringIO.StringIO(tardata)
    tar = tarfile.TarFile(mode="a", fileobj=tarstream)
    tar.addfile(verinfo, verstream)
    tar.close()
    out = gzip.open("../" + TARNAME, "wb")
    out.write(tarstream.getvalue())
    out.close()
Previous: René ScharfeNext: demerphq
Message 13 of 14 in “Adding files to a git-archive when it is generated, and whats the best way to find out what branch a commit is on?”
  1. demerphqJul 29, 2009
  2. Avery PennarunJul 29, 2009
  3. Santi BéjarJul 29, 2009
  4. demerphqJul 29, 2009
  5. Santi BéjarJul 29, 2009
  6. demerphqJul 29, 2009
  7. Santi BéjarJul 29, 2009
  8. René ScharfeJul 30, 2009
  9. demerphqJul 31, 2009
  10. René ScharfeAug 2, 2009
  11. demerphqAug 2, 2009
  12. René ScharfeAug 4, 2009
  13. Jeff EplerJul 29, 2009
  14. demerphqJul 31, 2009

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.