From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27304 invoked from network); 5 Jan 2021 13:10:02 -0000 Received: from krantz.zx2c4.com (192.95.5.69) by inbox.vuxu.org with ESMTPUTF8; 5 Jan 2021 13:10:02 -0000 Received: by krantz.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 21a12fa2; Tue, 5 Jan 2021 12:58:57 +0000 (UTC) Return-Path: Received: from mta01.prd.rdg.aluminati.org (mta01.prd.rdg.aluminati.org [94.76.243.214]) by krantz.zx2c4.com (ZX2C4 Mail Server) with ESMTPS id 127c5ea9 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for ; Tue, 5 Jan 2021 12:58:54 +0000 (UTC) Received: from mta01.prd.rdg.aluminati.org (localhost [127.0.0.1]) by mta.aluminati.local (Postfix) with ESMTP id CD9B7BF3BE; Tue, 5 Jan 2021 13:09:52 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by mta01.prd.rdg.aluminati.org (Postfix) with ESMTP id B5EE61FDCE; Tue, 5 Jan 2021 13:09:52 +0000 (GMT) X-Quarantine-ID: X-Virus-Scanned: Debian amavisd-new at mta01.prd.rdg.aluminati.org Received: from mta.aluminati.local ([127.0.0.1]) by localhost (mta01.prd.rdg.aluminati.org [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ahELDXD-jSU7; Tue, 5 Jan 2021 13:09:51 +0000 (GMT) Received: from john.keeping.me.uk (unknown [81.174.171.191]) by mta01.prd.rdg.aluminati.org (Postfix) with ESMTPSA id B95AE5F91D; Tue, 5 Jan 2021 13:09:49 +0000 (GMT) Date: Tue, 5 Jan 2021 13:09:47 +0000 From: John Keeping To: Gianni Ceccarelli Cc: cgit@lists.zx2c4.com Subject: Re: [PATCH] Handle tags outside of refs/tags gracefully. Message-ID: References: <20201228133550.67945-1-uqs@FreeBSD.org> <20201229203309.33f1fcae@thenautilus.net> <20210105115303.2cc704f9@nautilus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210105115303.2cc704f9@nautilus> Content-Transfer-Encoding: quoted-printable X-BeenThere: cgit@lists.zx2c4.com X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: List for cgit developers and users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: cgit-bounces@lists.zx2c4.com Sender: "CGit" On Tue, Jan 05, 2021 at 11:53:03AM +0000, Gianni Ceccarelli wrote: > I have found an annoying case=E2=80=A6 >=20 > In the repository created as per my previous message, I did:: >=20 > $ git tag -a foo > $ git rev-parse refs/tags/foo > .git/refs/weird/annotated > $ git push origin refs/weird/*:refs/weird/* >=20 > This creates an "annotated tag", which is an object in the store, not > just a reference. >=20 > Now CGit shows the ``refs/weird/annotated`` as a tag in > https://www.thenautilus.net/cgit/example/ and several other views, but > following that link goes to > https://www.thenautilus.net/cgit/example/tag/?h=3Drefs/weird/annotated > which says "bad tag reference" >=20 > I hope you'll concur this is not the best behaviour. >=20 > I see several ways to "fix" this: >=20 > * in all the various views, don't show links to annotated tags whose > ref is outside of ``refs/tags/`` > * in ``/tag``, try ``refs/tags/$h`` first, and if that doesn't work, > try ``$h``, and show that only if it's an annotated tag (not just a > reference) > * create another endpoint (``/atag``?) to show tag objects, and link > to that one for annotated tags whose ref is outside of > ``refs/tags/`` I think something like option 2 is the right answer here, since that brings us closer to Git's behaviour. Does the patch below help? -- >8 -- Subject: [PATCH] ui-tag: accept tags not under refs/tags/ In log views, we decorate commits with tags under any ref hierarchy, which generates links to ui-tag with, for example, refs/weird/tag. By forcing a refs/tags/ prefix onto this, a 404 not found error is guaranteed. Taking inspiration from Git's ref_rev_parse_rules, let's try to resolve the given tag name raw and relative to refs/ before trying refs/tags/. Reported-by: Gianni Ceccarelli Signed-off-by: John Keeping --- ui-tag.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ui-tag.c b/ui-tag.c index 846d5b1..c1f81d1 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -38,17 +38,32 @@ static void print_download_links(char *revname) html(""); } =20 +static const char *tag_patterns[] =3D { + "%s", + "refs/%s", + "refs/tags/%s", + NULL +}; + void cgit_print_tag(char *revname) { struct strbuf fullref =3D STRBUF_INIT; struct object_id oid; struct object *obj; + const char **pattern; =20 if (!revname) revname =3D ctx.qry.head; =20 - strbuf_addf(&fullref, "refs/tags/%s", revname); - if (get_oid(fullref.buf, &oid)) { + for (pattern =3D tag_patterns; *pattern; pattern++) { + strbuf_reset(&fullref); + strbuf_addf(&fullref, *pattern, revname); + + if (!get_oid(fullref.buf, &oid)) + break; + } + + if (!*pattern) { cgit_print_error_page(404, "Not found", "Bad tag reference: %s", revname); goto cleanup; --=20 2.30.0