{"thread":{"id":"60922","subject":"Bug: git-archive: --add-virtual-file doesn't seem to respect --prefix","startedAt":"2024-02-15T06:09:19Z","lastAt":"2024-02-15T11:49:23Z","messageCount":2,"participants":["Ron Yorston","stefan.naewe@atlas-elektronik.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"488686","messageId":"65cdaa23.MHIIVADqwryAD0ON%rmy@frippery.org","threadId":"60922","inReplyTo":null,"subject":"Bug: git-archive: --add-virtual-file doesn't seem to respect --prefix","fromName":"Ron Yorston","fromEmail":"rmy@frippery.org","sentAt":"2024-02-15T06:07:31Z","receivedAt":"2024-02-15T06:09:19Z","isPatch":false,"sender":{"key":"rmy@frippery.org","avatar":null},"body":"The man page for git-archive has similar language regarding the\n--add-file and --add-virtual-file options:\n\n   The path of the file in the archive is built by concatenating the\n   value of the last --prefix option (if any) before...\n\nHowever this doesn't seem to be true for --add-virtual-file.  In any\ngit repository:\n\n   $ touch real_added_file\n   $ git archive --format=tar --prefix=prefix/ --add-file=real_added_file \\\n      --add-virtual-file=virtual_added_file: HEAD | \\\n      tar tvf - | grep added_file\n   -rw-rw-r-- root/root         0 2017-02-22 17:18 prefix/real_added_file\n   -rw-rw-r-- root/root         0 2017-02-22 17:18 virtual_added_file\n\nI expected to see 'prefix/virtual_added_file'.\n\nRon\n"},{"id":"488733","messageId":"a143e25a70b44b82b4ee6fa3bb2bcda4@atlas-elektronik.com","threadId":"60922","inReplyTo":"65cdaa23.MHIIVADqwryAD0ON%rmy@frippery.org","subject":"AW: git-archive: --add-virtual-file doesn't seem to respect --prefix","fromName":"","fromEmail":"stefan.naewe@atlas-elektronik.com","sentAt":"2024-02-15T11:48:12Z","receivedAt":"2024-02-15T11:49:23Z","isPatch":false,"sender":{"key":"stefan.naewe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4468?v=4"},"body":"Classification - ISMS: Offen | VS: OFFEN\n\n> -----Ursprüngliche Nachricht-----\n> Von: Ron Yorston <rmy@frippery.org>\n> Gesendet: Donnerstag, 15. Februar 2024 07:08\n> An: git@vger.kernel.org\n> Betreff: Bug: git-archive: --add-virtual-file doesn't seem to respect --prefix\n> \n> The man page for git-archive has similar language regarding the --add-file and --\n> add-virtual-file options:\n> \n>    The path of the file in the archive is built by concatenating the\n>    value of the last --prefix option (if any) before...\n> \n> However this doesn't seem to be true for --add-virtual-file.  In any git repository:\n> \n>    $ touch real_added_file\n>    $ git archive --format=tar --prefix=prefix/ --add-file=real_added_file \\\n>       --add-virtual-file=virtual_added_file: HEAD | \\\n>       tar tvf - | grep added_file\n>    -rw-rw-r-- root/root         0 2017-02-22 17:18 prefix/real_added_file\n>    -rw-rw-r-- root/root         0 2017-02-22 17:18 virtual_added_file\n> \n> I expected to see 'prefix/virtual_added_file'.\n> \n> Ron\n\nMaybe something like this does the job:\n\n\ndiff --git a/archive.c b/archive.c\nindex 941495f5d7..b6b885a632 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -331,11 +331,11 @@ int write_archive_entries(struct archiver_args *args,\n\n                put_be64(fake_oid.hash, i + 1);\n\n+               strbuf_reset(&path_in_archive);\n+               if (info->base)\n+                       strbuf_addstr(&path_in_archive, info->base);\n+               strbuf_addstr(&path_in_archive, basename(path));\n                if (!info->content) {\n-                       strbuf_reset(&path_in_archive);\n-                       if (info->base)\n-                               strbuf_addstr(&path_in_archive, info->base);\n-                       strbuf_addstr(&path_in_archive, basename(path));\n\n                        strbuf_reset(&content);\n                        if (strbuf_read_file(&content, path, info->stat.st_size) < 0)\n@@ -347,7 +347,7 @@ int write_archive_entries(struct archiver_args *args,\n                                                  content.buf, content.len);\n                } else {\n                        err = write_entry(args, &fake_oid,\n-                                         path, strlen(path),\n+                                         path_in_archive.buf, path_in_archive.len,\n                                          canon_mode(info->stat.st_mode),\n                                          info->content, info->stat.st_size);\n                }\n\n\nStefan\n"}]}