{"thread":{"id":"21157","subject":"Git archive and trailing \"/\" in prefix","startedAt":"2009-10-08T15:35:44Z","lastAt":"2009-10-09T12:49:47Z","messageCount":7,"participants":["Sergio Callegari","Junio C Hamano","René Scharfe","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"124383","messageId":"loom.20091008T172303-658@post.gmane.org","threadId":"21157","inReplyTo":null,"subject":"Git archive and trailing \"/\" in prefix","fromName":"Sergio Callegari","fromEmail":"sergio.callegari@gmail.com","sentAt":"2009-10-08T15:35:44Z","receivedAt":"2009-10-08T15:35:44Z","isPatch":false,"sender":{"key":"sergio.callegari@gmail.com","avatar":"https://gravatar.com/avatar/c98f41317e0422c1e630385de0e3970227b8e5ad15f35ba8586066467cc833bc?d=mp&s=160"},"body":"Hi!\n\nThe git-archive man page indicates that if the --prefix option is passed to\ngit-archive, it is compulsory to end the prefix with a \"/\"\n\n git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>] ...\n\nAs a matter of fact, the archiver behaves quite strangely if that slash is\nmissing. Files in the root of the working dir are added to the archive with\ntheir own name modified by the prefix and the same happens for working dir\nsub-directories. However, no file present in the sub-directories, nor\nsub-sub-directories are added.\n\nI would like to know if there some reason why a trailing \"/\" is not added\nautomatically to the prefix when it is missing and the prefix is not empty.\nWould that break anything?\n\nThanks!\n\nSergio\n"},{"id":"124385","messageId":"7v4oq9j1gs.fsf@alter.siamese.dyndns.org","threadId":"21157","inReplyTo":"loom.20091008T172303-658@post.gmane.org","subject":"Re: Git archive and trailing \"/\" in prefix","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-08T16:26:59Z","receivedAt":"2009-10-08T16:26:59Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sergio Callegari <sergio.callegari@gmail.com> writes:\n\n> The git-archive man page indicates that if the --prefix option is passed to\n> git-archive, it is compulsory to end the prefix with a \"/\"\n\nNo, it does not have to.\n\n\t$ git archive --prefix=v1.6.0- v1.6.0 Makefile | tar xf -\n\t$ make -f v1.6.0-Makefile\n\nThis is consistent with the way the same --prefix option can be used with\ncheckout-index.  e.g. to swap Makefile in work tree and in the index:\n\n\t$ edit Makefile\n\t$ git checkout-index --prefix=old- Makefile\n\t$ git update-index Makefile\n        $ mv old-Makefile Makefile\n\nThese may or may not be useful examples, but this feature has been with us\nfor a long time.  I wouldn't be surprised if removing the ability to\narchive or checkout with filename prefix (not leading directory path\nprefix) causes grief to existing scripts of people.\n"},{"id":"124387","messageId":"4ACE177E.209@lsrfire.ath.cx","threadId":"21157","inReplyTo":"loom.20091008T172303-658@post.gmane.org","subject":"Re: Git archive and trailing \"/\" in prefix","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-10-08T16:46:54Z","receivedAt":"2009-10-08T16:46:54Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Sergio Callegari schrieb:\n> Hi!\n> \n> The git-archive man page indicates that if the --prefix option is passed to\n> git-archive, it is compulsory to end the prefix with a \"/\"\n> \n>  git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>] ...\n> \n> As a matter of fact, the archiver behaves quite strangely if that slash is\n> missing. Files in the root of the working dir are added to the archive with\n> their own name modified by the prefix and the same happens for working dir\n> sub-directories. However, no file present in the sub-directories, nor\n> sub-sub-directories are added.\n\nThe latter is a bug.\n\n> I would like to know if there some reason why a trailing \"/\" is not added\n> automatically to the prefix when it is missing and the prefix is not empty.\n> Would that break anything?\n\nThe --prefix option is intended to add a string to the beginning (i.e. \"to\nprefix\") of the name of the archive entries.  I'm not sure if there's a use\ncase for anything else than adding a fake directory for all entries to live\nin (thus requiring a trailing slash), but I also don't see why we should\ndisallow it.\n\nThe following patch fixes handling of prefixes without trailing slashes by\ntaking it out of the hands of get_pathspec() and read_tree_recursive() --\nwhich can only handle prefixes that are path components -- and adding the\nprefix later, in write_archive_entry().  \n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n archive.c |    7 ++++---\n 1 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 73b8e8a..0cc79d2 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -115,6 +115,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,\n \n \tstrbuf_reset(&path);\n \tstrbuf_grow(&path, PATH_MAX);\n+\tstrbuf_add(&path, args->base, args->baselen);\n \tstrbuf_add(&path, base, baselen);\n \tstrbuf_addstr(&path, filename);\n \tpath_without_prefix = path.buf + args->baselen;\n@@ -187,8 +188,8 @@ int write_archive_entries(struct archiver_args *args,\n \t\tgit_attr_set_direction(GIT_ATTR_INDEX, &the_index);\n \t}\n \n-\terr =  read_tree_recursive(args->tree, args->base, args->baselen, 0,\n-\t\t\targs->pathspec, write_archive_entry, &context);\n+\terr = read_tree_recursive(args->tree, \"\", 0, 0, args->pathspec,\n+\t\t\t\t  write_archive_entry, &context);\n \tif (err == READ_TREE_RECURSIVE)\n \t\terr = 0;\n \treturn err;\n@@ -211,7 +212,7 @@ static const struct archiver *lookup_archiver(const char *name)\n static void parse_pathspec_arg(const char **pathspec,\n \t\tstruct archiver_args *ar_args)\n {\n-\tar_args->pathspec = get_pathspec(ar_args->base, pathspec);\n+\tar_args->pathspec = get_pathspec(\"\", pathspec);\n }\n \n static void parse_treeish_arg(const char **argv,\n"},{"id":"124402","messageId":"alpine.LFD.2.01.0910081329570.3432@localhost.localdomain","threadId":"21157","inReplyTo":"loom.20091008T172303-658@post.gmane.org","subject":"Re: Git archive and trailing \"/\" in prefix","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-10-08T20:35:25Z","receivedAt":"2009-10-08T20:35:25Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 8 Oct 2009, Sergio Callegari wrote:\n> \n> The git-archive man page indicates that if the --prefix option is passed to\n> git-archive, it is compulsory to end the prefix with a \"/\"\n\nYeah, that part is intentional. And:\n\n> As a matter of fact, the archiver behaves quite strangely if that slash is\n> missing. Files in the root of the working dir are added to the archive with\n> their own name modified by the prefix and the same happens for working dir\n> sub-directories.\n\nSo far so good. But\n\n> However, no file present in the sub-directories, nor sub-sub-directories \n> are added.\n\nOk, that is a bug. It's supposed to just add the prefix to everything, and \nit sounds like it's simply broken. I wonder how long it's been broken? \nPerhaps forever. \n\n> I would like to know if there some reason why a trailing \"/\" is not added\n> automatically to the prefix when it is missing and the prefix is not empty.\n> Would that break anything?\n\nIt really was meant to be useful to prefix things without forcing a \ndirectory structure. IOW, being able to use \"--prefix=compat-\" and just \nhave everything unpack with their own names, but with the prefix.\n\nWhether anybody uses that, and whether it's worth it, I can't say.\n\n\t\t\tLinus\n"},{"id":"124406","messageId":"4ACE62B1.8070801@gmail.com","threadId":"21157","inReplyTo":"7v4oq9j1gs.fsf@alter.siamese.dyndns.org","subject":"Re: Git archive and trailing \"/\" in prefix","fromName":"Sergio Callegari","fromEmail":"sergio.callegari@gmail.com","sentAt":"2009-10-08T22:07:45Z","receivedAt":"2009-10-08T22:07:45Z","isPatch":false,"sender":{"key":"sergio.callegari@gmail.com","avatar":"https://gravatar.com/avatar/c98f41317e0422c1e630385de0e3970227b8e5ad15f35ba8586066467cc833bc?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> Sergio Callegari <sergio.callegari@gmail.com> writes:\n>\n>   \n>> The git-archive man page indicates that if the --prefix option is passed to\n>> git-archive, it is compulsory to end the prefix with a \"/\"\n>>     \n>\n> No, it does not have to.\n>\n> \t$ git archive --prefix=v1.6.0- v1.6.0 Makefile | tar xf -\n> \t$ make -f v1.6.0-Makefile\n>   \nThanks... I now see better all the possible uses.\n\n> This is consistent with the way the same --prefix option can be used with\n> checkout-index.  e.g. to swap Makefile in work tree and in the index:\n>\n> \t$ edit Makefile\n> \t$ git checkout-index --prefix=old- Makefile\n> \t$ git update-index Makefile\n>         $ mv old-Makefile Makefile\n>\n> These may or may not be useful examples, but this feature has been with us\n> for a long time.  I wouldn't be surprised if removing the ability to\n> archive or checkout with filename prefix (not leading directory path\n> prefix) causes grief to existing scripts of people.\n>   \nThat's why I asked btw. I did not want to start experimenting \nmodification like auto adding a \"/\"\nafter the prefix without knowing whether they could have limited some \nother uses or broken some\nconsistency. I now see they would do.\n\nI guess the bug in using --prefix on a worktree with subdirs without \nspecifying a path is not specific\nto git archive, then.\n\nSergio\n>   \n>\n>   \n"},{"id":"124432","messageId":"7vpr8x5acz.fsf@alter.siamese.dyndns.org","threadId":"21157","inReplyTo":"4ACE177E.209@lsrfire.ath.cx","subject":"Re: Git archive and trailing \"/\" in prefix","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-09T06:50:52Z","receivedAt":"2009-10-09T06:50:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:\n\n> Sergio Callegari schrieb:\n> ...\n>> As a matter of fact, the archiver behaves quite strangely if that slash is\n>> missing. Files in the root of the working dir are added to the archive with\n>> their own name modified by the prefix and the same happens for working dir\n>> sub-directories. However, no file present in the sub-directories, nor\n>> sub-sub-directories are added.\n>\n> The latter is a bug.\n> ...\n> The following patch fixes...\n\nThanks.  Applied with a trivial test.\n"},{"id":"124485","messageId":"4ACF316B.5090807@lsrfire.ath.cx","threadId":"21157","inReplyTo":"4ACE62B1.8070801@gmail.com","subject":"Re: Git archive and trailing \"/\" in prefix","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-10-09T12:49:47Z","receivedAt":"2009-10-09T12:49:47Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Sergio Callegari schrieb:\n> I guess the bug in using --prefix on a worktree with subdirs without\n> specifying a path is not specific to git archive, then.\n\nThe bug should be limited to archive; after my patch all calls to\nread_tree_recursive() specify an empty base parameter (except in tree.c,\nwhere the function itself lives).\n\nRené\n"}]}