{"thread":{"id":"20273","subject":"Adding files to a git-archive when it is generated, and whats the best way to find out what branch a commit is on?","startedAt":"2009-07-29T08:15:29Z","lastAt":"2009-08-04T17:50:04Z","messageCount":14,"participants":["demerphq","Avery Pennarun","Santi Béjar","Jeff Epler","René Scharfe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"119028","messageId":"9b18b3110907290115v1f30eeat748631bb09f92517@mail.gmail.com","threadId":"20273","inReplyTo":null,"subject":"Adding files to a git-archive when it is generated, and whats the best way to find out what branch a commit is on?","fromName":"demerphq","fromEmail":"demerphq@gmail.com","sentAt":"2009-07-29T08:15:29Z","receivedAt":"2009-07-29T08:15:29Z","isPatch":false,"sender":{"key":"demerphq@gmail.com","avatar":null},"body":"I was wondering if anybody had any suggestions on a sane way to add a\nfile to a git-archive when it is being produced.\n\nFor  instance build procedures that expect to be run inside of a git\nWD wont work if built from an archived version of the tree. Being able\nto provide a file of additional data to the archive package would be a\nvery convenient way to work around this.\n\nIdeally id like to be able to specify a set of additional files to\ninclude in the archive as part of the git-archive command line\ninterface, but I'd be nearly as a happy with almost any solution other\nthan the one I came up with, which is to use archive to generate a tar\nfile, then use tar to append the additional files to the tar, and then\ncompress it. This process turns out to be quite slow in comparison to\nproducing a compressed archive directly from git-archive.\n\nAnother question is whether anyone has any advice on the best way to\nfind out the \"best\" branch an arbitrary commit is on. Where best can\nbe flexibly definied to handle commits that are reachable from\nmultiple branches.  I have hacked a solution involving git-log and\ngrep, but it performs quite poorly. I was wondering if there is a\nbetter solution.\n\ncheers,\nYves\n\n\n\n-- \nperl -Mre=debug -e \"/just|another|perl|hacker/\"\n"},{"id":"119036","messageId":"32541b130907290140y25c6a0b2r5ed0123e0ce1ae1@mail.gmail.com","threadId":"20273","inReplyTo":"9b18b3110907290115v1f30eeat748631bb09f92517@mail.gmail.com","subject":"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?","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2009-07-29T08:40:19Z","receivedAt":"2009-07-29T08:40:19Z","isPatch":false,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On Wed, Jul 29, 2009 at 4:15 AM, demerphq<demerphq@gmail.com> wrote:\n> Another question is whether anyone has any advice on the best way to\n> find out the \"best\" branch an arbitrary commit is on. Where best can\n> be flexibly definied to handle commits that are reachable from\n> multiple branches.  I have hacked a solution involving git-log and\n> grep, but it performs quite poorly. I was wondering if there is a\n> better solution.\n\n'git describe' does this.\n\nAvery\n"},{"id":"119037","messageId":"adf1fd3d0907290141v24cf129eue3939bf1afd518d2@mail.gmail.com","threadId":"20273","inReplyTo":"9b18b3110907290115v1f30eeat748631bb09f92517@mail.gmail.com","subject":"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?","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-07-29T08:41:01Z","receivedAt":"2009-07-29T08:41:01Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/7/29 demerphq <demerphq@gmail.com>:\n> I was wondering if anybody had any suggestions on a sane way to add a\n> file to a git-archive when it is being produced.\n>\n> For  instance build procedures that expect to be run inside of a git\n> WD wont work if built from an archived version of the tree. Being able\n> to provide a file of additional data to the archive package would be a\n> very convenient way to work around this.\n>\n> Ideally id like to be able to specify a set of additional files to\n> include in the archive as part of the git-archive command line\n> interface, but I'd be nearly as a happy with almost any solution other\n> than the one I came up with, which is to use archive to generate a tar\n> file, then use tar to append the additional files to the tar, and then\n> compress it. This process turns out to be quite slow in comparison to\n> producing a compressed archive directly from git-archive.\n\nThen I don't know. It is exactly the way it is done in git.git itself,\nlook the dist target in the makefile.\n\n>\n> Another question is whether anyone has any advice on the best way to\n> find out the \"best\" branch an arbitrary commit is on. Where best can\n> be flexibly definied to handle commits that are reachable from\n> multiple branches.  I have hacked a solution involving git-log and\n> grep, but it performs quite poorly. I was wondering if there is a\n> better solution.\n\nThe \"best\" tag is easy: git describe commit. For branches I think you\ncould use \"git name-ref --refs=refs/heads/* commit\", because git\ndescribe does not have a --branches flag.\n\nHTH,\nSanti\n"},{"id":"119045","messageId":"9b18b3110907290221o8afc72s157969ef7d707d4d@mail.gmail.com","threadId":"20273","inReplyTo":"adf1fd3d0907290141v24cf129eue3939bf1afd518d2@mail.gmail.com","subject":"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?","fromName":"demerphq","fromEmail":"demerphq@gmail.com","sentAt":"2009-07-29T09:21:32Z","receivedAt":"2009-07-29T09:21:32Z","isPatch":false,"sender":{"key":"demerphq@gmail.com","avatar":null},"body":"2009/7/29 Santi Béjar <santi@agolina.net>:\n> 2009/7/29 demerphq <demerphq@gmail.com>:\n>> I was wondering if anybody had any suggestions on a sane way to add a\n>> file to a git-archive when it is being produced.\n>>\n>> For  instance build procedures that expect to be run inside of a git\n>> WD wont work if built from an archived version of the tree. Being able\n>> to provide a file of additional data to the archive package would be a\n>> very convenient way to work around this.\n>>\n>> Ideally id like to be able to specify a set of additional files to\n>> include in the archive as part of the git-archive command line\n>> interface, but I'd be nearly as a happy with almost any solution other\n>> than the one I came up with, which is to use archive to generate a tar\n>> file, then use tar to append the additional files to the tar, and then\n>> compress it. This process turns out to be quite slow in comparison to\n>> producing a compressed archive directly from git-archive.\n>\n> Then I don't know. It is exactly the way it is done in git.git itself,\n> look the dist target in the makefile.\n\nSo then git also would benefit from support in git-archive for adding\narbitrary files to the archive during generation?\n\nOne problem here is that we (the Perl project) are supporting VMS\nsmoke-testers and need the ability to provide snapshots that are\nbuildable without using git at all. So we hacked the snapshot support\nin gitweb to do this. However we dont want to do this for every\ncommit, just the ones that people actually fetch. So while the process\nwe use is fine for rolling a dist, its not so fine when people are\nexpecting a download to start promptly after clicking on the snapshot\nlink.\n\n>\n>>\n>> Another question is whether anyone has any advice on the best way to\n>> find out the \"best\" branch an arbitrary commit is on. Where best can\n>> be flexibly definied to handle commits that are reachable from\n>> multiple branches.  I have hacked a solution involving git-log and\n>> grep, but it performs quite poorly. I was wondering if there is a\n>> better solution.\n>\n> The \"best\" tag is easy: git describe commit. For branches I think you\n> could use \"git name-ref --refs=refs/heads/* commit\", because git\n> describe does not have a --branches flag.\n\nDang, I guess this is from a newer release than mine. So now i have an\nexcuse to upgrade.\n\n:-)\n\nYves\n\n\n\n\n-- \nperl -Mre=debug -e \"/just|another|perl|hacker/\"\n"},{"id":"119047","messageId":"adf1fd3d0907290233y78514f98h89a2fca7bf68b4f2@mail.gmail.com","threadId":"20273","inReplyTo":"9b18b3110907290221o8afc72s157969ef7d707d4d@mail.gmail.com","subject":"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?","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-07-29T09:33:04Z","receivedAt":"2009-07-29T09:33:04Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/7/29 demerphq <demerphq@gmail.com>:\n> 2009/7/29 Santi Béjar <santi@agolina.net>:\n>> 2009/7/29 demerphq <demerphq@gmail.com>:\n>>> Another question is whether anyone has any advice on the best way to\n>>> find out the \"best\" branch an arbitrary commit is on. Where best can\n>>> be flexibly definied to handle commits that are reachable from\n>>> multiple branches.  I have hacked a solution involving git-log and\n>>> grep, but it performs quite poorly. I was wondering if there is a\n>>> better solution.\n>>\n>> The \"best\" tag is easy: git describe commit. For branches I think you\n>> could use \"git name-ref --refs=refs/heads/* commit\", because git\n>> describe does not have a --branches flag.\n>\n> Dang, I guess this is from a newer release than mine. So now i have an\n> excuse to upgrade.\n\nNo, it is quite old (the --refs flag since the v1.5.1). If the problem\nis that you don't find the \"git name-ref\" command is because it is\n\"git name-rev\", oops.\n\nSanti\n"},{"id":"119050","messageId":"9b18b3110907290251t4d8c83d3rf12d0ea9268c19bd@mail.gmail.com","threadId":"20273","inReplyTo":"adf1fd3d0907290233y78514f98h89a2fca7bf68b4f2@mail.gmail.com","subject":"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?","fromName":"demerphq","fromEmail":"demerphq@gmail.com","sentAt":"2009-07-29T09:51:42Z","receivedAt":"2009-07-29T09:51:42Z","isPatch":false,"sender":{"key":"demerphq@gmail.com","avatar":null},"body":"2009/7/29 Santi Béjar <santi@agolina.net>:\n> 2009/7/29 demerphq <demerphq@gmail.com>:\n>> 2009/7/29 Santi Béjar <santi@agolina.net>:\n>>> 2009/7/29 demerphq <demerphq@gmail.com>:\n>>>> Another question is whether anyone has any advice on the best way to\n>>>> find out the \"best\" branch an arbitrary commit is on. Where best can\n>>>> be flexibly definied to handle commits that are reachable from\n>>>> multiple branches.  I have hacked a solution involving git-log and\n>>>> grep, but it performs quite poorly. I was wondering if there is a\n>>>> better solution.\n>>>\n>>> The \"best\" tag is easy: git describe commit. For branches I think you\n>>> could use \"git name-ref --refs=refs/heads/* commit\", because git\n>>> describe does not have a --branches flag.\n>>\n>> Dang, I guess this is from a newer release than mine. So now i have an\n>> excuse to upgrade.\n>\n> No, it is quite old (the --refs flag since the v1.5.1). If the problem\n> is that you don't find the \"git name-ref\" command is because it is\n> \"git name-rev\", oops.\n\nDang, guess i need a different excuse. :-)\n\nBut it doesn't seem to do what i need:\n\n$ git name-rev --refs=refs/heads/* faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7\nfaa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7 undefined\n\nBut i think that just because in this case I need remote refs:\n\ngit name-rev --refs=refs/remotes/* faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7\nfaa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7 remotes/origin/maint-5.005~25\n\nWhich is definitely better. Can I safely strip the ~25 off the end to\nget the real branch name?\n\nBTW, this is the shell version of what I'm currently using:\n\n$ for b in $(git branch -r); do git log --pretty='format:%H' $b | grep\nfaa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7 && echo $b; done\nfaa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7\norigin/maint-5.005\n\nThe main difference with the real code I use (in perl) is that I can\nspecify the order of the branches to be searched, so that I can ensure\nthat if its on two it is reported to be \"from\" the most likely\ncandidate. And of course the perl version I use stops searching as\nsoon as it finds a match.\n\nAnyway, if I can reliably strip off the ~25 then this is a big step\nforward for me.\n\nThanks Santi, and of course thanks Johannes (author of name-rev).\n\ncheers,\nYves\n\n-- \nperl -Mre=debug -e \"/just|another|perl|hacker/\"\n"},{"id":"119052","messageId":"adf1fd3d0907290413x4aa0d091ldb651537a101a2f8@mail.gmail.com","threadId":"20273","inReplyTo":"9b18b3110907290251t4d8c83d3rf12d0ea9268c19bd@mail.gmail.com","subject":"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?","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-07-29T11:13:45Z","receivedAt":"2009-07-29T11:13:45Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/7/29 demerphq <demerphq@gmail.com>:\n> 2009/7/29 Santi Béjar <santi@agolina.net>:\n>> 2009/7/29 demerphq <demerphq@gmail.com>:\n>>> 2009/7/29 Santi Béjar <santi@agolina.net>:\n>>>> 2009/7/29 demerphq <demerphq@gmail.com>:\n>>>>> Another question is whether anyone has any advice on the best way to\n>>>>> find out the \"best\" branch an arbitrary commit is on. Where best can\n>>>>> be flexibly definied to handle commits that are reachable from\n>>>>> multiple branches.  I have hacked a solution involving git-log and\n>>>>> grep, but it performs quite poorly. I was wondering if there is a\n>>>>> better solution.\n>>>>\n>>>> The \"best\" tag is easy: git describe commit. For branches I think you\n>>>> could use \"git name-ref --refs=refs/heads/* commit\", because git\n>>>> describe does not have a --branches flag.\n>>>\n>>> Dang, I guess this is from a newer release than mine. So now i have an\n>>> excuse to upgrade.\n>>\n>> No, it is quite old (the --refs flag since the v1.5.1). If the problem\n>> is that you don't find the \"git name-ref\" command is because it is\n>> \"git name-rev\", oops.\n>\n> Dang, guess i need a different excuse. :-)\n>\n> But it doesn't seem to do what i need:\n>\n> $ git name-rev --refs=refs/heads/* faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7\n> faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7 undefined\n>\n> But i think that just because in this case I need remote refs:\n>\n> git name-rev --refs=refs/remotes/* faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7\n> faa7dc9f4d3a618b0ad8b3c95edd54e24c6976e7 remotes/origin/maint-5.005~25\n>\n> Which is definitely better. Can I safely strip the ~25 off the end to\n> get the real branch name?\n\nYes, it describes the relation between both, you can strip everything\nafter ^ or ~ (and you can use the --name-only to remove the sha1).\n\nHTH,\nSanti\n"},{"id":"119074","messageId":"20090729161202.GA2443@unpythonic.net","threadId":"20273","inReplyTo":"9b18b3110907290115v1f30eeat748631bb09f92517@mail.gmail.com","subject":"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?","fromName":"Jeff Epler","fromEmail":"jepler@unpythonic.net","sentAt":"2009-07-29T16:12:02Z","receivedAt":"2009-07-29T16:12:02Z","isPatch":false,"sender":{"key":"jepler@unpythonic.net","avatar":"https://avatars.githubusercontent.com/u/1517291?v=4"},"body":"When I wanted to add extra files to a tar produced by git-archive, I\nused python's tarfile module.  This assumes the tar will fit comfortably\nin memory.  The specifics probably don't apply in your case, but maybe\nit will be useful anyhow.\n\nYou could also use tar's -r or gnu tar's -A modes to add to the\ngit-archive tar once it's been created:\n    git-archive ... > temp.tar\n    tar -rf temp.tar additional-file\n(unfortunately, -r and -A don't operate on pipes)\n\ndef main(args):\n    if len(args) == 1:\n        version = args[0]\n    elif len(args) > 1:\n        raise SystemExit, \"Usage: %s [version]\" % sys.argv[0]\n    else:\n        status, gitversion = commands.getstatusoutput(\"git-describe --tags\")\n        version = highest_version()\n        if status != 0 or version != gitversion:\n            raise SystemExit, \"\"\"\\\nHighest version %r doesn't match description %r.\nSpecify version number explicitly if this is what you want\"\"\" % (\n                    version, gitversion)\n\n    version = version.lstrip(\"v\")\n\n    DIRNAME = \"%(p)s-%(v)s\" % {'p': PACKAGE_NAME, 'v': version}\n    TARNAME = DIRNAME + '.tar.gz'\n\n    verstream = StringIO.StringIO(\"%s\\n\" % version)\n    verinfo = tarfile.TarInfo(DIRNAME + \"/VERSION\")\n    verinfo.mode = 0660\n    verinfo.size = len(verstream.getvalue())\n    verinfo.mtime = time.time()\n\n    tardata = os.popen(\"git-archive --prefix=%(p)s/ v%(v)s\"\n                            % {'p': DIRNAME, 'v': version}).read()\n    tarstream = StringIO.StringIO(tardata)\n\n    tar = tarfile.TarFile(mode=\"a\", fileobj=tarstream)\n    tar.addfile(verinfo, verstream)\n    tar.close()\n\n    out = gzip.open(\"../\" + TARNAME, \"wb\")\n    out.write(tarstream.getvalue())\n    out.close()\n"},{"id":"119191","messageId":"4A720393.6030607@lsrfire.ath.cx","threadId":"20273","inReplyTo":"9b18b3110907290221o8afc72s157969ef7d707d4d@mail.gmail.com","subject":"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?","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-07-30T20:33:23Z","receivedAt":"2009-07-30T20:33:23Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"demerphq schrieb:\n> So then git also would benefit from support in git-archive for adding\n> arbitrary files to the archive during generation?\n\nYes, and this has come up before.\n\nHow about the following?  It's missing documentation and a test case,\nbut you could try\n\n\t$ git archive --add-file extra HEAD >HEAD+extra.tar\n\nor\n\n\t$ git archive --prefix=a/ --add-file extra --prefix=b/ HEAD >ba.tar\n\nOnly the file name part (after the last slash) of the extra file is used,\ntogether with the prefix, to form the path of the archive entry.\n\nOpening the extra files when parsing the command line arguments and closing\nthem after they have been written into the archive is a bit iffy, but it's\nimpractical to report open errors after parts of the archive have already\nbeen created.\n\nRené\n\n---\n archive.c |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----\n archive.h |    3 ++\n 2 files changed, 71 insertions(+), 6 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 0bca9ca..368e7e8 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -25,6 +25,12 @@ static const struct archiver {\n \t{ \"zip\", write_zip_archive, USES_ZLIB_COMPRESSION },\n };\n \n+struct extra_file {\n+\tchar *path;\n+\tint fd;\n+\tstruct extra_file *next;\n+};\n+\n static void format_subst(const struct commit *commit,\n                          const char *src, size_t len,\n                          struct strbuf *buf)\n@@ -147,12 +153,29 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,\n \treturn err;\n }\n \n+static int write_extra_file(struct extra_file *extra_file,\n+\t\t\t    struct archiver_args *args,\n+\t\t\t    write_archive_entry_fn_t write_entry)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint err;\n+\n+\tif (strbuf_read(&buf, extra_file->fd, 0) < 0)\n+\t\treturn error(\"cannot read extra file: %s\", extra_file->path);\n+\tclose(extra_file->fd);\n+\terr = write_entry(args, null_sha1, extra_file->path,\n+\t\t\t  strlen(extra_file->path), 0100644, buf.buf, buf.len);\n+\tstrbuf_release(&buf);\n+\treturn err;\n+}\n+\n int write_archive_entries(struct archiver_args *args,\n \t\twrite_archive_entry_fn_t write_entry)\n {\n \tstruct archiver_context context;\n \tstruct unpack_trees_options opts;\n \tstruct tree_desc t;\n+\tstruct extra_file *extra_file = args->extra_files;\n \tint err;\n \n \tif (args->baselen > 0 && args->base[args->baselen - 1] == '/') {\n@@ -191,6 +214,12 @@ int write_archive_entries(struct archiver_args *args,\n \t\t\targs->pathspec, write_archive_entry, &context);\n \tif (err == READ_TREE_RECURSIVE)\n \t\terr = 0;\n+\n+\twhile (!err && extra_file) {\n+\t\terr = write_extra_file(extra_file, args, write_entry);\n+\t\textra_file = extra_file->next;\n+\t}\n+\n \treturn err;\n }\n \n@@ -265,11 +294,41 @@ static void parse_treeish_arg(const char **argv,\n \t{ OPTION_SET_INT, (s), NULL, (v), NULL, \"\", \\\n \t  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_HIDDEN, NULL, (p) }\n \n+static int extra_files_cb(const struct option *opt, const char *arg, int unset)\n+{\n+\tstruct archiver_args *args = opt->value;\n+\tstruct extra_file *e = xmalloc(sizeof(struct extra_file));\n+\tstruct strbuf path = STRBUF_INIT;\n+\tconst char *last_slash, *prefix = args->base;\n+\n+\te->fd = open(arg, O_RDONLY);\n+\tif (e->fd == -1)\n+\t\tdie_errno(\"Could not open file '%s'\", arg);\n+\n+\tif (prefix)\n+\t\tstrbuf_addstr(&path, prefix);\n+\tlast_slash = strrchr(arg, '/');\n+\tstrbuf_addstr(&path, last_slash ? last_slash + 1 : arg);\n+\te->path = strbuf_detach(&path, NULL);\n+\n+\te->next = NULL;\n+\n+\tif (args->extra_files) {\n+\t\tstruct extra_file *prev = args->extra_files;\n+\t\twhile (prev->next)\n+\t\t\tprev = prev->next;\n+\t\tprev->next = e;\n+\t} else {\n+\t\targs->extra_files = e;\n+\t}\n+\n+\treturn 0;\n+}\n+\n static int parse_archive_args(int argc, const char **argv,\n \t\tconst struct archiver **ar, struct archiver_args *args)\n {\n \tconst char *format = \"tar\";\n-\tconst char *base = NULL;\n \tconst char *remote = NULL;\n \tconst char *exec = NULL;\n \tconst char *output = NULL;\n@@ -281,10 +340,13 @@ static int parse_archive_args(int argc, const char **argv,\n \tstruct option opts[] = {\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_STRING(0, \"format\", &format, \"fmt\", \"archive format\"),\n-\t\tOPT_STRING(0, \"prefix\", &base, \"prefix\",\n+\t\tOPT_STRING(0, \"prefix\", &args->base, \"prefix\",\n \t\t\t\"prepend prefix to each pathname in the archive\"),\n \t\tOPT_STRING(0, \"output\", &output, \"file\",\n \t\t\t\"write the archive to this file\"),\n+\t\t{ OPTION_CALLBACK, 0, \"add-file\", args, \"file\",\n+\t\t\t\"add file to the archive, using prefix as path\",\n+\t\t\tPARSE_OPT_NONEG, extra_files_cb },\n \t\tOPT_BOOLEAN(0, \"worktree-attributes\", &worktree_attributes,\n \t\t\t\"read .gitattributes in working directory\"),\n \t\tOPT__VERBOSE(&verbose),\n@@ -318,8 +380,8 @@ static int parse_archive_args(int argc, const char **argv,\n \tif (output)\n \t\tdie(\"Unexpected option --output\");\n \n-\tif (!base)\n-\t\tbase = \"\";\n+\tif (!args->base)\n+\t\targs->base = \"\";\n \n \tif (list) {\n \t\tfor (i = 0; i < ARRAY_SIZE(archivers); i++)\n@@ -344,8 +406,7 @@ static int parse_archive_args(int argc, const char **argv,\n \t\t}\n \t}\n \targs->verbose = verbose;\n-\targs->base = base;\n-\targs->baselen = strlen(base);\n+\targs->baselen = strlen(args->base);\n \targs->worktree_attributes = worktree_attributes;\n \n \treturn argc;\n@@ -357,6 +418,7 @@ int write_archive(int argc, const char **argv, const char *prefix,\n \tconst struct archiver *ar = NULL;\n \tstruct archiver_args args;\n \n+\tmemset(&args, 0, sizeof(struct archiver_args));\n \targc = parse_archive_args(argc, argv, &ar, &args);\n \tif (setup_prefix && prefix == NULL)\n \t\tprefix = setup_git_directory();\ndiff --git a/archive.h b/archive.h\nindex 038ac35..a88bdbb 100644\n--- a/archive.h\n+++ b/archive.h\n@@ -1,6 +1,8 @@\n #ifndef ARCHIVE_H\n #define ARCHIVE_H\n \n+struct extra_file;\n+\n struct archiver_args {\n \tconst char *base;\n \tsize_t baselen;\n@@ -11,6 +13,7 @@ struct archiver_args {\n \tconst char **pathspec;\n \tunsigned int verbose : 1;\n \tunsigned int worktree_attributes : 1;\n+\tstruct extra_file *extra_files;\n \tint compression_level;\n };\n \n"},{"id":"119242","messageId":"9b18b3110907310304w261ee30bw8c06c6a65e936e6e@mail.gmail.com","threadId":"20273","inReplyTo":"4A720393.6030607@lsrfire.ath.cx","subject":"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?","fromName":"demerphq","fromEmail":"demerphq@gmail.com","sentAt":"2009-07-31T10:04:50Z","receivedAt":"2009-07-31T10:04:50Z","isPatch":false,"sender":{"key":"demerphq@gmail.com","avatar":null},"body":"2009/7/30 René Scharfe <rene.scharfe@lsrfire.ath.cx>:\n> demerphq schrieb:\n>> So then git also would benefit from support in git-archive for adding\n>> arbitrary files to the archive during generation?\n>\n> Yes, and this has come up before.\n>\n> How about the following?  It's missing documentation and a test case,\n> but you could try\n>\n>        $ git archive --add-file extra HEAD >HEAD+extra.tar\n>\n> or\n>\n>        $ git archive --prefix=a/ --add-file extra --prefix=b/ HEAD >ba.tar\n>\n> Only the file name part (after the last slash) of the extra file is used,\n> together with the prefix, to form the path of the archive entry.\n>\n> Opening the extra files when parsing the command line arguments and closing\n> them after they have been written into the archive is a bit iffy, but it's\n> impractical to report open errors after parts of the archive have already\n> been created.\n\nI havent managed to try it out yet but this is pretty much exactly\nwhat I was looking for. Only thought I had was that it might be nice\nto be able to specify what name the file should be added as so that\nyou can add files to subpaths deeper than the root/root prefix of the\ntar. However for /my/ particular purposes that is unnecessary, it only\noccurs to me as a nice to have. But if you were inclined to think\nabout extending it I was thinking an argument notation like --add-file\nfoo:bar/baz/bop might be useful.\n\nAnyway, thanks a lot, assuming it works ok, which I'm sure it does,\neven if it doesn't get accepted to git it is likely we will build a\ngit that does use it for the perl gitweb site. Much appreciated.\n\ncheers,\nYves\n\n\n\n-- \nperl -Mre=debug -e \"/just|another|perl|hacker/\"\n"},{"id":"119272","messageId":"9b18b3110907310648y4178da4cs9264dc01de50426@mail.gmail.com","threadId":"20273","inReplyTo":"m3hbwtrpip.fsf@localhost.localdomain","subject":"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?","fromName":"demerphq","fromEmail":"demerphq@gmail.com","sentAt":"2009-07-31T13:48:21Z","receivedAt":"2009-07-31T13:48:21Z","isPatch":false,"sender":{"key":"demerphq@gmail.com","avatar":null},"body":"2009/7/31 Jakub Narebski <jnareb@gmail.com>:\n> demerphq <demerphq@gmail.com> writes:\n>> 2009/7/30 René Scharfe <rene.scharfe@lsrfire.ath.cx>:\n>> > demerphq schrieb:\n>\n>>>> So then git also would benefit from support in git-archive for adding\n>>>> arbitrary files to the archive during generation?\n>>>\n>>> Yes, and this has come up before.\n>>>\n>>> How about the following?  It's missing documentation and a test case,\n>>> but you could try\n>>>\n>>>        $ git archive --add-file extra HEAD>HEAD+extra.tar\n>>>\n>>> or\n>>>\n>>>        $ git archive --prefix=a/ --add-file extra --prefix=b/ HEAD>ba.tar\n>>\n>> I havent managed to try it out yet but this is pretty much exactly\n>> what I was looking for. Only thought I had was that it might be nice\n>> to be able to specify what name the file should be added as so that\n>> you can add files to subpaths deeper than the root/root prefix of the\n>> tar. However for /my/ particular purposes that is unnecessary, it only\n>> occurs to me as a nice to have. But if you were inclined to think\n>> about extending it I was thinking an argument notation like --add-file\n>> foo:bar/baz/bop might be useful.\n>\n> Why not use notation used by --graft-points option of mkisofs, i.e.\n> \"--add-file foo=bar/baz/bop\", where 'foo' is name in archive\n> (respective to prefix if any, I think), and 'bar/baz/bop' is name in\n> filesystem.\n>\n> The proposed notation \"--add-file foo:bar/baz/bop\" looks for me (see\n> extended sha-1 syntax in git-rev-parse manpage) like adding file\n> 'bar/baz/bop' from 'foo' tree-ish.\n\nWhatever is most appropriate. I was just demonstrating what I had in mind.\n\ncheers,\nYves\n\n\n-- \nperl -Mre=debug -e \"/just|another|perl|hacker/\"\n"},{"id":"119381","messageId":"4A759A21.7070806@lsrfire.ath.cx","threadId":"20273","inReplyTo":"9b18b3110907310304w261ee30bw8c06c6a65e936e6e@mail.gmail.com","subject":"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?","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-08-02T13:52:33Z","receivedAt":"2009-08-02T13:52:33Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"demerphq schrieb:\n> 2009/7/30 René Scharfe <rene.scharfe@lsrfire.ath.cx>:\n>> demerphq schrieb:\n>>> So then git also would benefit from support in git-archive for adding\n>>> arbitrary files to the archive during generation?\n>> Yes, and this has come up before.\n>>\n>> How about the following?  It's missing documentation and a test case,\n>> but you could try\n>>\n>>        $ git archive --add-file extra HEAD >HEAD+extra.tar\n>>\n>> or\n>>\n>>        $ git archive --prefix=a/ --add-file extra --prefix=b/ HEAD >ba.tar\n>>\n>> Only the file name part (after the last slash) of the extra file is used,\n>> together with the prefix, to form the path of the archive entry.\n>>\n>> Opening the extra files when parsing the command line arguments and closing\n>> them after they have been written into the archive is a bit iffy, but it's\n>> impractical to report open errors after parts of the archive have already\n>> been created.\n> \n> I havent managed to try it out yet but this is pretty much exactly\n> what I was looking for. Only thought I had was that it might be nice\n> to be able to specify what name the file should be added as so that\n> you can add files to subpaths deeper than the root/root prefix of the\n> tar. However for /my/ particular purposes that is unnecessary, it only\n> occurs to me as a nice to have. But if you were inclined to think\n> about extending it I was thinking an argument notation like --add-file\n> foo:bar/baz/bop might be useful.\n\nWith the patch as-is, you can make a file named bop appear as\nbar/baz/bop in the archive (by using a prefix of bar/baz/), but not as\nfoo.  I wonder how often one needs to rename a file while adding it to\nthe archive -- or indeed if this is needed at all.  Being lazy, I'd wait\nfor such a case to appear before supporting it with a double-valued\ncommand line argument.\n\nRené\n"},{"id":"119382","messageId":"9b18b3110908020719h79cf4872p9f284346cd6a185b@mail.gmail.com","threadId":"20273","inReplyTo":"4A759A21.7070806@lsrfire.ath.cx","subject":"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?","fromName":"demerphq","fromEmail":"demerphq@gmail.com","sentAt":"2009-08-02T14:19:54Z","receivedAt":"2009-08-02T14:19:54Z","isPatch":false,"sender":{"key":"demerphq@gmail.com","avatar":null},"body":"2009/8/2 René Scharfe <rene.scharfe@lsrfire.ath.cx>:\n> demerphq schrieb:\n>> 2009/7/30 René Scharfe <rene.scharfe@lsrfire.ath.cx>:\n>>> demerphq schrieb:\n>>>> So then git also would benefit from support in git-archive for adding\n>>>> arbitrary files to the archive during generation?\n>>> Yes, and this has come up before.\n>>>\n>>> How about the following?  It's missing documentation and a test case,\n>>> but you could try\n>>>\n>>>        $ git archive --add-file extra HEAD >HEAD+extra.tar\n>>>\n>>> or\n>>>\n>>>        $ git archive --prefix=a/ --add-file extra --prefix=b/ HEAD >ba.tar\n>>>\n>>> Only the file name part (after the last slash) of the extra file is used,\n>>> together with the prefix, to form the path of the archive entry.\n>>>\n>>> Opening the extra files when parsing the command line arguments and closing\n>>> them after they have been written into the archive is a bit iffy, but it's\n>>> impractical to report open errors after parts of the archive have already\n>>> been created.\n>>\n>> I havent managed to try it out yet but this is pretty much exactly\n>> what I was looking for. Only thought I had was that it might be nice\n>> to be able to specify what name the file should be added as so that\n>> you can add files to subpaths deeper than the root/root prefix of the\n>> tar. However for /my/ particular purposes that is unnecessary, it only\n>> occurs to me as a nice to have. But if you were inclined to think\n>> about extending it I was thinking an argument notation like --add-file\n>> foo:bar/baz/bop might be useful.\n>\n> With the patch as-is, you can make a file named bop appear as\n> bar/baz/bop in the archive (by using a prefix of bar/baz/), but not as\n> foo.  I wonder how often one needs to rename a file while adding it to\n> the archive -- or indeed if this is needed at all.  Being lazy, I'd wait\n> for such a case to appear before supporting it with a double-valued\n> command line argument.\n\nWell I was kinda thinking the case of a snapshot generator on\nsomething like gitweb.\n\nIn that case you could have multiple processes trying to create the\nsame snapshot.\n\nOne solution is to do the work in a process specific temporary\ndirectory with the correct name and then add it that way.\n\nA slightly nicer approach is create the file in a common working\ndirectory with a temporary name and then have it added to the archive\nwith a different name. This is actually the approach I used by\nexploiting the the --transform option to tar. So while it might appear\nmy request is a YAGNI it is actually a IADNI (I Already Did Need It).\n\nEven nicer and cleaner of course would be support something like\n\"--add-file -=.patch\"  with the \"-\" meaning \"read from STDIN\", which\nthen means temporary files can be avoided, assuming one only needs to\nadd a single file to the archive. This is particularly nice if the\ncontent of  the file can be generated from the output of something\nlike git-describe or git rev-parse or any generic tool.\n\nSo IMO actually this functionality would be very useful, and isnt so\nweird when you think of it in context of generating snapshots for a\n\"git aware\" build process.\n\nOf course this is all very easy for me to say as a back-seat driver. :-)\n\ncheers,\nYves\n\n\n\n\n-- \nperl -Mre=debug -e \"/just|another|perl|hacker/\"\n"},{"id":"119509","messageId":"4A7874CC.9050702@lsrfire.ath.cx","threadId":"20273","inReplyTo":"9b18b3110908020719h79cf4872p9f284346cd6a185b@mail.gmail.com","subject":"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?","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-08-04T17:50:04Z","receivedAt":"2009-08-04T17:50:04Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"demerphq schrieb:\n> One solution is to do the work in a process specific temporary\n> directory with the correct name and then add it that way.\n> \n> A slightly nicer approach is create the file in a common working\n> directory with a temporary name and then have it added to the archive\n> with a different name. This is actually the approach I used by\n> exploiting the the --transform option to tar. So while it might appear\n> my request is a YAGNI it is actually a IADNI (I Already Did Need It).\n> \n> Even nicer and cleaner of course would be support something like\n> \"--add-file -=.patch\"  with the \"-\" meaning \"read from STDIN\", which\n> then means temporary files can be avoided, assuming one only needs to\n> add a single file to the archive. This is particularly nice if the\n> content of  the file can be generated from the output of something\n> like git-describe or git rev-parse or any generic tool.\n\nThis case (single file in archive, contents from stdin) could be handled\nby another option, e.g. named --add-stdin <name_in_archive>, without\nresorting to multi-valued option parameters.\n\nAlso, if a file can be generated using a --pretty=format: string, then\nyou can let git-archive expand a checked-in template by setting the\nattribute export-subst.  This works for multiple files, but doesn't if\nyou need git-describe style output (yet).\n\n> So IMO actually this functionality would be very useful, and isnt so\n> weird when you think of it in context of generating snapshots for a\n> \"git aware\" build process.\n\nNo doubt about it.  The question is: how to expose such functionality?\nPerhaps all that is needed for your purposes is a format place-holder\nfor git-describe output?\n\n(git itself needs more: in addition to the files \"version\" and\n\"git.spec\", which could benefit from such a place-holder, it adds the\ngenerated \"configure\" script and \"git-gui/version\" to the tarball.)\n\nRené\n"}]}