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-Status: No, score=-3.9 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, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 8F6771F8C2 for ; Mon, 8 Feb 2021 19:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235152AbhBHTsa (ORCPT ); Mon, 8 Feb 2021 14:48:30 -0500 Received: from mout.web.de ([212.227.17.12]:43561 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236475AbhBHTsN (ORCPT ); Mon, 8 Feb 2021 14:48:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1612813567; bh=q+dzEVAe5daiRmZOod3YCg2uECjRWFb7sPV54VnIHPs=; h=X-UI-Sender-Class:From:Subject:To:References:Date:In-Reply-To; b=RhYetEirJBppGJ3W/khEzre+AZg2lwz6Xv//a/I9J4xZtgj3a0N04Ttpy4qcFe8Ew GySa7QM+DtiddV6iSSKPfCWRp2SV7ef/CE3KcGxFXBKRWFLChijFypOHvTOLtdcvv7 nmodfm2ncL/W7yHKspbge9/pnSpMF1TB6Uq8dEHQ= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from Mini-von-Rene.fritz.box ([91.47.159.90]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MoeY7-1lfoOc1Kh7-00p7mr; Mon, 08 Feb 2021 20:46:07 +0100 From: =?UTF-8?Q?Ren=c3=a9_Scharfe?= Subject: Re: gitattributes export-subst and software versioning To: Eli Schwartz , git@vger.kernel.org References: <7418f1d8-78c2-61a7-4f03-62360b986a41@archlinux.org> Message-ID: Date: Mon, 8 Feb 2021 20:46:06 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <7418f1d8-78c2-61a7-4f03-62360b986a41@archlinux.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:9b5Rw+7Ee0FDHJLY9pucRGG1FvGayqMBbIsfa4x8Iz6dx1ysYNn RBK3gGBrbgBC1mgjXeuHjuSn4boN9TQqmmGPzt4iLE/nVO16R1yUFnKxqH2CMUWQZ0yR9CJ J3QrwpXT3PUbJ6dS5Wfggm4h9coyKR3+glcTI5ZCgTpCage02306TH7wsOwi6z9YQexSW2b PvHSXYg47D5yG3raOtEWQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:oYGS7FtHrss=:jtNrhBJXEb0RFJMvSuXSSD J+a5UtgrpkWB6wYEV3HujaDJ6xqyNjH24V7AvAidKq6OlCpa0Ebe0UBPVpL0mSjZgK/5YBakr vIzT8dSCQ6wuSc1ke0Wqks8jT//KuAflqceCyTyTaUvOoFiPkGOVdCg4vC3pHDLMj3LyJO0V+ bvY3aPc9DIBTC808BbSTHBPnUpkI5AOwlIXzTZcvNGeJbADS6v6zygjE0fLtmUzaGSyAlp+ah HOaPnogHF/njKBDT2UR7id0F0MagC+WlZjbtgfESQVMkGaKI0EDqQegb0BoecHI2w/ol8PMTF Jn34jmLKkCeqxdiieOe1tgiL9kjl/3VAvu1y8WC/d39DhijeHOxdZQQY75oLyuwjBx4v/8AWt YVPo2tg/x4Cn/8eOToE+9KhBPsZT67CvGGcn0/y6FD+SSPPG/INpdPIhb9uLd81jx9JEGvHsX 9p/3qwFJoQIgQ6lMgKqZzJxFYVozTqM4Ohv3wP/1WbSF9+A7soPsHAcn2HKvYGyHDGVspHxUH 5Q4M6bd8pWObK4HuiMBexqGzgvzy296rdhzgB7QeKeUSKGH8PxeXgJzhOJvSfPY8egApOZLCA eIGngeOd8B7+2K/ZlKLRrcO2gRtSgYxJIn4TY5bl5qPYW79p2RPgKuQPHIxgf/cW4vUS6lNs+ CAnsCras/Xergd09VuSCik4iK+7ttHVp+kHj255YypmwPfL/T4tNJUw4v9uyqFndhh2Mye3NL PnTH8kP2lTGRHtipJ9P5C8RaZeoq02RsMoCg13d6bb/Kei/P2i5h2xh6dFcZc9Z3HX/tFlz30 XPFw8CWOhEVKmBCDHLFuj+Y1qbKIWk8DdZA5qoX+PO8ttZhFPqN45pTCwVqKEEz33ko3oMqbg B1i32oVB1ANLB7glf/ag== Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Am 25.01.21 um 01:32 schrieb Eli Schwartz: > Periodically, I wonder if there is some better way for managing > tagged releases for software in git. Current state of the art seems > to be "write a custom Makefile that takes a version and seds out the > existing version, then runs git tag for you". Inelegant solutions > also abound; people release code that does not build properly unless > you build it from a git checkout so it can run git describe. (There > are half a dozen individually popular but mutually exclusive python > ecosystems for this, in fact, all of them varying degrees of > broken.) > > git does have a way to automatically insert metadata via the > export-subst attribute on a file, but it's very awkward to use and > you cannot get much info out of it. > > # get tags into a file, only on exact match: > > $ cat VERSION $Format:%d$ $Format:%D$ > > $ git archive HEAD | bsdtar -xOf - VERSION (HEAD -> master, tag: > 1.0) HEAD -> master, tag: 1.0 > > With sufficient regex, you can get a release out of this, but it > doesn't work if you try getting an autogenerated tarball for a commit > that isn't exactly a release. > > $ git commit --allow-empty -m ... $ git archive HEAD | bsdtar -xOf - > VERSION (HEAD -> master) HEAD -> master > > I think it would be much, much nicer if there was a format > placeholder for git describe. Totally. > It doesn't even need option support -- the default output in most > cases could be a replacement for or fall back to existing invocations > of the "git" program, followed by post-processing with e.g. "sed". > > However, the existence of current pretty formats such as %C() or > %(trailer:options) implies that options could be passed in a > git-describe format too. e.g. %(describe:--long --tags --match=3D"v*") > > Thoughts? git archive uses the pretty format code for export-subst. It is used by git log and others as well. git describe uses all object flags to find the best description. Simply plugging it into the pretty format code would clash with the object flag use of git log. And replacing the flags with a commit slab doesn't seem to be enough, either -- I get good results lots of commits, but for some git log with the new placeholder would just show some nonsensical output, as it seems to get the depth calculation wrong for them somehow. Anyway, we can of course do something like in the patch below. It works, it's easy, it's fast enough for git archive, and it's quite hideous. Hopefully it's bad enough to motivate someone to come up with a cleaner, faster solution. Ren=C3=A9 =2D-- pretty.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pretty.c b/pretty.c index 3922f6f9f2..bbfb5ca3e7 100644 =2D-- a/pretty.c +++ b/pretty.c @@ -12,6 +12,7 @@ #include "reflog-walk.h" #include "gpg-interface.h" #include "trailer.h" +#include "run-command.h" static char *user_format; static struct cmt_fmt_map { @@ -1213,6 +1214,21 @@ static size_t format_commit_one(struct strbuf *sb, = /* in UTF-8 */ return parse_padding_placeholder(placeholder, c); } + if (skip_prefix(placeholder, "(describe)", &arg)) { + struct child_process cmd =3D CHILD_PROCESS_INIT; + struct strbuf out =3D STRBUF_INIT; + + cmd.git_cmd =3D 1; + strvec_push(&cmd.args, "describe"); + strvec_push(&cmd.args, "--always"); + strvec_push(&cmd.args, oid_to_hex(&commit->object.oid)); + pipe_command(&cmd, NULL, 0, &out, 0, NULL, 0); + strbuf_rtrim(&out); + strbuf_addbuf(sb, &out); + strbuf_release(&out); + return arg - placeholder; + } + /* these depend on the commit */ if (!commit->object.parsed) parse_object(the_repository, &commit->object.oid); =2D- 2.30.0