From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id EB2EC1F4D7 for ; Fri, 20 May 2022 14:41:44 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=web.de header.i=@web.de header.b="V7FUBhIN"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237172AbiETOln (ORCPT ); Fri, 20 May 2022 10:41:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350446AbiETOl2 (ORCPT ); Fri, 20 May 2022 10:41:28 -0400 Received: from mout.web.de (mout.web.de [212.227.15.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F49E457A0 for ; Fri, 20 May 2022 07:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1653057668; bh=U/IGik8E+3ZaNZ+U67/oKmre7q5yubBH6dYbyaNNjZs=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=V7FUBhINhCxAkVErEAbNETZojzBhdsHLh6XdFxbrNKmAj2HJPw4OFZZB+zaA88M7t Qgqi3/z0lV9oRVHHQrqGDWG4hFL+9IPdayeSRll2o0gcM159BPIeOLL1AwMdxvQb7I R0yvDBSWCgjodGCxM4tWDKHc2KTK3+vvb9VELC9k= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.29] ([79.203.22.168]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MQxs3-1oCECJ10p5-00O6wA; Fri, 20 May 2022 16:41:08 +0200 Message-ID: <99ffe394-42bb-6c04-b8ab-2d67c38d7756@web.de> Date: Fri, 20 May 2022 16:41:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v5 1/7] archive: optionally add "virtual" files Content-Language: en-US To: Johannes Schindelin via GitGitGadget , git@vger.kernel.org Cc: Taylor Blau , Derrick Stolee , Elijah Newren , rsbecker@nexbridge.com, =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Johannes Schindelin References: <42e73fb0aaca1f2498ed817c517859103d72d32b.1652984283.git.gitgitgadget@gmail.com> From: =?UTF-8?Q?Ren=c3=a9_Scharfe?= In-Reply-To: <42e73fb0aaca1f2498ed817c517859103d72d32b.1652984283.git.gitgitgadget@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:V8ZSdHoqupgG8q2q05yJ8sGHTvEgP4EWoGdRIcTyUKjJwwD1Kx+ Sq8Ojk1TyWIViBGYNoKfAVEF3cAzP87ZuyHRg0nXsGicihsprNVBQPERTi1jWA9kyp+Mvw4 pjdlvsrM/dvGIEFHnVpTrsWtU1XwP4/S5rHL+xDFuLMogeLhoCTbFGwtsUVPEgH96M2ez/W vEW8hm/3m6uxMhqOAQ15w== X-UI-Out-Filterresults: notjunk:1;V03:K0:i+wt9ey66vI=:omSrav00V1ILJLNkxxhwJY ydE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PL88DDuBF+8qoeLkb7WH vKSHqgiq7LTuEricY+Q0s43TrsWN4ZA4Dbo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Am 19.05.22 um 20:17 schrieb Johannes Schindelin via GitGitGadget: > From: Johannes Schindelin > > With the `--add-file-with-content=3D:` option, `git ^^^^^^^^^^^^^^^^^^^^^^^ That's still the old option name. Same in the subject of patch 2. > archive` now supports use cases where relatively trivial files need to > be added that do not exist on disk. > > This will allow us to generate `.zip` files with generated content, > without having to add said content to the object database and without > having to write it out to disk. > > Signed-off-by: Johannes Schindelin > --- > Documentation/git-archive.txt | 11 ++++++++ > archive.c | 53 +++++++++++++++++++++++++++++------ > t/t5003-archive-zip.sh | 12 ++++++++ > 3 files changed, 68 insertions(+), 8 deletions(-) > > diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.t= xt > index bc4e76a7834..893cb1075bf 100644 > --- a/Documentation/git-archive.txt > +++ b/Documentation/git-archive.txt > @@ -61,6 +61,17 @@ OPTIONS > by concatenating the value for `--prefix` (if any) and the > basename of . > > +--add-virtual-file=3D::: > + Add the specified contents to the archive. Can be repeated to add > + multiple files. The path of the file in the archive is built > + by concatenating the value for `--prefix` (if any) and the > + basename of . > ++ > +The `` cannot contain any colon, the file mode is limited to > +a regular file, and the option may be subject to platform-dependent > +command-line limits. For non-trivial cases, write an untracked file > +and use `--add-file` instead. > + > --worktree-attributes:: > Look for attributes in .gitattributes files in the working tree > as well (see <>). > diff --git a/archive.c b/archive.c > index a3bbb091256..d20e16fa819 100644 > --- a/archive.c > +++ b/archive.c > @@ -263,6 +263,7 @@ static int queue_or_write_archive_entry(const struct= object_id *oid, > struct extra_file_info { > char *base; > struct stat stat; > + void *content; > }; > > int write_archive_entries(struct archiver_args *args, > @@ -337,7 +338,13 @@ int write_archive_entries(struct archiver_args *arg= s, > strbuf_addstr(&path_in_archive, basename(path)); > > strbuf_reset(&content); > - if (strbuf_read_file(&content, path, info->stat.st_size) < 0) > + if (info->content) > + err =3D write_entry(args, &fake_oid, path_in_archive.buf, > + path_in_archive.len, > + info->stat.st_mode, > + info->content, info->stat.st_size); > + else if (strbuf_read_file(&content, path, > + info->stat.st_size) < 0) > err =3D error_errno(_("could not read '%s'"), path); > else > err =3D write_entry(args, &fake_oid, path_in_archive.buf, > @@ -493,6 +500,7 @@ static void extra_file_info_clear(void *util, const = char *str) > { > struct extra_file_info *info =3D util; > free(info->base); > + free(info->content); > free(info); > } > > @@ -514,14 +522,40 @@ static int add_file_cb(const struct option *opt, c= onst char *arg, int unset) > if (!arg) > return -1; > > - path =3D prefix_filename(args->prefix, arg); > - item =3D string_list_append_nodup(&args->extra_files, path); > - item->util =3D info =3D xmalloc(sizeof(*info)); > + info =3D xmalloc(sizeof(*info)); > info->base =3D xstrdup_or_null(base); > - if (stat(path, &info->stat)) > - die(_("File not found: %s"), path); > - if (!S_ISREG(info->stat.st_mode)) > - die(_("Not a regular file: %s"), path); > + > + if (!strcmp(opt->long_name, "add-file")) { > + path =3D prefix_filename(args->prefix, arg); > + if (stat(path, &info->stat)) > + die(_("File not found: %s"), path); > + if (!S_ISREG(info->stat.st_mode)) > + die(_("Not a regular file: %s"), path); > + info->content =3D NULL; /* read the file later */ > + } else if (!strcmp(opt->long_name, "add-virtual-file")) { > + const char *colon =3D strchr(arg, ':'); > + char *p; > + > + if (!colon) > + die(_("missing colon: '%s'"), arg); > + > + p =3D xstrndup(arg, colon - arg); > + if (!args->prefix) > + path =3D p; > + else { > + path =3D prefix_filename(args->prefix, p); > + free(p); > + } > + memset(&info->stat, 0, sizeof(info->stat)); > + info->stat.st_mode =3D S_IFREG | 0644; > + info->content =3D xstrdup(colon + 1); > + info->stat.st_size =3D strlen(info->content); > + } else { > + BUG("add_file_cb() called for %s", opt->long_name); > + } > + item =3D string_list_append_nodup(&args->extra_files, path); > + item->util =3D info; > + > return 0; > } > > @@ -554,6 +588,9 @@ static int parse_archive_args(int argc, const char *= *argv, > { OPTION_CALLBACK, 0, "add-file", args, N_("file"), > N_("add untracked file to archive"), 0, add_file_cb, > (intptr_t)&base }, > + { OPTION_CALLBACK, 0, "add-virtual-file", args, > + N_("path:content"), N_("add untracked file to archive"), 0, > + add_file_cb, (intptr_t)&base }, > OPT_STRING('o', "output", &output, N_("file"), > N_("write the archive to this file")), > OPT_BOOL(0, "worktree-attributes", &worktree_attributes, > diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh > index 1e6d18b140e..ebc26e89a9b 100755 > --- a/t/t5003-archive-zip.sh > +++ b/t/t5003-archive-zip.sh > @@ -206,6 +206,18 @@ test_expect_success 'git archive --format=3Dzip --a= dd-file' ' > check_zip with_untracked > check_added with_untracked untracked untracked > > +test_expect_success UNZIP 'git archive --format=3Dzip --add-virtual-fil= e' ' > + git archive --format=3Dzip >with_file_with_content.zip \ > + --add-virtual-file=3Dhello:world $EMPTY_TREE && > + test_when_finished "rm -rf tmp-unpack" && > + mkdir tmp-unpack && ( > + cd tmp-unpack && > + "$GIT_UNZIP" ../with_file_with_content.zip && > + test_path_is_file hello && > + test world =3D $(cat hello) > + ) > +' > + > test_expect_success 'git archive --format=3Dzip --add-file twice' ' > echo untracked >untracked && > git archive --format=3Dzip --prefix=3Done/ --add-file=3Duntracked \