From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id B51F91F404
	for <e@80x24.org>; Mon,  2 Apr 2018 00:53:06 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754096AbeDBAxE (ORCPT <rfc822;e@80x24.org>);
        Sun, 1 Apr 2018 20:53:04 -0400
Received: from mail-lf0-f65.google.com ([209.85.215.65]:38854 "EHLO
        mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1753988AbeDBAxD (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 1 Apr 2018 20:53:03 -0400
Received: by mail-lf0-f65.google.com with SMTP id u3-v6so18604418lff.5
        for <git@vger.kernel.org>; Sun, 01 Apr 2018 17:53:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id;
        bh=IqbkyiSQYE8mOwCJVPBz+BSIpLIMaCqLXsQKgUrqzso=;
        b=GdTpa6oqWzTtTcGqWr64ckVp8TYHuzffSXdMyctYRVwYuMxbyZ0f9H9qWIWCjRatn4
         x7blGdFO7u8pJTDIe5RdBxDdaWIANve3CeyOeAN9hMust0fTxQQ7WK5ZsHdptfPx4wkn
         djWQtK0wQLaPGmDlLxQNPkqTWBt1aF3DD/C5Mws+624eYDztz/kRHYtSS2drYDDK+xsX
         orn9EsWMNzcuhtDCSH3+vsdMK2Wpd7AKSZ0mG2vdHybmuNvV90jdLxd02lr8EqxRUT/c
         wRlleh/aWUm1/4fdwrYJnImh+iXDKqfUJNcUgYT8MYyLaK1yGX6WKz+H2tVFQ5aDfYB7
         Q+Zw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id;
        bh=IqbkyiSQYE8mOwCJVPBz+BSIpLIMaCqLXsQKgUrqzso=;
        b=XiG1wS7Xg2QNzX54uzICmsET2fYCIHcF7Muszzpyilo3i29ERPUApYt/yFs4XnJ9yq
         25Ry9T5DvoF4SYb21YDcDp3fPFXufrFLWKyJ3wrJrvyLrfR711QqclyC6eJ176rX3ZGM
         jFERnU8izkpSh/ynevUKfYAg920XxytovNuSB66WG4VZON1yf5JvZm4wWqs01/f+8kko
         WhfhYO0vDTZqLx9iS3yDjB7d0jApo49g4uLmv+Uv7P8b0YHqg8vZOzeIxLw1MJwwE/4X
         eAJAHfX6C9NEdfL5ucqeqpc0i4gmeLnpcRA8ad30KvLrVn0pjEOXXHjWpn04TytlVtgc
         CghA==
X-Gm-Message-State: ALQs6tDgbZgChobOp4ELMO3bHr4wGYeNVM3ulP0xAFjiIITLON+f+utv
        XI3nJB/P453CpiuDcYiUlBmPZYED
X-Google-Smtp-Source: AIpwx48aKowP8yUZnCzQIi/VAQ5y1IPrGIpioE/ZVjecNht0hR2m5cS2whhP9b9qljxC05vqccNmMg==
X-Received: by 10.46.99.93 with SMTP id x90mr4792218ljb.2.1522630381524;
        Sun, 01 Apr 2018 17:53:01 -0700 (PDT)
Received: from localhost.localdomain ([94.234.36.18])
        by smtp.gmail.com with ESMTPSA id h68-v6sm2755528lfk.67.2018.04.01.17.53.00
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 01 Apr 2018 17:53:00 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH] ls-remote: create option to sort by versions
Date:   Mon,  2 Apr 2018 02:52:48 +0200
Message-Id: <20180402005248.52418-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create the options '-V ' and '--version-sort' to sort
'git ls-remote' output by version semantics. This is useful e.g. for
the Go repository after the release of version 1.10, where otherwise
v1.10 is sorted before v1.2. See:

	$ git ls-remote -t https://go.googlesource.com/go
	...
	205f850ceacfc39d1e9d76a9569416284594ce8c	refs/tags/go1.1
	d260448f6b6ac10efe4ae7f6dfe944e72bc2a676	refs/tags/go1.1.1
	1d6d8fca241bb611af51e265c1b5a2e9ae904702	refs/tags/go1.1.2
	bf86aec25972f3a100c3aa58a6abcbcc35bdea49	refs/tags/go1.10
	ac7c0ee26dda18076d5f6c151d8f920b43340ae3	refs/tags/go1.10.1
	9ce6b5c2ed5d3d5251b9a6a0c548d5fb2c8567e8	refs/tags/go1.10beta1
	594668a5a96267a46282ce3007a584ec07adf705	refs/tags/go1.10beta2
	5348aed83e39bd1d450d92d7f627e994c2db6ebf	refs/tags/go1.10rc1
	20e228f2fdb44350c858de941dff4aea9f3127b8	refs/tags/go1.10rc2
	1c5438aae896edcd1e9f9618f4776517f08053b3	refs/tags/go1.1rc2
	46a6097aa7943a490e9bd2e04274845d0e5e200f	refs/tags/go1.1rc3
	402d3590b54e4a0df9fb51ed14b2999e85ce0b76	refs/tags/go1.2
	9c9802fad57c1bcb72ea98c5c55ea2652efc5772	refs/tags/go1.2.1
	...

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 builtin/ls-remote.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..740c6f117 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -33,11 +34,20 @@ static int tail_match(const char **pattern, const char *path)
 	return 0;
 }
 
+static int cmp_ref_versions(const void *_a, const void *_b)
+{
+	const struct ref *a = *(const struct ref **)_a;
+	const struct ref *b = *(const struct ref **)_b;
+
+	return versioncmp(a->name, b->name);
+}
+
 int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 {
 	const char *dest = NULL;
 	unsigned flags = 0;
 	int get_url = 0;
+	int version_sort = 0;
 	int quiet = 0;
 	int status = 0;
 	int show_symref_target = 0;
@@ -47,6 +57,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	const struct ref **refs = NULL;
+	int nr = 0;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +72,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_BOOL('V', "version-sort", &version_sort,
+			 N_("sort tags by version numbers")),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -101,13 +115,22 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (transport_disconnect(transport))
 		return 1;
 
-	if (!dest && !quiet)
-		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+		REALLOC_ARRAY(refs, nr + 1);
+		refs[nr++] = ref;
+	}
+
+	if (version_sort)
+		QSORT(refs, nr, cmp_ref_versions);
+
+	if (!dest && !quiet)
+		fprintf(stderr, "From %s\n", *remote->url);
+	for (int i = 0; i < nr; i++) {
+		const struct ref *ref = refs[i];
 		if (show_symref_target && ref->symref)
 			printf("ref: %s\t%s\n", ref->symref, ref->name);
 		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	FROM_EXCESS_BASE64,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id ABCDE1F424
	for <e@80x24.org>; Mon,  2 Apr 2018 06:37:35 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754144AbeDBGhd (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 02:37:33 -0400
Received: from mail-wm0-f46.google.com ([74.125.82.46]:37484 "EHLO
        mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752485AbeDBGhc (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 02:37:32 -0400
Received: by mail-wm0-f46.google.com with SMTP id r131so25076724wmb.2
        for <git@vger.kernel.org>; Sun, 01 Apr 2018 23:37:32 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:references:user-agent:in-reply-to:date
         :message-id:mime-version;
        bh=V0uRW2OKWsLi7JrsWreA+A4qHP4iXE3Ja6av6kMsGTY=;
        b=TG7mwEegnIdwCHcoAIyaNHkqFcYEv80wCaLsRIBpMSatZ2IOmbXDfmAlXpPujaBdQz
         BxC4kmv/11OxAC1KzhQl4hB1Ypjd66hMHh3HpCwRYI9KnIqvkL6tAWL+IqNAoKdiAXqT
         UJEjl2LsTgzKMQTfNFNHk/mJvF+I/2DshksWMmMNNuxu3OoAMwcEzP6dJ+P9Rw9MmsgL
         28PjJtfFZUoYEdlQzGW7hEIYWBitqfAywvMV9amZfdFBTzwwaPYl71dLDuQdns54wV2E
         X8eM3fWeffVQ3EDtpWHEa0LFXv9XXVWf2nFa9H3D2I8Z/lHoLKN+pUVVg1hBJg2CYtQT
         vc9Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:references:user-agent
         :in-reply-to:date:message-id:mime-version;
        bh=V0uRW2OKWsLi7JrsWreA+A4qHP4iXE3Ja6av6kMsGTY=;
        b=fliG+4zSyiOmOvW/mgmj6ReIrJM/uYhBaRf+TWba+Ev6jVRM20qbHEvkbxN7VSgpbf
         NagtS/ucpzZUU948i8LSmKcWCHsAX+JKmSqZbmFEfH9xhRULWW6T83xss0/RR3z1pKpT
         di3bL837NJ7B2ihMZTvWgZbuCXxp46zAJ70prwLbn8PWMAWI3HhuoH8KxIEgg52uhI/9
         sT2FVz9Y0mMHexWxU14fTQ0tYFleFPyC46dpaCErkr55Gf2NxHRnI6Cm06dWd8V/qddO
         fUavEpgAYKQDZspe1BYJ42A299GQBUtvwrBAnHzNula0eMW3iHFy5uT4ufeJOYhv/GG2
         juSg==
X-Gm-Message-State: AElRT7HqdFk6zv6oU7b5tmbCCFwleuDLyNnnUZZeWAimLR8U319+TXQP
        wCxvYs/mzz/zSal2yo+erHlZVUMa
X-Google-Smtp-Source: AIpwx4/YfYp8o5JDBtHJtfOREE+gfQCRmW3nU7ySsRPgmcdpp1MABMqeHwC2jfJDLFH/aoo8jOlj/A==
X-Received: by 10.80.181.12 with SMTP id y12mr11573635edd.166.1522651051356;
        Sun, 01 Apr 2018 23:37:31 -0700 (PDT)
Received: from evledraar (dhcp-089-098-184-206.chello.nl. [89.98.184.206])
        by smtp.gmail.com with ESMTPSA id e18sm8392118edj.38.2018.04.01.23.37.30
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Sun, 01 Apr 2018 23:37:30 -0700 (PDT)
From:   =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org
Subject: Re: [PATCH] ls-remote: create option to sort by versions
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
User-agent: Debian GNU/Linux 9.4 (stretch); Emacs 25.1.1; mu4e 1.1.0
In-reply-to: <20180402005248.52418-1-haraldnordgren@gmail.com>
Date:   Mon, 02 Apr 2018 08:37:29 +0200
Message-ID: <87605aw1ue.fsf@evledraar.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org


On Mon, Apr 02 2018, Harald Nordgren wrote:

> Create the options '-V ' and '--version-sort' to sort
> 'git ls-remote' output by version semantics. This is useful e.g. for
> the Go repository after the release of version 1.10, where otherwise
> v1.10 is sorted before v1.2. See:
>
> 	$ git ls-remote -t https://go.googlesource.com/go
> 	...
> 	205f850ceacfc39d1e9d76a9569416284594ce8c	refs/tags/go1.1
> 	d260448f6b6ac10efe4ae7f6dfe944e72bc2a676	refs/tags/go1.1.1
> 	1d6d8fca241bb611af51e265c1b5a2e9ae904702	refs/tags/go1.1.2
> 	bf86aec25972f3a100c3aa58a6abcbcc35bdea49	refs/tags/go1.10
> 	ac7c0ee26dda18076d5f6c151d8f920b43340ae3	refs/tags/go1.10.1
> 	9ce6b5c2ed5d3d5251b9a6a0c548d5fb2c8567e8	refs/tags/go1.10beta1
> 	594668a5a96267a46282ce3007a584ec07adf705	refs/tags/go1.10beta2
> 	5348aed83e39bd1d450d92d7f627e994c2db6ebf	refs/tags/go1.10rc1
> 	20e228f2fdb44350c858de941dff4aea9f3127b8	refs/tags/go1.10rc2
> 	1c5438aae896edcd1e9f9618f4776517f08053b3	refs/tags/go1.1rc2
> 	46a6097aa7943a490e9bd2e04274845d0e5e200f	refs/tags/go1.1rc3
> 	402d3590b54e4a0df9fb51ed14b2999e85ce0b76	refs/tags/go1.2
> 	9c9802fad57c1bcb72ea98c5c55ea2652efc5772	refs/tags/go1.2.1
> 	...

This is a sensible thing to want, but why not follow the UI we have for
this with git-tag? I.e. --sort=<key> & -i (or --ignore-case)? Of course
ls-remote doesn't just show tags, so maybe we'd want --tag-sort=<key>
and --ignore-tag-case or something, but the rest should be equivalent,
no?

> [...]
> @@ -101,13 +115,22 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>  	if (transport_disconnect(transport))
>  		return 1;
>
> -	if (!dest && !quiet)
> -		fprintf(stderr, "From %s\n", *remote->url);
>  	for ( ; ref; ref = ref->next) {
>  		if (!check_ref_type(ref, flags))
>  			continue;
>  		if (!tail_match(pattern, ref->name))
>  			continue;
> +		REALLOC_ARRAY(refs, nr + 1);
> +		refs[nr++] = ref;
> +	}
> +
> +	if (version_sort)
> +		QSORT(refs, nr, cmp_ref_versions);
> +
> +	if (!dest && !quiet)
> +		fprintf(stderr, "From %s\n", *remote->url);

Is there some subtlety here I'm missing which means that when sorting
we'd now need to print this "From" line later (i.e. after sorting?

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 79CC11F404
	for <e@80x24.org>; Mon,  2 Apr 2018 16:27:33 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752918AbeDBQ1b (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 12:27:31 -0400
Received: from mail-oi0-f45.google.com ([209.85.218.45]:39521 "EHLO
        mail-oi0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752824AbeDBQ1a (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 12:27:30 -0400
Received: by mail-oi0-f45.google.com with SMTP id q71-v6so13335493oic.6
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 09:27:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc:content-transfer-encoding;
        bh=uh5ksUPa/KvSDnUK6YTC+EXOjC8lpxA5TA4K60ehOlI=;
        b=M+S6wKAJvGQk4ZuOgzZi3jZTj+deFlnrSW2KvBc2OGphn0zWuXxpA86P9gD3St3kOz
         myo5WFghsEYqx7txUEMDtzwGQx1C5a9h9VNaQ2eGmKsoGlImZTmRB3f46tiUNYcdwKoC
         miw82volmwfMPaPOPzSqe1HrFGIk2H+YzPFR2scqgcrOEF//APP3E34AzAsGb5ak6Yhq
         NvUZwu2nEytztwG7ZKfzMBPZeYb3gR2XVFT3x78Bh/14eVT4G7C2V+bxcSaAgXG7XIaG
         xXdlMQa+kreFjhNrONlp57F17cfMnp8DL/txj/neapoCiScyUgwJHjYxgZCgDy/heEJm
         dvrg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc:content-transfer-encoding;
        bh=uh5ksUPa/KvSDnUK6YTC+EXOjC8lpxA5TA4K60ehOlI=;
        b=BNas0NECdtze/TAJ6/2zWXb9AZbG/mI3HsvrjwfdUwLKOSNtfm7nfm/dCvzP5hjWVK
         CnOTBj2EsoDXQElGjY6z7sr2BQpvm8YDx8zr1/nSGlOl2Z3rw6IvZ01+ejr0MHi6u0ZQ
         FvE7EgK1fAR9ETXNZvJBI2BMY38pC9THFGI53LoCip5nwraOQCn3wgg9c86Y08QzB0Ab
         0Cbn9d9PEh/3Rqr0zWRoCDGuB4F31vF1CTsA79eP9X3XVWW7vi8QedzXU6tuytMiPGRl
         K+/7unfRtbtUrQcQT1PNaHzlpEJyciJNqn2K7380keDiKwhxK1m3zxS5WVdwCE7bsAuk
         KX5g==
X-Gm-Message-State: ALQs6tBP3EIJRClcqc2lveP+VJB0c48Zpv06rcUmhaIT3wuzjwtIEIe9
        4iTWCkpW+WfyDsGPtGI24eIMkJ4g9xt8SPoAlf4X2A==
X-Google-Smtp-Source: AIpwx4+/pfP05UexNpukeC4sHvAipwvrGLP3HM/lryAqDkWn19ktgKKQmwPB9kD9Lab0Mqyv96Ln23eUcAqhucSbqVE=
X-Received: by 2002:aca:e302:: with SMTP id a2-v6mr5873856oih.156.1522686449610;
 Mon, 02 Apr 2018 09:27:29 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Mon, 2 Apr 2018 09:26:49 -0700 (PDT)
In-Reply-To: <87605aw1ue.fsf@evledraar.gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com> <87605aw1ue.fsf@evledraar.gmail.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Mon, 2 Apr 2018 18:26:49 +0200
Message-ID: <CAHwyqnV1BwsaHVsh0xSx3MroNoJRT7UYrqF_WFKhkZMf-X9Evg@mail.gmail.com>
Subject: Re: [PATCH] ls-remote: create option to sort by versions
To:     =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>
Cc:     git@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Thanks for your comment =C3=86var!

In regards the the print statement, it was only moved down according
to the diff because I added more logic above. Basically there is 1)
the unrolling of the linked list to an array and 2) the printing
logic. I could move it and make the diff smaller, but that probably
makes the code a tiny bit more complicated.

It would be nice to have a uniform option like
'--sort=3Dversion:refname'. But spending a few hours to look over the
code, it seems that ls-remote.c would require a lot of rewrites if we
wanted to start using `ref_array` and `ref_array_item` for storing the
refs.

Which seems necessary in order to hook in to the sorting flow used in
other subcommands. That, or reimplement `cmp_ref_sorting`. But maybe
I'm missing something?

On Mon, Apr 2, 2018 at 8:37 AM, =C3=86var Arnfj=C3=B6r=C3=B0 Bjarmason
<avarab@gmail.com> wrote:
>
> On Mon, Apr 02 2018, Harald Nordgren wrote:
>
>> Create the options '-V ' and '--version-sort' to sort
>> 'git ls-remote' output by version semantics. This is useful e.g. for
>> the Go repository after the release of version 1.10, where otherwise
>> v1.10 is sorted before v1.2. See:
>>
>>       $ git ls-remote -t https://go.googlesource.com/go
>>       ...
>>       205f850ceacfc39d1e9d76a9569416284594ce8c        refs/tags/go1.1
>>       d260448f6b6ac10efe4ae7f6dfe944e72bc2a676        refs/tags/go1.1.1
>>       1d6d8fca241bb611af51e265c1b5a2e9ae904702        refs/tags/go1.1.2
>>       bf86aec25972f3a100c3aa58a6abcbcc35bdea49        refs/tags/go1.10
>>       ac7c0ee26dda18076d5f6c151d8f920b43340ae3        refs/tags/go1.10.1
>>       9ce6b5c2ed5d3d5251b9a6a0c548d5fb2c8567e8        refs/tags/go1.10be=
ta1
>>       594668a5a96267a46282ce3007a584ec07adf705        refs/tags/go1.10be=
ta2
>>       5348aed83e39bd1d450d92d7f627e994c2db6ebf        refs/tags/go1.10rc=
1
>>       20e228f2fdb44350c858de941dff4aea9f3127b8        refs/tags/go1.10rc=
2
>>       1c5438aae896edcd1e9f9618f4776517f08053b3        refs/tags/go1.1rc2
>>       46a6097aa7943a490e9bd2e04274845d0e5e200f        refs/tags/go1.1rc3
>>       402d3590b54e4a0df9fb51ed14b2999e85ce0b76        refs/tags/go1.2
>>       9c9802fad57c1bcb72ea98c5c55ea2652efc5772        refs/tags/go1.2.1
>>       ...
>
> This is a sensible thing to want, but why not follow the UI we have for
> this with git-tag? I.e. --sort=3D<key> & -i (or --ignore-case)? Of course
> ls-remote doesn't just show tags, so maybe we'd want --tag-sort=3D<key>
> and --ignore-tag-case or something, but the rest should be equivalent,
> no?
>
>> [...]
>> @@ -101,13 +115,22 @@ int cmd_ls_remote(int argc, const char **argv, con=
st char *prefix)
>>       if (transport_disconnect(transport))
>>               return 1;
>>
>> -     if (!dest && !quiet)
>> -             fprintf(stderr, "From %s\n", *remote->url);
>>       for ( ; ref; ref =3D ref->next) {
>>               if (!check_ref_type(ref, flags))
>>                       continue;
>>               if (!tail_match(pattern, ref->name))
>>                       continue;
>> +             REALLOC_ARRAY(refs, nr + 1);
>> +             refs[nr++] =3D ref;
>> +     }
>> +
>> +     if (version_sort)
>> +             QSORT(refs, nr, cmp_ref_versions);
>> +
>> +     if (!dest && !quiet)
>> +             fprintf(stderr, "From %s\n", *remote->url);
>
> Is there some subtlety here I'm missing which means that when sorting
> we'd now need to print this "From" line later (i.e. after sorting?

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	FROM_EXCESS_BASE64,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 8D15C1F404
	for <e@80x24.org>; Mon,  2 Apr 2018 17:32:38 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1753124AbeDBRcg (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 13:32:36 -0400
Received: from mail-wm0-f51.google.com ([74.125.82.51]:56063 "EHLO
        mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1753095AbeDBRcf (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 13:32:35 -0400
Received: by mail-wm0-f51.google.com with SMTP id b127so26336734wmf.5
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 10:32:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:references:user-agent:in-reply-to:date
         :message-id:mime-version:content-transfer-encoding;
        bh=ESVflRvm1OdSO1XTOP3CFFQMUMZbhPoxucxyyBdwK1E=;
        b=brletpqwGLbLDg06RhO/WemTBaNM4I12SSMkyAQnh1hqO/7A13gcusKCokGikWjVF0
         Grl7zB7ujzIcd2NiY1ZB6cp1nVE9CGGuZj+nfxk2bYvCUlF7JYX+AwO2aNtSK5mV/mLu
         yhM4ACPaDS4p6ileIKmPT4HSUGQBpR2jv3mulacNiYg5PbpVDa4tzTpRFEcmhJq5skfH
         HPKmlkLLihidfHEf72lCNs7I3MRTuUhcapcSoYHsDR4wINPcpXeweI0w8RRAlNzS27Yd
         aHzoJHkHTzKPdfg5n0WP467x4bf198ryez523U+Vc5kwJ6QfBnWAlz4dt42p19pvDQBk
         aRhw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:references:user-agent
         :in-reply-to:date:message-id:mime-version:content-transfer-encoding;
        bh=ESVflRvm1OdSO1XTOP3CFFQMUMZbhPoxucxyyBdwK1E=;
        b=S/AaxkkpkRT7HlHkuuLCf3CdPP58miTZCnEyu4GZa9aCPU3BxeAwXlNU6l3OfOb14Y
         EM3Upv9Du92cKaci2i4Swobsb7IUn4tlgEqTha3v25QZf9MQQGevN7CIXsNY7DpsXDv0
         1o9s6PGhVgJyYMxytIn2BDCJQLmj8ZlQ8BYCQBPQxq0TXj6ipxMFPaatV1C8/XXWY+5d
         PXxl97ligFe7u3XSaw74CFUKRfN+uYU22nixrsQjb8aG50YToL5LF+L/fAktzL4ucIop
         zTfePs1I3NLnltEFkMV8+iem2kqa9M5zAP95ISUsyC/tmHOfEwWOpBU/FMq5Cf30V8zZ
         3+tA==
X-Gm-Message-State: AElRT7FjQBjt8YnlEIpSlETq8kUrHLAsNOxtxscIOK2EfOAWfznRU8wZ
        a9hNbVxIYrD095ckOHN+JEMg2m7m
X-Google-Smtp-Source: AIpwx4/rrKHF7tiRIDmhvdAsMkduNsqTmBRrzABboAWwaSVxLTltUOrZ0Vnwt1vuyAaDbCiUtCrwNA==
X-Received: by 10.80.231.13 with SMTP id a13mr13601028edn.212.1522690353877;
        Mon, 02 Apr 2018 10:32:33 -0700 (PDT)
Received: from evledraar (dhcp-089-098-184-206.chello.nl. [89.98.184.206])
        by smtp.gmail.com with ESMTPSA id b47sm589817ede.13.2018.04.02.10.32.32
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Mon, 02 Apr 2018 10:32:33 -0700 (PDT)
From:   =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org
Subject: Re: [PATCH] ls-remote: create option to sort by versions
References: <20180402005248.52418-1-haraldnordgren@gmail.com> <87605aw1ue.fsf@evledraar.gmail.com> <CAHwyqnV1BwsaHVsh0xSx3MroNoJRT7UYrqF_WFKhkZMf-X9Evg@mail.gmail.com>
User-agent: Debian GNU/Linux 9.4 (stretch); Emacs 25.1.1; mu4e 1.1.0
In-reply-to: <CAHwyqnV1BwsaHVsh0xSx3MroNoJRT7UYrqF_WFKhkZMf-X9Evg@mail.gmail.com>
Date:   Mon, 02 Apr 2018 19:32:31 +0200
Message-ID: <87zi2lv7io.fsf@evledraar.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org


On Mon, Apr 02 2018, Harald Nordgren wrote:

> In regards the the print statement, it was only moved down according
> to the diff because I added more logic above. Basically there is 1)
> the unrolling of the linked list to an array and 2) the printing
> logic. I could move it and make the diff smaller, but that probably
> makes the code a tiny bit more complicated.

I was just wondering since it wasn't explained in the commit message,
makes sense to copy this explanation into v2, or lead with a purely code
re-arrangement patch.

> It would be nice to have a uniform option like
> '--sort=version:refname'. But spending a few hours to look over the
> code, it seems that ls-remote.c would require a lot of rewrites if we
> wanted to start using `ref_array` and `ref_array_item` for storing the
> refs.
>
> Which seems necessary in order to hook in to the sorting flow used in
> other subcommands. That, or reimplement `cmp_ref_sorting`. But maybe
> I'm missing something?

I'm thinking just in terms of UI. If it's the case that porting this to
whatever guts git-tag uses for sorting would be hard, then we could
still use the same command-line option convention (and perhaps just die
if anything except --sort=version:refname is supplied). Changing the
underlying implementation is easier than cleaning up UI-differences that
(seemingly) only arose due to underlying implementation details at the
time.

> On Mon, Apr 2, 2018 at 8:37 AM, Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>>
>> On Mon, Apr 02 2018, Harald Nordgren wrote:
>>
>>> Create the options '-V ' and '--version-sort' to sort
>>> 'git ls-remote' output by version semantics. This is useful e.g. for
>>> the Go repository after the release of version 1.10, where otherwise
>>> v1.10 is sorted before v1.2. See:
>>>
>>>       $ git ls-remote -t https://go.googlesource.com/go
>>>       ...
>>>       205f850ceacfc39d1e9d76a9569416284594ce8c        refs/tags/go1.1
>>>       d260448f6b6ac10efe4ae7f6dfe944e72bc2a676        refs/tags/go1.1.1
>>>       1d6d8fca241bb611af51e265c1b5a2e9ae904702        refs/tags/go1.1.2
>>>       bf86aec25972f3a100c3aa58a6abcbcc35bdea49        refs/tags/go1.10
>>>       ac7c0ee26dda18076d5f6c151d8f920b43340ae3        refs/tags/go1.10.1
>>>       9ce6b5c2ed5d3d5251b9a6a0c548d5fb2c8567e8        refs/tags/go1.10beta1
>>>       594668a5a96267a46282ce3007a584ec07adf705        refs/tags/go1.10beta2
>>>       5348aed83e39bd1d450d92d7f627e994c2db6ebf        refs/tags/go1.10rc1
>>>       20e228f2fdb44350c858de941dff4aea9f3127b8        refs/tags/go1.10rc2
>>>       1c5438aae896edcd1e9f9618f4776517f08053b3        refs/tags/go1.1rc2
>>>       46a6097aa7943a490e9bd2e04274845d0e5e200f        refs/tags/go1.1rc3
>>>       402d3590b54e4a0df9fb51ed14b2999e85ce0b76        refs/tags/go1.2
>>>       9c9802fad57c1bcb72ea98c5c55ea2652efc5772        refs/tags/go1.2.1
>>>       ...
>>
>> This is a sensible thing to want, but why not follow the UI we have for
>> this with git-tag? I.e. --sort=<key> & -i (or --ignore-case)? Of course
>> ls-remote doesn't just show tags, so maybe we'd want --tag-sort=<key>
>> and --ignore-tag-case or something, but the rest should be equivalent,
>> no?
>>
>>> [...]
>>> @@ -101,13 +115,22 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>>>       if (transport_disconnect(transport))
>>>               return 1;
>>>
>>> -     if (!dest && !quiet)
>>> -             fprintf(stderr, "From %s\n", *remote->url);
>>>       for ( ; ref; ref = ref->next) {
>>>               if (!check_ref_type(ref, flags))
>>>                       continue;
>>>               if (!tail_match(pattern, ref->name))
>>>                       continue;
>>> +             REALLOC_ARRAY(refs, nr + 1);
>>> +             refs[nr++] = ref;
>>> +     }
>>> +
>>> +     if (version_sort)
>>> +             QSORT(refs, nr, cmp_ref_versions);
>>> +
>>> +     if (!dest && !quiet)
>>> +             fprintf(stderr, "From %s\n", *remote->url);
>>
>> Is there some subtlety here I'm missing which means that when sorting
>> we'd now need to print this "From" line later (i.e. after sorting?

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 906D71F404
	for <e@80x24.org>; Mon,  2 Apr 2018 17:43:14 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1753096AbeDBRnL (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 13:43:11 -0400
Received: from mail-ot0-f180.google.com ([74.125.82.180]:32814 "EHLO
        mail-ot0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752321AbeDBRnL (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 13:43:11 -0400
Received: by mail-ot0-f180.google.com with SMTP id 23-v6so16462528otj.0
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 10:43:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc:content-transfer-encoding;
        bh=bie4s5/42SzezOz9uGvQNSbHiwmHt/4bGpI2+HfEZvc=;
        b=K4mOnVGY0z6q7khbMThRSUY73TFCmoQo6cPMrtdkjXNbYspR2EZNSoiyhT/07+hm9r
         JX3qU5XbX1fxhKMbYHcMdhlMWBK/B3cHcyXserXsYrvQ52BQN39zD1IkYlZYMDYztYAR
         zO4HLDDBwoKsqS2VxTlTQTHYjvItOXKewVxqr9CLO+hGLV6eqdFZL9c7QH+1mNnNbOz6
         rfJYX5qfJYaoMidMSH1qQdG4E0z0LZrV2ZY62cWLCEShb4p7x9ttApsjdfWtA+j+glH/
         8Brji+mYVlV3LrImSpAWhEGR7T4d694aw4HGKhol+jbiwqQbgI3jaVZ96+4RCzkMT3pE
         KQzQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc:content-transfer-encoding;
        bh=bie4s5/42SzezOz9uGvQNSbHiwmHt/4bGpI2+HfEZvc=;
        b=javfzx8yxvPKf2F9OyxJbaMxtVEDt0A53YuyM3aLwVE/xjcxiwFA33YshKARmwf6bv
         JcB1nMIFgthpDyK2SEbsbvlbdMQ1IwfuuC+dDAIHvDaz39XzYgFIbqMLE9U4wM4NEvZb
         gY1v5GSRwAMml8e53KjrBHs/ZMq0Tmc1X1klz4qEPUKvxt/LPaDJiGoSSVr8VIyTdbTe
         9fMoLZShEMLEtmJlgXXmqXsgaVDmN1aTiuMLZq3CrLiWDOX2jBm8mGd+GgZJTpGCPDdM
         5EIhvQgb1VnpLl4ty13ZSH54Na4JgWbdCvudssAQrl4bkgzB+wIGyM4nCwXZxktSTGyG
         NVcQ==
X-Gm-Message-State: ALQs6tDDevCRd1NZUxJ8xzBplq4+LWuQv/1t1ODcTY4fiVAaCaiKWJEY
        nZhdQCszaaSoqgDVuh7a1iQREYeS9ft/9LlKIMg=
X-Google-Smtp-Source: AIpwx49WFmgoLDwqXVlqwsVXtA4ksNo0bgVN48ZBpcBQzH0xDuehHTassx8A5l7xAfwRkycTo8MpGeHrATFNVxbDCeY=
X-Received: by 2002:a9d:3323:: with SMTP id f32-v6mr6532085otc.221.1522690990413;
 Mon, 02 Apr 2018 10:43:10 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Mon, 2 Apr 2018 10:42:29 -0700 (PDT)
In-Reply-To: <87zi2lv7io.fsf@evledraar.gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <87605aw1ue.fsf@evledraar.gmail.com> <CAHwyqnV1BwsaHVsh0xSx3MroNoJRT7UYrqF_WFKhkZMf-X9Evg@mail.gmail.com>
 <87zi2lv7io.fsf@evledraar.gmail.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Mon, 2 Apr 2018 19:42:29 +0200
Message-ID: <CAHwyqnU_5RVJBRLm4SBPo-xQKFQQTat33RdJBN2OOBSt1ZBNPQ@mail.gmail.com>
Subject: Re: [PATCH] ls-remote: create option to sort by versions
To:     =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>
Cc:     git@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Both points make sense and it sounds like a very pragmatic approach.
I'll look into it!

On Mon, Apr 2, 2018 at 7:32 PM, =C3=86var Arnfj=C3=B6r=C3=B0 Bjarmason
<avarab@gmail.com> wrote:
>
> On Mon, Apr 02 2018, Harald Nordgren wrote:
>
>> In regards the the print statement, it was only moved down according
>> to the diff because I added more logic above. Basically there is 1)
>> the unrolling of the linked list to an array and 2) the printing
>> logic. I could move it and make the diff smaller, but that probably
>> makes the code a tiny bit more complicated.
>
> I was just wondering since it wasn't explained in the commit message,
> makes sense to copy this explanation into v2, or lead with a purely code
> re-arrangement patch.
>
>> It would be nice to have a uniform option like
>> '--sort=3Dversion:refname'. But spending a few hours to look over the
>> code, it seems that ls-remote.c would require a lot of rewrites if we
>> wanted to start using `ref_array` and `ref_array_item` for storing the
>> refs.
>>
>> Which seems necessary in order to hook in to the sorting flow used in
>> other subcommands. That, or reimplement `cmp_ref_sorting`. But maybe
>> I'm missing something?
>
> I'm thinking just in terms of UI. If it's the case that porting this to
> whatever guts git-tag uses for sorting would be hard, then we could
> still use the same command-line option convention (and perhaps just die
> if anything except --sort=3Dversion:refname is supplied). Changing the
> underlying implementation is easier than cleaning up UI-differences that
> (seemingly) only arose due to underlying implementation details at the
> time.
>
>> On Mon, Apr 2, 2018 at 8:37 AM, =C3=86var Arnfj=C3=B6r=C3=B0 Bjarmason
>> <avarab@gmail.com> wrote:
>>>
>>> On Mon, Apr 02 2018, Harald Nordgren wrote:
>>>
>>>> Create the options '-V ' and '--version-sort' to sort
>>>> 'git ls-remote' output by version semantics. This is useful e.g. for
>>>> the Go repository after the release of version 1.10, where otherwise
>>>> v1.10 is sorted before v1.2. See:
>>>>
>>>>       $ git ls-remote -t https://go.googlesource.com/go
>>>>       ...
>>>>       205f850ceacfc39d1e9d76a9569416284594ce8c        refs/tags/go1.1
>>>>       d260448f6b6ac10efe4ae7f6dfe944e72bc2a676        refs/tags/go1.1.=
1
>>>>       1d6d8fca241bb611af51e265c1b5a2e9ae904702        refs/tags/go1.1.=
2
>>>>       bf86aec25972f3a100c3aa58a6abcbcc35bdea49        refs/tags/go1.10
>>>>       ac7c0ee26dda18076d5f6c151d8f920b43340ae3        refs/tags/go1.10=
.1
>>>>       9ce6b5c2ed5d3d5251b9a6a0c548d5fb2c8567e8        refs/tags/go1.10=
beta1
>>>>       594668a5a96267a46282ce3007a584ec07adf705        refs/tags/go1.10=
beta2
>>>>       5348aed83e39bd1d450d92d7f627e994c2db6ebf        refs/tags/go1.10=
rc1
>>>>       20e228f2fdb44350c858de941dff4aea9f3127b8        refs/tags/go1.10=
rc2
>>>>       1c5438aae896edcd1e9f9618f4776517f08053b3        refs/tags/go1.1r=
c2
>>>>       46a6097aa7943a490e9bd2e04274845d0e5e200f        refs/tags/go1.1r=
c3
>>>>       402d3590b54e4a0df9fb51ed14b2999e85ce0b76        refs/tags/go1.2
>>>>       9c9802fad57c1bcb72ea98c5c55ea2652efc5772        refs/tags/go1.2.=
1
>>>>       ...
>>>
>>> This is a sensible thing to want, but why not follow the UI we have for
>>> this with git-tag? I.e. --sort=3D<key> & -i (or --ignore-case)? Of cour=
se
>>> ls-remote doesn't just show tags, so maybe we'd want --tag-sort=3D<key>
>>> and --ignore-tag-case or something, but the rest should be equivalent,
>>> no?
>>>
>>>> [...]
>>>> @@ -101,13 +115,22 @@ int cmd_ls_remote(int argc, const char **argv, c=
onst char *prefix)
>>>>       if (transport_disconnect(transport))
>>>>               return 1;
>>>>
>>>> -     if (!dest && !quiet)
>>>> -             fprintf(stderr, "From %s\n", *remote->url);
>>>>       for ( ; ref; ref =3D ref->next) {
>>>>               if (!check_ref_type(ref, flags))
>>>>                       continue;
>>>>               if (!tail_match(pattern, ref->name))
>>>>                       continue;
>>>> +             REALLOC_ARRAY(refs, nr + 1);
>>>> +             refs[nr++] =3D ref;
>>>> +     }
>>>> +
>>>> +     if (version_sort)
>>>> +             QSORT(refs, nr, cmp_ref_versions);
>>>> +
>>>> +     if (!dest && !quiet)
>>>> +             fprintf(stderr, "From %s\n", *remote->url);
>>>
>>> Is there some subtlety here I'm missing which means that when sorting
>>> we'd now need to print this "From" line later (i.e. after sorting?

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 33B981F404
	for <e@80x24.org>; Mon,  2 Apr 2018 17:46:20 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1753136AbeDBRqS (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 13:46:18 -0400
Received: from cloud.peff.net ([104.130.231.41]:50826 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1752900AbeDBRqR (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 13:46:17 -0400
Received: (qmail 30161 invoked by uid 109); 2 Apr 2018 17:46:17 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Mon, 02 Apr 2018 17:46:17 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 18535 invoked by uid 111); 2 Apr 2018 17:47:17 -0000
Received: from Unknown (HELO sigill.intra.peff.net) (10.0.1.3)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Mon, 02 Apr 2018 13:47:17 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Mon, 02 Apr 2018 13:46:15 -0400
Date:   Mon, 2 Apr 2018 13:46:15 -0400
From:   Jeff King <peff@peff.net>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        git@vger.kernel.org
Subject: Re: [PATCH] ls-remote: create option to sort by versions
Message-ID: <20180402174614.GA28566@sigill.intra.peff.net>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <87605aw1ue.fsf@evledraar.gmail.com>
 <CAHwyqnV1BwsaHVsh0xSx3MroNoJRT7UYrqF_WFKhkZMf-X9Evg@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <CAHwyqnV1BwsaHVsh0xSx3MroNoJRT7UYrqF_WFKhkZMf-X9Evg@mail.gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Mon, Apr 02, 2018 at 06:26:49PM +0200, Harald Nordgren wrote:

> It would be nice to have a uniform option like
> '--sort=version:refname'. But spending a few hours to look over the
> code, it seems that ls-remote.c would require a lot of rewrites if we
> wanted to start using `ref_array` and `ref_array_item` for storing the
> refs.
> 
> Which seems necessary in order to hook in to the sorting flow used in
> other subcommands. That, or reimplement `cmp_ref_sorting`. But maybe
> I'm missing something?

I haven't looked at how painful it might be to use ref-filter.c, but it
would buy us even more if we could. That would open up other options
like --format, I think (OTOH there may be some funny corner cases; that
code assumes we're talking about local refs, so if you were to ask for
"%(committerdate)" or something, we might have to more cleanly handle
the case where we don't actually have the object).

-Peff

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id E623E1F404
	for <e@80x24.org>; Mon,  2 Apr 2018 18:33:01 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1753253AbeDBSdA (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 14:33:00 -0400
Received: from mail-wr0-f193.google.com ([209.85.128.193]:45364 "EHLO
        mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1753072AbeDBSc7 (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 14:32:59 -0400
Received: by mail-wr0-f193.google.com with SMTP id u11so15033309wri.12
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 11:32:58 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
         :user-agent:mime-version:content-transfer-encoding;
        bh=J1hSbS9Wgw53iTVfbE0WolQwG6KGsx7P8EAXUCZyGmc=;
        b=hVVBdgRhdoYyTvhUvia/FayTXt91tBc3sOIo8VlAbTtjh8zCpm9Tc5vVRMSjLhveQo
         Q9XaSxff1D4mMzvjXjwPWb21g95aaSZzmWguHZ7WhT8EDMZ4bgdWhT+yVL0RaroHrdJg
         HNzo/+9bG0U1Abf42f1ayuffKFfIToOqX8vuKmPMKjZpxAcA2yOXGtczdvpBnjVcY3LA
         i9BfSqkMf/29xITL7YBvXtP8cjYQCXa6xeJcn2+oxqO7cqHKyhGvb/NdfNhavnTdG5PL
         9DPJ7KQCoR4OINFY2LTIinwvYvgj+KPDLv1F5gU61Y9puU5Nb8S8+acsON/XpmD89SyM
         4/ug==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:sender:from:to:cc:subject:references:date
         :in-reply-to:message-id:user-agent:mime-version
         :content-transfer-encoding;
        bh=J1hSbS9Wgw53iTVfbE0WolQwG6KGsx7P8EAXUCZyGmc=;
        b=LLxzqbBqlNvgIFhGXNA5T47gERW9Qn14qAoMIRqhZSCvO23bVWuYzeDPk8MSCh0lPy
         HpyR5MoRpPug2oxDoORCpiy8ryzSTKasgT7B/6tr9eBJEVoQQMWdHyuk++R3qDheq0tc
         luYi5df3JnPbqrXyUqj2UMto6zcIn4R/QdKnyFYqeUgqlzDd4C1Pv4vwozpAVGDXeLHg
         8X6/f+UYekxIv5hcykavhrtBYtyiFwhjhaHkAFS75+2pG+j6PQHOFLY7yR3t+nPfiTMu
         2Ca4V97dsXxPFbS5sM1t0AtbOcIE9KdSdIs4Da/io6YjpsltiE4C9QH2t7OhXtlC/je8
         6pUg==
X-Gm-Message-State: AElRT7FoX5lDr2F+MOCLm/3cKkCOBDmCUFxGcJvr8Sn/6OO+fiCsq+od
        aAUHeisWbcvWlH1rj79M2DMROLGg
X-Google-Smtp-Source: AIpwx4+yWUM5T3DR5TYQYEO3PnvwyB5mQF4HETreLMR5sj6yNjsmV1mJqbGuHjuMoFWKcNnFzjXNRg==
X-Received: by 10.223.128.40 with SMTP id 37mr8007507wrk.73.1522693977800;
        Mon, 02 Apr 2018 11:32:57 -0700 (PDT)
Received: from localhost (112.68.155.104.bc.googleusercontent.com. [104.155.68.112])
        by smtp.gmail.com with ESMTPSA id b185sm122819wmb.48.2018.04.02.11.32.56
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Mon, 02 Apr 2018 11:32:56 -0700 (PDT)
From:   Junio C Hamano <gitster@pobox.com>
To:     =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] ls-remote: create option to sort by versions
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
        <87605aw1ue.fsf@evledraar.gmail.com>
Date:   Mon, 02 Apr 2018 11:32:56 -0700
In-Reply-To: <87605aw1ue.fsf@evledraar.gmail.com> (=?utf-8?B?IsOGdmFyIEFy?=
 =?utf-8?B?bmZqw7Zyw7A=?= Bjarmason"'s
        message of "Mon, 02 Apr 2018 08:37:29 +0200")
Message-ID: <xmqqbmf1zcfb.fsf@gitster-ct.c.googlers.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> This is a sensible thing to want, but why not follow the UI we have for
> this with git-tag? I.e. --sort=<key> & -i (or --ignore-case)? Of course
> ls-remote doesn't just show tags, so maybe we'd want --tag-sort=<key>
> and --ignore-tag-case or something, but the rest should be equivalent,
> no?

Yeah, and if we can reuse more of ref-filter.c machinery (which was
factored out of for-each-ref and tag you suggested borrows from),
that would be even better.  In the context of ls-remote, however, we
cannot inspect the object (we typically do not have them yet), so it
may not be practical, but I agree with your suggestion---we should
match the behaviour at the UI level at least when we can.


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id CBFC81F404
	for <e@80x24.org>; Mon,  2 Apr 2018 20:04:37 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1755451AbeDBUEf (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 16:04:35 -0400
Received: from mail-ot0-f170.google.com ([74.125.82.170]:38983 "EHLO
        mail-ot0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1753109AbeDBUEe (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 16:04:34 -0400
Received: by mail-ot0-f170.google.com with SMTP id h8-v6so16894323oti.6
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 13:04:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc:content-transfer-encoding;
        bh=jDcEqAbT/UJL3BJVs4imhgpXOktJgRFBaQEp7rw26nI=;
        b=BtIg3kFOzhwBlYQ6C8saKakfwUQqFs8DQ1djFnvZGM9uLfptezWAoQ7xgtqx0T4/L3
         msHdTQ+GbrZ7sNgHmT3XPRGmVRtsuY3rmND1dSR8WZqLK++xa2iw9YC1HfEMXSivBD9I
         ne/w1IBLLlNHDRhZKcWm417mkKKcoTzlDIzAvnUU8umUG/i8LHB/Pqi2iAkq4VyPMEqo
         3yS3OzEFaw1BTF6j9KXfCXatOQ40xfnb4GqtLgoGzrGM+RnqXdULiHATnA561TDR4pI7
         qAg5ZFiOv0CShLt1SFeKGUcWmbqu0fXxLpAUlShj8Bem/ahrYPqt0l2kP/nLIkGSJr7s
         IvMQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc:content-transfer-encoding;
        bh=jDcEqAbT/UJL3BJVs4imhgpXOktJgRFBaQEp7rw26nI=;
        b=K+IEOvtwMx7lLgZ8S5Jk/pAlox1U0qD4qu/JkSYhUpa0iTntGBaolafewCsF+jGB12
         QA1x1R1gPCsOy2bVYLuNo2tOj+NiXgdtqjlG9Loml1zCuK5GOF2W26/bIEj/2MJ7NpSk
         tpXVmZqPNlK392p9zWZpfsaeUi4Ss0HxbVjk9lenIAesOzU0gjflminQxL61OZGeBL5C
         b1pHC5OlesedS8GpO/ou6rZVCDQJRrF4offRCVWTrLg4bIHkQYgCuACEys+rwBJzIs3f
         uMfn0afgj+QzVfMgIsRB/R8TKOiQggDCE8fljEcsA8nshDX/B/98/cPlckFTrts8i1rm
         +/Pw==
X-Gm-Message-State: AElRT7HoOaBZLxHiV4xj4vscJd9DzPm70Jdh+hNqWT9G92oQQB3DmVsD
        05YtFCFEHJ78GbBMQ3p8Wqd19Umh8Q6wRoa4344=
X-Google-Smtp-Source: AIpwx49EH+micHdqDaJn5BXMU/0op32WfyBTjtggo+5nGdN9UUKQEJvN87Eu7SiAOyjWoGmmx1DhyjEec4JRGWlWSq4=
X-Received: by 2002:a9d:14ce:: with SMTP id r14-v6mr6071340otr.111.1522699474275;
 Mon, 02 Apr 2018 13:04:34 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Mon, 2 Apr 2018 13:03:53 -0700 (PDT)
In-Reply-To: <xmqqbmf1zcfb.fsf@gitster-ct.c.googlers.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <87605aw1ue.fsf@evledraar.gmail.com> <xmqqbmf1zcfb.fsf@gitster-ct.c.googlers.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Mon, 2 Apr 2018 22:03:53 +0200
Message-ID: <CAHwyqnV8tB63gQFVJhyNtr304Uv1TwWvYiX+3wuU0fDFhOphgg@mail.gmail.com>
Subject: Re: [PATCH] ls-remote: create option to sort by versions
To:     Junio C Hamano <gitster@pobox.com>
Cc:     =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        git@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Thanks for all the discussion!

I think I figured out a way to reuse more ref-filter.c machinery. I
will submit another patchset shortly.

On Mon, Apr 2, 2018 at 8:32 PM, Junio C Hamano <gitster@pobox.com> wrote:
> =C3=86var Arnfj=C3=B6r=C3=B0 Bjarmason <avarab@gmail.com> writes:
>
>> This is a sensible thing to want, but why not follow the UI we have for
>> this with git-tag? I.e. --sort=3D<key> & -i (or --ignore-case)? Of cours=
e
>> ls-remote doesn't just show tags, so maybe we'd want --tag-sort=3D<key>
>> and --ignore-tag-case or something, but the rest should be equivalent,
>> no?
>
> Yeah, and if we can reuse more of ref-filter.c machinery (which was
> factored out of for-each-ref and tag you suggested borrows from),
> that would be even better.  In the context of ls-remote, however, we
> cannot inspect the object (we typically do not have them yet), so it
> may not be practical, but I agree with your suggestion---we should
> match the behaviour at the UI level at least when we can.
>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 5E5A61F404
	for <e@80x24.org>; Mon,  2 Apr 2018 21:05:50 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754430AbeDBVFs (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 17:05:48 -0400
Received: from mail-wm0-f49.google.com ([74.125.82.49]:55827 "EHLO
        mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1754415AbeDBVFr (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 17:05:47 -0400
Received: by mail-wm0-f49.google.com with SMTP id b127so27694397wmf.5
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 14:05:46 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=Mkn/GGp9DsFJbCz3XvwHMWqMMsZ79nOX5MGrBVXGIaY=;
        b=GszPJllOA4LVD1z08uFEU5u9r8GtgENAhPynSJj0Eh3nF9r+hPXRqPQ0kNm1b8H7sx
         9j9H4olFcf6VCyZO0oDIRmwsWdw0DaZbj7SpkKnWgLLHJ09N/EBcLjljyBUclCdo5h6z
         ikzjfvos9fmfJvIS1t1OEMuiPSAdwSyEWKXSgR71wt6umRdbK63392oC7Xbb3m7sO6hx
         3jhjI7lkhInrstB4I0EqmNB5LwTkATZdYvmGWRVFOGVgKPQ/RAh+EFXjnNy/RcJHT38a
         MJ8wxsjVj3ABnS+4Mlv9I0bWhC7tIMTh0SV0KlifMi2UMfHAv+Ic2PnXsFGyCmH8qcWB
         xFvw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=Mkn/GGp9DsFJbCz3XvwHMWqMMsZ79nOX5MGrBVXGIaY=;
        b=qVC1Cy6m3XXzDI+XPP605Uj6rKfTZC+ahjMc6xcWc/zsrFdVpp799uACrga1e5SaOE
         z/7+lAdlodXCwjYfjHDX1iWcFoLiUhwIYbqNuUbemOdvdoAKeAYTn69M72cStGzwp3w3
         2du1jw1Dnr8IIiv6hYj34Z80ZprG5QCFpltGoSkZSZEdU+T75QJ3ZoN7LSfcdQXINiJZ
         LIF+1jmuE2vtQqhOJP4dQ22IF3rPOTPWz9pNExPH0fRT4ImiXIYu79Jgldb4BA33/TF5
         0SPMyAuIKrMonH+Bx5t+847fvyh7eIPen/iFvHuX6DD8ismooVTeinr9YpO+94kkPVOr
         K/rA==
X-Gm-Message-State: ALQs6tCUPNNpBfNzIWEAdl7/1CXhNnNKDYDsxkrt8R8MnPo2btlEmgpF
        hlbCdXaGag9eDLSAhl16HBonXsK4
X-Google-Smtp-Source: AIpwx486LL4BY32OEflclrct91IAITacEvsLtddw+Yzdm0hmqIm6H+R5nJLBBJV8XOpX1PbiZNh5JA==
X-Received: by 10.46.153.13 with SMTP id v13mr6537084lji.145.1522703145775;
        Mon, 02 Apr 2018 14:05:45 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2412-74736162.cust.telenor.se. [94.234.36.18])
        by smtp.gmail.com with ESMTPSA id o2sm189712lja.86.2018.04.02.14.05.44
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 02 Apr 2018 14:05:45 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v4] ls-remote: create '--sort' option
Date:   Mon,  2 Apr 2018 23:05:23 +0200
Message-Id: <20180402210523.83293-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 Documentation/git-ls-remote.txt | 12 +++++++++++-
 builtin/ls-remote.c             | 27 +++++++++++++++++++++++++--
 t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..17fae7218 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,16 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given.  Prefix `-` to sort in
+	descending order of the value. You may use the --sort=<key> option
+	multiple times, in which case the last key becomes the primary
+	key. Also supports "version:refname" or "v:refname" (tag
+	names are treated as versions). The "version:refname" sort
+	order can also be affected by the "versionsort.suffix"
+	configuration variable.
+	The keys supported are the same as those in `git for-each-ref`.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..5521c72f4 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -47,6 +48,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +63,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +73,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&array, 0, sizeof(array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -108,9 +115,25 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+
+		struct ref_array_item *item;
+		FLEX_ALLOC_MEM(item, refname, ref->name, strlen(ref->name));
+		item->symref = ref->symref;
+		item->objectname = ref->old_oid;
+
+		REALLOC_ARRAY(array.items, array.nr + 1);
+		array.items[array.nr++] = item;
+	}
+
+	if (sorting) {
+		ref_array_sort(sorting, &array);
+	}
+
+	for (int i = 0; i < array.nr; i++) {
+		const struct ref_array_item *ref = array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..66370cd88 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 74F851F404
	for <e@80x24.org>; Mon,  2 Apr 2018 22:11:48 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754526AbeDBWLq (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 18:11:46 -0400
Received: from mail-wm0-f53.google.com ([74.125.82.53]:35425 "EHLO
        mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1754430AbeDBWLp (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 18:11:45 -0400
Received: by mail-wm0-f53.google.com with SMTP id r82so30589199wme.0
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 15:11:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=QXrVwr+CD/Y8XPObuBh+hQb/gMNZT6xJqR9UtHTLzTQ=;
        b=VrwxeuGSgQohbDgoaRNkjyLuIA5hqO2HbpBECKA/rv0wjJSusgPFdSKZABgUj07ait
         1AcvqqEcLSZMeWkfXFUgvbToWD208TuePbdu2gcY/MGlfvXKqOt0dcfxwWNJ6wZH9mF3
         ++WQ8z12WPZK4lcX3hWxfHBBo5QwibPWUH1XUe3cQMyOZ0pMi6z/WhQFiZ0zYCNOAAem
         NVDrReg3ZZx5gHDZqMFlFjsfeDLHPVS+7Jut/lXft76WoQQjnyD/r81BhMwJReyISLvM
         NcR28O9Fh2FvYjv5eTvWRj/TxyyTrfYusZ4cBhQ2WJNZIuhFH+aRaJeKf8Eeqim4dOD0
         NtUQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=QXrVwr+CD/Y8XPObuBh+hQb/gMNZT6xJqR9UtHTLzTQ=;
        b=Zjh85anvl8F+IeyoOw/qv5i3nT57N1FUS4UWC2E9OYXYsL2WU7o2jEvL/nIlHevfJD
         N4FsrTh3pX/lIL0OVWEB3G/Zn6Vu6HVG3DPfIZX/S2ndOHp3jNyOR7tYks7csnn89StL
         eCbaSwWnV47S4LM/SSuFxme87+AA5/z/0SB7sUTqaCIAmestvoQXU5vinNqSLfN+hWde
         s48rKEOCy7pPbX7FbX35aHM8T7JMXY7Lek8cZrJ022hT1yzJqB9lCoKmrB7+iy3lDGWR
         j1ZAEAnWwf7wZ3cKKCs8ma07++C+tv26eIRBdGlFv0XME6UAFapiOLYwR83b2yNSTQz/
         Z/Kg==
X-Gm-Message-State: AElRT7HFa30D9htri7gk0wIxoEo6Bsfd5CiTbM16FYW1xa8YWMr8XxKq
        DXLls9QP3Cpz1jUpEqvXPpgHq7Ke
X-Google-Smtp-Source: AIpwx4/AUYSfY9croUez30vOCrzqjEIR0LzvCXikYL5v4XygOEPfZ0ZjeuxnDZv1mpmqL+wvY6k+IQ==
X-Received: by 10.46.134.129 with SMTP id l1mr7177035lji.23.1522707103787;
        Mon, 02 Apr 2018 15:11:43 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2412-74736162.cust.telenor.se. [94.234.36.18])
        by smtp.gmail.com with ESMTPSA id u12sm209202lji.87.2018.04.02.15.11.42
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 02 Apr 2018 15:11:43 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v5] ls-remote: create '--sort' option
Date:   Tue,  3 Apr 2018 00:11:24 +0200
Message-Id: <20180402221124.88049-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <CAHwyqnV8tB63gQFVJhyNtr304Uv1TwWvYiX+3wuU0fDFhOphgg@mail.gmail.com>
References: <CAHwyqnV8tB63gQFVJhyNtr304Uv1TwWvYiX+3wuU0fDFhOphgg@mail.gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 Documentation/git-ls-remote.txt | 12 +++++++++++-
 builtin/ls-remote.c             | 26 ++++++++++++++++++++++++--
 t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..17fae7218 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,16 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given.  Prefix `-` to sort in
+	descending order of the value. You may use the --sort=<key> option
+	multiple times, in which case the last key becomes the primary
+	key. Also supports "version:refname" or "v:refname" (tag
+	names are treated as versions). The "version:refname" sort
+	order can also be affected by the "versionsort.suffix"
+	configuration variable.
+	The keys supported are the same as those in `git for-each-ref`.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..7e2d820c4 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -47,6 +48,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +63,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +73,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&array, 0, sizeof(array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -104,13 +111,28 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
+		struct ref_array_item *item;
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+
+		FLEX_ALLOC_MEM(item, refname, ref->name, strlen(ref->name));
+		item->symref = ref->symref;
+		item->objectname = ref->old_oid;
+
+		REALLOC_ARRAY(array.items, array.nr + 1);
+		array.items[array.nr++] = item;
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &array);
+
+	for (int i = 0; i < array.nr; i++) {
+		const struct ref_array_item *ref = array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..66370cd88 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id CA7DF1F404
	for <e@80x24.org>; Mon,  2 Apr 2018 22:53:36 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754563AbeDBWxe (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 18:53:34 -0400
Received: from mail-qk0-f195.google.com ([209.85.220.195]:37673 "EHLO
        mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1754522AbeDBWxe (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 18:53:34 -0400
Received: by mail-qk0-f195.google.com with SMTP id w6so16744460qkb.4
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 15:53:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:sender:in-reply-to:references:from:date:message-id
         :subject:to:cc;
        bh=ijCoNDAGWjJFy8nOEItPmQf8xFqu6prZKMgoA3jAOtI=;
        b=NwlFNZWBWXAKG5oqqxFVj8ay6pA9eIAY07b0cshnmFvKxSNpVQUTECZnYPtQo2T3Wq
         ygZmPfwM2yjM5s9bLLOUNx6zzgkKZyPwDQHptGugwFwp5gMCFG7eVbLaZuYzsRcOtFky
         3ijRdGyrFjy2YzI9QYv6/Fpgvwyeurcs7JLxEhf89GwacOZWlAKv+no5mlAbf9ZIcY8Q
         nHHDORuROPaSe8VlfYpaSjWy8o7iPBRkkv3o29Rtg2VhdMt/hC8ehNDLd0RFO0mW8Z1Y
         8NJFc9HEvBny0GUmj2c00S3His20q8xZ7AOpYw3Z2GGxkIa1Khvgp5wK+HI1DBeCQ0AF
         f+tQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:cc;
        bh=ijCoNDAGWjJFy8nOEItPmQf8xFqu6prZKMgoA3jAOtI=;
        b=gxWH+7EDoAWo4HMi+Mf9Pt/NzszTpXfTlbRcQFVdu1RyFIU1EeFn0mxAdn7/sTgLrR
         JFUzQEHnC5jFHjV8Cvyzf4KN+IHuKw6D47LXQkng3ZwLO89uzljTCnmFc7nJ9HXUbvGi
         8oEnFiL5dE9lswUNeqTY4yz9XOaqwiQE9792TahJgO9SkyzBIa3Xy1Hr8A/AtU1I41cl
         nWLG44anDTMwnuRaW5HGGcOd9V3dvqj0AXHrNobCyt8fioMDz02JPQRmr3+1zliGSE1o
         br1EmwrliC2ManW1aFYYLrfWbGpRN83nw+Pe6YZRq2y7kUy9E6Qz01k+jgjXj3TZp0Lh
         YX+g==
X-Gm-Message-State: ALQs6tDk1KgfVBFClprLEbZm3r4Zo8YNK9pzXqd6J6jDuD21K43HGftO
        YCgRN6PXXKhElFuwxQwLOJ5CJTBDTXxuE6dSbBg=
X-Google-Smtp-Source: AIpwx4+T9PLUFC0K+r59HBKCU0jNnWNWjHsJOY5F/TcxIiHcpjc73msa12QLnf2jm7av8Rd+zPVpSjoFclNh03RWH/g=
X-Received: by 10.55.3.140 with SMTP id 134mr15814116qkd.26.1522709613291;
 Mon, 02 Apr 2018 15:53:33 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.12.174.202 with HTTP; Mon, 2 Apr 2018 15:53:32 -0700 (PDT)
In-Reply-To: <20180402221124.88049-1-haraldnordgren@gmail.com>
References: <CAHwyqnV8tB63gQFVJhyNtr304Uv1TwWvYiX+3wuU0fDFhOphgg@mail.gmail.com>
 <20180402221124.88049-1-haraldnordgren@gmail.com>
From:   Eric Sunshine <sunshine@sunshineco.com>
Date:   Mon, 2 Apr 2018 18:53:32 -0400
X-Google-Sender-Auth: qypdjKtZyGIAlr6Z1m3k9kHZSWo
Message-ID: <CAPig+cRTcY+XNedi=PdfRWpWR-LTAVvR4kkKkrs1e58LLYd3-Q@mail.gmail.com>
Subject: Re: [PATCH v5] ls-remote: create '--sort' option
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     Git List <git@vger.kernel.org>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Mon, Apr 2, 2018 at 6:11 PM, Harald Nordgren
<haraldnordgren@gmail.com> wrote:
> Create a '--sort' option for ls-remote, based on the one from
> for-each-ref. This e.g. allows ref names to be sorted by version
> semantics, so that v1.2 is sorted before v1.10.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---

Please take pity on reviewers and use this space below the "---" line
following your sign-off to explain what changed since the previous
attempt and to provide a link to the previous round(s), like this[1].
Thanks.

[1]: https://www.youtube.com/watch?v=r_8ydghbGSg

>  Documentation/git-ls-remote.txt | 12 +++++++++++-
>  builtin/ls-remote.c             | 26 ++++++++++++++++++++++++--
>  t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 75 insertions(+), 4 deletions(-)

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 2631E1F404
	for <e@80x24.org>; Mon,  2 Apr 2018 22:55:03 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754561AbeDBWzB (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 18:55:01 -0400
Received: from mail-qt0-f193.google.com ([209.85.216.193]:41204 "EHLO
        mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1754522AbeDBWzA (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 18:55:00 -0400
Received: by mail-qt0-f193.google.com with SMTP id d3so13939564qth.8
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 15:55:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:sender:in-reply-to:references:from:date:message-id
         :subject:to:cc;
        bh=awpAwqL7mC2PFe+yE5c+WoCsHknIn7VeDclRB5ZcPyk=;
        b=LPNcOvjYSB/u2Z4Hksav4TE4jIaskzc56Z5PzIkaBa13QE8znDUqS2WygHzSwG/cgi
         xWDYIgibaHN1Lu4AWsDFq/W1lC6W3cR43PKxsL8Qeh+9Tz2de6EOfIarcjGnFjsRePUi
         oprZ3DGBRlKH0PO/yOBXo5SQjdSawwzYXx94mI9U0QZKnF+OEwEL88TqWbONKOnlysbU
         pPPpPpgwiljt1Bj68TsJm62vBLEi0zI7IISQ6E0uDifuheQVwd3v6BwrKqzi3YaRdK3Q
         /Kej3qdSyektN65i+K1O6LsSfMzrASgFscNoPo/l+XpluM3TSW0IDsG+Si+WHrEJ5D6y
         4nwg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:cc;
        bh=awpAwqL7mC2PFe+yE5c+WoCsHknIn7VeDclRB5ZcPyk=;
        b=Jd0uwZKdLLZYyAJ7iXg+XSZuBOjNKKjkzaveEqz7Mir231wVVn9uu3ZoiT63dpSHnX
         1+E6t3Tt+9pYX+54UCwi4sKWJa6Z5iexBqcRv0hrtKUNXwIvb8h5SrCH2X4cb94TodCg
         Olbxv/Klm92M9HWAqnFGqiTNY5tQf6NO2XKyk3gP4cnaPzhd+PyR2RafO/lMJzMkFr+1
         Dj7Q9YWKdq/aUKf92vMdsy+R88ocD0vNkNLdRYn2/Gw/Z9IvNo0qxoJ6DlpKPv7lGYZQ
         Oxux70T5tCpglamwOMczSgjHZAbQ2c1Ef5k58I+JvYw0Gz7jpeqfG6M5/QZx+taUBIWK
         2yJQ==
X-Gm-Message-State: ALQs6tBM2/3JeljtAPidKTeQPf/GdRDHiGGZnWcYIiHB986oe1e+651W
        73xwHzCj9hiVkLZPK4G2OF1iORAWI1RdGNGxnQg=
X-Google-Smtp-Source: AIpwx49Cv01jOUc3sokSQSGdHbwXGPY/qwyei5q419BXWSW66Y9b3kK/KIkFmsal8KgcBSRrOGLpOCvnvzHfz0pdyUc=
X-Received: by 10.200.1.2 with SMTP id e2mr17235201qtg.121.1522709699821; Mon,
 02 Apr 2018 15:54:59 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.12.174.202 with HTTP; Mon, 2 Apr 2018 15:54:59 -0700 (PDT)
In-Reply-To: <CAPig+cRTcY+XNedi=PdfRWpWR-LTAVvR4kkKkrs1e58LLYd3-Q@mail.gmail.com>
References: <CAHwyqnV8tB63gQFVJhyNtr304Uv1TwWvYiX+3wuU0fDFhOphgg@mail.gmail.com>
 <20180402221124.88049-1-haraldnordgren@gmail.com> <CAPig+cRTcY+XNedi=PdfRWpWR-LTAVvR4kkKkrs1e58LLYd3-Q@mail.gmail.com>
From:   Eric Sunshine <sunshine@sunshineco.com>
Date:   Mon, 2 Apr 2018 18:54:59 -0400
X-Google-Sender-Auth: 4GuOfFtWaLhcdQqzRKWl1s27pd4
Message-ID: <CAPig+cQ4=aft738gxngHDGB+ZZPFFCmve=D6ExRg_F3jr8634g@mail.gmail.com>
Subject: Re: [PATCH v5] ls-remote: create '--sort' option
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     Git List <git@vger.kernel.org>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Mon, Apr 2, 2018 at 6:53 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Mon, Apr 2, 2018 at 6:11 PM, Harald Nordgren
> <haraldnordgren@gmail.com> wrote:
>> Create a '--sort' option for ls-remote, based on the one from
>> for-each-ref. This e.g. allows ref names to be sorted by version
>> semantics, so that v1.2 is sorted before v1.10.
>>
>> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
>> ---
>
> Please take pity on reviewers and use this space below the "---" line
> following your sign-off to explain what changed since the previous
> attempt and to provide a link to the previous round(s), like this[1].
> Thanks.
>
> [1]: https://www.youtube.com/watch?v=r_8ydghbGSg

Or, like this if we want to be really accurate[1].

[1]: https://public-inbox.org/git/20180402210523.83293-1-haraldnordgren@gmail.com/

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 766A41F404
	for <e@80x24.org>; Tue,  3 Apr 2018 00:48:40 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754667AbeDCAsi (ORCPT <rfc822;e@80x24.org>);
        Mon, 2 Apr 2018 20:48:38 -0400
Received: from mail-wr0-f180.google.com ([209.85.128.180]:42908 "EHLO
        mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1754550AbeDCAsh (ORCPT <rfc822;git@vger.kernel.org>);
        Mon, 2 Apr 2018 20:48:37 -0400
Received: by mail-wr0-f180.google.com with SMTP id s18so16191389wrg.9
        for <git@vger.kernel.org>; Mon, 02 Apr 2018 17:48:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=y+bEZRXefSQgQMp635vvNHE3aKqgCQYtmVTu6XRvYkc=;
        b=YPxuYhdL5NEx5CvPMGh4A/VJI34lrROTNzZPOSdnko9yJzE9Mpz3wwQboSpU9hZIkJ
         b7rd+1N+dO5tbuvVp7VyqsXy5zn/1IAtdxFUwIjb8vnr4bwAwkZRExJA5YoEMN+Kl2pb
         bIZez0AaoBAyAlsvX48cIaOHd5UvaTJnsW0YS+5vHDOjLGR7Gjb3Akw1BRFW0Rv+FUnt
         ftPrIgurRL5XB6Cv0kPcmJWiqkQiQ4Yj/x7xaAkcG+qxORDyfk/mFq+nxi9nGewsI5lE
         S0AC/KJUtbjRlDdqHrh499QPVJVV7xFEI4/lj1+SZlkEoP7dCu7GkwQP7J9Kl/dgdmUD
         3JKQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=y+bEZRXefSQgQMp635vvNHE3aKqgCQYtmVTu6XRvYkc=;
        b=JsH41Ie5TT89oFBgBKjOQhsjCGt5bnYIzLJ4iybiaSek5AwFux7LU0F9v95ClMN6um
         vfnOCKvYbC/xL+rwaYFjaIGuv006KAo24vJnmvOElz8FyFqPju/GSjV3ZjSZ14Yv+C/O
         cjTDy9QezmyKft4kcTOgZVLRbuo8xTG0eUtX0yblLMcWJAa4aPDWIUscg6AwXwKQMw05
         fsNbbzOpfPBqsNPrXYEN8CTxd3gHINvwEHYYoD/iBL5Pi2HpB+Lff+8kjcIcwf7VA/rj
         CZFM5PpIqKLWPCAo+cRJFfFvqKR9cqhQ/tPCjUvCF25CtkASOc6LF7Wlm0kj7s6Wgn7L
         0yuw==
X-Gm-Message-State: ALQs6tCid+EfL86Lyqj6/DxI+Jd6UUjSiX4Tkc5jRwmZwsTwKnCbX/nD
        fzyYNChrydj6yZSXM0P7YxyMRHv/
X-Google-Smtp-Source: AIpwx4+hxoa1wBq0tTAT4KhXHLZGjN49owgFynI7PQn6mkzxWUSSUnXx0CWKSHV9qwxcg91jFP1h0w==
X-Received: by 2002:a19:15d9:: with SMTP id 86-v6mr7008857lfv.96.1522716516063;
        Mon, 02 Apr 2018 17:48:36 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2412-74736162.cust.telenor.se. [94.234.36.18])
        by smtp.gmail.com with ESMTPSA id a19sm244215lji.65.2018.04.02.17.48.34
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 02 Apr 2018 17:48:35 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v6] ls-remote: create '--sort' option
Date:   Tue,  3 Apr 2018 02:48:18 +0200
Message-Id: <20180403004818.91941-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <CAHwyqnV8tB63gQFVJhyNtr304Uv1TwWvYiX+3wuU0fDFhOphgg@mail.gmail.com>
References: <CAHwyqnV8tB63gQFVJhyNtr304Uv1TwWvYiX+3wuU0fDFhOphgg@mail.gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Moving 'int i' declaration outside of 'for' loop init

 Documentation/git-ls-remote.txt | 12 +++++++++++-
 builtin/ls-remote.c             | 27 +++++++++++++++++++++++++--
 t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..17fae7218 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,16 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given.  Prefix `-` to sort in
+	descending order of the value. You may use the --sort=<key> option
+	multiple times, in which case the last key becomes the primary
+	key. Also supports "version:refname" or "v:refname" (tag
+	names are treated as versions). The "version:refname" sort
+	order can also be affected by the "versionsort.suffix"
+	configuration variable.
+	The keys supported are the same as those in `git for-each-ref`.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..113a2fd7d 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&array, 0, sizeof(array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -104,13 +112,28 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
+		struct ref_array_item *item;
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+
+		FLEX_ALLOC_MEM(item, refname, ref->name, strlen(ref->name));
+		item->symref = ref->symref;
+		item->objectname = ref->old_oid;
+
+		REALLOC_ARRAY(array.items, array.nr + 1);
+		array.items[array.nr++] = item;
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &array);
+
+	for (i = 0; i < array.nr; i++) {
+		const struct ref_array_item *ref = array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..66370cd88 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 11B761F404
	for <e@80x24.org>; Wed,  4 Apr 2018 17:12:15 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752721AbeDDRMN (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 13:12:13 -0400
Received: from mail-wr0-f173.google.com ([209.85.128.173]:40025 "EHLO
        mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752447AbeDDRML (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 13:12:11 -0400
Received: by mail-wr0-f173.google.com with SMTP id n2so20579048wrj.7
        for <git@vger.kernel.org>; Wed, 04 Apr 2018 10:12:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=F/kaLlJUTs4bMgTt3rf3eoizX1uAkTAEaUzQAZ+us8A=;
        b=H159RBCQBpOrggKFCSj3HT2s9UQNVAueMkNoxxpXU+oWs6e5ZWQ2YPlffTr/l1+S7y
         jl21PFlv2vW1vZutEsuQImtM8Rt8t9vL+JbI5fwHqfpkdyQWKSFZ2zgnfY4ATT+DuH7W
         uJ8hnHgXUaWsaIUYRdyutqFDG6kLGMTwEshnOIm9i8BXehnLG6N2qTWKmoVLeKGQqlJV
         Qz9pPvAptbTSznsmUNCJsFN8W1mVXtk07HTJQLMCsxSOIq2vsz1XfZw0M03Dd4/ajzQ9
         3Iiwqrw8AL4Bso9yK4JS+JDi2W+o7CTCmEBJ4msdXSl/wfpLFsj6OATHfmpbj556Il1E
         KIvQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=F/kaLlJUTs4bMgTt3rf3eoizX1uAkTAEaUzQAZ+us8A=;
        b=nUvzST30hzWoaIFpwtE9cxLxJHNdcgm+M75gH3guCcpsMOpH6Qt7VN2IOWjALbuQOc
         5J5r0wVCLttcZTMEwJDqx40n5mkH0E4m8RQzvZXfozJH17ORO3h5y3jlFTYFGowX1IKC
         dsv72sM/jt/xwodWm/dJ4rRLX4Te+pzvC+XEi+0dwfaab+Yhq72YL4Bc1nlza/X92k2C
         YXr9NKrnSLE8bNH4AisrGVB0OPzDsinnHawRLeFYHTeMjL9/F6pYjZ1/6uNIc38Fdj4U
         8oOzR6cgtxBGcJsn8MVI6krJ2ps0brTxXt6XT3fbSXPYjEDKnjJ7V1li9EAxsogJ4Huk
         8PYA==
X-Gm-Message-State: ALQs6tAxuh1gZoLNjQJQSRBKfttzq/RWiOKGdaIh+gbEjNm86cDDWmlk
        5YWDa6/YM2qMrac9XXSeukoepRgTOLQ=
X-Google-Smtp-Source: AIpwx4/4JSAB28ugJYc5AMpwxWez7MMkqnsGG4vwO6WLf6hA9uxh1LweRZDodHAN91lrqjLmssvfPg==
X-Received: by 2002:a19:1449:: with SMTP id k70-v6mr12041033lfi.23.1522861930098;
        Wed, 04 Apr 2018 10:12:10 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2375-74736162.cust.telenor.se. [94.234.35.117])
        by smtp.gmail.com with ESMTPSA id i18-v6sm1092339lfj.50.2018.04.04.10.12.08
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 04 Apr 2018 10:12:09 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v7] ls-remote: create '--sort' option
Date:   Wed,  4 Apr 2018 19:11:53 +0200
Message-Id: <20180404171153.4126-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Started using 'ALLOC_GROW'

 Documentation/git-ls-remote.txt | 12 +++++++++++-
 builtin/ls-remote.c             | 27 +++++++++++++++++++++++++--
 t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..17fae7218 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,16 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given.  Prefix `-` to sort in
+	descending order of the value. You may use the --sort=<key> option
+	multiple times, in which case the last key becomes the primary
+	key. Also supports "version:refname" or "v:refname" (tag
+	names are treated as versions). The "version:refname" sort
+	order can also be affected by the "versionsort.suffix"
+	configuration variable.
+	The keys supported are the same as those in `git for-each-ref`.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..5bb8ee68a 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&array, 0, sizeof(array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -104,13 +112,28 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
+		struct ref_array_item *item;
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+
+		FLEX_ALLOC_MEM(item, refname, ref->name, strlen(ref->name));
+		item->symref = ref->symref;
+		item->objectname = ref->old_oid;
+
+		ALLOC_GROW(array.items, array.nr + 1, array.alloc);
+		array.items[array.nr++] = item;
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &array);
+
+	for (i = 0; i < array.nr; i++) {
+		const struct ref_array_item *ref = array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..66370cd88 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id C05BB1F404
	for <e@80x24.org>; Wed,  4 Apr 2018 17:19:26 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751179AbeDDRTY (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 13:19:24 -0400
Received: from mail-oi0-f46.google.com ([209.85.218.46]:35633 "EHLO
        mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1750995AbeDDRTX (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 13:19:23 -0400
Received: by mail-oi0-f46.google.com with SMTP id z8-v6so19965340oix.2
        for <git@vger.kernel.org>; Wed, 04 Apr 2018 10:19:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=2UftOkMbien6OlXRwd21mBbh5aClVLy5Itu7OBur614=;
        b=TZ48nI5Eliq3vLwikT8oO7e4BkW/6BMoomvB9xuh8qxXe5ym6SGsMP3vPHnew5tYJN
         clZlyeKpnBLpIV4WNQRN3LgwuYfspJEEbMyLNP3nwlV6EqEu9URfNOcUVsGnFXjoamtY
         CZ8KY9ot4gN3mEaXSaE8zfS+S/w4WuH8ocSyZxWT0tisUcmYTQAPUu1syjli7aCfHMlW
         hFPJCeMew9P4ma18qsYGJOwHPA0c5T/wnQdcGzM/pGlhYSUM7iUWiKQQp5WvimmLwNzs
         e6equiWXLgKC/A7qgrA1Rs3NNdicBejFDecF+j4MSH7JxyWklJI7TL0cgfKNUxU3GBut
         FfSQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=2UftOkMbien6OlXRwd21mBbh5aClVLy5Itu7OBur614=;
        b=KZomTbEMxb2jZ8rA3Oxmdxhk1BxE+5j1n/YvP7wZobjD8CZaO/w43kXl7x5fQYKxIO
         oVk4ACqK5ukqRe+txTmeo6scRnZ0wYLFM3Caawstyb+EWbow7TDHVJLF5l68YXFVuI0r
         o06wqbo2V9iwhMeOMHl8suf2pTNMVU6P9cySTBjDkpQ402aUfIN89vzxK1elEZp4UKL7
         bx/oJ37HDeyEqyFdxbfOGbK2ho86xp5z4NaS8NmFNZTNCuvsFzMhoMLzq/3jArieqiN4
         JGasrwmwFqAZ/9usm7ZSBTohxWF72OYRnO2swpo81R4WG1tpp8cWHCUPmLj7wqAz0Anx
         0joA==
X-Gm-Message-State: ALQs6tAc+9nHpUU8A9AS7sIx84r1kGqfnOInKw26gjwWR6hAIYob+k6O
        Yzmp41friZivocZ3PKmQrPro17QW7btaMZIGr8mnI2Y6
X-Google-Smtp-Source: AIpwx4/LgRUilkeZvU1Y2Z+FYXpR48Wut3hhM1J+pKSvar90KaMoGNHACEZ+APdYlngeGixLkzRwq5KmQ4KfFPD7jx8=
X-Received: by 2002:aca:f13:: with SMTP id 19-v6mr10950507oip.298.1522862362928;
 Wed, 04 Apr 2018 10:19:22 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Wed, 4 Apr 2018 10:18:42 -0700 (PDT)
In-Reply-To: <20180404171153.4126-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com> <20180404171153.4126-1-haraldnordgren@gmail.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Wed, 4 Apr 2018 19:18:42 +0200
Message-ID: <CAHwyqnXtc-WgynCmE+EEVYtg6RRVweK8vwfBQS5VL4ygaFumKQ@mail.gmail.com>
Subject: Re: [PATCH v7] ls-remote: create '--sort' option
To:     git@vger.kernel.org,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

I updated the code to use 'ALLOC_GROW'. I makes sense, I now I realize
why array.alloc is there ;)

Jeff, you are right that 'git ls-remote --sort=committerdate' will not
work. Do you think we need to do something about this, or it's fine
that it fails the way you showed?

On Wed, Apr 4, 2018 at 7:11 PM, Harald Nordgren
<haraldnordgren@gmail.com> wrote:
> Create a '--sort' option for ls-remote, based on the one from
> for-each-ref. This e.g. allows ref names to be sorted by version
> semantics, so that v1.2 is sorted before v1.10.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>
> Notes:
>     Started using 'ALLOC_GROW'
>
>  Documentation/git-ls-remote.txt | 12 +++++++++++-
>  builtin/ls-remote.c             | 27 +++++++++++++++++++++++++--
>  t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 76 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
> index 5f2628c8f..17fae7218 100644
> --- a/Documentation/git-ls-remote.txt
> +++ b/Documentation/git-ls-remote.txt
> @@ -10,7 +10,7 @@ SYNOPSIS
>  --------
>  [verse]
>  'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
> -             [-q | --quiet] [--exit-code] [--get-url]
> +             [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
>               [--symref] [<repository> [<refs>...]]
>
>  DESCRIPTION
> @@ -60,6 +60,16 @@ OPTIONS
>         upload-pack only shows the symref HEAD, so it will be the only
>         one shown by ls-remote.
>
> +--sort=<key>::
> +       Sort based on the key given.  Prefix `-` to sort in
> +       descending order of the value. You may use the --sort=<key> option
> +       multiple times, in which case the last key becomes the primary
> +       key. Also supports "version:refname" or "v:refname" (tag
> +       names are treated as versions). The "version:refname" sort
> +       order can also be affected by the "versionsort.suffix"
> +       configuration variable.
> +       The keys supported are the same as those in `git for-each-ref`.
> +
>  <repository>::
>         The "remote" repository to query.  This parameter can be
>         either a URL or the name of a remote (see the GIT URLS and
> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
> index 540d56429..5bb8ee68a 100644
> --- a/builtin/ls-remote.c
> +++ b/builtin/ls-remote.c
> @@ -1,6 +1,7 @@
>  #include "builtin.h"
>  #include "cache.h"
>  #include "transport.h"
> +#include "ref-filter.h"
>  #include "remote.h"
>
>  static const char * const ls_remote_usage[] = {
> @@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>         int show_symref_target = 0;
>         const char *uploadpack = NULL;
>         const char **pattern = NULL;
> +       int i;
>
>         struct remote *remote;
>         struct transport *transport;
>         const struct ref *ref;
> +       struct ref_array array;
> +       static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
>
>         struct option options[] = {
>                 OPT__QUIET(&quiet, N_("do not print remote URL")),
> @@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>                 OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
>                 OPT_BOOL(0, "get-url", &get_url,
>                          N_("take url.<base>.insteadOf into account")),
> +               OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
> +                            N_("field name to sort on"), &parse_opt_ref_sorting),
>                 OPT_SET_INT_F(0, "exit-code", &status,
>                               N_("exit with exit code 2 if no matching refs are found"),
>                               2, PARSE_OPT_NOCOMPLETE),
> @@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>                 OPT_END()
>         };
>
> +       memset(&array, 0, sizeof(array));
> +
>         argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
>                              PARSE_OPT_STOP_AT_NON_OPTION);
>         dest = argv[0];
> @@ -104,13 +112,28 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>         if (!dest && !quiet)
>                 fprintf(stderr, "From %s\n", *remote->url);
>         for ( ; ref; ref = ref->next) {
> +               struct ref_array_item *item;
>                 if (!check_ref_type(ref, flags))
>                         continue;
>                 if (!tail_match(pattern, ref->name))
>                         continue;
> +
> +               FLEX_ALLOC_MEM(item, refname, ref->name, strlen(ref->name));
> +               item->symref = ref->symref;
> +               item->objectname = ref->old_oid;
> +
> +               ALLOC_GROW(array.items, array.nr + 1, array.alloc);
> +               array.items[array.nr++] = item;
> +       }
> +
> +       if (sorting)
> +               ref_array_sort(sorting, &array);
> +
> +       for (i = 0; i < array.nr; i++) {
> +               const struct ref_array_item *ref = array.items[i];
>                 if (show_symref_target && ref->symref)
> -                       printf("ref: %s\t%s\n", ref->symref, ref->name);
> -               printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
> +                       printf("ref: %s\t%s\n", ref->symref, ref->refname);
> +               printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
>                 status = 0; /* we found something */
>         }
>         return status;
> diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
> index 02106c922..66370cd88 100755
> --- a/t/t5512-ls-remote.sh
> +++ b/t/t5512-ls-remote.sh
> @@ -10,6 +10,9 @@ test_expect_success setup '
>         test_tick &&
>         git commit -m initial &&
>         git tag mark &&
> +       git tag mark1.1 &&
> +       git tag mark1.2 &&
> +       git tag mark1.10 &&
>         git show-ref --tags -d | sed -e "s/ /   /" >expected.tag &&
>         (
>                 echo "$(git rev-parse HEAD)     HEAD"
> @@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
>         test_cmp expected.all actual
>  '
>
> +test_expect_success 'ls-remote --sort="version:refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       EOF
> +       git ls-remote --sort="version:refname" --tags self >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       EOF
> +       git ls-remote --sort="-version:refname" --tags self >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success 'ls-remote --sort="-refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       EOF
> +       git ls-remote --sort="-refname" --tags self >actual &&
> +       test_cmp expect actual
> +'
> +
>  test_expect_success 'dies when no remote specified and no default remotes found' '
>         test_must_fail git ls-remote
>  '
> @@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
>
>  test_expect_success 'Report match with --exit-code' '
>         git ls-remote --exit-code other.git "refs/tags/*" >actual &&
> -       git ls-remote . tags/mark >expect &&
> +       git ls-remote . tags/mark* >expect &&
>         test_cmp expect actual
>  '
>
> @@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/remotes/origin/HEAD
>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/remotes/origin/master
>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
>         EOF
>         git ls-remote --symref >actual &&
>         test_cmp expect actual
> --
> 2.14.3 (Apple Git-98)
>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 8EC0A1F404
	for <e@80x24.org>; Wed,  4 Apr 2018 17:47:54 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751213AbeDDRrv (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 13:47:51 -0400
Received: from mail-ot0-f178.google.com ([74.125.82.178]:38530 "EHLO
        mail-ot0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1750890AbeDDRru (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 13:47:50 -0400
Received: by mail-ot0-f178.google.com with SMTP id o9-v6so24292349otj.5
        for <git@vger.kernel.org>; Wed, 04 Apr 2018 10:47:50 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=FY7NRHUg0rZE51nymKM5Rt+CqvcsqWnwEHujkPJe2Zg=;
        b=oxY4m2bf0yzMcGyfhEp9cFBUpl8rnksvkKxxjUaRFXTOujYWbxC/wUjOIdCkSB5gLH
         ON9U82ojkTlr40gDSnzLfNRNMGfDH3CH3/RluHin6U7F/eVNNPPMyWD5iUpiE2fyMGsr
         8/jPN0fLbYVQnACV7ps5OtgW0Yy6yO4izJiSBoh+wG4m4aWkpX9SJswBoRs/c+06+2oG
         Cn80PXq9ZRfaqTLu2g50e6XlCP7BWVMMTHxGbmrBkYaNIBwHVapLucmmpoypoGlagm3Z
         QJqemXqD7eyAbSdLTQgc6eAyUpVCy4kiGegwRURfo7vGt2ZD86cDAwgHTWvZC+0DglQE
         HB4g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=FY7NRHUg0rZE51nymKM5Rt+CqvcsqWnwEHujkPJe2Zg=;
        b=BABc+jX/YHng/3koGzth9yQJB7+De/Sxb/NsMEdbdaRg/nwnnS5Yw3I8NRnmP4Ni87
         N+ngRm2lSpnohoBYEUEhghdAs31CRD4LpzqTaRqtCJGCA74N/gP1NmU7jLvc1gPBUPMx
         7u85nm5jvehiVmn7I+TY7U1cZtV7XT0cXt3hsAcFL6QTYrH+qcV0UFxeCWfg2BuANnQ7
         u+3MlZ+VvJDElE0i2S921KUx4bIzvvvkrS/tUoXr7xw8ALHcwmKSGWOagMm/vOj+PGIW
         HBtLGqwwNKVoYri/ZE0fEosJLk1VSAxz+axHB/bDBCfItOAte05xoFuX52SsA+ONOUXt
         +kug==
X-Gm-Message-State: ALQs6tCUxqHADw7BaKSmS/nYHveuE/eA3aAn61ve5o70QmVBEdg75jBX
        g6ny7xJjqkIZbdu8t60NvwEXxvyGEcUp9XheKYwpYta0
X-Google-Smtp-Source: AIpwx48sb3UkbQ1kRUM6TEOPwE5T4R117lfrF9tQdVa1yuAidsmOmT+M/OrqzAk+Ev3FBva3iwutxlPqUvXABGrJ46A=
X-Received: by 2002:a9d:481a:: with SMTP id c26-v6mr12062877otf.393.1522864069796;
 Wed, 04 Apr 2018 10:47:49 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Wed, 4 Apr 2018 10:47:09 -0700 (PDT)
In-Reply-To: <CAHwyqnXtc-WgynCmE+EEVYtg6RRVweK8vwfBQS5VL4ygaFumKQ@mail.gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180404171153.4126-1-haraldnordgren@gmail.com> <CAHwyqnXtc-WgynCmE+EEVYtg6RRVweK8vwfBQS5VL4ygaFumKQ@mail.gmail.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Wed, 4 Apr 2018 19:47:09 +0200
Message-ID: <CAHwyqnX614p+xbmUBLJwY2yK1gOddRuzEM806z1Fu1VPU8rzJw@mail.gmail.com>
Subject: Re: [PATCH v7] ls-remote: create '--sort' option
To:     git@vger.kernel.org,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Links to previous revisions:

[1] https://public-inbox.org/git/20180402174614.GA28566@sigill.intra.peff.net/T/#m108fe8c83f3558afaea8e317e680f7eaa136e9a9
[2] https://public-inbox.org/git/20180402211920.GA32099@sigill.intra.peff.net/T/#ma9ec4e0ce664160086e535c012e20d76822c60e5
...
[4] https://public-inbox.org/git/20180402174614.GA28566@sigill.intra.peff.net/T/#maa02c40c87b192e56c370c312098d469c9fce757
[5] https://public-inbox.org/git/20180402174614.GA28566@sigill.intra.peff.net/T/#m52cdbbbba3f359e1257e7bdfe19cd9a26f55fa20
[6] https://public-inbox.org/git/20180402174614.GA28566@sigill.intra.peff.net/T/#m6d3ce17f0f6dabeddaf03336c92512b7c413422b

On Wed, Apr 4, 2018 at 7:18 PM, Harald Nordgren
<haraldnordgren@gmail.com> wrote:
> I updated the code to use 'ALLOC_GROW'. I makes sense, I now I realize
> why array.alloc is there ;)
>
> Jeff, you are right that 'git ls-remote --sort=committerdate' will not
> work. Do you think we need to do something about this, or it's fine
> that it fails the way you showed?
>
> On Wed, Apr 4, 2018 at 7:11 PM, Harald Nordgren
> <haraldnordgren@gmail.com> wrote:
>> Create a '--sort' option for ls-remote, based on the one from
>> for-each-ref. This e.g. allows ref names to be sorted by version
>> semantics, so that v1.2 is sorted before v1.10.
>>
>> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
>> ---
>>
>> Notes:
>>     Started using 'ALLOC_GROW'
>>
>>  Documentation/git-ls-remote.txt | 12 +++++++++++-
>>  builtin/ls-remote.c             | 27 +++++++++++++++++++++++++--
>>  t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
>>  3 files changed, 76 insertions(+), 4 deletions(-)
>>
>> diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
>> index 5f2628c8f..17fae7218 100644
>> --- a/Documentation/git-ls-remote.txt
>> +++ b/Documentation/git-ls-remote.txt
>> @@ -10,7 +10,7 @@ SYNOPSIS
>>  --------
>>  [verse]
>>  'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
>> -             [-q | --quiet] [--exit-code] [--get-url]
>> +             [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
>>               [--symref] [<repository> [<refs>...]]
>>
>>  DESCRIPTION
>> @@ -60,6 +60,16 @@ OPTIONS
>>         upload-pack only shows the symref HEAD, so it will be the only
>>         one shown by ls-remote.
>>
>> +--sort=<key>::
>> +       Sort based on the key given.  Prefix `-` to sort in
>> +       descending order of the value. You may use the --sort=<key> option
>> +       multiple times, in which case the last key becomes the primary
>> +       key. Also supports "version:refname" or "v:refname" (tag
>> +       names are treated as versions). The "version:refname" sort
>> +       order can also be affected by the "versionsort.suffix"
>> +       configuration variable.
>> +       The keys supported are the same as those in `git for-each-ref`.
>> +
>>  <repository>::
>>         The "remote" repository to query.  This parameter can be
>>         either a URL or the name of a remote (see the GIT URLS and
>> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
>> index 540d56429..5bb8ee68a 100644
>> --- a/builtin/ls-remote.c
>> +++ b/builtin/ls-remote.c
>> @@ -1,6 +1,7 @@
>>  #include "builtin.h"
>>  #include "cache.h"
>>  #include "transport.h"
>> +#include "ref-filter.h"
>>  #include "remote.h"
>>
>>  static const char * const ls_remote_usage[] = {
>> @@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>>         int show_symref_target = 0;
>>         const char *uploadpack = NULL;
>>         const char **pattern = NULL;
>> +       int i;
>>
>>         struct remote *remote;
>>         struct transport *transport;
>>         const struct ref *ref;
>> +       struct ref_array array;
>> +       static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
>>
>>         struct option options[] = {
>>                 OPT__QUIET(&quiet, N_("do not print remote URL")),
>> @@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>>                 OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
>>                 OPT_BOOL(0, "get-url", &get_url,
>>                          N_("take url.<base>.insteadOf into account")),
>> +               OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
>> +                            N_("field name to sort on"), &parse_opt_ref_sorting),
>>                 OPT_SET_INT_F(0, "exit-code", &status,
>>                               N_("exit with exit code 2 if no matching refs are found"),
>>                               2, PARSE_OPT_NOCOMPLETE),
>> @@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>>                 OPT_END()
>>         };
>>
>> +       memset(&array, 0, sizeof(array));
>> +
>>         argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
>>                              PARSE_OPT_STOP_AT_NON_OPTION);
>>         dest = argv[0];
>> @@ -104,13 +112,28 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>>         if (!dest && !quiet)
>>                 fprintf(stderr, "From %s\n", *remote->url);
>>         for ( ; ref; ref = ref->next) {
>> +               struct ref_array_item *item;
>>                 if (!check_ref_type(ref, flags))
>>                         continue;
>>                 if (!tail_match(pattern, ref->name))
>>                         continue;
>> +
>> +               FLEX_ALLOC_MEM(item, refname, ref->name, strlen(ref->name));
>> +               item->symref = ref->symref;
>> +               item->objectname = ref->old_oid;
>> +
>> +               ALLOC_GROW(array.items, array.nr + 1, array.alloc);
>> +               array.items[array.nr++] = item;
>> +       }
>> +
>> +       if (sorting)
>> +               ref_array_sort(sorting, &array);
>> +
>> +       for (i = 0; i < array.nr; i++) {
>> +               const struct ref_array_item *ref = array.items[i];
>>                 if (show_symref_target && ref->symref)
>> -                       printf("ref: %s\t%s\n", ref->symref, ref->name);
>> -               printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
>> +                       printf("ref: %s\t%s\n", ref->symref, ref->refname);
>> +               printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
>>                 status = 0; /* we found something */
>>         }
>>         return status;
>> diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
>> index 02106c922..66370cd88 100755
>> --- a/t/t5512-ls-remote.sh
>> +++ b/t/t5512-ls-remote.sh
>> @@ -10,6 +10,9 @@ test_expect_success setup '
>>         test_tick &&
>>         git commit -m initial &&
>>         git tag mark &&
>> +       git tag mark1.1 &&
>> +       git tag mark1.2 &&
>> +       git tag mark1.10 &&
>>         git show-ref --tags -d | sed -e "s/ /   /" >expected.tag &&
>>         (
>>                 echo "$(git rev-parse HEAD)     HEAD"
>> @@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
>>         test_cmp expected.all actual
>>  '
>>
>> +test_expect_success 'ls-remote --sort="version:refname" --tags self' '
>> +       cat >expect <<-\EOF &&
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
>> +       EOF
>> +       git ls-remote --sort="version:refname" --tags self >actual &&
>> +       test_cmp expect actual
>> +'
>> +
>> +test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
>> +       cat >expect <<-\EOF &&
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
>> +       EOF
>> +       git ls-remote --sort="-version:refname" --tags self >actual &&
>> +       test_cmp expect actual
>> +'
>> +
>> +test_expect_success 'ls-remote --sort="-refname" --tags self' '
>> +       cat >expect <<-\EOF &&
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
>> +       EOF
>> +       git ls-remote --sort="-refname" --tags self >actual &&
>> +       test_cmp expect actual
>> +'
>> +
>>  test_expect_success 'dies when no remote specified and no default remotes found' '
>>         test_must_fail git ls-remote
>>  '
>> @@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
>>
>>  test_expect_success 'Report match with --exit-code' '
>>         git ls-remote --exit-code other.git "refs/tags/*" >actual &&
>> -       git ls-remote . tags/mark >expect &&
>> +       git ls-remote . tags/mark* >expect &&
>>         test_cmp expect actual
>>  '
>>
>> @@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
>>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/remotes/origin/HEAD
>>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/remotes/origin/master
>>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
>> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
>>         EOF
>>         git ls-remote --symref >actual &&
>>         test_cmp expect actual
>> --
>> 2.14.3 (Apple Git-98)
>>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 15F941F404
	for <e@80x24.org>; Wed,  4 Apr 2018 18:55:26 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751807AbeDDSzX (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 14:55:23 -0400
Received: from cloud.peff.net ([104.130.231.41]:53482 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1751769AbeDDSzV (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 14:55:21 -0400
Received: (qmail 16955 invoked by uid 109); 4 Apr 2018 18:55:21 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Wed, 04 Apr 2018 18:55:21 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 7044 invoked by uid 111); 4 Apr 2018 18:56:21 -0000
Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Wed, 04 Apr 2018 14:56:21 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Wed, 04 Apr 2018 14:55:19 -0400
Date:   Wed, 4 Apr 2018 14:55:19 -0400
From:   Jeff King <peff@peff.net>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org, avarab@gmail.com, gitster@pobox.com,
        sunshine@sunshineco.com
Subject: Re: [PATCH v7] ls-remote: create '--sort' option
Message-ID: <20180404185518.GD9055@sigill.intra.peff.net>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180404171153.4126-1-haraldnordgren@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <20180404171153.4126-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Wed, Apr 04, 2018 at 07:11:53PM +0200, Harald Nordgren wrote:

> @@ -60,6 +60,16 @@ OPTIONS
>  	upload-pack only shows the symref HEAD, so it will be the only
>  	one shown by ls-remote.
>  
> +--sort=<key>::
> +	Sort based on the key given.  Prefix `-` to sort in
> +	descending order of the value. You may use the --sort=<key> option
> +	multiple times, in which case the last key becomes the primary
> +	key. Also supports "version:refname" or "v:refname" (tag
> +	names are treated as versions). The "version:refname" sort
> +	order can also be affected by the "versionsort.suffix"
> +	configuration variable.
> +	The keys supported are the same as those in `git for-each-ref`.

We probably ought to warn the user in that final sentence that keys
which actually look at the objects may not work, since we don't
necessarily have the objects.

There's one other subtlety, which is that things like %(HEAD) assume
we're talking about local refs, not the remote HEAD. So that wouldn't
work (of course it seems unlikely that anybody woudl _sort_ on that).

> @@ -104,13 +112,28 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>  	if (!dest && !quiet)
>  		fprintf(stderr, "From %s\n", *remote->url);
>  	for ( ; ref; ref = ref->next) {
> +		struct ref_array_item *item;
>  		if (!check_ref_type(ref, flags))
>  			continue;
>  		if (!tail_match(pattern, ref->name))
>  			continue;
> +
> +		FLEX_ALLOC_MEM(item, refname, ref->name, strlen(ref->name));

I think this can use the slightly-simpler FLEX_ALLOC_STR().

> +		item->symref = ref->symref;

Normally a ref_array_item's symref is an allocated string owned by the
item. I don't think it actually matters now, but in the spirit of
least-surprise for the future, should this be xstrdup_or_null(ref->symref)?

> +		item->objectname = ref->old_oid;

This is actually a struct assignment. Which does work, but our usual
mechanism would be to use "oidcpy(&item->objectname, &ref->old_oid)".

All of this might be a little nicer if ref-filter provided a function to
allocate a new item. We're pushing the boundaries of ref-filter was
meant to be used here, as it was assumed you'd always start with a call
to filter_refs().

> +		ALLOC_GROW(array.items, array.nr + 1, array.alloc);
> +		array.items[array.nr++] = item;

The existing ref-filter code fails to use ALLOC_GROW() correctly. I
don't think it actually matters, since we don't intermingle this with
allocations done there. But perhaps we should be fixing that one while
we're looking at it. Or again, maybe it would be nicer still if there
were a ref-filter function to do this, and the whole call here could
just be:

  ref_array_push(&array, ref->name, &ref->old_oid);

One more drastic alternative is to actually use the existing
filter_refs(), and just teach it to populate the array from a list of
refs. As you can see from its implementation, it does a few other setup
steps. I don't think they matter now, but if you eventually wanted to be
able to do "git ls-remote --contains HEAD", you'd need that setup.

-Peff

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 98DE61F404
	for <e@80x24.org>; Wed,  4 Apr 2018 18:56:11 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751926AbeDDS4J (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 14:56:09 -0400
Received: from cloud.peff.net ([104.130.231.41]:53500 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1751367AbeDDS4I (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 14:56:08 -0400
Received: (qmail 17019 invoked by uid 109); 4 Apr 2018 18:56:08 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Wed, 04 Apr 2018 18:56:08 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 7064 invoked by uid 111); 4 Apr 2018 18:57:09 -0000
Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Wed, 04 Apr 2018 14:57:09 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Wed, 04 Apr 2018 14:56:06 -0400
Date:   Wed, 4 Apr 2018 14:56:06 -0400
From:   Jeff King <peff@peff.net>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v7] ls-remote: create '--sort' option
Message-ID: <20180404185606.GE9055@sigill.intra.peff.net>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180404171153.4126-1-haraldnordgren@gmail.com>
 <CAHwyqnXtc-WgynCmE+EEVYtg6RRVweK8vwfBQS5VL4ygaFumKQ@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <CAHwyqnXtc-WgynCmE+EEVYtg6RRVweK8vwfBQS5VL4ygaFumKQ@mail.gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Wed, Apr 04, 2018 at 07:18:42PM +0200, Harald Nordgren wrote:

> Jeff, you are right that 'git ls-remote --sort=committerdate' will not
> work. Do you think we need to do something about this, or it's fine
> that it fails the way you showed?

It's a reasonable-sized footgun, but one that I think most people would
be unlikely to trigger. I think it's probably OK as long as we warn the
user in the documentation (see my other response).

-Peff

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 7AA001F404
	for <e@80x24.org>; Wed,  4 Apr 2018 23:01:32 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752365AbeDDXBa (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 19:01:30 -0400
Received: from mail-wr0-f180.google.com ([209.85.128.180]:46562 "EHLO
        mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752264AbeDDXB3 (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 19:01:29 -0400
Received: by mail-wr0-f180.google.com with SMTP id d1so25287822wrj.13
        for <git@vger.kernel.org>; Wed, 04 Apr 2018 16:01:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=KuiGWWa776xVxmqAHlfJEwGtnj76YBcQs6LmM2C2wSY=;
        b=HoNZQc+nxSDcTj6JHZOWJfhCbdiB5rFwKRTfgbqYDOlkTTtZlr7SSkqxL4W/tpOMYx
         l2l54oqxcS+mzNxogN26pe3BBLAxj0GctSn4ZVv+/nQ5VfYpBc9GUZTTTAoGACF/F48D
         FfALjtUhLpRwrt7e3dA3XVoL+Y7gw10kvZQJdkjRlBYOcwdtsU3suqYtFsldSmr74Yf9
         3p+75uhJdFvzICILuqb7I37/FHlpu/a+p2Jd+0YaoIMQGNFNwMJASmgpk0J0yzOT556u
         0VosahmJ/WJpA4JrH8nKk/vUJfzkbY1wNv6TGE3Unoe0STwHLZdQC/MaRDDEU2H1y9T/
         uwyw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=KuiGWWa776xVxmqAHlfJEwGtnj76YBcQs6LmM2C2wSY=;
        b=mCI1D4PweZWXhyUZQYELF7gtq/NtER4b7KhKbteX24NlodoS0Zqge1UzUHth/U+u61
         +48pAiS4t3vYD+7bkIj5V5BwWcpNWV9MuhiBKX1ru4NqfRful4Q7TAIB04VE6qtuq6Z7
         m7hjtLixszXzo8+5Yq05piy57YM1H1xXxrM2GfOfjGIOEjF5sY9eSNPewAjxxI9h5W8N
         uO3cKHkfM97WtsArGdWKGvjeiH1AmKanVlzyoEeVYKZSGJUO30my5yRrPuYamX32sUOw
         mDwokBTCGFO+JUEL2jk0eL/ZSBtICy1stqMPXKz4h+T+gPpn/ftp9gmplXwToiXyDclG
         rPrg==
X-Gm-Message-State: ALQs6tDobOfWXzF2G6RWfZG+RmjAs/Hsn33X3a0fzFMHhOEZ4brwr0pG
        LNl6R1aUpAJTk069CNiQZr6rzpsqfv0=
X-Google-Smtp-Source: AIpwx49yydAD1mawCaKGkdow5jSp1Nzgq9tN8JUDabCmWa/xKB2iEN0tkannQgX8T9bF6xEM1auuOg==
X-Received: by 2002:a19:c713:: with SMTP id x19-v6mr12547035lff.32.1522882887747;
        Wed, 04 Apr 2018 16:01:27 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2375-74736162.cust.telenor.se. [94.234.35.117])
        by smtp.gmail.com with ESMTPSA id x7-v6sm1205958lff.64.2018.04.04.16.01.25
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 04 Apr 2018 16:01:26 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v8] ls-remote: create '--sort' option
Date:   Thu,  5 Apr 2018 01:01:10 +0200
Message-Id: <20180404230110.9950-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Partial fixes from Jeff King's comments

 Documentation/git-ls-remote.txt | 15 ++++++++++++++-
 builtin/ls-remote.c             | 27 +++++++++++++++++++++++++--
 t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..fa4505fd7 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,19 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given.  Prefix `-` to sort in
+	descending order of the value. You may use the --sort=<key> option
+	multiple times, in which case the last key becomes the primary
+	key. Also supports "version:refname" or "v:refname" (tag
+	names are treated as versions). The "version:refname" sort
+	order can also be affected by the "versionsort.suffix"
+	configuration variable.
+	The keys supported are the same as those in `git for-each-ref`,
+	except that because `ls-remote` deals only with remotes, keys like
+	`committerdate` that require access to the objects themselves will
+	not work.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..fbec2bc95 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&array, 0, sizeof(array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -104,13 +112,28 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
+		struct ref_array_item *item;
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+
+		FLEX_ALLOC_STR(item, refname, ref->name);
+		item->symref = xstrdup_or_null(ref->symref);
+		oidcpy(&item->objectname, &ref->old_oid);
+
+		ALLOC_GROW(array.items, array.nr + 1, array.alloc);
+		array.items[array.nr++] = item;
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &array);
+
+	for (i = 0; i < array.nr; i++) {
+		const struct ref_array_item *ref = array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..66370cd88 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id ACC121F404
	for <e@80x24.org>; Wed,  4 Apr 2018 23:12:19 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752628AbeDDXMR (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 19:12:17 -0400
Received: from mail-ot0-f178.google.com ([74.125.82.178]:46364 "EHLO
        mail-ot0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752553AbeDDXMP (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 19:12:15 -0400
Received: by mail-ot0-f178.google.com with SMTP id v64-v6so25214861otb.13
        for <git@vger.kernel.org>; Wed, 04 Apr 2018 16:12:15 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=BBiIhgyQrWoRJ9jRvJZEVqABmSFv/Leuj2oUZ/MvPHA=;
        b=YqY9843rrP4JkelpMm5wZp6Kd1jJI0l5BGC770fwFRVJlZvOHa+VUiD2Le8wUKc/St
         ZPFcKWcxFTM2W1P//yk8eo+X9lFYcvRIK3qmPQUaHjKNwx+Flj9Jv6TzMc5G/6lrTAIU
         UGvpwOiSndZe+Zxbb24L/bE7Gw4+cwNKZhg/ooLCsb3jlGXxvr0RRe7y/rhj1Obh7AS8
         eeNk5X1+pgeIH7Fl3jbRkKcGIoReczZJcDbBIMRzGJZqDVOxkpYIRcfIRKkgdspW+8L0
         T8oLrQXt3bsGotJUXopXD4wBuKzyko2CnqIIcp2RGBALUVbrK3n8EcpsM/XMZqSlVy36
         GbbQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=BBiIhgyQrWoRJ9jRvJZEVqABmSFv/Leuj2oUZ/MvPHA=;
        b=Lzbr67Q1tdrYTn3RJ4yvlUlCuEovYmSjH8I3L4XxidrYks3zq5lV84GtQvzKymTdb9
         GNQ+KtUX9fS9yL/XxdKf1QB3fi78XnfXgq0A1usYItCbw7PaNf19DhzbY0ivS6vtT9ce
         YQ4E8J6nr3JFn/rTpzYOE9ITs+iT2q3djSSmQplVzDzgn6D5QznFBsMM46x9480oyctp
         gT30aQo/1y7Bg+AcNQ/sbgChyVtiQfYzv8Tdczpnuaros9EcijhcaPuTDnyHTmGYAWTT
         i+qQRAxKRej0GVh5Aupu5LRXDe8NORMbK9Qkyi0LDjS27nNczwSjuh7pKQkyTGPXIgnj
         dweg==
X-Gm-Message-State: ALQs6tCeXTN+dyY9lgpUY+jg7bmrP1ju6gfgl4S1Ziq1RwSmk/1eNqaw
        RNfY1QobHUlMpXwegtO5FQdCgqdYynyIbCXTX1+LNKIp
X-Google-Smtp-Source: AIpwx49SrRiivA5F6GBMqY/8TZUv36Vuz4gKV3zQa1qB/38sgt5qvqnkVAeBk1j52DgHqVwHIfuUC3VvBgfEgnphEjw=
X-Received: by 2002:a9d:4005:: with SMTP id m5-v6mr11439250ote.326.1522883534766;
 Wed, 04 Apr 2018 16:12:14 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Wed, 4 Apr 2018 16:11:34 -0700 (PDT)
In-Reply-To: <20180404230110.9950-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com> <20180404230110.9950-1-haraldnordgren@gmail.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Thu, 5 Apr 2018 01:11:34 +0200
Message-ID: <CAHwyqnU4jv=wW_no4ff_E2TgvGtga1GOhZoDKd93J5MMUtLFCA@mail.gmail.com>
Subject: Re: [PATCH v8] ls-remote: create '--sort' option
To:     git@vger.kernel.org,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Without digging to much into the `ref-filter` code itself, it seems
like there is an opportunity to generalize and unfify the logic
between these two cases. As well as using `ALLOC_GROW`. But maybe that
is best left as a follow-up task? Especially since this patch focuses
on `ls-remote`. Seems possibly like too big of a change to start
changing a different sub-command.

Wouldn't a `ref_array_push()` also require `ref->symref`, maybe then
we could pass the whole ref? It needs to be very clear that it's a
`ref` and not a `ref_array_item` that is being pushed. Much of my
logic here deals specifically with trying to treat a ref as
ref_array_item.

>From my viewpoint as implementer, I was very happy that I could
implement the feature *without* invoking `filter_refs` since that
`filter->kind` switching looks a pretty daunting. I'm not exactly sure
what a `git ls-remote --contains HEAD` would do, maybe you could
explain a bit more?

On Thu, Apr 5, 2018 at 1:01 AM, Harald Nordgren
<haraldnordgren@gmail.com> wrote:
> Create a '--sort' option for ls-remote, based on the one from
> for-each-ref. This e.g. allows ref names to be sorted by version
> semantics, so that v1.2 is sorted before v1.10.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>
> Notes:
>     Partial fixes from Jeff King's comments
>
>  Documentation/git-ls-remote.txt | 15 ++++++++++++++-
>  builtin/ls-remote.c             | 27 +++++++++++++++++++++++++--
>  t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 79 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
> index 5f2628c8f..fa4505fd7 100644
> --- a/Documentation/git-ls-remote.txt
> +++ b/Documentation/git-ls-remote.txt
> @@ -10,7 +10,7 @@ SYNOPSIS
>  --------
>  [verse]
>  'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
> -             [-q | --quiet] [--exit-code] [--get-url]
> +             [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
>               [--symref] [<repository> [<refs>...]]
>
>  DESCRIPTION
> @@ -60,6 +60,19 @@ OPTIONS
>         upload-pack only shows the symref HEAD, so it will be the only
>         one shown by ls-remote.
>
> +--sort=<key>::
> +       Sort based on the key given.  Prefix `-` to sort in
> +       descending order of the value. You may use the --sort=<key> option
> +       multiple times, in which case the last key becomes the primary
> +       key. Also supports "version:refname" or "v:refname" (tag
> +       names are treated as versions). The "version:refname" sort
> +       order can also be affected by the "versionsort.suffix"
> +       configuration variable.
> +       The keys supported are the same as those in `git for-each-ref`,
> +       except that because `ls-remote` deals only with remotes, keys like
> +       `committerdate` that require access to the objects themselves will
> +       not work.
> +
>  <repository>::
>         The "remote" repository to query.  This parameter can be
>         either a URL or the name of a remote (see the GIT URLS and
> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
> index 540d56429..fbec2bc95 100644
> --- a/builtin/ls-remote.c
> +++ b/builtin/ls-remote.c
> @@ -1,6 +1,7 @@
>  #include "builtin.h"
>  #include "cache.h"
>  #include "transport.h"
> +#include "ref-filter.h"
>  #include "remote.h"
>
>  static const char * const ls_remote_usage[] = {
> @@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>         int show_symref_target = 0;
>         const char *uploadpack = NULL;
>         const char **pattern = NULL;
> +       int i;
>
>         struct remote *remote;
>         struct transport *transport;
>         const struct ref *ref;
> +       struct ref_array array;
> +       static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
>
>         struct option options[] = {
>                 OPT__QUIET(&quiet, N_("do not print remote URL")),
> @@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>                 OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
>                 OPT_BOOL(0, "get-url", &get_url,
>                          N_("take url.<base>.insteadOf into account")),
> +               OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
> +                            N_("field name to sort on"), &parse_opt_ref_sorting),
>                 OPT_SET_INT_F(0, "exit-code", &status,
>                               N_("exit with exit code 2 if no matching refs are found"),
>                               2, PARSE_OPT_NOCOMPLETE),
> @@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>                 OPT_END()
>         };
>
> +       memset(&array, 0, sizeof(array));
> +
>         argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
>                              PARSE_OPT_STOP_AT_NON_OPTION);
>         dest = argv[0];
> @@ -104,13 +112,28 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>         if (!dest && !quiet)
>                 fprintf(stderr, "From %s\n", *remote->url);
>         for ( ; ref; ref = ref->next) {
> +               struct ref_array_item *item;
>                 if (!check_ref_type(ref, flags))
>                         continue;
>                 if (!tail_match(pattern, ref->name))
>                         continue;
> +
> +               FLEX_ALLOC_STR(item, refname, ref->name);
> +               item->symref = xstrdup_or_null(ref->symref);
> +               oidcpy(&item->objectname, &ref->old_oid);
> +
> +               ALLOC_GROW(array.items, array.nr + 1, array.alloc);
> +               array.items[array.nr++] = item;
> +       }
> +
> +       if (sorting)
> +               ref_array_sort(sorting, &array);
> +
> +       for (i = 0; i < array.nr; i++) {
> +               const struct ref_array_item *ref = array.items[i];
>                 if (show_symref_target && ref->symref)
> -                       printf("ref: %s\t%s\n", ref->symref, ref->name);
> -               printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
> +                       printf("ref: %s\t%s\n", ref->symref, ref->refname);
> +               printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
>                 status = 0; /* we found something */
>         }
>         return status;
> diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
> index 02106c922..66370cd88 100755
> --- a/t/t5512-ls-remote.sh
> +++ b/t/t5512-ls-remote.sh
> @@ -10,6 +10,9 @@ test_expect_success setup '
>         test_tick &&
>         git commit -m initial &&
>         git tag mark &&
> +       git tag mark1.1 &&
> +       git tag mark1.2 &&
> +       git tag mark1.10 &&
>         git show-ref --tags -d | sed -e "s/ /   /" >expected.tag &&
>         (
>                 echo "$(git rev-parse HEAD)     HEAD"
> @@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
>         test_cmp expected.all actual
>  '
>
> +test_expect_success 'ls-remote --sort="version:refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       EOF
> +       git ls-remote --sort="version:refname" --tags self >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       EOF
> +       git ls-remote --sort="-version:refname" --tags self >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success 'ls-remote --sort="-refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       EOF
> +       git ls-remote --sort="-refname" --tags self >actual &&
> +       test_cmp expect actual
> +'
> +
>  test_expect_success 'dies when no remote specified and no default remotes found' '
>         test_must_fail git ls-remote
>  '
> @@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
>
>  test_expect_success 'Report match with --exit-code' '
>         git ls-remote --exit-code other.git "refs/tags/*" >actual &&
> -       git ls-remote . tags/mark >expect &&
> +       git ls-remote . tags/mark* >expect &&
>         test_cmp expect actual
>  '
>
> @@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/remotes/origin/HEAD
>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/remotes/origin/master
>         1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
>         EOF
>         git ls-remote --symref >actual &&
>         test_cmp expect actual
> --
> 2.14.3 (Apple Git-98)
>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id F33D21F404
	for <e@80x24.org>; Wed,  4 Apr 2018 23:32:55 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752518AbeDDXcx (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 19:32:53 -0400
Received: from mail-wr0-f177.google.com ([209.85.128.177]:34675 "EHLO
        mail-wr0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752395AbeDDXcw (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 19:32:52 -0400
Received: by mail-wr0-f177.google.com with SMTP id d17so9992998wre.1
        for <git@vger.kernel.org>; Wed, 04 Apr 2018 16:32:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=ZIjVvcnyOu6ZCwjWpdyZ0KxyhRsBTo9814/+bQNw4rk=;
        b=gxxExyQ67D9Kyd84x/ZXDgOQ3AY1APRn0tUO1lFsIP4jJwXVVSWJqKq+MEEBoiYd7x
         611AhTxlI6lWaQpQVfzk2K/DA7qcvRs7koVaJj5b+e9YKYdMwSYu66q+0BeB/WLxv2tK
         VrViwyHu6c+xYzGu/IVwPF8g3dUVD049fNad9NISoeLOt1aOFOPFnN4nnu3tAIANwgfC
         8z7XbCmK1ib07jnwXR7J5d5G/0+XgXEzOQlcp6XwASN/fMFIep0EELI18zXqAzABgB+b
         DPXBAHvVhebedXyNDNr1+vcn1r3gPhO8yfINXjX/D7v+7pSmXgptzV+sOKeZLork+xG+
         gC3A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=ZIjVvcnyOu6ZCwjWpdyZ0KxyhRsBTo9814/+bQNw4rk=;
        b=RmIAsvlh8XTn0G8SLdp7N+Oy/1IryeYxYqHkwTH5iNzgJ/5zbXN9OU/DVTwSdO1Q+J
         XALuNzKuOoGH7LhDH+qY5lN8ZQ8K7TdplE4tRJY+J6IZieYPY7AfWfe/yPLcxovk0UP0
         /B6kW1hG39jsdyFNBoVkQM2N0tva5KpCBjsAsz9qJO8j7TlUFn0e4dKI1GuI44DAV83U
         NSoHOrYgvDtj1t1bDlB2nopc+zJ5C5plBwAhAzUp6t4kAAy8DehMzRUlQW+n39jOPoWg
         QX2SWpL+nyZF6+aRbhVimNe0NRZxQ305qf8C0ByeAHQpurjUKJBiwPz/xhgAeFyPlTxZ
         3qGg==
X-Gm-Message-State: ALQs6tAoaywz+BbvR7pkn0Bz3Ld/8ZMVTgmM/7Abv+SxMfuNql+Oh5ZB
        xbYTmoJrEVeawnjFdbOe+73quAgV0aw=
X-Google-Smtp-Source: AIpwx48LpVpKQ3YtF6n3S2gT6gj/thBaVkcV+zlquecpbn2KJEmozzEupo/eb0maq8yL1lAkJOyjmw==
X-Received: by 2002:a19:1903:: with SMTP id 3-v6mr11795607lfz.59.1522884770410;
        Wed, 04 Apr 2018 16:32:50 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2375-74736162.cust.telenor.se. [94.234.35.117])
        by smtp.gmail.com with ESMTPSA id t6sm1052139ljd.55.2018.04.04.16.32.48
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 04 Apr 2018 16:32:49 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v9] ls-remote: create '--sort' option
Date:   Thu,  5 Apr 2018 01:32:32 +0200
Message-Id: <20180404233232.14913-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Create 'ref_array_push' function in ref-filter

 Documentation/git-ls-remote.txt | 15 ++++++++++++++-
 builtin/ls-remote.c             | 20 ++++++++++++++++++--
 ref-filter.c                    | 12 ++++++++++++
 ref-filter.h                    |  2 ++
 t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 86 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..fa4505fd7 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,19 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given.  Prefix `-` to sort in
+	descending order of the value. You may use the --sort=<key> option
+	multiple times, in which case the last key becomes the primary
+	key. Also supports "version:refname" or "v:refname" (tag
+	names are treated as versions). The "version:refname" sort
+	order can also be affected by the "versionsort.suffix"
+	configuration variable.
+	The keys supported are the same as those in `git for-each-ref`,
+	except that because `ls-remote` deals only with remotes, keys like
+	`committerdate` that require access to the objects themselves will
+	not work.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..f87b2657c 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&array, 0, sizeof(array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -108,9 +116,17 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+		ref_array_push(&array, ref);
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &array);
+
+	for (i = 0; i < array.nr; i++) {
+		const struct ref_array_item *ref = array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/ref-filter.c b/ref-filter.c
index 45fc56216..a5686dacd 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1861,6 +1861,18 @@ static int ref_kind_from_refname(const char *refname)
 	return FILTER_REFS_OTHERS;
 }
 
+void ref_array_push(struct ref_array *array, const struct ref *ref)
+{
+	struct ref_array_item *item;
+
+	FLEX_ALLOC_STR(item, refname, ref->name);
+	item->symref = xstrdup_or_null(ref->symref);
+	oidcpy(&item->objectname, &ref->old_oid);
+
+	ALLOC_GROW(array->items, array->nr + 1, array->alloc);
+	array->items[array->nr++] = item;
+}
+
 static int filter_ref_kind(struct ref_filter *filter, const char *refname)
 {
 	if (filter->kind == FILTER_REFS_BRANCHES ||
diff --git a/ref-filter.h b/ref-filter.h
index 0d98342b3..43e713a72 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -127,6 +127,8 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
 char *get_head_description(void);
 /*  Set up translated strings in the output. */
 void setup_ref_filter_porcelain_msg(void);
+/*  Create a ref_array_item from a ref and push it to the ref_array */
+void ref_array_push(struct ref_array *array, const struct ref *ref);
 
 /*
  * Print a single ref, outside of any ref-filter. Note that the
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..66370cd88 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD
	shortcircuit=no autolearn=no autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 98CD61F404
	for <e@80x24.org>; Thu,  5 Apr 2018 00:05:12 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752622AbeDEAFH (ORCPT <rfc822;e@80x24.org>);
        Wed, 4 Apr 2018 20:05:07 -0400
Received: from mail-wm0-f42.google.com ([74.125.82.42]:39367 "EHLO
        mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752484AbeDEAFE (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 4 Apr 2018 20:05:04 -0400
Received: by mail-wm0-f42.google.com with SMTP id f125so1765593wme.4
        for <git@vger.kernel.org>; Wed, 04 Apr 2018 17:05:03 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=WWH0TXX57Vev1GyXzYJ/K1jw9EkbIgiqjYAgD6msY94=;
        b=q8tb0XDneLokhfjS+2l6qrvPw3iYbE8p+ZIVO0tXExhYW/eLVsefnRUHhcvhkbw81d
         i56SgAsTf7dhr3vIOwVgRQoSGKVpJL44wxoANhfpEj+qrwGf5mxs2Mq9M6q4SRjDJb8p
         pd8CAvv3uaaZlrW5MGreGIA3UacX9FpKiEb/qdJKx8zMZWrQF9p67NuOumSy2iMHX3sj
         kBQa+EXWgzg9uF+/yirp6biD+ZmH+LGnVIe74rECMCjrcT+VVbfdlKfvfV5cx06bFWVJ
         BIfDHaI9x09nUuzhLBJ/dnEjGY+CnEjvHVVRIkkbXxUqbhTBE6zxevEbRFgj6gmL7Gez
         b81A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=WWH0TXX57Vev1GyXzYJ/K1jw9EkbIgiqjYAgD6msY94=;
        b=TRflQMZYMozqRI4TaAdOjOecLn65d5kUrHkfs8jiR9jUaiMZOkCwS+oLN5LGHMmIyZ
         DZ9aXl3e3bv8/pXdEysLvJ11F8VwZxgkbcDBHMILTqFC11bGO09MAsWVBjhMf3KtD1Xq
         +DT77UcEC2cwS5ureltY2FYtdfLpTK8vQ+2oqVr19A+Ch85A2fFMCiBK8jbVylxPpPqV
         +o8VYjcY8Jb8+coOD+qlapDXIFHPQ4mWQ8UYxVRauusyVcdrZ2ezhcfnkrDQ6BGvC2Iz
         j2RFpEmdDOjuDm48iaPpfGzp22Temz/0CbKGugeGKDroGxF6IHHGskMO918xnhY8Lg/k
         N22A==
X-Gm-Message-State: ALQs6tDfgrX44FsKNztlLMYQtRLMrJTYQIVDmlZe2NowPgeOKcGzguDa
        Olp0umVU88iEJ5lsTQoQGjzTNFfA9rQ=
X-Google-Smtp-Source: AIpwx49NOJ9fCtGQKwZAPXYQqS+jKUA87pPi9/8oAOm2K2cH29TF5tDwa+1WkpB94O0QgxSoVykezA==
X-Received: by 10.46.134.141 with SMTP id l13mr12194306lji.5.1522886701848;
        Wed, 04 Apr 2018 17:05:01 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2375-74736162.cust.telenor.se. [94.234.35.117])
        by smtp.gmail.com with ESMTPSA id u12-v6sm1243281lfg.27.2018.04.04.17.05.00
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 04 Apr 2018 17:05:01 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v10] ls-remote: create '--sort' option
Date:   Thu,  5 Apr 2018 02:04:47 +0200
Message-Id: <20180405000447.19443-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Use 'ref_array_item_push' to fix 'REALLOC_ARRAY' call in ref-filter

 Documentation/git-ls-remote.txt | 15 ++++++++++++++-
 builtin/ls-remote.c             | 20 ++++++++++++++++++--
 ref-filter.c                    | 20 ++++++++++++++++++--
 ref-filter.h                    |  2 ++
 t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 92 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..fa4505fd7 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,19 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given.  Prefix `-` to sort in
+	descending order of the value. You may use the --sort=<key> option
+	multiple times, in which case the last key becomes the primary
+	key. Also supports "version:refname" or "v:refname" (tag
+	names are treated as versions). The "version:refname" sort
+	order can also be affected by the "versionsort.suffix"
+	configuration variable.
+	The keys supported are the same as those in `git for-each-ref`,
+	except that because `ls-remote` deals only with remotes, keys like
+	`committerdate` that require access to the objects themselves will
+	not work.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..f87b2657c 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&array, 0, sizeof(array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -108,9 +116,17 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+		ref_array_push(&array, ref);
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &array);
+
+	for (i = 0; i < array.nr; i++) {
+		const struct ref_array_item *ref = array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/ref-filter.c b/ref-filter.c
index 45fc56216..6dbafba07 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1861,6 +1861,23 @@ static int ref_kind_from_refname(const char *refname)
 	return FILTER_REFS_OTHERS;
 }
 
+void ref_array_item_push(struct ref_array *array, struct ref_array_item *item)
+{
+	ALLOC_GROW(array->items, array->nr + 1, array->alloc);
+	array->items[array->nr++] = item;
+}
+
+void ref_array_push(struct ref_array *array, const struct ref *ref)
+{
+	struct ref_array_item *item;
+
+	FLEX_ALLOC_STR(item, refname, ref->name);
+	item->symref = xstrdup_or_null(ref->symref);
+	oidcpy(&item->objectname, &ref->old_oid);
+
+	ref_array_item_push(array, item);
+}
+
 static int filter_ref_kind(struct ref_filter *filter, const char *refname)
 {
 	if (filter->kind == FILTER_REFS_BRANCHES ||
@@ -1930,8 +1947,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	ref = new_ref_array_item(refname, oid->hash, flag);
 	ref->commit = commit;
 
-	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
-	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
+	ref_array_item_push(ref_cbdata->array, ref);
 	ref->kind = kind;
 	return 0;
 }
diff --git a/ref-filter.h b/ref-filter.h
index 0d98342b3..43e713a72 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -127,6 +127,8 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
 char *get_head_description(void);
 /*  Set up translated strings in the output. */
 void setup_ref_filter_porcelain_msg(void);
+/*  Create a ref_array_item from a ref and push it to the ref_array */
+void ref_array_push(struct ref_array *array, const struct ref *ref);
 
 /*
  * Print a single ref, outside of any ref-filter. Note that the
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..66370cd88 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 701EE1F404
	for <e@80x24.org>; Fri,  6 Apr 2018 18:58:06 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751808AbeDFS6E (ORCPT <rfc822;e@80x24.org>);
        Fri, 6 Apr 2018 14:58:04 -0400
Received: from cloud.peff.net ([104.130.231.41]:56138 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1751779AbeDFS6D (ORCPT <rfc822;git@vger.kernel.org>);
        Fri, 6 Apr 2018 14:58:03 -0400
Received: (qmail 23447 invoked by uid 109); 6 Apr 2018 18:58:03 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Fri, 06 Apr 2018 18:58:03 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 28034 invoked by uid 111); 6 Apr 2018 18:59:04 -0000
Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Fri, 06 Apr 2018 14:59:04 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Fri, 06 Apr 2018 14:58:01 -0400
Date:   Fri, 6 Apr 2018 14:58:01 -0400
From:   Jeff King <peff@peff.net>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v8] ls-remote: create '--sort' option
Message-ID: <20180406185801.GA921@sigill.intra.peff.net>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180404230110.9950-1-haraldnordgren@gmail.com>
 <CAHwyqnU4jv=wW_no4ff_E2TgvGtga1GOhZoDKd93J5MMUtLFCA@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <CAHwyqnU4jv=wW_no4ff_E2TgvGtga1GOhZoDKd93J5MMUtLFCA@mail.gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Thu, Apr 05, 2018 at 01:11:34AM +0200, Harald Nordgren wrote:

> Without digging to much into the `ref-filter` code itself, it seems
> like there is an opportunity to generalize and unfify the logic
> between these two cases. As well as using `ALLOC_GROW`. But maybe that
> is best left as a follow-up task? Especially since this patch focuses
> on `ls-remote`. Seems possibly like too big of a change to start
> changing a different sub-command.

Yes and no. By refactoring we have the potential to regress another
unrelated command. But by not refactoring, we set up a potential misuse
of the other interface which may lead to more bugs down the road.

I think an important thing is to split out the refactoring steps into
their own patches, so it's easy to see that they're not hurting the
existing uses. I have some sample patches, which I'll send in a moment.

> Wouldn't a `ref_array_push()` also require `ref->symref`, maybe then
> we could pass the whole ref? It needs to be very clear that it's a
> `ref` and not a `ref_array_item` that is being pushed. Much of my
> logic here deals specifically with trying to treat a ref as
> ref_array_item.

I think it would be OK to have the push operation return the actual
item, which can then be filled in more. That's how the internal
ref-filter code does it already.

> From my viewpoint as implementer, I was very happy that I could
> implement the feature *without* invoking `filter_refs` since that
> `filter->kind` switching looks a pretty daunting. I'm not exactly sure
> what a `git ls-remote --contains HEAD` would do, maybe you could
> explain a bit more?

I agree it would be a bit larger of a retro-fit to adapt filter_refs()
for our purpose here. And since we're not doing any filtering at this
point, there's not much benefit.

Here are the refactoring patches I came up with. I think they're a
benefit to ref-filter on their own, and then it should be pretty easy
for you to build your patch on top.

  [1/3]: ref-filter: use "struct object_id" consistently
  [2/3]: ref-filter: make ref_array_item allocation more consistent
  [3/3]: ref-filter: factor ref_array pushing into its own function

 builtin/tag.c        |  2 +-
 builtin/verify-tag.c |  2 +-
 ref-filter.c         | 36 +++++++++++++++++++++++++-----------
 ref-filter.h         | 10 +++++++++-
 4 files changed, 36 insertions(+), 14 deletions(-)

-Peff

PS I'm going to be offline for a few weeks starting tomorrow, so I won't
   be responsive to this thread. :) If you like the direction, please
   feel free to pick up those patches, rebase yours on top, and then
   send them all out as a series.

   In case it's easier than applying from the list, you can fetch them
   from the "jk/ref-array-push" branch of https://github.com/peff/git.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id E50B61F404
	for <e@80x24.org>; Fri,  6 Apr 2018 18:58:37 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751944AbeDFS6g (ORCPT <rfc822;e@80x24.org>);
        Fri, 6 Apr 2018 14:58:36 -0400
Received: from cloud.peff.net ([104.130.231.41]:56156 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1751276AbeDFS6e (ORCPT <rfc822;git@vger.kernel.org>);
        Fri, 6 Apr 2018 14:58:34 -0400
Received: (qmail 23504 invoked by uid 109); 6 Apr 2018 18:58:34 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Fri, 06 Apr 2018 18:58:34 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 28066 invoked by uid 111); 6 Apr 2018 18:59:35 -0000
Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Fri, 06 Apr 2018 14:59:35 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Fri, 06 Apr 2018 14:58:32 -0400
Date:   Fri, 6 Apr 2018 14:58:32 -0400
From:   Jeff King <peff@peff.net>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH 1/3] ref-filter: use "struct object_id" consistently
Message-ID: <20180406185831.GA11108@sigill.intra.peff.net>
References: <20180406185801.GA921@sigill.intra.peff.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <20180406185801.GA921@sigill.intra.peff.net>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Internally we store a "struct object_id", and all of our
callers have one to pass us. But we insist that they peel it
to its bare-sha1 hash, which we then hashcpy() into place.
Let's pass it around as an object_id, which future-proofs us
for a post-sha1 world.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/tag.c        |  2 +-
 builtin/verify-tag.c |  2 +-
 ref-filter.c         | 10 +++++-----
 ref-filter.h         |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index da186691ed..42278f5167 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -117,7 +117,7 @@ static int verify_tag(const char *name, const char *ref,
 		return -1;
 
 	if (format->format)
-		pretty_print_ref(name, oid->hash, format);
+		pretty_print_ref(name, oid, format);
 
 	return 0;
 }
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index ad7b79fa5c..6fa04b751a 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -72,7 +72,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 		}
 
 		if (format.format)
-			pretty_print_ref(name, oid.hash, &format);
+			pretty_print_ref(name, &oid, &format);
 	}
 	return had_error;
 }
diff --git a/ref-filter.c b/ref-filter.c
index 45fc56216a..ade97a8486 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1826,12 +1826,12 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 
 /* Allocate space for a new ref_array_item and copy the objectname and flag to it */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const unsigned char *objectname,
+						 const struct object_id *oid,
 						 int flag)
 {
 	struct ref_array_item *ref;
 	FLEX_ALLOC_STR(ref, refname, refname);
-	hashcpy(ref->objectname.hash, objectname);
+	oidcpy(&ref->objectname, oid);
 	ref->flag = flag;
 
 	return ref;
@@ -1927,7 +1927,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid->hash, flag);
+	ref = new_ref_array_item(refname, oid, flag);
 	ref->commit = commit;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
@@ -2165,11 +2165,11 @@ void show_ref_array_item(struct ref_array_item *info,
 	putchar('\n');
 }
 
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, sha1, 0);
+	ref_item = new_ref_array_item(name, oid, 0);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
diff --git a/ref-filter.h b/ref-filter.h
index 0d98342b34..68268f9ebc 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -132,7 +132,7 @@ void setup_ref_filter_porcelain_msg(void);
  * Print a single ref, outside of any ref-filter. Note that the
  * name must be a fully qualified refname.
  */
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
 #endif /*  REF_FILTER_H  */
-- 
2.17.0.686.g08b0810b04


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 754C01F404
	for <e@80x24.org>; Fri,  6 Apr 2018 18:59:30 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751418AbeDFS72 (ORCPT <rfc822;e@80x24.org>);
        Fri, 6 Apr 2018 14:59:28 -0400
Received: from cloud.peff.net ([104.130.231.41]:56174 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1750815AbeDFS72 (ORCPT <rfc822;git@vger.kernel.org>);
        Fri, 6 Apr 2018 14:59:28 -0400
Received: (qmail 23550 invoked by uid 109); 6 Apr 2018 18:59:28 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Fri, 06 Apr 2018 18:59:28 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 28086 invoked by uid 111); 6 Apr 2018 19:00:29 -0000
Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Fri, 06 Apr 2018 15:00:29 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Fri, 06 Apr 2018 14:59:26 -0400
Date:   Fri, 6 Apr 2018 14:59:26 -0400
From:   Jeff King <peff@peff.net>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH 2/3] ref-filter: make ref_array_item allocation more
 consistent
Message-ID: <20180406185925.GB11108@sigill.intra.peff.net>
References: <20180406185801.GA921@sigill.intra.peff.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <20180406185801.GA921@sigill.intra.peff.net>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

We have a helper function to allocate ref_array_item
structs, but it only takes a subset of the possible fields
in the struct as initializers. We could have it accept an
argument for _every_ field, but that becomes a pain for the
fields which some callers don't want to set initially.

Instead, let's be explicit that it takes only the minimum
required to create the ref, and that callers should then
fill in the rest themselves.

Signed-off-by: Jeff King <peff@peff.net>
---
Technically we don't need the oid to create the struct, just the name,
but I figured that every caller is going to have to have some oid.

 ref-filter.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index ade97a8486..c1c3cc9480 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 	return NULL;
 }
 
-/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
+/*
+ * Allocate space for a new ref_array_item and copy the name and oid to it.
+ *
+ * Callers can then fill in other struct members at their leisure.
+ */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const struct object_id *oid,
-						 int flag)
+						 const struct object_id *oid)
 {
 	struct ref_array_item *ref;
+
 	FLEX_ALLOC_STR(ref, refname, refname);
 	oidcpy(&ref->objectname, oid);
-	ref->flag = flag;
 
 	return ref;
 }
@@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid, flag);
+	ref = new_ref_array_item(refname, oid);
 	ref->commit = commit;
+	ref->flag = flag;
+	ref->kind = kind;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
 	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
-	ref->kind = kind;
 	return 0;
 }
 
@@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, oid, 0);
+	ref_item = new_ref_array_item(name, oid);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
-- 
2.17.0.686.g08b0810b04


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 52EC61F404
	for <e@80x24.org>; Fri,  6 Apr 2018 18:59:50 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751618AbeDFS7s (ORCPT <rfc822;e@80x24.org>);
        Fri, 6 Apr 2018 14:59:48 -0400
Received: from cloud.peff.net ([104.130.231.41]:56188 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1750815AbeDFS7r (ORCPT <rfc822;git@vger.kernel.org>);
        Fri, 6 Apr 2018 14:59:47 -0400
Received: (qmail 23572 invoked by uid 109); 6 Apr 2018 18:59:47 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Fri, 06 Apr 2018 18:59:47 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 28107 invoked by uid 111); 6 Apr 2018 19:00:49 -0000
Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Fri, 06 Apr 2018 15:00:49 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Fri, 06 Apr 2018 14:59:45 -0400
Date:   Fri, 6 Apr 2018 14:59:45 -0400
From:   Jeff King <peff@peff.net>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH 3/3] ref-filter: factor ref_array pushing into its own
 function
Message-ID: <20180406185945.GC11108@sigill.intra.peff.net>
References: <20180406185801.GA921@sigill.intra.peff.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <20180406185801.GA921@sigill.intra.peff.net>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

In preparation for callers constructing their own ref_array
structs, let's move our own internal push operation into its
own function.

While we're at it, we can replace REALLOC_ARRAY() with
ALLOC_GROW(), which should give the growth operation
amortized linear complexity (as opposed to growing by one,
which is potentially quadratic, though in-place realloc
growth often makes this faster in practice).

Signed-off-by: Jeff King <peff@peff.net>
---
 ref-filter.c | 16 +++++++++++++---
 ref-filter.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index c1c3cc9480..6e9328b274 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1840,6 +1840,18 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
 	return ref;
 }
 
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid)
+{
+	struct ref_array_item *ref = new_ref_array_item(refname, oid);
+
+	ALLOC_GROW(array->items, array->nr + 1, array->alloc);
+	array->items[array->nr++] = ref;
+
+	return ref;
+}
+
 static int ref_kind_from_refname(const char *refname)
 {
 	unsigned int i;
@@ -1930,13 +1942,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid);
+	ref = ref_array_push(ref_cbdata->array, refname, oid);
 	ref->commit = commit;
 	ref->flag = flag;
 	ref->kind = kind;
 
-	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
-	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
 	return 0;
 }
 
diff --git a/ref-filter.h b/ref-filter.h
index 68268f9ebc..76cf87cb6c 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -135,4 +135,12 @@ void setup_ref_filter_porcelain_msg(void);
 void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
+/*
+ * Push a single ref onto the array; this can be used to construct your own
+ * ref_array without using filter_refs().
+ */
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid);
+
 #endif /*  REF_FILTER_H  */
-- 
2.17.0.686.g08b0810b04

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id E53E41F404
	for <e@80x24.org>; Fri,  6 Apr 2018 19:27:24 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751344AbeDFT1W (ORCPT <rfc822;e@80x24.org>);
        Fri, 6 Apr 2018 15:27:22 -0400
Received: from mail-pl0-f67.google.com ([209.85.160.67]:34996 "EHLO
        mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751276AbeDFT1V (ORCPT <rfc822;git@vger.kernel.org>);
        Fri, 6 Apr 2018 15:27:21 -0400
Received: by mail-pl0-f67.google.com with SMTP id 61-v6so1224121plb.2
        for <git@vger.kernel.org>; Fri, 06 Apr 2018 12:27:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=subject:to:cc:references:from:message-id:date:user-agent
         :mime-version:in-reply-to:content-transfer-encoding:content-language;
        bh=H6TXKustq+ArzHRZDfhdrjSsB+BTVXDDTLAq2sIk/Lo=;
        b=PY0VktrHQq0sa44lmXPqpuxIHVdw4e6y5tG8cbzLa20nSCTYS/YI/F/fXNNM1TWMnE
         eEyL2y9Zyw+W/NHCWYUv4cHRy8gEBgME2OKe9fhRW2TblL0oR/Z8mPbWAl72Jy2zMg/Q
         VP02VIvSlRxeIlGHCqTGOh37XOIBryHRc9rayrawIaLfIn+W3DIipbGLsDuEgYzst7Hx
         j1RUB5JtGfe7p+9hEbeyLLnvuHTg1aODbTy5iFu/3HFRWTtDke2J/LeJK0XS7bx4mH4Z
         efIruB7NPwdep+Lx3QFDBiVQYwuhrOTgzib1fhw2Px8RdCN6tpYSyk9Xm4bJoCaFxgz4
         Lf8A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:cc:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-transfer-encoding
         :content-language;
        bh=H6TXKustq+ArzHRZDfhdrjSsB+BTVXDDTLAq2sIk/Lo=;
        b=YD3gfXvVvhwedJTrRcLcQdFfHyW6tz4JJj5jBGoVAVBB8kbnZmjUVZ0q9lU75vRAiE
         Nlg5OxVC1sc9cHbl2ucZZPmxzX6AEUdAF5c65IX/2OwMmnWQFqQujgtZSXMhQMqAz64i
         9XFNn94bFLSyiZWzNX+J5z96kWsH8ub0t+QG6N3IbzIfvbc+/W2NqV8AuVPhCKINzuEK
         tFdRGv/KwSCr05FvTDqo9O/yfy1ZkmTYFoHeoc1QGUusCaOHhESTYjng71iTlIxy+ArP
         34hrijnyzDwdS6byo2gBkgNWv7bUN5RJOHWC7AszXJQx8Z3JAx2qkZi1fwPX+ltPjcco
         eBmA==
X-Gm-Message-State: AElRT7G0dpeln1lAp93zRvT72ukZeizliaZ1rYzLnd5dxnDHwc1nNZOD
        cGfU9duae2BLRwxco8zsESuiIdqgeMY=
X-Google-Smtp-Source: AIpwx4+qrIM0y0kaeN9GzO55aXoy3K/Uoj802Sq2D8DDvJfcqjoFTPP5gGkom9v6LoE+/82Ef7uOlQ==
X-Received: by 2002:a17:902:82c2:: with SMTP id u2-v6mr27886731plz.401.1523042841294;
        Fri, 06 Apr 2018 12:27:21 -0700 (PDT)
Received: from ?IPv6:2001:4898:6808:13e:c4e6:7a22:56f1:df04? ([2001:4898:8010:0:ae1c:7a22:56f1:df04])
        by smtp.gmail.com with ESMTPSA id t25sm22539269pfj.187.2018.04.06.12.27.17
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 06 Apr 2018 12:27:20 -0700 (PDT)
Subject: Re: [PATCH 3/3] ref-filter: factor ref_array pushing into its own
 function
To:     Jeff King <peff@peff.net>,
        Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
References: <20180406185801.GA921@sigill.intra.peff.net>
 <20180406185945.GC11108@sigill.intra.peff.net>
From:   Derrick Stolee <stolee@gmail.com>
Message-ID: <51135137-97ea-354a-7acd-4e905ee69a80@gmail.com>
Date:   Fri, 6 Apr 2018 15:27:13 -0400
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
 Thunderbird/52.7.0
MIME-Version: 1.0
In-Reply-To: <20180406185945.GC11108@sigill.intra.peff.net>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-US
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On 4/6/2018 2:59 PM, Jeff King wrote:
> In preparation for callers constructing their own ref_array
> structs, let's move our own internal push operation into its
> own function.
>
> While we're at it, we can replace REALLOC_ARRAY() with
> ALLOC_GROW(), which should give the growth operation
> amortized linear complexity (as opposed to growing by one,
> which is potentially quadratic, though in-place realloc
> growth often makes this faster in practice).
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>   ref-filter.c | 16 +++++++++++++---
>   ref-filter.h |  8 ++++++++
>   2 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index c1c3cc9480..6e9328b274 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -1840,6 +1840,18 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
>   	return ref;
>   }
>   
> +struct ref_array_item *ref_array_push(struct ref_array *array,
> +				      const char *refname,
> +				      const struct object_id *oid)
> +{
> +	struct ref_array_item *ref = new_ref_array_item(refname, oid);
> +
> +	ALLOC_GROW(array->items, array->nr + 1, array->alloc);
> +	array->items[array->nr++] = ref;
> +
> +	return ref;
> +}
> +
>   static int ref_kind_from_refname(const char *refname)
>   {
>   	unsigned int i;
> @@ -1930,13 +1942,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
>   	 * to do its job and the resulting list may yet to be pruned
>   	 * by maxcount logic.
>   	 */
> -	ref = new_ref_array_item(refname, oid);
> +	ref = ref_array_push(ref_cbdata->array, refname, oid);
>   	ref->commit = commit;
>   	ref->flag = flag;
>   	ref->kind = kind;
>   
> -	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
> -	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
>   	return 0;
>   }
>   
> diff --git a/ref-filter.h b/ref-filter.h
> index 68268f9ebc..76cf87cb6c 100644
> --- a/ref-filter.h
> +++ b/ref-filter.h
> @@ -135,4 +135,12 @@ void setup_ref_filter_porcelain_msg(void);
>   void pretty_print_ref(const char *name, const struct object_id *oid,
>   		      const struct ref_format *format);
>   
> +/*
> + * Push a single ref onto the array; this can be used to construct your own
> + * ref_array without using filter_refs().
> + */
> +struct ref_array_item *ref_array_push(struct ref_array *array,
> +				      const char *refname,
> +				      const struct object_id *oid);
> +
>   #endif /*  REF_FILTER_H  */

The three patches in this series look good to me.

Reviewed-by: Derrick Stolee <dstolee@microsoft.com>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 51EE21F404
	for <e@80x24.org>; Sat,  7 Apr 2018 15:22:59 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751741AbeDGPW4 (ORCPT <rfc822;e@80x24.org>);
        Sat, 7 Apr 2018 11:22:56 -0400
Received: from mail-ot0-f196.google.com ([74.125.82.196]:40558 "EHLO
        mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751579AbeDGPW4 (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 7 Apr 2018 11:22:56 -0400
Received: by mail-ot0-f196.google.com with SMTP id j8-v6so4260537ota.7
        for <git@vger.kernel.org>; Sat, 07 Apr 2018 08:22:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=dIRu75wWzCPsgK9OyAUdtmNI3u0uGM48lSsGxwpCRIg=;
        b=RBA85QpmKtw+HlHqcPO3mNtC08eMI/7PHN2XBHc9HWlTMoD+3p/qV1WsN0Ya1XTY5G
         iDktVB10Agf7Q4jRls+N5MqlcNw1f5CE9lFLMHHl2LFsRv+sFjGNoV4Yj3r5i/ghRS+b
         613xkw8gMesowmNERRSDDE9XXo6HQkTqE+sDm2zpaCLSJvcxtVUuf2lAS/iL5eee+Zpi
         gr1kvgEBpPfv7EvkkMsW7V+qvLg0jqGynu2N/xzmHHEyTPVXFXtjhHQxjOS/6aXiKB91
         JxvhfwwarVqh9EQYWFhEXfQRNHRv/vaxHeG43u+21znBFKJzvJvB8amf0YuIm9VpV/3N
         BHEw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=dIRu75wWzCPsgK9OyAUdtmNI3u0uGM48lSsGxwpCRIg=;
        b=Q800XEabIZTvEGNvhwgVDR2QNPltgm3g3h+qwZKUSyi7/GJIQ9pMsShF/8hqDIDw4C
         HHGn2B/cKdRYKZiY8wuPs22gxJ1fyeSVxsmrJtoUzhPWZkctuz9qszMm5+6lz95d/wda
         3oiaxbi/V1G5gYTqgKCEh+kxxTuZkvucGfcK8/u3eWm8Lp5h5wiZd9iZXsSMu9SPi5oC
         5P8vnesQNFUNVnNrcYPLjH3IZ3rwZrKDWeVgY/gwst2OwisVQm3TTTv7ZL2bQB98wzNd
         5NDiESmkNoFBZyAp6FWLkAXAozqqF7ChBWZQtvRMcyRNTID0Ko5W9bI2hDO/wtFvNmdf
         M3iQ==
X-Gm-Message-State: ALQs6tDhuRuQT+QlM+s1NEo4qclGdIU6zXJr8jPeupG0+u7HSIStVHXY
        WP7VPny/o3FmUajSiDINvv1TjFlkddo+fGd0/m/JQg==
X-Google-Smtp-Source: AIpwx4/OHTGCckl9Iok1fqpdK1J3IbtRueRjngUFGLRrXwgZoWsVPYZaWbQeyvsU/nray+dKikcVcKjjzNNjxItKGa8=
X-Received: by 2002:a9d:3323:: with SMTP id f32-v6mr20043901otc.221.1523114575266;
 Sat, 07 Apr 2018 08:22:55 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Sat, 7 Apr 2018 08:22:14 -0700 (PDT)
In-Reply-To: <51135137-97ea-354a-7acd-4e905ee69a80@gmail.com>
References: <20180406185801.GA921@sigill.intra.peff.net> <20180406185945.GC11108@sigill.intra.peff.net>
 <51135137-97ea-354a-7acd-4e905ee69a80@gmail.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Sat, 7 Apr 2018 17:22:14 +0200
Message-ID: <CAHwyqnV5JcW_ffMWDUqyioVS7fwAndixA8Xgjqx7TPq0huUWTQ@mail.gmail.com>
Subject: Re: [PATCH 3/3] ref-filter: factor ref_array pushing into its own function
To:     Derrick Stolee <stolee@gmail.com>
Cc:     Jeff King <peff@peff.net>, git@vger.kernel.org,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Looks good to me.

Reviewed-by: Harald Nordgren <haraldnordgren@gmail.com>

On Fri, Apr 6, 2018 at 9:27 PM, Derrick Stolee <stolee@gmail.com> wrote:
> On 4/6/2018 2:59 PM, Jeff King wrote:
>>
>> In preparation for callers constructing their own ref_array
>> structs, let's move our own internal push operation into its
>> own function.
>>
>> While we're at it, we can replace REALLOC_ARRAY() with
>> ALLOC_GROW(), which should give the growth operation
>> amortized linear complexity (as opposed to growing by one,
>> which is potentially quadratic, though in-place realloc
>> growth often makes this faster in practice).
>>
>> Signed-off-by: Jeff King <peff@peff.net>
>> ---
>>   ref-filter.c | 16 +++++++++++++---
>>   ref-filter.h |  8 ++++++++
>>   2 files changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/ref-filter.c b/ref-filter.c
>> index c1c3cc9480..6e9328b274 100644
>> --- a/ref-filter.c
>> +++ b/ref-filter.c
>> @@ -1840,6 +1840,18 @@ static struct ref_array_item
>> *new_ref_array_item(const char *refname,
>>         return ref;
>>   }
>>   +struct ref_array_item *ref_array_push(struct ref_array *array,
>> +                                     const char *refname,
>> +                                     const struct object_id *oid)
>> +{
>> +       struct ref_array_item *ref = new_ref_array_item(refname, oid);
>> +
>> +       ALLOC_GROW(array->items, array->nr + 1, array->alloc);
>> +       array->items[array->nr++] = ref;
>> +
>> +       return ref;
>> +}
>> +
>>   static int ref_kind_from_refname(const char *refname)
>>   {
>>         unsigned int i;
>> @@ -1930,13 +1942,11 @@ static int ref_filter_handler(const char *refname,
>> const struct object_id *oid,
>>          * to do its job and the resulting list may yet to be pruned
>>          * by maxcount logic.
>>          */
>> -       ref = new_ref_array_item(refname, oid);
>> +       ref = ref_array_push(ref_cbdata->array, refname, oid);
>>         ref->commit = commit;
>>         ref->flag = flag;
>>         ref->kind = kind;
>>   -     REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr +
>> 1);
>> -       ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
>>         return 0;
>>   }
>>   diff --git a/ref-filter.h b/ref-filter.h
>> index 68268f9ebc..76cf87cb6c 100644
>> --- a/ref-filter.h
>> +++ b/ref-filter.h
>> @@ -135,4 +135,12 @@ void setup_ref_filter_porcelain_msg(void);
>>   void pretty_print_ref(const char *name, const struct object_id *oid,
>>                       const struct ref_format *format);
>>   +/*
>> + * Push a single ref onto the array; this can be used to construct your
>> own
>> + * ref_array without using filter_refs().
>> + */
>> +struct ref_array_item *ref_array_push(struct ref_array *array,
>> +                                     const char *refname,
>> +                                     const struct object_id *oid);
>> +
>>   #endif /*  REF_FILTER_H  */
>
>
> The three patches in this series look good to me.
>
> Reviewed-by: Derrick Stolee <dstolee@microsoft.com>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id D03E81F404
	for <e@80x24.org>; Sat,  7 Apr 2018 16:43:21 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751636AbeDGQnT (ORCPT <rfc822;e@80x24.org>);
        Sat, 7 Apr 2018 12:43:19 -0400
Received: from mail-lf0-f66.google.com ([209.85.215.66]:41564 "EHLO
        mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751499AbeDGQnS (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 7 Apr 2018 12:43:18 -0400
Received: by mail-lf0-f66.google.com with SMTP id o102-v6so4518475lfg.8
        for <git@vger.kernel.org>; Sat, 07 Apr 2018 09:43:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:subject:date:message-id:in-reply-to:references;
        bh=0rjBjFJSshuZ3VKR0uNEGGsnNfU0adJJx+jLv+aIUUc=;
        b=Y9+L0+MOUBKW8m1D1iGgfHD6u0BV4SQXKwCoVMvR2I1y9M86OGczDqF/vxnFUu9goi
         jhLAyRvPEfAGpfJTbxYNaETmblDC4vL5mDaHo7OSYHDWNXv1jKC8d49CSdP2LEOSk+av
         oF2xHpr1kFEgN6gXy15gXRRJbM6x8ClyhA3vyb7GINvmgJW2C4hViwtCwGohVyiI+8Co
         6Yqhj4dANRMMSu4EyJC4wPWOXm4CQ8segQO06KYxkmevcZFl3UrDjiOnBQCPApfMtRVC
         v1cE5zPoIFvjCbHgMZBGirdyZKP0dms+BKwLUBZwfDPJfnmMdfgWMHXShRsg+0kC++u6
         SDwQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references;
        bh=0rjBjFJSshuZ3VKR0uNEGGsnNfU0adJJx+jLv+aIUUc=;
        b=aEzneI4cxUwFfI52EXE7vdko/5BHXJHA3NTQpGVvjeFXh6I24LIYS7xgCJNFTCbn3d
         HmTv2lO4pSKdVORP5bQ3suXaGEf9i4HdQoPxYmfkrQfYNvS8DYUjXuuU0XRkPg0hZQn1
         Prr5/+558aw1PWGpdYfwrxpaIKsWPF7gY1t3l8qFkEqa8RgkX/OBRlQZSlV638g4enNY
         kA524A0wL5jidOrdo8ltPI39gOL90AHOE5iyA6x8tYbJzpLsDJC+M9miFhdgv8Utb4xN
         mDab5SBDEVCGUaP/WKF4UlxyadlBqSlg7HnypPL+aVPTdnMxFj0JSc1BXifu3OwnAKg/
         XN0A==
X-Gm-Message-State: ALQs6tDY0+CKr8hozPoinW2vsM4zw6v9wcO64v25ynizxjkBzkIw6+SJ
        EQ4fPv7IjE73RdoKDl1QMtvP/1aopUs=
X-Google-Smtp-Source: AIpwx49RwyJAhoc98l49PVfTT/SXBv5UQ5/UzmQAL2T/5Qfd+lFRQ7fTg6AO7wpZbtx3LXymeFx2tw==
X-Received: by 2002:a19:a8d4:: with SMTP id r203-v6mr2836661lfe.146.1523119396810;
        Sat, 07 Apr 2018 09:43:16 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2591-74736162.cust.telenor.se. [94.234.37.145])
        by smtp.gmail.com with ESMTPSA id f200-v6sm2613958lff.35.2018.04.07.09.43.14
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 07 Apr 2018 09:43:15 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Subject: [PATCH v11 1/4] ref-filter: use "struct object_id" consistently
Date:   Sat,  7 Apr 2018 18:42:47 +0200
Message-Id: <20180407164250.54303-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

Internally we store a "struct object_id", and all of our
callers have one to pass us. But we insist that they peel it
to its bare-sha1 hash, which we then hashcpy() into place.
Let's pass it around as an object_id, which future-proofs us
for a post-sha1 world.
---
 builtin/tag.c        |  2 +-
 builtin/verify-tag.c |  2 +-
 ref-filter.c         | 10 +++++-----
 ref-filter.h         |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index da186691e..42278f516 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -117,7 +117,7 @@ static int verify_tag(const char *name, const char *ref,
 		return -1;
 
 	if (format->format)
-		pretty_print_ref(name, oid->hash, format);
+		pretty_print_ref(name, oid, format);
 
 	return 0;
 }
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index ad7b79fa5..6fa04b751 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -72,7 +72,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 		}
 
 		if (format.format)
-			pretty_print_ref(name, oid.hash, &format);
+			pretty_print_ref(name, &oid, &format);
 	}
 	return had_error;
 }
diff --git a/ref-filter.c b/ref-filter.c
index 45fc56216..ade97a848 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1826,12 +1826,12 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 
 /* Allocate space for a new ref_array_item and copy the objectname and flag to it */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const unsigned char *objectname,
+						 const struct object_id *oid,
 						 int flag)
 {
 	struct ref_array_item *ref;
 	FLEX_ALLOC_STR(ref, refname, refname);
-	hashcpy(ref->objectname.hash, objectname);
+	oidcpy(&ref->objectname, oid);
 	ref->flag = flag;
 
 	return ref;
@@ -1927,7 +1927,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid->hash, flag);
+	ref = new_ref_array_item(refname, oid, flag);
 	ref->commit = commit;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
@@ -2165,11 +2165,11 @@ void show_ref_array_item(struct ref_array_item *info,
 	putchar('\n');
 }
 
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, sha1, 0);
+	ref_item = new_ref_array_item(name, oid, 0);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
diff --git a/ref-filter.h b/ref-filter.h
index 0d98342b3..68268f9eb 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -132,7 +132,7 @@ void setup_ref_filter_porcelain_msg(void);
  * Print a single ref, outside of any ref-filter. Note that the
  * name must be a fully qualified refname.
  */
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
 #endif /*  REF_FILTER_H  */
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 571821F404
	for <e@80x24.org>; Sat,  7 Apr 2018 16:43:37 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751804AbeDGQn0 (ORCPT <rfc822;e@80x24.org>);
        Sat, 7 Apr 2018 12:43:26 -0400
Received: from mail-lf0-f65.google.com ([209.85.215.65]:42663 "EHLO
        mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751681AbeDGQnZ (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 7 Apr 2018 12:43:25 -0400
Received: by mail-lf0-f65.google.com with SMTP id q9-v6so4515430lfk.9
        for <git@vger.kernel.org>; Sat, 07 Apr 2018 09:43:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to
         :references;
        bh=HpZQADpynqYaw7XFsBJgE70DoGT4/KipbmRJkKrOhuw=;
        b=d2lRktjCv2Gd6jJ7Fh8JkLio0v7vS8xhvtyfNlhJM0NCIALOX+k/Nwb6U3qPAapAe0
         wEv61a16xZHfwa6eK2EZJ4JKxzzx6QkJZzdbca7XxKuoMJBXIc/wNvEjNakkEe8ADzFW
         ZhFDmtVZ7QJWvYp0ZcvDEsJvNaTGSVHrp6TxjIq0yPynW+/1D225oWQXq0sj9hLrF/CC
         x2Q5yFjD+0Y0/sygYVh+2hreYcP0QEgHU2Kr5sXwua2ccyeER7/WLHRo1tkS98ynuybM
         fI97H+C6A6uqVTp5TysjdTGc9PILI77Qcr3/uQU71kqlu95ja9d09MMwsRyd6mL2Xt+3
         UCoA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=HpZQADpynqYaw7XFsBJgE70DoGT4/KipbmRJkKrOhuw=;
        b=qlpkncW+7o42FmwfQSVWyhNaUUmsMPC8VSGkEXfoPh8LkzgM4BhJy07+p75oowrfzn
         OVP35jUTmTAXF/crBsYTj2N3W2BnE3ewKrrw7n8sUJIV3dgoauvfWkwmbes7LDAlr+Sb
         /oObIXUeP/MkB42TqxDb3/w27lm+/1umqDb4MI5FJI2voDsxIdg+D+ivZiPoFqijf/Z1
         xjpZ4AR0Y5PE5mmYTtunhToB0y7rn+FPSfBYgmuWgtovmbM4tnQkhUw+sx4A22IFiapX
         sQUFDwXWuGgkhxpWdmoMw3qXyP8IFmtaeowkHSvCzN+Wa2PEyNSMAZV6/CmxcpuOlFuU
         1waQ==
X-Gm-Message-State: ALQs6tBpRbxqeWJxIV59W3O2rV+vbvD454748hlnWBw6vmWImu+o8npl
        Uej4KKtNKo3wQ6Cadp0adYP8V8P52yY=
X-Google-Smtp-Source: AIpwx4+dlOK2rA+gp1NcM9aAHyM+3nXLoEMemozx0OtNDAaVtsBszT1codrsgGDm2vQTaS11Cs8ZAQ==
X-Received: by 2002:a19:9855:: with SMTP id a82-v6mr18585005lfe.49.1523119403813;
        Sat, 07 Apr 2018 09:43:23 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2591-74736162.cust.telenor.se. [94.234.37.145])
        by smtp.gmail.com with ESMTPSA id f200-v6sm2613958lff.35.2018.04.07.09.43.22
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 07 Apr 2018 09:43:23 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Subject: [PATCH v11 2/4] ref-filter: make ref_array_item allocation more consistent
Date:   Sat,  7 Apr 2018 18:42:48 +0200
Message-Id: <20180407164250.54303-2-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180407164250.54303-1-haraldnordgren@gmail.com>
References: <20180407164250.54303-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

We have a helper function to allocate ref_array_item
structs, but it only takes a subset of the possible fields
in the struct as initializers. We could have it accept an
argument for _every_ field, but that becomes a pain for the
fields which some callers don't want to set initially.

Instead, let's be explicit that it takes only the minimum
required to create the ref, and that callers should then
fill in the rest themselves.
---
 ref-filter.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index ade97a848..c1c3cc948 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 	return NULL;
 }
 
-/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
+/*
+ * Allocate space for a new ref_array_item and copy the name and oid to it.
+ *
+ * Callers can then fill in other struct members at their leisure.
+ */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const struct object_id *oid,
-						 int flag)
+						 const struct object_id *oid)
 {
 	struct ref_array_item *ref;
+
 	FLEX_ALLOC_STR(ref, refname, refname);
 	oidcpy(&ref->objectname, oid);
-	ref->flag = flag;
 
 	return ref;
 }
@@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid, flag);
+	ref = new_ref_array_item(refname, oid);
 	ref->commit = commit;
+	ref->flag = flag;
+	ref->kind = kind;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
 	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
-	ref->kind = kind;
 	return 0;
 }
 
@@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, oid, 0);
+	ref_item = new_ref_array_item(name, oid);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 6BF771F404
	for <e@80x24.org>; Sat,  7 Apr 2018 16:43:37 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751956AbeDGQnf (ORCPT <rfc822;e@80x24.org>);
        Sat, 7 Apr 2018 12:43:35 -0400
Received: from mail-lf0-f67.google.com ([209.85.215.67]:36760 "EHLO
        mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751681AbeDGQne (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 7 Apr 2018 12:43:34 -0400
Received: by mail-lf0-f67.google.com with SMTP id z143-v6so4522694lff.3
        for <git@vger.kernel.org>; Sat, 07 Apr 2018 09:43:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to
         :references;
        bh=BeVf9HaCq8LUpwGeCmR3SvfnftSUxTFcl+r6WL7KwiI=;
        b=QpYFqlde+NVcHsocPXB/q7mSYqoLoYDCSVH4UBvgLOepg2l75KabixJgLTGaGLKtPW
         VxzBc5YIoIgwW3ezeNN2NvSo8Q4aOsZh/Z5lO+hqqip+3P+K8gnADesG8Wg0105Zkrpd
         WHgpVg536wCCWAlagMEQkrDgrWoJ++5BUnoaZWrChc/KAVm+tB/BOgvON5A7bKqLcjrD
         YTO7Q3D4+TcviaodNSqNb5dq8OcRCBGzDpainKEJARCeRem2YugWXCQQfWI4/oW2NZtl
         Gnzq21VytnDWZILf8OyvGThRAP2OpeTL/VNBh3MqJBHLrFsN9sP5ZyxJSzx95muRpjTV
         QZZw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=BeVf9HaCq8LUpwGeCmR3SvfnftSUxTFcl+r6WL7KwiI=;
        b=jX8kl0nzYn0y7vU+iz7OYydKQ3v8TYQULrblf5IRCuXqbjmi5Qrd4ihY3EGUQDApv+
         XasbFMlT11SYvbjrJZzwCCXYiXalyXaiF/NKOB9lHQaBPb70aTiJjMkgw3d+nHvnDpBE
         TH62Jfbhv72b6hPxKNJ6c7ZTF9EqcKWixbUk07BC/JlnUnoFK4TpRy2Mewe/lf23tQWX
         gqGKDMJdvCQCqUzIVib4mx4LfXGTLf2Tb81DJkvWGLXl0da3R0LYCTTL13KJpqbKOzGD
         B7eJ3OUG1I3L+e5G/kxWvEBWlrfgIcxqG4DT+HNV0UkisUnuAKbiSgImXa39L917PEve
         hNOw==
X-Gm-Message-State: ALQs6tBAtbPq0Ac5gQtUS3v7mboBjbK8zXT3UtQmveQidWsnaU57Wj6R
        Iz/Jd90EB1H0cbk1Jsm2yjef7jAgg3I=
X-Google-Smtp-Source: AIpwx49Jy4XPX4mZTpgYsNzP45PAYiG4AzsDfqFBaeDxKbhY4xjIqnOnXhsc1W5CQT7PR2Bl51KrtA==
X-Received: by 10.46.153.142 with SMTP id w14mr19573930lji.116.1523119412643;
        Sat, 07 Apr 2018 09:43:32 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2591-74736162.cust.telenor.se. [94.234.37.145])
        by smtp.gmail.com with ESMTPSA id f200-v6sm2613958lff.35.2018.04.07.09.43.31
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 07 Apr 2018 09:43:32 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Subject: [PATCH v11 3/4] ref-filter: factor ref_array pushing into its own function
Date:   Sat,  7 Apr 2018 18:42:49 +0200
Message-Id: <20180407164250.54303-3-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180407164250.54303-1-haraldnordgren@gmail.com>
References: <20180407164250.54303-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

In preparation for callers constructing their own ref_array
structs, let's move our own internal push operation into its
own function.

While we're at it, we can replace REALLOC_ARRAY() with
ALLOC_GROW(), which should give the growth operation
amortized linear complexity (as opposed to growing by one,
which is potentially quadratic, though in-place realloc
growth often makes this faster in practice).
---
 ref-filter.c | 16 +++++++++++++---
 ref-filter.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index c1c3cc948..6e9328b27 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1840,6 +1840,18 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
 	return ref;
 }
 
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid)
+{
+	struct ref_array_item *ref = new_ref_array_item(refname, oid);
+
+	ALLOC_GROW(array->items, array->nr + 1, array->alloc);
+	array->items[array->nr++] = ref;
+
+	return ref;
+}
+
 static int ref_kind_from_refname(const char *refname)
 {
 	unsigned int i;
@@ -1930,13 +1942,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid);
+	ref = ref_array_push(ref_cbdata->array, refname, oid);
 	ref->commit = commit;
 	ref->flag = flag;
 	ref->kind = kind;
 
-	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
-	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
 	return 0;
 }
 
diff --git a/ref-filter.h b/ref-filter.h
index 68268f9eb..76cf87cb6 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -135,4 +135,12 @@ void setup_ref_filter_porcelain_msg(void);
 void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
+/*
+ * Push a single ref onto the array; this can be used to construct your own
+ * ref_array without using filter_refs().
+ */
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid);
+
 #endif /*  REF_FILTER_H  */
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 616381F404
	for <e@80x24.org>; Sat,  7 Apr 2018 16:43:41 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751984AbeDGQnj (ORCPT <rfc822;e@80x24.org>);
        Sat, 7 Apr 2018 12:43:39 -0400
Received: from mail-lf0-f44.google.com ([209.85.215.44]:46625 "EHLO
        mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751807AbeDGQnh (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 7 Apr 2018 12:43:37 -0400
Received: by mail-lf0-f44.google.com with SMTP id j68-v6so4526886lfg.13
        for <git@vger.kernel.org>; Sat, 07 Apr 2018 09:43:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=WqHRY9m0e4kILaNapNTNArG+k3RMIhxIpRopSnaNk60=;
        b=ojNOcVYLRa3i9MaTEjeTyXt/woU/Ysza/bsYVgb5NSgdsROrGLWKjj+tyZV8LysmDO
         OeIb8bgQIxy4gOfhSDrvhr3U8Ao6VoJJzTuLGujKefowqoLc6VNwkAznLls0XoVO0D/r
         7/KsLf3MKXhvCifPdtxplKeqIZQ9eB82uhPnnlXD5TKs9Eo/WZb+jhZTMTOH3zQ+EWWh
         fm8Gmm5InMKG3cDUHIl2sdtUOlmOfTMArZXX6Vka/VJTIGRIc4Uwuyg3fy+lHEwf2M03
         lMShy93mYWyZ77eOvPWOhtjq3e/hdKQN11A6mc+WQuWWudnqCrUQSNAl+qbjh/7bArO4
         u4cg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=WqHRY9m0e4kILaNapNTNArG+k3RMIhxIpRopSnaNk60=;
        b=BiKKnDwG0zrSQ0K0QBu+tcpqLxQj2Xm3/BqjHA0eMi3Kd8E7tUNPw2B23p5g1yTBHK
         14rKqCYCTlP7+ZLD2nLUxqo6O9l7VXS6AamYynO3/ur//RWVJfEqV4uKZl2Yx7Kxw/4D
         xU7vMXBIRhuvQjoitfJeoXT+XHAvcOJ1aP4wVq/SH/xU810fYArXz17G/GnVe1ziYgFt
         jLRQPeZ4xWxc6zPwWA0t9yF7oGGUOQrRGFin14rR7xDgaXu1o2oXVI1GJb/R8agIrJxf
         /CDYxZrsbA3rn/Iq2Twd2QOgUfoye4uptQBoMuemzYY7tmWmVDeK41oW1fqVChCl+cIW
         cxiw==
X-Gm-Message-State: AElRT7G5tkLLXqYKU0mR8MPn2AL8ghFFJ97DyzmnKSGUFXKjWjiEPNu6
        lpe0bxwp0l3VyFCBSOuCSjaIr1/fQF0=
X-Google-Smtp-Source: AIpwx4+1urTQYGL9eOrs9IQ1xTnvRTvZKHPgAG9C4eQniVpH0J+HKLXnzpr+qd9R5RM6ULcr1sitDw==
X-Received: by 10.46.112.24 with SMTP id l24mr19706475ljc.104.1523119415996;
        Sat, 07 Apr 2018 09:43:35 -0700 (PDT)
Received: from localhost.localdomain (c-5eea2591-74736162.cust.telenor.se. [94.234.37.145])
        by smtp.gmail.com with ESMTPSA id f200-v6sm2613958lff.35.2018.04.07.09.43.34
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 07 Apr 2018 09:43:35 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v11 4/4] ls-remote: create '--sort' option
Date:   Sat,  7 Apr 2018 18:42:50 +0200
Message-Id: <20180407164250.54303-4-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180407164250.54303-1-haraldnordgren@gmail.com>
References: <20180407164250.54303-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Rebasing my patch on Jeff King's refatoring patches

 Documentation/git-ls-remote.txt | 15 ++++++++++++++-
 builtin/ls-remote.c             | 22 ++++++++++++++++++++--
 t/t5512-ls-remote.sh            | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..fa4505fd7 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,19 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given.  Prefix `-` to sort in
+	descending order of the value. You may use the --sort=<key> option
+	multiple times, in which case the last key becomes the primary
+	key. Also supports "version:refname" or "v:refname" (tag
+	names are treated as versions). The "version:refname" sort
+	order can also be affected by the "versionsort.suffix"
+	configuration variable.
+	The keys supported are the same as those in `git for-each-ref`,
+	except that because `ls-remote` deals only with remotes, keys like
+	`committerdate` that require access to the objects themselves will
+	not work.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..4375e8322 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&array, 0, sizeof(array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -104,13 +112,23 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
+		struct ref_array_item *item;
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+		item = ref_array_push(&array, ref->name, &ref->old_oid);
+		item->symref = xstrdup_or_null(ref->symref);
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &array);
+
+	for (i = 0; i < array.nr; i++) {
+		const struct ref_array_item *ref = array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..66370cd88 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -178,6 +214,9 @@ test_expect_success 'ls-remote --symref' '
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
 	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.1
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.10
+	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 43C091F404
	for <e@80x24.org>; Sun,  8 Apr 2018 01:06:13 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752034AbeDHBGK (ORCPT <rfc822;e@80x24.org>);
        Sat, 7 Apr 2018 21:06:10 -0400
Received: from mail-qt0-f171.google.com ([209.85.216.171]:44443 "EHLO
        mail-qt0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751387AbeDHBGK (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 7 Apr 2018 21:06:10 -0400
Received: by mail-qt0-f171.google.com with SMTP id j26so5341564qtl.11
        for <git@vger.kernel.org>; Sat, 07 Apr 2018 18:06:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:sender:in-reply-to:references:from:date:message-id
         :subject:to:cc;
        bh=xSlC8SbpMLBN1KYColqlNZoAcFZUb9B+L12H/Gfdp2M=;
        b=X9zK03mpiMbGu5t1a8iXzcsmEcn8Ef5Yfx4a4K1TPCJjAlpNyHCEPyi31QbU91gv0d
         a7EiWPDNk7TEaToy+OUA/HIJK8PfVkOmT3Mt+LFhcmZhgf86/M1F/t97bAX5EgOrlvft
         4tZAE4Np2NYxQfuM7ptwIGEN6dG2g3fo7aBsBhDGIpsNiNAhElczZhVYj+HdwGvbJxm2
         aTlnLJTspTytqJdsPlaFTbQ09138bzluoZ8TB/hNJsTeh4YjgYxr6kjOEs0R2dEPBVIx
         sYEttJ9vGpHkN9UKF2aPxEf2bGOMZaD91EVjotl6wLaDn+7bv5TAknxETNyAb3wkVE0y
         jRUg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:cc;
        bh=xSlC8SbpMLBN1KYColqlNZoAcFZUb9B+L12H/Gfdp2M=;
        b=m+LryJRQMLxpLBPSMPq+I067o5ZaR3Vbs+LzFakUB8uifVTxM1ss8PBnsgfOM7XrsM
         7bsb3prwOZ6RLAARquIZ5nO60zSeO6Tkbq5Irvwc0c8wxRMORWgjiYEWkkI0YaoYb4yg
         QGdTzjIoBA8CyCXu5ORrD+0B3IS5uKerXdIJ+ozCl7DDaU1ce4ORCiIc6maClKwYYgAI
         2Ml1JUYykXq0n8KvjOC2Uc63PcM5FTYiSjnN59qzH8brIK2ut1FkPsLQRLl7QDlxu67S
         D27A6hSwRjmgSJJAVKtf+g6c3QgHR9hqL1OkjuftyEEW1RzttwD4CSxjLc+JJTtQHv5A
         ZcFw==
X-Gm-Message-State: ALQs6tCflIpfNRt0UD7jsby7HUDuHqQ5pf5EUniBQk5yjlP2h4PGunFK
        ttzw0rquFr0wXKrStPjrnkqpVfb3XS+PAnGhuRo=
X-Google-Smtp-Source: AIpwx49kxTm3TFBuPY3VBJNLhgb3J4l63JuprSVSmSKBKMApAuDzcwGw0KuiIfBAVKg7NqAV5/mTNYIUqM5CDZrlSNU=
X-Received: by 10.200.42.37 with SMTP id k34mr46632082qtk.101.1523149569495;
 Sat, 07 Apr 2018 18:06:09 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.12.174.202 with HTTP; Sat, 7 Apr 2018 18:06:08 -0700 (PDT)
In-Reply-To: <20180407164250.54303-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com> <20180407164250.54303-1-haraldnordgren@gmail.com>
From:   Eric Sunshine <sunshine@sunshineco.com>
Date:   Sat, 7 Apr 2018 21:06:08 -0400
X-Google-Sender-Auth: BN5HYzxvEClEiazed9mHc2Z5-pA
Message-ID: <CAPig+cTQ1ZzWTp6Qsj96nE8QwhuRuqB51orTNsCQjGKD=_veyg@mail.gmail.com>
Subject: Re: [PATCH v11 1/4] ref-filter: use "struct object_id" consistently
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Sat, Apr 7, 2018 at 12:42 PM, Harald Nordgren
<haraldnordgren@gmail.com> wrote:
> From: Jeff King <peff@peff.net>
>
> Internally we store a "struct object_id", and all of our
> callers have one to pass us. But we insist that they peel it
> to its bare-sha1 hash, which we then hashcpy() into place.
> Let's pass it around as an object_id, which future-proofs us
> for a post-sha1 world.
> ---

You incorrectly dropped Peff's sign-off[1] when re-sending the patches
he authored in the series. And, your sign-off should follow his.

Also, if you made any changes to Peff's patch, it's a good idea to
state so with a bracketed comment at the end of the commit message
(before the sign-offs). For instance:

    [hn: tweaked doodle blap]

or such.

[1]: https://public-inbox.org/git/20180406185831.GA11108@sigill.intra.peff.net/

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 1DB741F404
	for <e@80x24.org>; Sun,  8 Apr 2018 01:48:58 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752068AbeDHBsN (ORCPT <rfc822;e@80x24.org>);
        Sat, 7 Apr 2018 21:48:13 -0400
Received: from mail-qk0-f175.google.com ([209.85.220.175]:47020 "EHLO
        mail-qk0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752006AbeDHBsM (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 7 Apr 2018 21:48:12 -0400
Received: by mail-qk0-f175.google.com with SMTP id p67so5499209qke.13
        for <git@vger.kernel.org>; Sat, 07 Apr 2018 18:48:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:sender:in-reply-to:references:from:date:message-id
         :subject:to:cc;
        bh=XqqDtclcHtjb+ZrxuBBebtaL8qYamCby6pUI7VMe9PA=;
        b=i4z0ynuc+KIlP8lyT72gEeYSbI31+qPjmUNacZttxXzRA5mhUjblOvAlPbq51pw03N
         GkqM7YDcumB4CsFS6x9VuMPcA9x6260rAxncadgt+nvOvp8EhsoOv524dB2hQTYBv5L+
         EMJ8j4IYeL/CqlcLbRZjeNu5jGw8L/hINJmOoNtvM2rIV2Qs6vjhDIQ1N8Q5NNKrBI7e
         Oj4cEtx5nPptSFdCbLDF+T9sNMXdvDt8gVGw9FkX+/pBOA+cJMjdTFTp1zo5zUFVEsPN
         KRPPk6ugmnmHpn4jdgyhrXQB6T+TNEs5m1wb8GnYCWACMDz5PhokCC+49s43QujWD0lH
         ZHgg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:cc;
        bh=XqqDtclcHtjb+ZrxuBBebtaL8qYamCby6pUI7VMe9PA=;
        b=eCFqgQDMpwjvwi5qOGKqIGxFz08N4+PGgH5Xi/Co67e4SdIFngpzqm82I7eTQW0RWo
         r6HJ0gaiK1fnz9doAtkvA8q31+yV5O89vCTzW0pAtE8Eo52NSaAt2utmI9zyUK8fPIbG
         Xj/QCS3hndt4zPZEiroPyw62iZGuvUxR3WRxDOuF9nGUt1Logo+kf3p5K6SunrStNZVX
         l1aTWk4g54zKuBi8sxuMBPX8ZcS8X62IY8iurE+1PrXyzXKZYHtwbJDq3R9hH3/KgCUf
         mJFEf9ZXbu6rPm/Mo9WUW2rK/xlreATAD4AeSih2D1UTRxjjkZhDHT64i5YO6i/Y3Tbr
         BI3A==
X-Gm-Message-State: ALQs6tC7xdUt8c7DnsyrsTpr5hdQMBK/7h1eORnMUGA3oJB7cjhLf0cs
        U/cSYxBtdXnTUCJKLqtlhvRx83FQ5B/UFhHnDSM=
X-Google-Smtp-Source: AIpwx4/37NjI7adA7Azt8xyklDMNzm6G6RDkBQnkq//QU2Eg5rdn+0oyrebPRbuAhduh5gD2sOYVAn7S8WedLFaVUBU=
X-Received: by 10.55.198.217 with SMTP id s86mr42626320qkl.153.1523152091334;
 Sat, 07 Apr 2018 18:48:11 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.12.174.202 with HTTP; Sat, 7 Apr 2018 18:48:10 -0700 (PDT)
In-Reply-To: <20180407164250.54303-4-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180407164250.54303-1-haraldnordgren@gmail.com> <20180407164250.54303-4-haraldnordgren@gmail.com>
From:   Eric Sunshine <sunshine@sunshineco.com>
Date:   Sat, 7 Apr 2018 21:48:10 -0400
X-Google-Sender-Auth: s4je8ITete6T93oSKcWWEopkbKk
Message-ID: <CAPig+cQnkvs8uPU-=woEzYC=mu1Bbi2u_TgH60aVUyh+m3DKDA@mail.gmail.com>
Subject: Re: [PATCH v11 4/4] ls-remote: create '--sort' option
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Sat, Apr 7, 2018 at 12:42 PM, Harald Nordgren
<haraldnordgren@gmail.com> wrote:
> Create a '--sort' option for ls-remote, based on the one from
> for-each-ref. This e.g. allows ref names to be sorted by version
> semantics, so that v1.2 is sorted before v1.10.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
> diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
> @@ -60,6 +60,19 @@ OPTIONS
> +--sort=<key>::
> +       Sort based on the key given.  Prefix `-` to sort in
> +       descending order of the value. You may use the --sort=<key> option
> +       multiple times, in which case the last key becomes the primary

This "last becomes primary key" feels counterintuitive to me, however,
I see it mirrors precedence of other Git commands.

In what situations would it make sense to specify --sort= multiple
times in the context of ls-remote? If there are none, then I wonder if
this should instead be documented as "last wins"...

> +       key. Also supports "version:refname" or "v:refname" (tag

To what does "Also" refer?

> +       names are treated as versions). The "version:refname" sort
> +       order can also be affected by the "versionsort.suffix"
> +       configuration variable.
> +       The keys supported are the same as those in `git for-each-ref`,
> +       except that because `ls-remote` deals only with remotes, keys like
> +       `committerdate` that require access to the objects themselves will
> +       not work.

What does "not work" mean in this context? Will the command crash
outright? Will it emit a suitable error message or warning? Will the
sorting be somehow dysfunctional?

It seems like the sentence "The keys supported..." should go above the
"Also supports..." sentence for this explanation to be more cohesive.

Finally, how about adding a linkgit:git-for-each-ref[1] to give the
user an easy way to access the referenced documentation. For instance:

    The keys supported are the same as those accepted by the
    `--sort=` option of linkgit:git-for-each-ref[1], except...

> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
> @@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
> +       struct ref_array array;
> +       static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
> @@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
> +       memset(&array, 0, sizeof(array));

Can we have a more meaningful name than 'array'? Even a name a simple
as 'refs' would convey more information.

> @@ -104,13 +112,23 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>         for ( ; ref; ref = ref->next) {
> +               struct ref_array_item *item;
>                 if (!check_ref_type(ref, flags))
>                         continue;
>                 if (!tail_match(pattern, ref->name))
>                         continue;
> +               item = ref_array_push(&array, ref->name, &ref->old_oid);
> +               item->symref = xstrdup_or_null(ref->symref);

Do we need to worry about freeing memory allocated by these two lines?

More generally, do we care that 'array' and 'sorting' are being
leaked? If not, perhaps they should be annotated by UNLEAK.

> +       }
> diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
> @@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
> +test_expect_success 'ls-remote --sort="version:refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       EOF
> +       git ls-remote --sort="version:refname" --tags self >actual &&
> +       test_cmp expect actual
> +'

This test script is already filled with these hardcoded SHA-1's, so
this is not a new problem, but work is under way to make it possible
to replace SHA-1 with some other hashing algorithm. Test scripts are
being retrofitted to avoid hard-coding them; instead determining the
hash value dynamically (for example, [1]). It would be nice if the new
tests followed suit, thus saving someone else extra work down the
road. (This, itself, is not worth a re-roll, but something to consider
if you do re-roll.)

[1]: https://public-inbox.org/git/20180325192055.841459-10-sandals@crustytoothpaste.net/

> +test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       EOF
> +       git ls-remote --sort="-version:refname" --tags self >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success 'ls-remote --sort="-refname" --tags self' '
> +       cat >expect <<-\EOF &&
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.2
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.10
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark1.1
> +       1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
> +       EOF
> +       git ls-remote --sort="-refname" --tags self >actual &&
> +       test_cmp expect actual
> +'

Do we want a test verifying that multiple sort keys are respected? (Is
it even possible to construct such a test?)

> @@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
>  test_expect_success 'Report match with --exit-code' '
>         git ls-remote --exit-code other.git "refs/tags/*" >actual &&
> -       git ls-remote . tags/mark >expect &&
> +       git ls-remote . tags/mark* >expect &&
>         test_cmp expect actual
>  '

Why this change?

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 27A771F404
	for <e@80x24.org>; Sun,  8 Apr 2018 12:28:20 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751521AbeDHM2R (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 08:28:17 -0400
Received: from mail-oi0-f50.google.com ([209.85.218.50]:39761 "EHLO
        mail-oi0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751340AbeDHM2Q (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 08:28:16 -0400
Received: by mail-oi0-f50.google.com with SMTP id q71-v6so5123092oic.6
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 05:28:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=Ln+EUefhpot8pQ+dzp9yn9A9N15q2Cfj5Z+a50iJr34=;
        b=moJIl19KJxra0UJ/AKtBoMI/6862SR75aMey9+CBtv6jjuj4EiVGwhcEyk+e/O0Xqi
         ixj8TMJzQato5RRzOWj47F5oFh2t+LonN4AoBo5dteTA7xBzwnWYkZpYLWH+h1RgSkxy
         NPDpdXSVJqdyFhkOCvuu7b6MmCxBUdf5ynWpRiMfAMkxpDEXOBi6uB/vmbIi4nJ5a4xu
         XzSzxy1Vq5//EKHlLfAs4N84p1iYhFRQigOlOePczXea8M8CmzXdIx36k1ZrGzM8JekP
         UOAWbvV/ygtIjIMGFYQ2wpibHwxayqkopUPk/8ZgwbW9NKbY6PMy2AFYS0y/b106WXMh
         tHjw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=Ln+EUefhpot8pQ+dzp9yn9A9N15q2Cfj5Z+a50iJr34=;
        b=oms40IlILCHqDkuCUT5pBEXabenxZLe22D7hDVMnRt1SxMz5pDc3OXaJOPYERIz5YQ
         j6xC21eBgxIHfdXGu7WJIpubvilsmXZufIo8PKRv8ZQzJhHjnS2aZYcY/A92s2tPRmLW
         WqV2PQMZWIJCI5EG0PG0oDtOeVrw4IAQ3vc00SeumlQ04iq9h08Fk00upig4+tx6WhVy
         ZMBpGgE9Lz4RARsMRBGc3N8crPnK4HjN3WShUtomsrl3YSxT0aorHCx+BEROrL/rSUZM
         kmUmKq5ayome0U0fg7D3oC2pdPHmMkGUHCfRHZwGRWwn8wlYzy9jZ09gIqYD8VVGqgF0
         RQkA==
X-Gm-Message-State: ALQs6tBsaOQBP9l6IQURAf+WAWqqM+dcvyrz+13NCz9fUU2RTnW7AM7A
        kAiaB40DZaFgtgZvamAsFN+tCqU4uOvCXErCZ4o=
X-Google-Smtp-Source: AIpwx4/Q8OGj0CHZVusBNROG1vT1mKyGmn1tnePg335SqV57AP/VWvtBjyCF+iLKKLvN6PJnWRj2f/vdsdqcLh5jac4=
X-Received: by 2002:aca:b5c2:: with SMTP id e185-v6mr18398564oif.166.1523190495766;
 Sun, 08 Apr 2018 05:28:15 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Sun, 8 Apr 2018 05:27:35 -0700 (PDT)
In-Reply-To: <CAPig+cTQ1ZzWTp6Qsj96nE8QwhuRuqB51orTNsCQjGKD=_veyg@mail.gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180407164250.54303-1-haraldnordgren@gmail.com> <CAPig+cTQ1ZzWTp6Qsj96nE8QwhuRuqB51orTNsCQjGKD=_veyg@mail.gmail.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Sun, 8 Apr 2018 14:27:35 +0200
Message-ID: <CAHwyqnVWhwmDKhgoJ1p-UuxL-=pAczMCe3KdDbkhayh4n88jPg@mail.gmail.com>
Subject: Re: [PATCH v11 1/4] ref-filter: use "struct object_id" consistently
To:     Eric Sunshine <sunshine@sunshineco.com>
Cc:     Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Thanks for your very thorough review Eric! I think I address all the
points, but if I missed something please let me know.


On Sun, Apr 8, 2018 at 3:06 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:

>
> You incorrectly dropped Peff's sign-off[1] when re-sending the patches
> he authored in the series. And, your sign-off should follow his.

I just rebased on https://github.com/peff/git/tree/jk/ref-array-push
where there were no sign-off tags.

But I amended the commit messages now to add the sign-off. And also
added my own sign-off.

> Also, if you made any changes to Peff's patch, it's a good idea to
> state so with a bracketed comment at the end of the commit message
> (before the sign-offs). For instance:
>
>     [hn: tweaked doodle blap]
>
> or such.
>
> [1]: https://public-inbox.org/git/20180406185831.GA11108@sigill.intra.peff.net/

As a sign of respect I probably wouldn't want to tweak the patches.

They currently work well together with my implementation, so there is no need.

> This "last becomes primary key" feels counterintuitive to me, however,
> I see it mirrors precedence of other Git commands.
>
> In what situations would it make sense to specify --sort= multiple
> times in the context of ls-remote? If there are none, then I wonder if
> this should instead be documented as "last wins"...
>
> To what does "Also" refer?

This was copied wholesale from Documentation/git-tag.txt.

I minimized the text now and removed all the references to using
'sort' multiple times. Although you technically could use multiple
keys, since 'ls-remote' only outputs two columns, I guess it's never
needed.

> What does "not work" mean in this context? Will the command crash
> outright? Will it emit a suitable error message or warning? Will the
> sorting be somehow dysfunctional?

This will be the output when trying to sort by commiterdate:

    From git@github.com:git/git.git
    fatal: missing object f0d0fd3a5985d5e588da1e1d11c85fba0ae132f8 for
refs/pull/10/head

I added a a note in the documentation saying that it will "cause a
failure". Should we be even more explicit than that?

This is one side-effect of borrowing the ref-filter logic in this
patch. We inherit things that won't work on remotes.

> It seems like the sentence "The keys supported..." should go above the
> "Also supports..." sentence for this explanation to be more cohesive.
>
> Finally, how about adding a linkgit:git-for-each-ref[1] to give the
> user an easy way to access the referenced documentation. For instance:
>
>     The keys supported are the same as those accepted by the
>     `--sort=` option of linkgit:git-for-each-ref[1], except...
>

Added a "linkgit" to git-for-each-ref. And a "See also" section at the bottom.

> Can we have a more meaningful name than 'array'? Even a name a simple
> as 'refs' would convey more information.

I think 'refs' would be confusing considering that the return value of
'transport_get_remote_refs' is stored as 'ref'. I renamed it to
'ref_array'. I hope it's not a problem that is shadows its struct
name. But I've seen us this naming paradigm in other places -- and in
this file.

> Do we need to worry about freeing memory allocated by these two lines?
>
> More generally, do we care that 'array' and 'sorting' are being
> leaked? If not, perhaps they should be annotated by UNLEAK.

Since 'cmd_ls_remote' is always (?) called from another process I
don't think we need to worry explicitly freeing the memory. I added
UNLEAK annotations to my code.

> This test script is already filled with these hardcoded SHA-1's, so
> this is not a new problem, but work is under way to make it possible
> to replace SHA-1 with some other hashing algorithm. Test scripts are
> being retrofitted to avoid hard-coding them; instead determining the
> hash value dynamically (for example, [1]). It would be nice if the new
> tests followed suit, thus saving someone else extra work down the
> road. (This, itself, is not worth a re-roll, but something to consider
> if you do re-roll.)
>
> [1]: https://public-inbox.org/git/20180325192055.841459-10-sandals@crustytoothpaste.net/

Added 'git rev-parse' calls to my tests do decrease the reliance on
SHA-1's. For the test

    ls-remote --symref

I couldn't figure out a way to extract the hash for
'refs/remotes/origin/HEAD' so I re-used HEAD. I tried different ways
of fetching origin, making another commit and pushing, but origin/HEAD
is still unavailable.

By calling 'git fetch origin' before the test, at least I am able to
extract 'git rev-parse refs/remotes/origin/master'.

This all makes the tests a bit more complicated, so I hope it helps us
in the future! :)

> Do we want a test verifying that multiple sort keys are respected? (Is
> it even possible to construct such a test?)

To add to my previous point: Since 'ls-remote' outputs only two
columns, I don't see a use case for multiple keys.

And I don't know what the test would look like either.

>> @@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
>>  test_expect_success 'Report match with --exit-code' '
>>         git ls-remote --exit-code other.git "refs/tags/*" >actual &&
>> -       git ls-remote . tags/mark >expect &&
>> +       git ls-remote . tags/mark* >expect &&
>>         test_cmp expect actual
>>  '
>
> Why this change?

I added the asterisk to 'mark*' because without it, the test

    Report match with --exit-code

will fail because the input 'git ls-remote refs/tags/*' now gives
gives back more tags (mark, mark1.1, mark1.2, mark1.10). So I think
the asterisk is the cleanest solution to not have to create e.g. two
separate setup functions.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id C57211F404
	for <e@80x24.org>; Sun,  8 Apr 2018 12:28:52 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751626AbeDHM2u (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 08:28:50 -0400
Received: from mail-wr0-f193.google.com ([209.85.128.193]:37726 "EHLO
        mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751526AbeDHM2t (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 08:28:49 -0400
Received: by mail-wr0-f193.google.com with SMTP id l49so5654478wrl.4
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 05:28:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=X8YoKxMRjxPUNYvAckl51qp3Zpnob1shYxxfJiEG3iQ=;
        b=l5oSaRZpfMUyFyLKBsu4tEtOZZEC+/EwKnQ4rxRSuLBJ6qRODC2HU9ci19I8aj3eau
         ERghBDOhh/RqLiUGEpr1Yo+es3XGYtvnnN3PY/qymcRP8qZUnT92+NAld/ngFFlV67g2
         YAd1VE/x8LRyrD97zxLWpQHFHTf4BPQBKD+yDIODq4NJR3S8DMA+CVww4eG0IRT4Nfjn
         L/dVFeWO3PU+MtyVT2/adaCSAhuy7TXLQh+gpWsglFRdy727grZ1JnVEIxd1hsXFf3u0
         3xEUop+vdfddnXXvySfn7P+n0ljisMIf2DMWQeL4nT5LoEo49tzFlDHPjtKh/TF+Z89s
         Zpsw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=X8YoKxMRjxPUNYvAckl51qp3Zpnob1shYxxfJiEG3iQ=;
        b=QEkUodMxXkME8m8o7HB1FvnEsopfKNtMfKhSRP5sgsl8JIWgGP11XHiw059WW4xw0g
         kuGwnJaFqaMBgcPKP8vyInHf5DpmIt02cDR8WIcGHM3EexdqchlwJLfPTgfW0yN8BUNW
         i1mbU8UGKw9sN1XlxfTGRAVHZibratG/EqdXHf4rGRSPhASjFt/yscQ+l+HzjjC1QYVY
         uY7MY5SxX/b4s84H2ezZHxDfTrA6mUtnaactCvFu0nP3Simz7n2n91gyGhvqnwaPUYTa
         B1VnSSy/uoQtAD7zGZ29vF+OAaYk592p85rtUxYQDMiPcz2x2u9KBTntw8F6xO/q3VYn
         g1pQ==
X-Gm-Message-State: ALQs6tBgzNNXIcBu0mxKJKa03BB+2R87cJLeo5d02YKl3TQ6HZpNR+FW
        RP86/ZUPD8l4LziBD789InLsY6sywcM=
X-Google-Smtp-Source: AIpwx4/yEVLgAwE4GOOjv5T7pvuaoRQOB1rchcyIqBTL3wU79JncRrjWNOuGYaWv80GU/Vcm5SL9BA==
X-Received: by 2002:a19:9dc5:: with SMTP id g188-v6mr20706259lfe.95.1523190527566;
        Sun, 08 Apr 2018 05:28:47 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id p9-v6sm2965038lfh.93.2018.04.08.05.28.45
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 05:28:46 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v12 1/4] ref-filter: use "struct object_id" consistently
Date:   Sun,  8 Apr 2018 14:28:29 +0200
Message-Id: <20180408122832.65414-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

Internally we store a "struct object_id", and all of our
callers have one to pass us. But we insist that they peel it
to its bare-sha1 hash, which we then hashcpy() into place.
Let's pass it around as an object_id, which future-proofs us
for a post-sha1 world.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 builtin/tag.c        |  2 +-
 builtin/verify-tag.c |  2 +-
 ref-filter.c         | 10 +++++-----
 ref-filter.h         |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index da186691e..42278f516 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -117,7 +117,7 @@ static int verify_tag(const char *name, const char *ref,
 		return -1;
 
 	if (format->format)
-		pretty_print_ref(name, oid->hash, format);
+		pretty_print_ref(name, oid, format);
 
 	return 0;
 }
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index ad7b79fa5..6fa04b751 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -72,7 +72,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 		}
 
 		if (format.format)
-			pretty_print_ref(name, oid.hash, &format);
+			pretty_print_ref(name, &oid, &format);
 	}
 	return had_error;
 }
diff --git a/ref-filter.c b/ref-filter.c
index 45fc56216..ade97a848 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1826,12 +1826,12 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 
 /* Allocate space for a new ref_array_item and copy the objectname and flag to it */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const unsigned char *objectname,
+						 const struct object_id *oid,
 						 int flag)
 {
 	struct ref_array_item *ref;
 	FLEX_ALLOC_STR(ref, refname, refname);
-	hashcpy(ref->objectname.hash, objectname);
+	oidcpy(&ref->objectname, oid);
 	ref->flag = flag;
 
 	return ref;
@@ -1927,7 +1927,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid->hash, flag);
+	ref = new_ref_array_item(refname, oid, flag);
 	ref->commit = commit;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
@@ -2165,11 +2165,11 @@ void show_ref_array_item(struct ref_array_item *info,
 	putchar('\n');
 }
 
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, sha1, 0);
+	ref_item = new_ref_array_item(name, oid, 0);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
diff --git a/ref-filter.h b/ref-filter.h
index 0d98342b3..68268f9eb 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -132,7 +132,7 @@ void setup_ref_filter_porcelain_msg(void);
  * Print a single ref, outside of any ref-filter. Note that the
  * name must be a fully qualified refname.
  */
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
 #endif /*  REF_FILTER_H  */
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id CFC981F404
	for <e@80x24.org>; Sun,  8 Apr 2018 12:28:57 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751788AbeDHM2w (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 08:28:52 -0400
Received: from mail-wr0-f195.google.com ([209.85.128.195]:38176 "EHLO
        mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751664AbeDHM2v (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 08:28:51 -0400
Received: by mail-wr0-f195.google.com with SMTP id m13so5639032wrj.5
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 05:28:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=QKcry4kzV21/y/X71Ud+Q6qoV4iWVtcFVAyqWjIBh8M=;
        b=UW8FrHswsQcpTkohkr+bu85EA24e0lRs0B5PerOSRstr58QtFve8pLN1MPty+XDS+P
         wEvO872CZhvIBoHy1v37DcJ7EVSX6wdXatUZ/gmGVZARlIQK2+v6ibFZYaIHWZQkv/G4
         XbKJZZ64DWVmGXZVHPdpeFnEefYYTWRVL9DYFKpxRWNss/1uqFwQytC12APlYCCGfYmt
         HjdOEs9dp8R7mLBld1eHgIpSYQ2P3swHDNfsvdqoKXDTDRr5Fq7eV0gE2hLPp9fpE7Wl
         pQE7RM9mQQ62ClB/JXDUwGxBgrXWgc9EXHwu/adJykS8Uatuq3Pc/SWTT9icTqLqw5nB
         Vt1g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=QKcry4kzV21/y/X71Ud+Q6qoV4iWVtcFVAyqWjIBh8M=;
        b=WN5Vo1qKZ9bbTEDzbsVEsxHGrqF6yP4jdwcyDM4yssM1bfAOmgWfWEUxaeyBCqeTTR
         9RqYviqcCWKau6mMFUYxcGAgscIDX7VWYsgV9XsxNVXrw3Wy9jWo7YTxLBe7RHaB/+Zi
         zCpTU7rGn7K5QCGaWPdIPzU79LuztvQbOOAIFwqE5KHjxdwIheumDVMQQrDuQ2h71LNs
         tB8P9s28S/3dbYIk/IPHiCi7oppmBYqQgIiVvOZ6nItXVMalzC7j86BrrINHE/k4Wlif
         PIOlR8K/cNtNMUzC4qgM8nKC7hkTboF8rURz5bqdw1LBQHNbAqGXKZtdGoHzuVoifZmQ
         mPsQ==
X-Gm-Message-State: ALQs6tC4xRElzrvDyxMz2aeR9/fyrbnsMfVPbuN6ioGTjdXCOriBMCLp
        a/I35R4KclvxJcCvUwJAG2uqtdxHMQg=
X-Google-Smtp-Source: AIpwx4+OxlWxyV9a6+tmbGxoU4b6q2GiPVDmxpSEkU2XTiHUUh9rRI3yY9+Mb9Tzc8cig98b431cQg==
X-Received: by 2002:a19:1619:: with SMTP id m25-v6mr20879742lfi.17.1523190530152;
        Sun, 08 Apr 2018 05:28:50 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id p9-v6sm2965038lfh.93.2018.04.08.05.28.48
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 05:28:49 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v12 3/4] ref-filter: factor ref_array pushing into its own function
Date:   Sun,  8 Apr 2018 14:28:31 +0200
Message-Id: <20180408122832.65414-3-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180408122832.65414-1-haraldnordgren@gmail.com>
References: <20180408122832.65414-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

In preparation for callers constructing their own ref_array
structs, let's move our own internal push operation into its
own function.

While we're at it, we can replace REALLOC_ARRAY() with
ALLOC_GROW(), which should give the growth operation
amortized linear complexity (as opposed to growing by one,
which is potentially quadratic, though in-place realloc
growth often makes this faster in practice).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 ref-filter.c | 16 +++++++++++++---
 ref-filter.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index c1c3cc948..6e9328b27 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1840,6 +1840,18 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
 	return ref;
 }
 
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid)
+{
+	struct ref_array_item *ref = new_ref_array_item(refname, oid);
+
+	ALLOC_GROW(array->items, array->nr + 1, array->alloc);
+	array->items[array->nr++] = ref;
+
+	return ref;
+}
+
 static int ref_kind_from_refname(const char *refname)
 {
 	unsigned int i;
@@ -1930,13 +1942,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid);
+	ref = ref_array_push(ref_cbdata->array, refname, oid);
 	ref->commit = commit;
 	ref->flag = flag;
 	ref->kind = kind;
 
-	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
-	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
 	return 0;
 }
 
diff --git a/ref-filter.h b/ref-filter.h
index 68268f9eb..76cf87cb6 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -135,4 +135,12 @@ void setup_ref_filter_porcelain_msg(void);
 void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
+/*
+ * Push a single ref onto the array; this can be used to construct your own
+ * ref_array without using filter_refs().
+ */
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid);
+
 #endif /*  REF_FILTER_H  */
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 29AC81F404
	for <e@80x24.org>; Sun,  8 Apr 2018 12:28:59 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751896AbeDHM2z (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 08:28:55 -0400
Received: from mail-wr0-f195.google.com ([209.85.128.195]:34380 "EHLO
        mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751794AbeDHM2x (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 08:28:53 -0400
Received: by mail-wr0-f195.google.com with SMTP id d19so1736300wre.1
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 05:28:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=//slVdyuM65CS0xWpc9QhnW7kRwRVk5+cTN+C9PdU6E=;
        b=hmSGh1cwzjPiwvwuJxQ2O4JxWDFOgw4d4H6OgKckBVI+WH0hJPKDQSZf4JrCPiVPf1
         3Yr74FwyEzPjYRC2LwH4aYXsmjHdG1t2ew2qv/+bhVG+0LF8uAP+/8TO93tIigydC70h
         DNP/rlCCL2GJEqHggVd+eeKRtdZek+MAMJA67Zc0D8Z4UmiaUtVEr34SqcoqR/yzOF9a
         HRyL4pKGanIdt+O4J5cesN1LCjCxpF11PJXvt+2iJ9o5hXUILPWPBANk1mUVsoETpey1
         vM6WGXAAA72PYdnN/H0T6tRF5pS/gZwcmz+/tgkRbETEPigYnBRnZgDZoLGIW6rn7mq+
         P9iQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=//slVdyuM65CS0xWpc9QhnW7kRwRVk5+cTN+C9PdU6E=;
        b=s8HaK0YAYRqxFsPozlYuspkzlFu/3pFzIag66SgU0mfIwhCPTxapFcNNs15px+9yig
         XqzWmAgSgHXks+YneR2U0xQQ6iUVVEL6HaCIeCpARv16ZN1W6azEC8QOpGJrvwCOAAIN
         xP+dYW8Qse7agu15eGoVbjX2VUJFiTGxqmdlFcVVHHmEST3RpdCGTveFqtQSSwemZJ/Z
         DjB+xzWF6rQtPBEuQOckvB1cqtC6+BG+PPAcymfOcBvBmL357ISmYrAU1UoLFBiIFU2o
         9QGCE5KFItacA2NgxN9RKMSw429x+WGZz/Y6HESkGYhyf/SJsm/LrhLEvOUISkU8sy3j
         mfqw==
X-Gm-Message-State: ALQs6tDl4BTsytjcz/RDy/udgw6eJFXsd1lhDN7bwfHKL5302acfMa0+
        iUIyU4w5DwJuRtQU5ROXME66WSo9iJs=
X-Google-Smtp-Source: AIpwx4+O55CHmeHSZT+xFTwdkEJfSLmWx5irYYzR9GlMjoBxvWYDOKOdwEsFvZJ9W1k1uJS8OkDHbQ==
X-Received: by 2002:a19:53cf:: with SMTP id h76-v6mr19992756lfl.87.1523190531721;
        Sun, 08 Apr 2018 05:28:51 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id p9-v6sm2965038lfh.93.2018.04.08.05.28.50
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 05:28:51 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v12 4/4] ls-remote: create '--sort' option
Date:   Sun,  8 Apr 2018 14:28:32 +0200
Message-Id: <20180408122832.65414-4-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180408122832.65414-1-haraldnordgren@gmail.com>
References: <20180408122832.65414-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Changes according to Eric Sunshine's code review

 Documentation/git-ls-remote.txt | 16 ++++++++++++-
 builtin/ls-remote.c             | 30 +++++++++++++++++++++---
 t/t5512-ls-remote.sh            | 52 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 88 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..80a09b518 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,16 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given. Prefix `-` to sort in descending order
+	of the value. Supports "version:refname" or "v:refname" (tag names
+	are treated as versions). The "version:refname" sort order can also
+	be affected by the "versionsort.suffix" configuration variable.
+	See linkgit:git-for-each-ref[1] for more sort options, but be aware
+	that because `ls-remote` deals only with remotes, any key like
+	`committerdate` that requires access to the object itself will
+	cause a failure.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
@@ -90,6 +100,10 @@ EXAMPLES
 	c5db5456ae3b0873fc659c19fafdde22313cc441	refs/tags/v0.99.2
 	7ceca275d047c90c0c7d5afb13ab97efdf51bd6e	refs/tags/v0.99.3
 
+SEE ALSO
+--------
+linkgit:git-check-ref-format[1].
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..d3851074c 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array ref_array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&ref_array, 0, sizeof(ref_array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -90,6 +98,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 
 	if (get_url) {
 		printf("%s\n", *remote->url);
+		UNLEAK(sorting);
 		return 0;
 	}
 
@@ -98,20 +107,35 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
 
 	ref = transport_get_remote_refs(transport);
-	if (transport_disconnect(transport))
+	if (transport_disconnect(transport)) {
+		UNLEAK(sorting);
 		return 1;
+	}
 
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
+		struct ref_array_item *item;
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+		item = ref_array_push(&ref_array, ref->name, &ref->old_oid);
+		item->symref = xstrdup_or_null(ref->symref);
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &ref_array);
+
+	for (i = 0; i < ref_array.nr; i++) {
+		const struct ref_array_item *ref = ref_array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
+
+	UNLEAK(sorting);
+	UNLEAK(ref_array);
 	return status;
 }
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..e8df4c7e0 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	'$(git rev-parse mark)'	refs/tags/mark
+	'$(git rev-parse mark1.1)'	refs/tags/mark1.1
+	'$(git rev-parse mark1.2)'	refs/tags/mark1.2
+	'$(git rev-parse mark1.10)'	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-\EOF &&
+	'$(git rev-parse mark1.10)'	refs/tags/mark1.10
+	'$(git rev-parse mark1.2)'	refs/tags/mark1.2
+	'$(git rev-parse mark1.1)'	refs/tags/mark1.1
+	'$(git rev-parse mark)'	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-\EOF &&
+	'$(git rev-parse mark1.2)'	refs/tags/mark1.2
+	'$(git rev-parse mark1.10)'	refs/tags/mark1.10
+	'$(git rev-parse mark1.1)'	refs/tags/mark1.1
+	'$(git rev-parse mark)'	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -170,14 +206,18 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
 	grep refs/tags/magic actual
 '
 
+git fetch origin
 test_expect_success 'ls-remote --symref' '
 	cat >expect <<-\EOF &&
 	ref: refs/heads/master	HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/heads/master
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	'$(git rev-parse HEAD)'	HEAD
+	'$(git rev-parse refs/heads/master)'	refs/heads/master
+	'$(git rev-parse HEAD)'	refs/remotes/origin/HEAD
+	'$(git rev-parse refs/remotes/origin/master)'	refs/remotes/origin/master
+	'$(git rev-parse refs/tags/mark)'	refs/tags/mark
+	'$(git rev-parse refs/tags/mark1.1)'	refs/tags/mark1.1
+	'$(git rev-parse refs/tags/mark1.10)'	refs/tags/mark1.10
+	'$(git rev-parse refs/tags/mark1.2)'	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id DAE501F404
	for <e@80x24.org>; Sun,  8 Apr 2018 12:29:01 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751736AbeDHM2v (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 08:28:51 -0400
Received: from mail-wr0-f193.google.com ([209.85.128.193]:39010 "EHLO
        mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751610AbeDHM2u (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 08:28:50 -0400
Received: by mail-wr0-f193.google.com with SMTP id c24so5644007wrc.6
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 05:28:49 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=14dDpLUz/O8Jo87ZEY1u02btoPmxPBcw8Y4WaAc1l9E=;
        b=JmsESZZFfqoGIKcWfFBomXXeJ2KvuHpoWe17ycwVp/dk02dFzO2vASwftFa6uhW6eh
         ElDlJPvT06POTigGTmuCraK8OZk4OaBwPD7zR80lz8CMwXykhYQt9SyQTsnDLC1dHLTx
         X+o/qlCu5SvvDjzr7YoisFF6oUgE2BWHQ40cWr8kNb+W7SdlJTsxV7ryePdUI6lldmqF
         s8lnr4qsrIhjLNNSp1KjK3sPnxRrgTJnzajVDlyzLdm3Wy6HaZDfqrfpJPX8lsZKLTyi
         rhmn/r3l0B4RijfMjBTc1H0HAJKNecftx4E6Njt6DIvJw17RD6WDrvenJeMr3+YXNzPM
         a2kg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=14dDpLUz/O8Jo87ZEY1u02btoPmxPBcw8Y4WaAc1l9E=;
        b=e/20LJUBiThysVLBlND3VJrhjKeSFDuenCKWtfFc1XAM7fivr9rCkzd5R9HqIKQSFM
         Ibj/VeLxv6fL6l0TLEHudty8okqsQ96kP2bJardqBuklROQienF/Zh6Y43HkjmwiJzpQ
         c3mfSI+B504aC93e+Dkcr8uawXNX9l7DoACPxuhRucQUuZv36cYTaQUxqJ7Bg7ZX+aj5
         rhzjRIJ6Gu2dVpIUuZk7LVoBSM+FOJTpcRbGZbLvR6qndWOSyKK+9EAIzzsPbSFJs0y3
         lgWX6ps8neHflPD34JxWFgviz+4awgtLNo27y4hP9H4t6AWK5ckdANSSvzybgDUKLO2R
         KCeA==
X-Gm-Message-State: ALQs6tAColXSlaOamlFTaHMMaRVrzdtFh5Gv4/I3/pK5pQOpf5q66qed
        iGszBIzWdOqvzEWusWv5Fs26h5GXI34=
X-Google-Smtp-Source: AIpwx49K0qP8Ihqb9ZVTkmTMQk1JWAmd6kzoM3Ec2FRgo6w7EfpVGQ79F5d3VKNE1DjcobLHx2Et3g==
X-Received: by 2002:a19:c441:: with SMTP id u62-v6mr20641656lff.104.1523190528903;
        Sun, 08 Apr 2018 05:28:48 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id p9-v6sm2965038lfh.93.2018.04.08.05.28.47
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 05:28:48 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v12 2/4] ref-filter: make ref_array_item allocation more consistent
Date:   Sun,  8 Apr 2018 14:28:30 +0200
Message-Id: <20180408122832.65414-2-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180408122832.65414-1-haraldnordgren@gmail.com>
References: <20180408122832.65414-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

We have a helper function to allocate ref_array_item
structs, but it only takes a subset of the possible fields
in the struct as initializers. We could have it accept an
argument for _every_ field, but that becomes a pain for the
fields which some callers don't want to set initially.

Instead, let's be explicit that it takes only the minimum
required to create the ref, and that callers should then
fill in the rest themselves.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 ref-filter.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index ade97a848..c1c3cc948 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 	return NULL;
 }
 
-/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
+/*
+ * Allocate space for a new ref_array_item and copy the name and oid to it.
+ *
+ * Callers can then fill in other struct members at their leisure.
+ */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const struct object_id *oid,
-						 int flag)
+						 const struct object_id *oid)
 {
 	struct ref_array_item *ref;
+
 	FLEX_ALLOC_STR(ref, refname, refname);
 	oidcpy(&ref->objectname, oid);
-	ref->flag = flag;
 
 	return ref;
 }
@@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid, flag);
+	ref = new_ref_array_item(refname, oid);
 	ref->commit = commit;
+	ref->flag = flag;
+	ref->kind = kind;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
 	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
-	ref->kind = kind;
 	return 0;
 }
 
@@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, oid, 0);
+	ref_item = new_ref_array_item(name, oid);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 3EBBA1F404
	for <e@80x24.org>; Sun,  8 Apr 2018 22:16:54 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752212AbeDHWQv (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 18:16:51 -0400
Received: from mail-wr0-f179.google.com ([209.85.128.179]:39686 "EHLO
        mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751552AbeDHWQu (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 18:16:50 -0400
Received: by mail-wr0-f179.google.com with SMTP id c24so6896315wrc.6
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 15:16:50 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
         :user-agent:mime-version;
        bh=q76mxxekbGNCrU2JQmfYy44XPVq0RkTMp80qSd8zfo4=;
        b=WMvo/Lm582g83Gfz+Dr75/lhinDnFzyenksBjmEpFB7SB3JJer1ehi0hqM3ZhRV4Kk
         6cZxIMIWB3q+qvr/Co1fDdj34tA6A61h4A7wOvpkj0y7LLUZVNUK/SoD90MQJ3NE6mMN
         SseR3X4VeWqGmites7pHbZk3bjSfIuTy8s/I7sxBX+k8t4/xT+NTvmpQr7cUxxZxCMpT
         XqbU+velwGbTLyazJ+vl//Hdql9Fmep6Cl+WY1NM7NUdkrs4EmnDdEx6M07qYYbcer01
         k8bsaxRXSHIQEK1KXt+n0d/LKQO/0PvOHaFbpyFc9HNJ0SiGGNh2cGx6NN6rjIM0dn+t
         zS+A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:sender:from:to:cc:subject:references:date
         :in-reply-to:message-id:user-agent:mime-version;
        bh=q76mxxekbGNCrU2JQmfYy44XPVq0RkTMp80qSd8zfo4=;
        b=gDIDUlflbilZWXaNmvWbAOTQ8aJKjJo/D/YlNr9nBS9q/s0jHfxqNeruUdT2lXcC9O
         PVTzoO+TrAgbcSdiXp9HZv7hEZoPZ+Swq2ews3/PclF1VMIr2VCSCjaeSIxS7eU4YbaR
         kUntLpS94vh44mLEujbF7FzMZml74R1tCSThIB/smg7H33fm9QHPfChXkT/OIC2LI+QR
         hrj7xeY902YY3UeAwft/AXABVwGeZvyDK+EGuzMxlGPurrMCEiG2VblfUM+dreIryjZn
         C0cc6kA0m4Cnu6p6yI7geWyGdufaV+mnsvD3wCdfEm4il4OsD0x4vrqA1TaeVxAKILBs
         3taw==
X-Gm-Message-State: AElRT7FvrPXhidms7FmD8/ZLGxNqRknDGCDWdYJKoaq/IfcP4qmOzW2P
        pik5kq0ul7Cuk6/tFAVj90m19Wgx
X-Google-Smtp-Source: AIpwx48fW+51KHD9855HbL2FK1ThvaMS6uyj5k+RzLmkNH7hPdPjim+GAelx3ycBWgTwInv/cl1wbg==
X-Received: by 10.223.171.213 with SMTP id s79mr22829877wrc.52.1523225809206;
        Sun, 08 Apr 2018 15:16:49 -0700 (PDT)
Received: from localhost (112.68.155.104.bc.googleusercontent.com. [104.155.68.112])
        by smtp.gmail.com with ESMTPSA id o23sm26260374wrf.93.2018.04.08.15.16.48
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Sun, 08 Apr 2018 15:16:48 -0700 (PDT)
From:   Junio C Hamano <gitster@pobox.com>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        sunshine@sunshineco.com
Subject: Re: [PATCH v12 4/4] ls-remote: create '--sort' option
References: <20180408122832.65414-1-haraldnordgren@gmail.com>
        <20180402005248.52418-1-haraldnordgren@gmail.com>
        <20180408122832.65414-4-haraldnordgren@gmail.com>
Date:   Mon, 09 Apr 2018 07:16:47 +0900
In-Reply-To: <20180408122832.65414-4-haraldnordgren@gmail.com> (Harald
        Nordgren's message of "Sun, 8 Apr 2018 14:28:32 +0200")
Message-ID: <xmqq7eph9wds.fsf@gitster-ct.c.googlers.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Harald Nordgren <haraldnordgren@gmail.com> writes:

> +--sort=<key>::
> +	Sort based on the key given. Prefix `-` to sort in descending order
> +	of the value. Supports "version:refname" or "v:refname" (tag names
> +	are treated as versions). The "version:refname" sort order can also
> +	be affected by the "versionsort.suffix" configuration variable.
> +	See linkgit:git-for-each-ref[1] for more sort options, but be aware
> +	that because `ls-remote` deals only with remotes, any key like
> +	`committerdate` that requires access to the object itself will
> +	cause a failure.

I can connect "because it deals only with remotes" and "access to
the object may fail", but I wonder if we can clarify the former a
bit better to make it easier to understand for those who are not yet
familiar with Git.  

    Keys like `committerdate` that require access to the object will
    not work [***HOW??? Do we get a segfault or something???***] for
    refs whose objects have not yet been fetched from the remote.

I added "for refs whose objects have not yet been fetched", whose
explicit-ness made "will not work" to be an OK expression, but
without it I would have suggested to rephrase it to "may not work".

This is a tangent but I suspect that the description of --sort in
git-for-each-ref documentation is wrong on the use of multiple
options, or I am misreading parse_opt_ref_sorting(), which I think
appends later keys to the end of the list, and compare_refs() which
I think yields results when an earlier key in the last decides two
are not equal and ignores the later keys.  The commit that added the
description was c0f6dc9b ("git-for-each-ref.txt: minor
improvements", 2008-06-05), and I think even back then the code in
builtin-for-each-ref.c appended later keys at the end, and it seems
nobody complained, so it is possible I am not reading the code right
before fully adjusting to timezone change ;-)

> +	for (i = 0; i < ref_array.nr; i++) {
> +		const struct ref_array_item *ref = ref_array.items[i];
>  		if (show_symref_target && ref->symref)
> -			printf("ref: %s\t%s\n", ref->symref, ref->name);
> -		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
> +			printf("ref: %s\t%s\n", ref->symref, ref->refname);
> +		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
>  		status = 0; /* we found something */
>  	}
> +
> +	UNLEAK(sorting);
> +	UNLEAK(ref_array);
>  	return status;
>  }

It is not too big a deal, but I find that liberal sprinkling of
UNLEAK() is somewhat unsightly.  From the code we leave with this
change, it is clear what we'd need to do when we make the code fully
leak-proof (i.e. we'd have a several lines to free resources held by
these two variables here, and then UNLEAK() that appear earlier in
the function will become a "goto cleanup;" after setting appropriate
value to "status"), so let's not worry about it.

> +test_expect_success 'ls-remote --sort="version:refname" --tags self' '
> +	cat >expect <<-\EOF &&
> +	'$(git rev-parse mark)'	refs/tags/mark
> +	'$(git rev-parse mark1.1)'	refs/tags/mark1.1
> +	'$(git rev-parse mark1.2)'	refs/tags/mark1.2
> +	'$(git rev-parse mark1.10)'	refs/tags/mark1.10
> +	EOF

Please do *NOT* step outside the pair of single quotes that protects
the body of the test scriptlet and execute commands like "git
rev-parse".  These execute in order to prepare the command line
argument strings BEFORE test_expect_success can run (or the test
framework decides if the test will be skipped via GIT_TEST_SKIP).

Instead do it like so:

	cat >expect <<-EOF &&
	$(git rev-parse mark)	refs/tags/mark
	$(git rev-parse mark1.1)	refs/tags/mark1.1
	$(git rev-parse mark1.2)	refs/tags/mark1.2
	$(git rev-parse mark1.10)	refs/tags/mark1.10
	EOF

I.e. the end token for << that is not quoted allows $var and $(cmd)
to be substituted.

Same comment applies throughout the remainder of this file.

Other than that, this patch was a very pleasant read.  Thanks.



From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 69E0A1F404
	for <e@80x24.org>; Sun,  8 Apr 2018 23:18:40 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752706AbeDHXSi (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 19:18:38 -0400
Received: from mail-wr0-f180.google.com ([209.85.128.180]:38707 "EHLO
        mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752320AbeDHXSi (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 19:18:38 -0400
Received: by mail-wr0-f180.google.com with SMTP id m13so7004252wrj.5
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 16:18:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=sender:from:to:cc:subject:references:date:message-id:user-agent
         :mime-version;
        bh=WKQkOip+QybE0EZffprspA0mdxgftey9zVgWFiwqnIc=;
        b=lNAxozIQQVuwx6hl3EiDW6OTYQd/CrmEJGlJpbExjG0qt8inCVIJaQHz0LH9jaeLGb
         Cc7tHEZYfjGEQ9tZGulUHI5R8oxXkeCApzrkrgGp6rhzrIQilhFWNd0CKSIKesMk1PH8
         FtiQNL9EX10O7uBaMA3xLqcF30MFZP89UR5MgZcjbudhnbXRh+B/sxq7NggdWD/aQeKY
         9MioSoudJveKqkcRJrBXej7c6+781XzmF+NK39ZcZu9ppLI3rtI2PWrDGW9h/dmYPSg1
         fx/71gzpqOdBTPBHucH2j83kjB7+foDG8jMGiCQyCyvl9J8wO2Bz7rB//rhwNrdUqQHQ
         jI5A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:sender:from:to:cc:subject:references:date
         :message-id:user-agent:mime-version;
        bh=WKQkOip+QybE0EZffprspA0mdxgftey9zVgWFiwqnIc=;
        b=G3phJ/2cGqgwfz8b9BCqRVF7238WFBH5hKYHsXk7N60XaRcDqwxcAX1tIALQ0FHE2+
         jrXIXO1zBcHfu1seqfH/uKkyCSC540ZpYNu/v7Rpn0YmZ9b+97G+mD1E2an1Zk0Rtuci
         iREPSTDqAa41xUQ2WALYh4iAAGQNOpDb6LkcC2Jl6MZT+NLYtiwKcYZDxJewoBVdQwnv
         y6RRKfFYG0iPrI4gm0mwI9N2jhftftzKXfnULkWCDmrPBZfVIv4Ghdvkt0U2QasUHewt
         gOJioT6yYWfP5V+rpLPAgeiuSwRmxLdpQ9AAfOkqUw6C5RqxNo7RP1IACQ94zpjNindc
         irZQ==
X-Gm-Message-State: AElRT7El0cirDH/TSBHbj88zEp8I4pyhu0AkLo+rRgV1yvmnkrL4qnHO
        U99StweShR6C7hcz5GqZpdk=
X-Google-Smtp-Source: AIpwx4+4VzQrCqnrXNrboWoOHD/RAzXEdrVATRnyDQGsILKXAzl7sjnQx3dtwJO6Z7szSDjn0lUO8g==
X-Received: by 10.223.191.11 with SMTP id p11mr25940250wrh.160.1523229516680;
        Sun, 08 Apr 2018 16:18:36 -0700 (PDT)
Received: from localhost (168.50.187.35.bc.googleusercontent.com. [35.187.50.168])
        by smtp.gmail.com with ESMTPSA id b38sm16211297wrg.81.2018.04.08.16.18.35
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Sun, 08 Apr 2018 16:18:36 -0700 (PDT)
From:   Junio C Hamano <gitster@pobox.com>
To:     Jeff King <peff@peff.net>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>, git@vger.kernel.org,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH 3/3] ref-filter: factor ref_array pushing into its own function
References: <20180406185801.GA921@sigill.intra.peff.net>
        <20180406185945.GC11108@sigill.intra.peff.net>
Date:   Mon, 09 Apr 2018 08:18:35 +0900
Message-ID: <xmqqy3hx70dw.fsf@gitster-ct.c.googlers.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Jeff King <peff@peff.net> writes:

> In preparation for callers constructing their own ref_array
> structs, let's move our own internal push operation into its
> own function.
>
> While we're at it, we can replace REALLOC_ARRAY() with
> ALLOC_GROW(), which should give the growth operation
> amortized linear complexity (as opposed to growing by one,
> which is potentially quadratic, though in-place realloc
> growth often makes this faster in practice).

Sorry, but I do not quite get the last part this paragraph.  Up to
but not including ", though in-place..." I would understand as:

     - With ALLOC_GROW(), we are explicit in that we are amortizing
       the allocation cost by growing in exponential batches.

     - With REALLOC_ARRAY(), we are telling the underlying
       realloc(3) that it is OK to pretend that we grow by one, but
       if that permission is literally followed, it could end up
       quadratic.

    So if you have really a bad realloc(3) implementation, switching
    to use ALLOC_GROW() is an improvement.

But after that I am not sure what you are getting at.  Do you mean
"In practice, a well-done realloc(3) does the amortizing internally
anyway, which makes it faster than the grow-by-one quadratic, so
this change may not make that much of a difference"?  Or do you mean
"In practice, a well-done realloc(3) internally amortizes better
than we do manually, so this change may hurt performance"?

In either case, I think this splitting into a helper is obviously a
good move, and using ALLOC_GROW() is conceptually cleaner, as we use
it everywhere and tend to avoid realloc(3) just to add one item.

Other than that small confusion (not even a nit), three patches were
pleasant read.  Thanks.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 1106E1F404
	for <e@80x24.org>; Sun,  8 Apr 2018 23:58:36 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752809AbeDHX6d (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 19:58:33 -0400
Received: from mail-wm0-f66.google.com ([74.125.82.66]:33151 "EHLO
        mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752763AbeDHX6c (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 19:58:32 -0400
Received: by mail-wm0-f66.google.com with SMTP id o23so15162350wmf.0
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 16:58:31 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=X8YoKxMRjxPUNYvAckl51qp3Zpnob1shYxxfJiEG3iQ=;
        b=CHbJtfzqfeefW8MxqIiKjrwLJD8NCJ/oAWDv0/g+A6zhG3xcZtdiXi3mxyxet/orW7
         +euntfLe8HV1njFOhScXI5b6xOseRXNAjVJWcQ791eioK7Pe7Mf4aFvAz/C2E7Up/UMe
         N/6FG2FO5Dr4rkstbQwrV7PikPnwGFyZf3RHcbipsO3Ki4kNO55fgX5kd+z5V6PuOZba
         0T+bo+yEzVkFS+kwBG4sVk56eF0NsckDKNihsO1O1+PUSpCBPTn/oVdtORFIkuyClYDo
         IC9rITwptuTI+9PlXGrF7+Zlf6tbqate4QOWpSbxqj14CR3kVp8nZPjEyLmRvj6QTTjY
         88xw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=X8YoKxMRjxPUNYvAckl51qp3Zpnob1shYxxfJiEG3iQ=;
        b=OrXRBKSAj5U0gAkYjWBapXvPRUZRC1O8H6m+6R+ZVwtxZceYmpMQyvbh1hrrUeG67Z
         YYxj3AZtEbeLWHYrA7GrhdKGDUsm/DrlwlkGbfCMccwVvl5X+JXOAQBYArG80K/6cQ9B
         HNM3cCzQ01Ur0PwBvUp3P3sMJeI1Z/ph4CN8XmPRq2oz9TyCIUFehhs4vN6zAf/JAqdQ
         PL31tjVahIk0U9miZ+h+JZqqsdjicjXl37Zl5lvM/2i6yg6U2C1VfbqOeTScnwZ06eeK
         JxspcdBuX0XdQw6Ip+95X6Wyx00e63kLkYjpdV1M1kJJz4WW3a8vC9Zc7uPFGG2wtZHn
         4bEQ==
X-Gm-Message-State: ALQs6tDPPoh66RgLEZfOr81KMUdWj2SGuoNbQJwrsHv/mmElrCnxT6ix
        kSoVdAIP29WXFfHgLRvYvHFUYlejbCc=
X-Google-Smtp-Source: AIpwx48ZuJfbCL3V0AAvud1ed27gjjBV0Y907hj7VU6I4BO8L7E6YL7rkD2hRTKOEe7DRM2rePXINw==
X-Received: by 10.46.157.214 with SMTP id x22mr6395252ljj.135.1523231910840;
        Sun, 08 Apr 2018 16:58:30 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id x4-v6sm3108742lfa.23.2018.04.08.16.58.29
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 16:58:30 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v13 1/4] ref-filter: use "struct object_id" consistently
Date:   Mon,  9 Apr 2018 01:58:12 +0200
Message-Id: <20180408235815.36582-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

Internally we store a "struct object_id", and all of our
callers have one to pass us. But we insist that they peel it
to its bare-sha1 hash, which we then hashcpy() into place.
Let's pass it around as an object_id, which future-proofs us
for a post-sha1 world.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 builtin/tag.c        |  2 +-
 builtin/verify-tag.c |  2 +-
 ref-filter.c         | 10 +++++-----
 ref-filter.h         |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index da186691e..42278f516 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -117,7 +117,7 @@ static int verify_tag(const char *name, const char *ref,
 		return -1;
 
 	if (format->format)
-		pretty_print_ref(name, oid->hash, format);
+		pretty_print_ref(name, oid, format);
 
 	return 0;
 }
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index ad7b79fa5..6fa04b751 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -72,7 +72,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 		}
 
 		if (format.format)
-			pretty_print_ref(name, oid.hash, &format);
+			pretty_print_ref(name, &oid, &format);
 	}
 	return had_error;
 }
diff --git a/ref-filter.c b/ref-filter.c
index 45fc56216..ade97a848 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1826,12 +1826,12 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 
 /* Allocate space for a new ref_array_item and copy the objectname and flag to it */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const unsigned char *objectname,
+						 const struct object_id *oid,
 						 int flag)
 {
 	struct ref_array_item *ref;
 	FLEX_ALLOC_STR(ref, refname, refname);
-	hashcpy(ref->objectname.hash, objectname);
+	oidcpy(&ref->objectname, oid);
 	ref->flag = flag;
 
 	return ref;
@@ -1927,7 +1927,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid->hash, flag);
+	ref = new_ref_array_item(refname, oid, flag);
 	ref->commit = commit;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
@@ -2165,11 +2165,11 @@ void show_ref_array_item(struct ref_array_item *info,
 	putchar('\n');
 }
 
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, sha1, 0);
+	ref_item = new_ref_array_item(name, oid, 0);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
diff --git a/ref-filter.h b/ref-filter.h
index 0d98342b3..68268f9eb 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -132,7 +132,7 @@ void setup_ref_filter_porcelain_msg(void);
  * Print a single ref, outside of any ref-filter. Note that the
  * name must be a fully qualified refname.
  */
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
 #endif /*  REF_FILTER_H  */
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id DCF7B1F404
	for <e@80x24.org>; Sun,  8 Apr 2018 23:58:37 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752839AbeDHX6f (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 19:58:35 -0400
Received: from mail-wm0-f66.google.com ([74.125.82.66]:55180 "EHLO
        mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752793AbeDHX6d (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 19:58:33 -0400
Received: by mail-wm0-f66.google.com with SMTP id r191so14580790wmg.4
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 16:58:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=14dDpLUz/O8Jo87ZEY1u02btoPmxPBcw8Y4WaAc1l9E=;
        b=Y1x6L016JtgUM/1qbMi6uMxz9Kv2FRiqlHMG9oBkNwJIABIYdmEwHGeGLgzQLeJpnN
         FtgIIc8QOQW2kuXKA36HI1cNu9hdpBXgv5Io8n32P3rGJYmtkA8eE2iFXEQLVtpuYGVZ
         G3OF89KGsDoQFZXZ6oYa0JMYSjhTwZ4q4uE6tv7bJAiJrhq5x6As8RQf6neo5wznbZC6
         GAcDXd6VOo+P6RaaCNOltJLv5yDk6GFtLewC6N0HHpF30B9adrrVAlMNDvYFWwGy2oPP
         Hg1K7kaqfTmGsKE988FAzzH99zWs5T5mNdLnBxTjf8lQhpPckF5rKm5ppU3sD1anCVls
         OX/g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=14dDpLUz/O8Jo87ZEY1u02btoPmxPBcw8Y4WaAc1l9E=;
        b=cpIq7W3rMjYKvUKnU7/m5y0MThfMLDOIpQGSM4T9WkVjcSvBexS02uhJvCvD1zoRaf
         BoFA8wurREJJ7oyacekC8pCF1yt8W2070MqBqk5TAfXfOjXwFvhNpDT2oOtkJXegRGxb
         +hxKidRKtQ/YcL3VvREELpmMfVudObu7lYOH/0Kp1rST1WLa6BKfgHcUZI5i0ALt/Vy2
         9ESyH7V5gwPp0GWEkwmh94mdeogzzF1VSefhL+xCjDCOjnTj6oKmnZ4HiMViVkmQHvuf
         f5VImfrM2DGut/gGn2UKIJvSxsi1nXVsp/4+SZxEe1heuDKFgL6H/oerNnGQAgvPC6hi
         5tlw==
X-Gm-Message-State: ALQs6tAPetw97oQMm8rPt0jJ48mBmA3E/7SllYALb/8dY46T9i46YFdh
        PMwBuDDGgYIzVW8Nmk8l6GmAS8ymWUk=
X-Google-Smtp-Source: AIpwx49z/kHQm7GG1LQejOebBLObi297mG1LMFTYdt0QLhcZwFEdE8AmPL3XiS6BYKV/QZd+8/8CJw==
X-Received: by 10.46.151.195 with SMTP id m3mr5040845ljj.100.1523231912116;
        Sun, 08 Apr 2018 16:58:32 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id x4-v6sm3108742lfa.23.2018.04.08.16.58.30
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 16:58:31 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v13 2/4] ref-filter: make ref_array_item allocation more consistent
Date:   Mon,  9 Apr 2018 01:58:13 +0200
Message-Id: <20180408235815.36582-2-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180408235815.36582-1-haraldnordgren@gmail.com>
References: <20180408235815.36582-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

We have a helper function to allocate ref_array_item
structs, but it only takes a subset of the possible fields
in the struct as initializers. We could have it accept an
argument for _every_ field, but that becomes a pain for the
fields which some callers don't want to set initially.

Instead, let's be explicit that it takes only the minimum
required to create the ref, and that callers should then
fill in the rest themselves.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 ref-filter.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index ade97a848..c1c3cc948 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 	return NULL;
 }
 
-/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
+/*
+ * Allocate space for a new ref_array_item and copy the name and oid to it.
+ *
+ * Callers can then fill in other struct members at their leisure.
+ */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const struct object_id *oid,
-						 int flag)
+						 const struct object_id *oid)
 {
 	struct ref_array_item *ref;
+
 	FLEX_ALLOC_STR(ref, refname, refname);
 	oidcpy(&ref->objectname, oid);
-	ref->flag = flag;
 
 	return ref;
 }
@@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid, flag);
+	ref = new_ref_array_item(refname, oid);
 	ref->commit = commit;
+	ref->flag = flag;
+	ref->kind = kind;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
 	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
-	ref->kind = kind;
 	return 0;
 }
 
@@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, oid, 0);
+	ref_item = new_ref_array_item(name, oid);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.6 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id B0CBA1F404
	for <e@80x24.org>; Sun,  8 Apr 2018 23:58:42 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752894AbeDHX6i (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 19:58:38 -0400
Received: from mail-wr0-f196.google.com ([209.85.128.196]:36526 "EHLO
        mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752842AbeDHX6g (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 19:58:36 -0400
Received: by mail-wr0-f196.google.com with SMTP id y55so7090733wry.3
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 16:58:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=96Pp81XDiYluxdxAwDr1azU//xCb7rdnW1D/hW/5XPY=;
        b=BZ6veemqKB2wMHRuPexJ8IFOCipSbEhAs7W+txckKtye2585J66iN1nfu3IajS2+tw
         m2b6FRK+rkfJd9Jes5gcXFObSHmUpFoZ1nuTdr/g9p7tjvB2PF+rouQLCW8/CzRHSF1j
         IAJWkeaGrzFoN1qcxGjgTtJrcN7zW6Zm3qDXQ5ik9K6X50YnfXbsd7bFDiUuVXPlL2Fk
         lHgFpaa6OEBgW/3a3VloOOG5LlOuiO6m1Bn67fhWi8FHUUhBiumkGoNtc4KXorse7Y7t
         M/pgiVKOcrzYJ0Gdypqm65JZVMCqd06NTj7tPaE/dRAIoQUzlouIELiV9h6/8sYmPsAK
         Fu/Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=96Pp81XDiYluxdxAwDr1azU//xCb7rdnW1D/hW/5XPY=;
        b=lvTocAKbZKx7VeodixpJVeIRwyDRFc7CG4LHoy2ZMgpZis4nKnYacRb2cdJg6DGHjw
         pWlGiPogQQUv5wjpJgIjw4fikGnMbl2RsPGb9yvDoCt4fyewUQYNUL9rVHANYxexpuPY
         7t6epKkuvjljwcbxAhr+APooBMENzKHjNT0VeShv4drt6S7JEZhS3MAMtaYqtYSqWXoy
         LR4nge6ylSYhy6AwqmLGcMf4BMewQru6pKmpRtKXqnm7ZSPcxzLy/icWREyBvY9YMiR6
         lCTElt4cu6ZKUSKUsgsTRXWtmajDfrM4m9rRafsSg0w3/e6kNnF8L60K3RLtudB1rAeG
         9HwQ==
X-Gm-Message-State: ALQs6tCgfGA4aaasi3XT9DtCLqMRRxUaYipf2UC5NTrVQKeXFAhYWbno
        ScZiKQ/rrKrJFg95IbymsbhWfWScKSU=
X-Google-Smtp-Source: AIpwx48XpptJh6Rfrgs0I3M+NKFcMrsP80X0BeVevd1getvpx/hsn9GbU8jGsn4TlPhlBhKjyQ2NSg==
X-Received: by 2002:a19:2ad5:: with SMTP id q82-v6mr20312893lfq.79.1523231914840;
        Sun, 08 Apr 2018 16:58:34 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id x4-v6sm3108742lfa.23.2018.04.08.16.58.33
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 16:58:34 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v13 4/4] ls-remote: create '--sort' option
Date:   Mon,  9 Apr 2018 01:58:15 +0200
Message-Id: <20180408235815.36582-4-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180408235815.36582-1-haraldnordgren@gmail.com>
References: <20180408235815.36582-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Changes according to Junio Hamano's code review

 Documentation/git-ls-remote.txt | 17 ++++++++++++-
 builtin/ls-remote.c             | 25 +++++++++++++++++--
 t/t5512-ls-remote.sh            | 54 +++++++++++++++++++++++++++++++++++------
 3 files changed, 86 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..0e26a67a1 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,17 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given. Prefix `-` to sort in descending order
+	of the value. Supports "version:refname" or "v:refname" (tag names
+	are treated as versions). The "version:refname" sort order can also
+	be affected by the "versionsort.suffix" configuration variable.
+	See linkgit:git-for-each-ref[1] for more sort options, but be aware
+	that because `ls-remote` deals only with remotes, keys like
+	`committerdate` that requires access to the objects themselves will
+	not work for refs whose objects have not yet been fetched from the
+	remote.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
@@ -90,6 +101,10 @@ EXAMPLES
 	c5db5456ae3b0873fc659c19fafdde22313cc441	refs/tags/v0.99.2
 	7ceca275d047c90c0c7d5afb13ab97efdf51bd6e	refs/tags/v0.99.3
 
+SEE ALSO
+--------
+linkgit:git-check-ref-format[1].
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..b5ca67167 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array ref_array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&ref_array, 0, sizeof(ref_array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -104,14 +112,27 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
+		struct ref_array_item *item;
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+		item = ref_array_push(&ref_array, ref->name, &ref->old_oid);
+		item->symref = xstrdup_or_null(ref->symref);
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &ref_array);
+
+	for (i = 0; i < ref_array.nr; i++) {
+		const struct ref_array_item *ref = ref_array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
+
+	UNLEAK(sorting);
+	UNLEAK(ref_array);
 	return status;
 }
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..83cd35c39 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-EOF &&
+	$(git rev-parse mark)	refs/tags/mark
+	$(git rev-parse mark1.1)	refs/tags/mark1.1
+	$(git rev-parse mark1.2)	refs/tags/mark1.2
+	$(git rev-parse mark1.10)	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-EOF &&
+	$(git rev-parse mark1.10)	refs/tags/mark1.10
+	$(git rev-parse mark1.2)	refs/tags/mark1.2
+	$(git rev-parse mark1.1)	refs/tags/mark1.1
+	$(git rev-parse mark)	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-EOF &&
+	$(git rev-parse mark1.2)	refs/tags/mark1.2
+	$(git rev-parse mark1.10)	refs/tags/mark1.10
+	$(git rev-parse mark1.1)	refs/tags/mark1.1
+	$(git rev-parse mark)	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -170,14 +206,18 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
 	grep refs/tags/magic actual
 '
 
+git fetch origin
 test_expect_success 'ls-remote --symref' '
-	cat >expect <<-\EOF &&
+	cat >expect <<-EOF &&
 	ref: refs/heads/master	HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/heads/master
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	$(git rev-parse HEAD)	HEAD
+	$(git rev-parse refs/heads/master)	refs/heads/master
+	$(git rev-parse HEAD)	refs/remotes/origin/HEAD
+	$(git rev-parse refs/remotes/origin/master)	refs/remotes/origin/master
+	$(git rev-parse refs/tags/mark)	refs/tags/mark
+	$(git rev-parse refs/tags/mark1.1)	refs/tags/mark1.1
+	$(git rev-parse refs/tags/mark1.10)	refs/tags/mark1.10
+	$(git rev-parse refs/tags/mark1.2)	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.6 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id E7F331F404
	for <e@80x24.org>; Sun,  8 Apr 2018 23:58:56 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752919AbeDHX6y (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 19:58:54 -0400
Received: from mail-wr0-f193.google.com ([209.85.128.193]:34678 "EHLO
        mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752763AbeDHX6e (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 19:58:34 -0400
Received: by mail-wr0-f193.google.com with SMTP id d19so3171033wre.1
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 16:58:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=QKcry4kzV21/y/X71Ud+Q6qoV4iWVtcFVAyqWjIBh8M=;
        b=YrkTQ8qmKSs5f9zYkhPH5FljoiW6Q1SORQ0LfVJDHW77dnmqe42IosCNAJuqyijvKa
         EpE5G0OXxqwmEnY6BtBu8OR/DI5yca4U8o6qEOwUTQizO0796HWog2fIbvO8GiqXJjX1
         hmLqJlu44TszFhCopWTuQio8MkiWIXGUVyZC7paPlKVCihFGY4f/tOoHDOrrP78v/+72
         OfsidEIjGv8TIeqGH1omxkcIDR6c7jC8QS5wiyPxcD8xzQXuLBnBgRLgu2X6N73hyelB
         +CX2oGcAjOf4WobisHgSDP32YxbUWFKEdP0Z7XuC7f4TNhNdELVACovgsZEv3/owCK4k
         N4JQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=QKcry4kzV21/y/X71Ud+Q6qoV4iWVtcFVAyqWjIBh8M=;
        b=LX6ZKR7tvEyFlqmnoeByt/2JabLPKTRXwLyTdieYlX3NHOZvqZNXtUwVNvWN0L0AI6
         SBehrrPplckZjg2MBEM3bUA8dMQt9a+sGwYwAdmOaXxQgz0GvNZVo44Nrm4oU8BhgxUs
         OeNGNQqFfXAyVm3hMJojeuMSBOBDDPPXFFWRE6MspTiASNmrtG2z2LLsJchx//s1kqAq
         RoNqSrhizOg3rYTgMBoMSm+roxUa9ooQhatLZQPq+AnmX3t4r2M0kBxHEDWe732kVMiY
         wpSpXOk8iR44WE4q4HA6DoEJLkIOUlw9i28e/WCF+2+BcqlF4mOpSe7CaQY8jGre8IqN
         AUbw==
X-Gm-Message-State: ALQs6tBExXl3S3kUGoUHei2QMsnaIw3PLUDdgqj55htnU1Q8GFxgvyo6
        AJUb4uEtJZbg2XumMTwywbdxyJKh8ks=
X-Google-Smtp-Source: AIpwx48qxyYYwhjjFyvT4tkwl9mBKGTFRb+LlFmhaNPIVKtB+ofnbZzVsuy13dBv6N7mVsnSEq6oSQ==
X-Received: by 2002:a19:4e5d:: with SMTP id c90-v6mr20206367lfb.98.1523231913344;
        Sun, 08 Apr 2018 16:58:33 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id x4-v6sm3108742lfa.23.2018.04.08.16.58.32
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 16:58:32 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v13 3/4] ref-filter: factor ref_array pushing into its own function
Date:   Mon,  9 Apr 2018 01:58:14 +0200
Message-Id: <20180408235815.36582-3-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180408235815.36582-1-haraldnordgren@gmail.com>
References: <20180408235815.36582-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

In preparation for callers constructing their own ref_array
structs, let's move our own internal push operation into its
own function.

While we're at it, we can replace REALLOC_ARRAY() with
ALLOC_GROW(), which should give the growth operation
amortized linear complexity (as opposed to growing by one,
which is potentially quadratic, though in-place realloc
growth often makes this faster in practice).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 ref-filter.c | 16 +++++++++++++---
 ref-filter.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index c1c3cc948..6e9328b27 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1840,6 +1840,18 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
 	return ref;
 }
 
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid)
+{
+	struct ref_array_item *ref = new_ref_array_item(refname, oid);
+
+	ALLOC_GROW(array->items, array->nr + 1, array->alloc);
+	array->items[array->nr++] = ref;
+
+	return ref;
+}
+
 static int ref_kind_from_refname(const char *refname)
 {
 	unsigned int i;
@@ -1930,13 +1942,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid);
+	ref = ref_array_push(ref_cbdata->array, refname, oid);
 	ref->commit = commit;
 	ref->flag = flag;
 	ref->kind = kind;
 
-	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
-	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
 	return 0;
 }
 
diff --git a/ref-filter.h b/ref-filter.h
index 68268f9eb..76cf87cb6 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -135,4 +135,12 @@ void setup_ref_filter_porcelain_msg(void);
 void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
+/*
+ * Push a single ref onto the array; this can be used to construct your own
+ * ref_array without using filter_refs().
+ */
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid);
+
 #endif /*  REF_FILTER_H  */
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id C42F41F404
	for <e@80x24.org>; Mon,  9 Apr 2018 00:09:59 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752061AbeDIAJ5 (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 20:09:57 -0400
Received: from mail-oi0-f52.google.com ([209.85.218.52]:40015 "EHLO
        mail-oi0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751587AbeDIAJ4 (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 20:09:56 -0400
Received: by mail-oi0-f52.google.com with SMTP id x9-v6so5996816oig.7
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 17:09:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=Odlthl61TbY26TQmCyTXgTyIXnvIOw5OILvlMnYIaW8=;
        b=kWIsB8qKL+jtSVc/nyX0fO15gkpnirl48bubClVmFlOOE+VB65kATB+VVloQ4+9l8d
         sa7YU9Rdel3LAijfhJaAlrFCmK3ji7J7Cc4DsSS+SY1aHgIBfrLeFrxgKWxWcN5InQwY
         /wyM89VJLtvppnpNsEfZQdlwU8TSyu6f2sDlon64i3G4hg8eRqwIboAAZO3J35wCQz2U
         zCRuYfBLn5TXo+5/q8AHjRY2wtv72LIOAV0qQWlijdMQD2VYG8IEfQvZE7uyNudKltyg
         lgk4TdJ2wg/r/eoy7++UmdRPUe03F3KiXucwvFGUbjPdEmgu7TooIsjrELlPY9EN39IW
         kd+A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=Odlthl61TbY26TQmCyTXgTyIXnvIOw5OILvlMnYIaW8=;
        b=KT3/UOyHO2k4K39BzAef+q8bePimpoNHuBGYzUr24eYUpJT8B+8X99dNPlj26DfNqX
         eY0+kCxgNUsMaY+4qHS3C4h+aiUMi7ng1MEn21jNgNw1NEDxjtDr4F4B+PgM4E/lVHVh
         quKLPJanX2XKezBqKIouq4zVQpjMdMrvg0lJKMvg8TyFLNMTu0Bca4ZdVqoa6RawQvLf
         +NzguYUaWjrAzThH6TVVLftDj0zgSKWgF+Dpru7qxDPsV/FftfVG3PJc6Cl2uU/3dgHC
         sHoqqwOit78eBmE93NWXXK1Oa3lFQyb8JHdUsr63SY7xdNSm1Oik7ayayzwii5XZuoSV
         Gbnw==
X-Gm-Message-State: ALQs6tC5tBTrRDBKoFv5b6ZChvM9oRmA4//nN3WHcQNYt6oSX0we/84S
        RHozfVCLCh45A0oRlfDvlsErDXHdhkJacQCDBnw=
X-Google-Smtp-Source: AIpwx4+HnG23zJ+zhNnf+RDC79zHtSVEaQuy/SRCv+sG68UV2I1tnEAnW2F6Kp7Zjh7v0JT4vG/zdzaSYDfqMwOYWqc=
X-Received: by 2002:aca:f13:: with SMTP id 19-v6mr21209280oip.298.1523232595976;
 Sun, 08 Apr 2018 17:09:55 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Sun, 8 Apr 2018 17:09:15 -0700 (PDT)
In-Reply-To: <xmqq7eph9wds.fsf@gitster-ct.c.googlers.com>
References: <20180408122832.65414-1-haraldnordgren@gmail.com>
 <20180402005248.52418-1-haraldnordgren@gmail.com> <20180408122832.65414-4-haraldnordgren@gmail.com>
 <xmqq7eph9wds.fsf@gitster-ct.c.googlers.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Mon, 9 Apr 2018 02:09:15 +0200
Message-ID: <CAHwyqnWe=KmmdGJJ_DnCK+D_FoC0sAQG_8=_p+4+Yxmr8s8sPA@mail.gmail.com>
Subject: Re: [PATCH v12 4/4] ls-remote: create '--sort' option
To:     Junio C Hamano <gitster@pobox.com>
Cc:     Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>,
        Eric Sunshine <sunshine@sunshineco.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Mon, Apr 9, 2018 at 12:16 AM, Junio C Hamano <gitster@pobox.com> wrote:
>
> I can connect "because it deals only with remotes" and "access to
> the object may fail", but I wonder if we can clarify the former a
> bit better to make it easier to understand for those who are not yet
> familiar with Git.
>
>     Keys like `committerdate` that require access to the object will
>     not work [***HOW??? Do we get a segfault or something???***] for
>     refs whose objects have not yet been fetched from the remote.
>
> I added "for refs whose objects have not yet been fetched", whose
> explicit-ness made "will not work" to be an OK expression, but
> without it I would have suggested to rephrase it to "may not work".
>
> This is a tangent but I suspect that the description of --sort in
> git-for-each-ref documentation is wrong on the use of multiple
> options, or I am misreading parse_opt_ref_sorting(), which I think
> appends later keys to the end of the list, and compare_refs() which
> I think yields results when an earlier key in the last decides two
> are not equal and ignores the later keys.  The commit that added the
> description was c0f6dc9b ("git-for-each-ref.txt: minor
> improvements", 2008-06-05), and I think even back then the code in
> builtin-for-each-ref.c appended later keys at the end, and it seems
> nobody complained, so it is possible I am not reading the code right
> before fully adjusting to timezone change ;-)

Updated the docs.

>
> It is not too big a deal, but I find that liberal sprinkling of
> UNLEAK() is somewhat unsightly.  From the code we leave with this
> change, it is clear what we'd need to do when we make the code fully
> leak-proof (i.e. we'd have a several lines to free resources held by
> these two variables here, and then UNLEAK() that appear earlier in
> the function will become a "goto cleanup;" after setting appropriate
> value to "status"), so let's not worry about it.

Removed the "extra" unleak annotations within the if-return blocks,
but kept them at the end.

> Please do *NOT* step outside the pair of single quotes that protects
> the body of the test scriptlet and execute commands like "git
> rev-parse".  These execute in order to prepare the command line
> argument strings BEFORE test_expect_success can run (or the test
> framework decides if the test will be skipped via GIT_TEST_SKIP).
>
> Instead do it like so:
>
>         cat >expect <<-EOF &&
>         $(git rev-parse mark)   refs/tags/mark
>         $(git rev-parse mark1.1)        refs/tags/mark1.1
>         $(git rev-parse mark1.2)        refs/tags/mark1.2
>         $(git rev-parse mark1.10)       refs/tags/mark1.10
>         EOF
>
> I.e. the end token for << that is not quoted allows $var and $(cmd)
> to be substituted.
>
> Same comment applies throughout the remainder of this file.

Ah, thanks! I was looking for some way to allow the values to expand
within the proper test context.

So turns out '<<-\EOF' vs '<<-EOF' makes all the difference :)

> Other than that, this patch was a very pleasant read.  Thanks.

Thank you!

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 764D51F404
	for <e@80x24.org>; Mon,  9 Apr 2018 00:49:02 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1757133AbeDIAs6 (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 20:48:58 -0400
Received: from mail-wm0-f49.google.com ([74.125.82.49]:39908 "EHLO
        mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1757128AbeDIAs4 (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 20:48:56 -0400
Received: by mail-wm0-f49.google.com with SMTP id f125so12800041wme.4
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 17:48:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
         :user-agent:mime-version;
        bh=IP8Qs4qc+qIHNsm73E9GY2XFnvX0AQaId8kF3pRrkb0=;
        b=IetKAbK2M83RowKZECu6Zlmi9/dDDWTen58YbVWmg5gLfw9TKzFpiGkxGnIF+puv0E
         TW6jE/1eWsgpoYLDmTMwKLhUXJWIkYVna5mF7324uNJhrRiTublu2YETGwVxjxdZ/H40
         KOqQXekqf3RGTZw4wMDFeyRmOQLRwAifU21d+jJs9sKYzO+czsdJP7z27Fc7VwF85FNQ
         gu/kZRIuFaOCBfi6mnqUPoy1veHKP9smoeqP+X6NtcnvedCAtwg9cQQve71hQcb8ibD8
         Fj2hlanq45gZCjmM4l6l2KWpM+sxM5jBXLOpiK+sZLtpDSlMXuZx2uPW3kEwmQV77BVq
         u92A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:sender:from:to:cc:subject:references:date
         :in-reply-to:message-id:user-agent:mime-version;
        bh=IP8Qs4qc+qIHNsm73E9GY2XFnvX0AQaId8kF3pRrkb0=;
        b=axhKjgXeMvTVQpz/FTyrhbuG7BUcMk8ufPT+sA+mHXQwHrMYPVxwirW9vUxylvgH9u
         M6xL9NpsU8RHLc23CYkWhk+8NkVhQ61Gy9xkO3/GHxDSjrBjyzK+i+Zj0HHvzNk/J0SQ
         Vm51MAHB6uWxAQup5eyfxXcrpiVnROGlHNRnpPoiadIrZjw/U1rmy5+jO5U7b05Ntd2/
         UNMiepY6TSw/X0WlmE9sFuQvxudRQKS404zvDKNV/ejEljnsnQey0mkQ89AjK9tAJoji
         Cv2kLk+tuVa6txl0FLNrz7WAswbFCH2UqTyl+NR8MIUUT+pAcyIBnClWR4Q1Hbpxxnar
         NyDQ==
X-Gm-Message-State: AElRT7GomVrTcsZRibj74fTzP+Hxt3RqJKHdFDJQ3KWybmiXDFHBSYfe
        t8xXhXGuxhciOrEbwC3Pb5Y=
X-Google-Smtp-Source: AIpwx49+TgbjXFmGHj75jW3EiZopSZNhh7is6TICFW5uq+ULR0X+5wx5aBWxWkY4ayXQNr9u3PRK8g==
X-Received: by 10.28.110.17 with SMTP id j17mr21179741wmc.65.1523234935305;
        Sun, 08 Apr 2018 17:48:55 -0700 (PDT)
Received: from localhost (112.68.155.104.bc.googleusercontent.com. [104.155.68.112])
        by smtp.gmail.com with ESMTPSA id j4sm14994024wrd.53.2018.04.08.17.48.54
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Sun, 08 Apr 2018 17:48:54 -0700 (PDT)
From:   Junio C Hamano <gitster@pobox.com>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     Git List <git@vger.kernel.org>,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Jeff King <peff@peff.net>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v12 4/4] ls-remote: create '--sort' option
References: <20180408122832.65414-1-haraldnordgren@gmail.com>
        <20180402005248.52418-1-haraldnordgren@gmail.com>
        <20180408122832.65414-4-haraldnordgren@gmail.com>
        <xmqq7eph9wds.fsf@gitster-ct.c.googlers.com>
        <CAHwyqnWe=KmmdGJJ_DnCK+D_FoC0sAQG_8=_p+4+Yxmr8s8sPA@mail.gmail.com>
Date:   Mon, 09 Apr 2018 09:48:54 +0900
In-Reply-To: <CAHwyqnWe=KmmdGJJ_DnCK+D_FoC0sAQG_8=_p+4+Yxmr8s8sPA@mail.gmail.com>
        (Harald Nordgren's message of "Mon, 9 Apr 2018 02:09:15 +0200")
Message-ID: <xmqqmuyd6w7d.fsf@gitster-ct.c.googlers.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Harald Nordgren <haraldnordgren@gmail.com> writes:

>> It is not too big a deal, but I find that liberal sprinkling of
>> UNLEAK() is somewhat unsightly.  From the code we leave with this
>> change, it is clear what we'd need to do when we make the code fully
>> leak-proof (i.e. we'd have a several lines to free resources held by
>> these two variables here, and then UNLEAK() that appear earlier in
>> the function will become a "goto cleanup;" after setting appropriate
>> value to "status"), so let's not worry about it.
>
> Removed the "extra" unleak annotations within the if-return blocks,
> but kept them at the end.

I actually think that is worse.  The UNLEAK()s near early-return
serve to remind us: "here we are making early return and when we
properly plug the leak, here is one of the places we need to fix".
Please keep them, unless (and I do not recommend to do this) you are
plugging the leaks for real.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 1DAA91F404
	for <e@80x24.org>; Mon,  9 Apr 2018 00:56:57 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S933617AbeDIA4x (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 20:56:53 -0400
Received: from mail-wm0-f67.google.com ([74.125.82.67]:33222 "EHLO
        mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S933442AbeDIA4w (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 20:56:52 -0400
Received: by mail-wm0-f67.google.com with SMTP id o23so15283659wmf.0
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 17:56:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
         :user-agent:mime-version;
        bh=+awndxW2JZzqytYazxTWFd/IDlO8g/BOy278HoeSFyk=;
        b=SsLyq7zgkSAJz+B+Rz2yfJ9soLSgqx1chKYVJcv5vB6gO8QCv1dnkDFqwN2z5RKuFe
         qoQiPdf+NBraaxdcjaTv5RjYItvIOP+ZmslgxOJ/sG9E4f4/N70LsJiIlxUIYdlnj6hl
         ZR9SI0VDwta8G6uTu2a+eZP/HV7XI3DAW/m0lZr1lM6Rp0U2um9/t8SxyX7RiAa6Y7G9
         8BvvbSD57FxYSaaCCke+4YIZE0ylPIKt6wjeEYia3WVElykYGdnBgcrbW7QEKrkIZKTf
         pkFhIL7fvuUOUDTZI77pU47A8W3rbEpAOo5Wn7h6Urw45fUP0lqFbqB322GZ7s7hVNaD
         ESOQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:sender:from:to:cc:subject:references:date
         :in-reply-to:message-id:user-agent:mime-version;
        bh=+awndxW2JZzqytYazxTWFd/IDlO8g/BOy278HoeSFyk=;
        b=AqM6GJhEGhBa9742B2XbDwV37qlbF5RRlS2VIKxwF9Igy6Mn1gXXzoogwx+7RtyKd8
         o/uDFXfyfXmXTYKtbbGw+8Y7lSC4os+kCoUhFtmPP0NKSJXmB9o/Qm/Zw3brUIy6L0Tp
         Nwbo7ln0Lw0cgpL+urLaR8U9rFpNn6rrouGEyWtg1KPGFyopIV5i9C4dASExXMNIKXu1
         kxqanNWD/x5UI5+/P82SJESpaKEW8jMEDyCWKqqELPayvnydUoWC1/QBXn+3BG5FlHUk
         RA0fpimPA72xCwstA3zjPwQabItcYc4AbGMx+O/dBLQ6dIxGI2EhK+giuENDTaQfXkJy
         54EQ==
X-Gm-Message-State: AElRT7E/K1n8xkbD+ylnSAJ0Y/zQoJcNPVsFeBEst4K3p1ysUPin+kyJ
        wR6ZMhMMwS2Az4D/98qXNM4=
X-Google-Smtp-Source: AIpwx49yxB5y2lsAq+Y47Efec23yMyhfKHPx0j9Rvty19kb798kZtYJmWsQ1qH2ZoWhXh0QRXqlKvg==
X-Received: by 10.28.110.17 with SMTP id j17mr21191187wmc.65.1523235410620;
        Sun, 08 Apr 2018 17:56:50 -0700 (PDT)
Received: from localhost (168.50.187.35.bc.googleusercontent.com. [35.187.50.168])
        by smtp.gmail.com with ESMTPSA id 19sm22663905wmv.18.2018.04.08.17.56.49
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Sun, 08 Apr 2018 17:56:50 -0700 (PDT)
From:   Junio C Hamano <gitster@pobox.com>
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        sunshine@sunshineco.com
Subject: Re: [PATCH v13 4/4] ls-remote: create '--sort' option
References: <20180408235815.36582-1-haraldnordgren@gmail.com>
        <20180402005248.52418-1-haraldnordgren@gmail.com>
        <20180408235815.36582-4-haraldnordgren@gmail.com>
Date:   Mon, 09 Apr 2018 09:56:49 +0900
In-Reply-To: <20180408235815.36582-4-haraldnordgren@gmail.com> (Harald
        Nordgren's message of "Mon, 9 Apr 2018 01:58:15 +0200")
Message-ID: <xmqqin916vu6.fsf@gitster-ct.c.googlers.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Harald Nordgren <haraldnordgren@gmail.com> writes:

> Create a '--sort' option for ls-remote, based on the one from
> for-each-ref. This e.g. allows ref names to be sorted by version
> semantics, so that v1.2 is sorted before v1.10.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---

Thanks.

> +--sort=<key>::
> +	Sort based on the key given. Prefix `-` to sort in descending order
> +	of the value. Supports "version:refname" or "v:refname" (tag names
> +	are treated as versions). The "version:refname" sort order can also
> +	be affected by the "versionsort.suffix" configuration variable.
> +	See linkgit:git-for-each-ref[1] for more sort options, but be aware
> +	that because `ls-remote` deals only with remotes, keys like
> +	`committerdate` that requires access to the objects themselves will
> +	not work for refs whose objects have not yet been fetched from the
> +	remote.

With the update since v12, I think "because `ls-remote` deals only
with remotes," can be dropped entirely, and still convey what needs
to be told: "Be aware some keys that needs access to objects that
are not here won't work".

Instead, it is probably a better idea to spend that half-line worth
of characters to describe in what way they do not work (do they try
to deref a NULL pointer and dump core?  do they notice we need
missing objects and give an error?).

> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
> index 540d56429..b5ca67167 100644
> --- a/builtin/ls-remote.c
> +++ b/builtin/ls-remote.c

As I said earlier, let's keep these extra UNLEAK() near early
return; they point developers at the places that needs future work.

Thanks.



diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index b5ca67167d..d3851074c2 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -98,6 +98,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 
 	if (get_url) {
 		printf("%s\n", *remote->url);
+		UNLEAK(sorting);
 		return 0;
 	}
 
@@ -106,8 +107,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
 
 	ref = transport_get_remote_refs(transport);
-	if (transport_disconnect(transport))
+	if (transport_disconnect(transport)) {
+		UNLEAK(sorting);
 		return 1;
+	}
 
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);



From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.6 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 3DE141F404
	for <e@80x24.org>; Mon,  9 Apr 2018 01:42:52 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S932953AbeDIBmt (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 21:42:49 -0400
Received: from mail-wm0-f66.google.com ([74.125.82.66]:38120 "EHLO
        mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S932520AbeDIBmn (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 21:42:43 -0400
Received: by mail-wm0-f66.google.com with SMTP id i3so12959646wmf.3
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 18:42:42 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=X8YoKxMRjxPUNYvAckl51qp3Zpnob1shYxxfJiEG3iQ=;
        b=DdVtOme1n0a0wl0JwnkeBJZ/YkK2ft6r2r1pY95nYUr+vvctA80UNQGS37AA10neRl
         X6aNUkG517Dc36PK+Le5ajRRdqVzmW3Id9GXKahfvRZdn4QqZAHJCiM3Hn4TWtWNwc8b
         VcKg2BjuSvyAnpffTtWrzF5Yc8Whi+XyPeN1Asf5RAk5+QDDD5zLaPFsNkR8ElH/LsaB
         x2mdHY0C1GNEO7zOEU4u9nHh2qv1ZHDYPT7hD9lV9aFRqfSHoz3UtrtQ6Q8Aj+5sFQm7
         bG89EKLdCFFJbQG+Apt9ysxqMBzquEHTDz9Gp/Vwgy/Duka/1vNnT0J0YhiXAWjiW3sv
         6nNQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=X8YoKxMRjxPUNYvAckl51qp3Zpnob1shYxxfJiEG3iQ=;
        b=Hqi1XwbcFg4S19q0XGZNxiZKDb2DtjaP94RTMuUrkadeODx8Bq/W3L82ZsXu2BM0EH
         UQui5j34wl/NZEBZEEjA62h65ZEyNTC4hVZyGat4tY9rF5idoCHLVvPBZ7cdIuhGphuP
         7doD1ww+SBvCayrNX1LoW1Siy3aV3ZoFWJqaQ4BE7Etyony5szmGSCuZ8lMlh//VHooT
         KqM0mGQyHvTbyY/+anc87gQGtTbZ2yveNlCJcFuvMhAjZHGDbA9c+8ccT1+tpUSqqn72
         vW8UQPS2KHeTtnPlJjYzPafK7/nQ9xp6ksB6zh78m73sR5hpdr/X2shaOqjxRzJ3MdGc
         +5RA==
X-Gm-Message-State: AElRT7EXHT/uBdTtJDUBtp5So0OMWVceKbW0idXsp3eXeRpIhX0hu44D
        z6x0LF70WQmExktflOcYAb4XoEgCc50=
X-Google-Smtp-Source: AIpwx4+TynliSu/PlchbjCz8elDytLv8ay+jmjgAEJByKZA5HV0JVRyCH7G/2HrfQbQYbujN0p9Q1w==
X-Received: by 10.46.64.26 with SMTP id n26mr20929831lja.50.1523238161540;
        Sun, 08 Apr 2018 18:42:41 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id n62-v6sm3197231lfi.4.2018.04.08.18.42.39
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 18:42:40 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v14 1/4] ref-filter: use "struct object_id" consistently
Date:   Mon,  9 Apr 2018 03:42:23 +0200
Message-Id: <20180409014226.2647-1-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

Internally we store a "struct object_id", and all of our
callers have one to pass us. But we insist that they peel it
to its bare-sha1 hash, which we then hashcpy() into place.
Let's pass it around as an object_id, which future-proofs us
for a post-sha1 world.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 builtin/tag.c        |  2 +-
 builtin/verify-tag.c |  2 +-
 ref-filter.c         | 10 +++++-----
 ref-filter.h         |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index da186691e..42278f516 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -117,7 +117,7 @@ static int verify_tag(const char *name, const char *ref,
 		return -1;
 
 	if (format->format)
-		pretty_print_ref(name, oid->hash, format);
+		pretty_print_ref(name, oid, format);
 
 	return 0;
 }
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index ad7b79fa5..6fa04b751 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -72,7 +72,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 		}
 
 		if (format.format)
-			pretty_print_ref(name, oid.hash, &format);
+			pretty_print_ref(name, &oid, &format);
 	}
 	return had_error;
 }
diff --git a/ref-filter.c b/ref-filter.c
index 45fc56216..ade97a848 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1826,12 +1826,12 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 
 /* Allocate space for a new ref_array_item and copy the objectname and flag to it */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const unsigned char *objectname,
+						 const struct object_id *oid,
 						 int flag)
 {
 	struct ref_array_item *ref;
 	FLEX_ALLOC_STR(ref, refname, refname);
-	hashcpy(ref->objectname.hash, objectname);
+	oidcpy(&ref->objectname, oid);
 	ref->flag = flag;
 
 	return ref;
@@ -1927,7 +1927,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid->hash, flag);
+	ref = new_ref_array_item(refname, oid, flag);
 	ref->commit = commit;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
@@ -2165,11 +2165,11 @@ void show_ref_array_item(struct ref_array_item *info,
 	putchar('\n');
 }
 
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, sha1, 0);
+	ref_item = new_ref_array_item(name, oid, 0);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
diff --git a/ref-filter.h b/ref-filter.h
index 0d98342b3..68268f9eb 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -132,7 +132,7 @@ void setup_ref_filter_porcelain_msg(void);
  * Print a single ref, outside of any ref-filter. Note that the
  * name must be a fully qualified refname.
  */
-void pretty_print_ref(const char *name, const unsigned char *sha1,
+void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
 #endif /*  REF_FILTER_H  */
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.6 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 8FC0E1F404
	for <e@80x24.org>; Mon,  9 Apr 2018 01:42:55 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S932932AbeDIBms (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 21:42:48 -0400
Received: from mail-wm0-f67.google.com ([74.125.82.67]:34703 "EHLO
        mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S932909AbeDIBmo (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 21:42:44 -0400
Received: by mail-wm0-f67.google.com with SMTP id w2so15434669wmw.1
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 18:42:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=14dDpLUz/O8Jo87ZEY1u02btoPmxPBcw8Y4WaAc1l9E=;
        b=ccNFibnaehsLrr7pYvSv3fflVD5LoIaqQmZrH57EXMfjPBT6K3aSANCLChhrN+5gme
         2o/dcpkVezZfF8zX4CPPE7aA25awVRGdYwjTKq4lGqnSLxMSdm8+Xn/5SacOmXouPk1J
         iPelipgt/q79bXC7dRcKGpJRnewEdgcbfpjtxYlUbXwreBqVpdy1MN8r5OaY/rjmJc4Q
         /ZY0PpBwBTIvA7FcGRlCw87H5SjYFpAzKVvdI7BLc/q26g5YC17kcr3T7Za3ENFwQ8n1
         /Zv7DzKYppF7vV16ZJ+XoLBTqpbXOLgUJfjsi2dMYBgcaRSLNBxJacFwDx1l4tNKH+aV
         B88A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=14dDpLUz/O8Jo87ZEY1u02btoPmxPBcw8Y4WaAc1l9E=;
        b=gASz6yMuEHST/scCnaBibYgZ+o731XEqMmLYbYTCPdc9SMx19B3Eo0DJuTqO1r7jlE
         bqKsHpUZ7LDTb30mFTG/6TeLhNgxQ5ckA1ImgrBID3wXR+NlaPVtJfYuO7rgPMeVWYvV
         KXxaA0nBsZs895GPVO5rv2yAQYL4b/XejRRl9rYRM71S63Yf2q9B+3N0sScbYJtQCtt8
         hV1yHFYqhmLFR+J2YiR2WkYwn2WhphBdhWqKuyNLJ8Eoq11tofhsnq54FQKHeDQY2P77
         eB1gJAC7JAxfVeJSoJnopLEKN2wD5GRDTA90GKyFlQDv1OWbAlXkYVSoOZy3ma3Kfelk
         9quw==
X-Gm-Message-State: AElRT7HCyvOVHcRwUcu668cI016+u39MR8rKF/hB7TvXFd+ZDHZrfeP9
        6/gNk3ABHpyUjymqiIW2dzlTMrVH+VA=
X-Google-Smtp-Source: AIpwx4/uv/6I6aTlJppsk7Hub9vnCs5PgzvHWg9MNxW5a/ALg1B7vPQh7i3LcAd+A31kORUlZT7etA==
X-Received: by 10.46.154.71 with SMTP id k7mr21044354ljj.42.1523238162934;
        Sun, 08 Apr 2018 18:42:42 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id n62-v6sm3197231lfi.4.2018.04.08.18.42.41
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 18:42:42 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v14 2/4] ref-filter: make ref_array_item allocation more consistent
Date:   Mon,  9 Apr 2018 03:42:24 +0200
Message-Id: <20180409014226.2647-2-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180409014226.2647-1-haraldnordgren@gmail.com>
References: <20180409014226.2647-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

We have a helper function to allocate ref_array_item
structs, but it only takes a subset of the possible fields
in the struct as initializers. We could have it accept an
argument for _every_ field, but that becomes a pain for the
fields which some callers don't want to set initially.

Instead, let's be explicit that it takes only the minimum
required to create the ref, and that callers should then
fill in the rest themselves.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 ref-filter.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index ade97a848..c1c3cc948 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 	return NULL;
 }
 
-/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
+/*
+ * Allocate space for a new ref_array_item and copy the name and oid to it.
+ *
+ * Callers can then fill in other struct members at their leisure.
+ */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-						 const struct object_id *oid,
-						 int flag)
+						 const struct object_id *oid)
 {
 	struct ref_array_item *ref;
+
 	FLEX_ALLOC_STR(ref, refname, refname);
 	oidcpy(&ref->objectname, oid);
-	ref->flag = flag;
 
 	return ref;
 }
@@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid, flag);
+	ref = new_ref_array_item(refname, oid);
 	ref->commit = commit;
+	ref->flag = flag;
+	ref->kind = kind;
 
 	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
 	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
-	ref->kind = kind;
 	return 0;
 }
 
@@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format)
 {
 	struct ref_array_item *ref_item;
-	ref_item = new_ref_array_item(name, oid, 0);
+	ref_item = new_ref_array_item(name, oid);
 	ref_item->kind = ref_kind_from_refname(name);
 	show_ref_array_item(ref_item, format);
 	free_array_item(ref_item);
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.6 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 2AD021F404
	for <e@80x24.org>; Mon,  9 Apr 2018 01:42:56 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S932944AbeDIBmr (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 21:42:47 -0400
Received: from mail-wm0-f65.google.com ([74.125.82.65]:39865 "EHLO
        mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S932921AbeDIBmp (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 21:42:45 -0400
Received: by mail-wm0-f65.google.com with SMTP id f125so12951525wme.4
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 18:42:45 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=QKcry4kzV21/y/X71Ud+Q6qoV4iWVtcFVAyqWjIBh8M=;
        b=NWM1ao2b8XJJdpZhT8EQxHP6YsexVtQQROF0nrk7agVXeP5Z0JFJ8FbdJoJjPz+8mN
         nrt7sRoplebk+lAv/QKvCw5FJ6LKdyAgMz8DqxD7s1CshhvLkjFaYAOCUF7f1Z8fpxm8
         kCcyjZYuSsqYL54Gy0T0JkKyrL+2wFFbQ0q7FJDhY1//tzXHk5XtkawRE0po5mUbPNXe
         ovJwLRuJrpuUoUmx40cFBbls0+YnPAIF31VfWcsEYXWT3KsoqYL+2kf+f8DpUeCV8Qz+
         yssbhv2nQjlyyl9a1MSlGP7T4vxtPk2P/Kgsdi/7ja+7XyNwIm0uurP5MHebyq3ojLEE
         tJrA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=QKcry4kzV21/y/X71Ud+Q6qoV4iWVtcFVAyqWjIBh8M=;
        b=s5tfEakglDPqeQcUSOWqCRa1kc/Q6kQpVfIzUltyXBkifw3u/Zy8VjdTxeCPL1RRQY
         SuKNSaF5sFgRVHz9VqjoU/G78PO2Bn/swdM3cyGKBAGzTWrt4Ty76NYXxkm4xA1u++k9
         nEE90zBJmmqwiIlRZoRn29gHnvuONAZR/4OwF+s5FbbhheQXZjeaSw6zwnHRd6dUfcL+
         kXUpDo4j6gK8FrJa/llheEIsxROWVNRN7T14lOMt8cdr62+TO4iTtQVTYPfmD9ZCu6gg
         NAKib9qeTUbhkwU7xLkluZyOgGv/vfIQuUqMAc9uYk0c4yMTqx66agJBTIqGmmd1s8J4
         CrfA==
X-Gm-Message-State: ALQs6tCk6B5NWASX9iTpwB5loULCtR1APcTK9yQoqrNogYSdcE3zOtls
        p8futC1KtgZdhD8K6BIcBDue7pNgwjg=
X-Google-Smtp-Source: AIpwx49sa6Tf73gRNf1NGj2MukeEf26t/VpVggg4269Jg/eT+oEP+Ve2Ts/HpusJ4qkXLhzzOZC63Q==
X-Received: by 10.46.84.93 with SMTP id y29mr20554078ljd.11.1523238164142;
        Sun, 08 Apr 2018 18:42:44 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id n62-v6sm3197231lfi.4.2018.04.08.18.42.43
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 18:42:43 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v14 3/4] ref-filter: factor ref_array pushing into its own function
Date:   Mon,  9 Apr 2018 03:42:25 +0200
Message-Id: <20180409014226.2647-3-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180409014226.2647-1-haraldnordgren@gmail.com>
References: <20180409014226.2647-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

From: Jeff King <peff@peff.net>

In preparation for callers constructing their own ref_array
structs, let's move our own internal push operation into its
own function.

While we're at it, we can replace REALLOC_ARRAY() with
ALLOC_GROW(), which should give the growth operation
amortized linear complexity (as opposed to growing by one,
which is potentially quadratic, though in-place realloc
growth often makes this faster in practice).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 ref-filter.c | 16 +++++++++++++---
 ref-filter.h |  8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index c1c3cc948..6e9328b27 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1840,6 +1840,18 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
 	return ref;
 }
 
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid)
+{
+	struct ref_array_item *ref = new_ref_array_item(refname, oid);
+
+	ALLOC_GROW(array->items, array->nr + 1, array->alloc);
+	array->items[array->nr++] = ref;
+
+	return ref;
+}
+
 static int ref_kind_from_refname(const char *refname)
 {
 	unsigned int i;
@@ -1930,13 +1942,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 	 * to do its job and the resulting list may yet to be pruned
 	 * by maxcount logic.
 	 */
-	ref = new_ref_array_item(refname, oid);
+	ref = ref_array_push(ref_cbdata->array, refname, oid);
 	ref->commit = commit;
 	ref->flag = flag;
 	ref->kind = kind;
 
-	REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
-	ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
 	return 0;
 }
 
diff --git a/ref-filter.h b/ref-filter.h
index 68268f9eb..76cf87cb6 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -135,4 +135,12 @@ void setup_ref_filter_porcelain_msg(void);
 void pretty_print_ref(const char *name, const struct object_id *oid,
 		      const struct ref_format *format);
 
+/*
+ * Push a single ref onto the array; this can be used to construct your own
+ * ref_array without using filter_refs().
+ */
+struct ref_array_item *ref_array_push(struct ref_array *array,
+				      const char *refname,
+				      const struct object_id *oid);
+
 #endif /*  REF_FILTER_H  */
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.6 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id E07171F404
	for <e@80x24.org>; Mon,  9 Apr 2018 01:42:57 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S932909AbeDIBmz (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 21:42:55 -0400
Received: from mail-wm0-f65.google.com ([74.125.82.65]:53437 "EHLO
        mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S932933AbeDIBmr (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 21:42:47 -0400
Received: by mail-wm0-f65.google.com with SMTP id 66so8719328wmd.3
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 18:42:46 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references
         :in-reply-to:references;
        bh=qSVTKpjfalkJPvElj6z34aEX0nJl2qpsL//Ip9zUaNw=;
        b=m7F2iPz5meAZ+/pW0zh37hAJovlExVL5aFT8CMQTo3Yrd2d/4uASpy2Vz3B98fVt9T
         8s7y9K3WwAwQvhICvpmH2pAebd87ed7+bemsP4ElTIX7RxYiK3KCnS0fMgM8fB2k9CV9
         w36AlUrYiW118gixaQdqPq9wjsHC6GiFzN5sIkB/FjfSoQwke6aRU7qiZ38Yeu2JHRgI
         7mbY2FSVTP7e6G4qEuuSxL21gpPOgjX//2OttrX74kwpvcTh7lae4YadiX4MTfswOCPk
         p0N8Ei9GZbgI4AcbhICmxCi8VXYIV0t3cHKIh04opePkQBuLefPXGgJlAqFlsZreZ2Sx
         ndlQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references:in-reply-to:references;
        bh=qSVTKpjfalkJPvElj6z34aEX0nJl2qpsL//Ip9zUaNw=;
        b=ggDO88WR269lpST69G6cYJe6LYcIjDCyD2UQOtK8CxrUe+rTJD9AR3DbYct1KNulrn
         iICUMEWxOyiicTaJ36G+dqOSqjJwORcU2Du6ZxtS7u4Bw/kJAXEu7hIEzrnNi4hd6lC8
         3sfxfIa/wLnfX+MAneyFf3tJbgNBChfsvD2ShFnahSi2tp9engXWo2wBQ4y/Bt0p6uqd
         VsQKWIM+4QY03UN+VckfqEN8WdP5N6TzcM/RYUaO+NsWktOgfz0+5JDbZ1fjiPOaXmHn
         GE6jttOr7ixgDyhIudLCEqDyAMac4zUAMb+f5KS1ys4f8nG8gTzLOQ/CjCPiPCOqgmcT
         +Cyg==
X-Gm-Message-State: ALQs6tAKvw1MWqSqI+9P5Uu14EyY7j7k11Tvn3hwGM9xHZJKsrrCe5L8
        rAaugNT1PNKyJAJMZBAfr0T5qUZdeyE=
X-Google-Smtp-Source: AIpwx48yki3swc1JW4HZyeMFR3vpRaQ5SzgR/4xqUAkPBFB1jpAqCPNrpYwJwnb4wV43WpRMi4q3lg==
X-Received: by 10.46.137.71 with SMTP id b7mr14791476ljk.39.1523238165457;
        Sun, 08 Apr 2018 18:42:45 -0700 (PDT)
Received: from localhost.localdomain ([94.234.37.145])
        by smtp.gmail.com with ESMTPSA id n62-v6sm3197231lfi.4.2018.04.08.18.42.44
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 08 Apr 2018 18:42:44 -0700 (PDT)
From:   Harald Nordgren <haraldnordgren@gmail.com>
To:     git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
        gitster@pobox.com, sunshine@sunshineco.com
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v14 4/4] ls-remote: create '--sort' option
Date:   Mon,  9 Apr 2018 03:42:26 +0200
Message-Id: <20180409014226.2647-4-haraldnordgren@gmail.com>
X-Mailer: git-send-email 2.14.3 (Apple Git-98)
In-Reply-To: <20180409014226.2647-1-haraldnordgren@gmail.com>
References: <20180409014226.2647-1-haraldnordgren@gmail.com>
In-Reply-To: <20180402005248.52418-1-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Create a '--sort' option for ls-remote, based on the one from
for-each-ref. This e.g. allows ref names to be sorted by version
semantics, so that v1.2 is sorted before v1.10.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---

Notes:
    Changes according to Junio Hamano's code review (2)

 Documentation/git-ls-remote.txt | 16 +++++++++++-
 builtin/ls-remote.c             | 28 ++++++++++++++++++---
 t/t5512-ls-remote.sh            | 54 +++++++++++++++++++++++++++++++++++------
 3 files changed, 87 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index 5f2628c8f..6ad1e34af 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
-	      [-q | --quiet] [--exit-code] [--get-url]
+	      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
 	      [--symref] [<repository> [<refs>...]]
 
 DESCRIPTION
@@ -60,6 +60,16 @@ OPTIONS
 	upload-pack only shows the symref HEAD, so it will be the only
 	one shown by ls-remote.
 
+--sort=<key>::
+	Sort based on the key given. Prefix `-` to sort in descending order
+	of the value. Supports "version:refname" or "v:refname" (tag names
+	are treated as versions). The "version:refname" sort order can also
+	be affected by the "versionsort.suffix" configuration variable.
+	See linkgit:git-for-each-ref[1] for more sort options, but be aware
+	keys like `committerdate` that require access to the objects
+	themselves will not work for refs whose objects have not yet been
+	fetched from the remote, and will give a `missing object` error.
+
 <repository>::
 	The "remote" repository to query.  This parameter can be
 	either a URL or the name of a remote (see the GIT URLS and
@@ -90,6 +100,10 @@ EXAMPLES
 	c5db5456ae3b0873fc659c19fafdde22313cc441	refs/tags/v0.99.2
 	7ceca275d047c90c0c7d5afb13ab97efdf51bd6e	refs/tags/v0.99.3
 
+SEE ALSO
+--------
+linkgit:git-check-ref-format[1].
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 540d56429..b26c53670 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "transport.h"
+#include "ref-filter.h"
 #include "remote.h"
 
 static const char * const ls_remote_usage[] = {
@@ -43,10 +44,13 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	int show_symref_target = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
+	int i;
 
 	struct remote *remote;
 	struct transport *transport;
 	const struct ref *ref;
+	struct ref_array ref_array;
+	static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print remote URL")),
@@ -60,6 +64,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
 		OPT_BOOL(0, "get-url", &get_url,
 			 N_("take url.<base>.insteadOf into account")),
+		OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
+			     N_("field name to sort on"), &parse_opt_ref_sorting),
 		OPT_SET_INT_F(0, "exit-code", &status,
 			      N_("exit with exit code 2 if no matching refs are found"),
 			      2, PARSE_OPT_NOCOMPLETE),
@@ -68,6 +74,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	memset(&ref_array, 0, sizeof(ref_array));
+
 	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	dest = argv[0];
@@ -90,6 +98,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 
 	if (get_url) {
 		printf("%s\n", *remote->url);
+		UNLEAK(sorting);
 		return 0;
 	}
 
@@ -98,20 +107,33 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
 
 	ref = transport_get_remote_refs(transport);
-	if (transport_disconnect(transport))
+	if (transport_disconnect(transport)) {
+		UNLEAK(sorting);
 		return 1;
+	}
 
 	if (!dest && !quiet)
 		fprintf(stderr, "From %s\n", *remote->url);
 	for ( ; ref; ref = ref->next) {
+		struct ref_array_item *item;
 		if (!check_ref_type(ref, flags))
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
+		item = ref_array_push(&ref_array, ref->name, &ref->old_oid);
+		item->symref = xstrdup_or_null(ref->symref);
+	}
+
+	if (sorting)
+		ref_array_sort(sorting, &ref_array);
+
+	for (i = 0; i < ref_array.nr; i++) {
+		const struct ref_array_item *ref = ref_array.items[i];
 		if (show_symref_target && ref->symref)
-			printf("ref: %s\t%s\n", ref->symref, ref->name);
-		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
+			printf("ref: %s\t%s\n", ref->symref, ref->refname);
+		printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
 		status = 0; /* we found something */
 	}
+
 	return status;
 }
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 02106c922..83cd35c39 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -10,6 +10,9 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m initial &&
 	git tag mark &&
+	git tag mark1.1 &&
+	git tag mark1.2 &&
+	git tag mark1.10 &&
 	git show-ref --tags -d | sed -e "s/ /	/" >expected.tag &&
 	(
 		echo "$(git rev-parse HEAD)	HEAD"
@@ -39,6 +42,39 @@ test_expect_success 'ls-remote self' '
 	test_cmp expected.all actual
 '
 
+test_expect_success 'ls-remote --sort="version:refname" --tags self' '
+	cat >expect <<-EOF &&
+	$(git rev-parse mark)	refs/tags/mark
+	$(git rev-parse mark1.1)	refs/tags/mark1.1
+	$(git rev-parse mark1.2)	refs/tags/mark1.2
+	$(git rev-parse mark1.10)	refs/tags/mark1.10
+	EOF
+	git ls-remote --sort="version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
+	cat >expect <<-EOF &&
+	$(git rev-parse mark1.10)	refs/tags/mark1.10
+	$(git rev-parse mark1.2)	refs/tags/mark1.2
+	$(git rev-parse mark1.1)	refs/tags/mark1.1
+	$(git rev-parse mark)	refs/tags/mark
+	EOF
+	git ls-remote --sort="-version:refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'ls-remote --sort="-refname" --tags self' '
+	cat >expect <<-EOF &&
+	$(git rev-parse mark1.2)	refs/tags/mark1.2
+	$(git rev-parse mark1.10)	refs/tags/mark1.10
+	$(git rev-parse mark1.1)	refs/tags/mark1.1
+	$(git rev-parse mark)	refs/tags/mark
+	EOF
+	git ls-remote --sort="-refname" --tags self >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'dies when no remote specified and no default remotes found' '
 	test_must_fail git ls-remote
 '
@@ -131,7 +167,7 @@ test_expect_success 'Report no-match with --exit-code' '
 
 test_expect_success 'Report match with --exit-code' '
 	git ls-remote --exit-code other.git "refs/tags/*" >actual &&
-	git ls-remote . tags/mark >expect &&
+	git ls-remote . tags/mark* >expect &&
 	test_cmp expect actual
 '
 
@@ -170,14 +206,18 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
 	grep refs/tags/magic actual
 '
 
+git fetch origin
 test_expect_success 'ls-remote --symref' '
-	cat >expect <<-\EOF &&
+	cat >expect <<-EOF &&
 	ref: refs/heads/master	HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/heads/master
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
-	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
+	$(git rev-parse HEAD)	HEAD
+	$(git rev-parse refs/heads/master)	refs/heads/master
+	$(git rev-parse HEAD)	refs/remotes/origin/HEAD
+	$(git rev-parse refs/remotes/origin/master)	refs/remotes/origin/master
+	$(git rev-parse refs/tags/mark)	refs/tags/mark
+	$(git rev-parse refs/tags/mark1.1)	refs/tags/mark1.1
+	$(git rev-parse refs/tags/mark1.10)	refs/tags/mark1.10
+	$(git rev-parse refs/tags/mark1.2)	refs/tags/mark1.2
 	EOF
 	git ls-remote --symref >actual &&
 	test_cmp expect actual
-- 
2.14.3 (Apple Git-98)


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 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,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 88E551F404
	for <e@80x24.org>; Mon,  9 Apr 2018 01:46:30 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1756612AbeDIBq2 (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 21:46:28 -0400
Received: from mail-ot0-f182.google.com ([74.125.82.182]:33594 "EHLO
        mail-ot0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1756610AbeDIBqY (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 21:46:24 -0400
Received: by mail-ot0-f182.google.com with SMTP id 23-v6so6924439otj.0
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 18:46:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=i+gW5Ca+Fc/Vl/bhw89s2rbKpyiyqXO/L43eu83JcT4=;
        b=I8cHLD/pUoQvCcl+niSNUQr8c7CsGsC24e97fxB9Vl/J611Zf4/3IE66CsV1D8tioY
         hqYu/sv8/c+0klF+uSeM9g9DGSF1OXGcNzEFLHHTWjsyu7bds9+IA8AXI540qCrM0FAt
         /jytu9MNKGxw0NUo7tdzt+IefJkDQ/0ZiOBbqPCOBetAZ+kdBOACAz3CZtUiWSKlKSDa
         dduhj5tnCKcCmKaOBc35yWEeQbwQA3nRDJ+YDD3p7RK0itFLE+q5C7F3Ktu2CKqdeKq3
         wYjQHTFFO1C8BCY8mKx4i/APeBDtZurzziaGnCMIr/24PKPqBrFX8cZz6B2b13rx8S5t
         +rWQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=i+gW5Ca+Fc/Vl/bhw89s2rbKpyiyqXO/L43eu83JcT4=;
        b=GOcQyzoKe5Lri2uQZyrOxnM28v7UcAQS0S2pqBF2uBLjq9q15/2zZrEivcaH4M1prA
         R23H5THuCT/zp1gELYsDrzEawUZZs9+RLlKvMruVSw71ChEnd1SqktDqrZf+XjNKgcxX
         eZmhfN+bE74jvxtS/m5pOehH8xjnD+Y80mDmfOfyp082dAzY52LEhZ19vMX4FSpn8pMd
         p9uaSFa8cmj4BtWtSrkzCUC6rJBl8zbhBAIzbgfAJwi36XCLUZZEaG2heEyLkfreZWFP
         Rt5XiOlzhvv3cQuALMr0+70xCEf0rYLTjZ55bEzrusmLT9ljQ2qTC5bTSC73XZy56m9h
         QdKQ==
X-Gm-Message-State: AElRT7GFvsg6v1QcdGCkC1krNw3kjla2+g+bvDnW+wdTLX3JuXxDbsAK
        jNiqwJF2OpkOsmgNqsFrl3zMXss7G5EJgw0RTLEGLhIW
X-Google-Smtp-Source: AIpwx48UU/z8cag5jS91ZASHx3/A22n82FfClOz1qhK5PLjj+jLa1iynUfa+A+Eb5CjWTRZSyKJP/xcNTjItBmxigYY=
X-Received: by 2002:a9d:6258:: with SMTP id i24-v6mr18018093otk.239.1523238383902;
 Sun, 08 Apr 2018 18:46:23 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Sun, 8 Apr 2018 18:45:43 -0700 (PDT)
In-Reply-To: <xmqqin916vu6.fsf@gitster-ct.c.googlers.com>
References: <20180408235815.36582-1-haraldnordgren@gmail.com>
 <20180402005248.52418-1-haraldnordgren@gmail.com> <20180408235815.36582-4-haraldnordgren@gmail.com>
 <xmqqin916vu6.fsf@gitster-ct.c.googlers.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Mon, 9 Apr 2018 03:45:43 +0200
Message-ID: <CAHwyqnU-hyRboVDG8BBRJU_uURRdoh4UPg7=PjsJ+V9YPwqYcw@mail.gmail.com>
Subject: Re: [PATCH v13 4/4] ls-remote: create '--sort' option
To:     Junio C Hamano <gitster@pobox.com>
Cc:     Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>,
        Eric Sunshine <sunshine@sunshineco.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Mon, Apr 9, 2018 at 2:56 AM, Junio C Hamano <gitster@pobox.com> wrote:
>
> With the update since v12, I think "because `ls-remote` deals only
> with remotes," can be dropped entirely, and still convey what needs
> to be told: "Be aware some keys that needs access to objects that
> are not here won't work".
>
> Instead, it is probably a better idea to spend that half-line worth
> of characters to describe in what way they do not work (do they try
> to deref a NULL pointer and dump core?  do they notice we need
> missing objects and give an error?).

Updated the docs again. The specific error we get on commiterdate is

    fatal: missing object f0d0fd3a5985d5e588da1e1d11c85fba0ae132f8 for
refs/pull/10/head

So no core dump. But a fatal error with a possibly confusing message.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 00EA31F404
	for <e@80x24.org>; Mon,  9 Apr 2018 02:31:49 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1756464AbeDICbr (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 22:31:47 -0400
Received: from mail-qk0-f172.google.com ([209.85.220.172]:45888 "EHLO
        mail-qk0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1754944AbeDICbp (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 22:31:45 -0400
Received: by mail-qk0-f172.google.com with SMTP id s9so7719241qke.12
        for <git@vger.kernel.org>; Sun, 08 Apr 2018 19:31:45 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:sender:in-reply-to:references:from:date:message-id
         :subject:to:cc;
        bh=/GKcEgfh9lNI1EfDIEOqcc1PGBhX8c9hhSMJN9l5VFU=;
        b=ScgWs42c3DR+P45iBSy5yPzHKLje1FNiU4jec1Aw4B6mAU5Z8SDgd66fJ7TnZzrW+N
         PBpKE9PZ3sOpFPPc7KmxXO5/+rzAu1tZgRQseze73xuIypb1bsB0Swt+rzlRUmDDPyy2
         veqInMoHCpxBrYQmtQuR327A6rPAWD9ujEthl73ypk4lLWJd5o1r4rqN3f6rfvHAOqcX
         HksxpsIfu72a4vbIYf37czNHsTNR7B0qfJlh+1DEdwJcR23RRnVoMqirX64uoB4tEU78
         fli/l48RlxkUNO5NdYj/mGwwHn5OaHJMQeb/30ofnYJbZB+/hRQnO/0+Qzl2I59SRLlb
         lTxQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:cc;
        bh=/GKcEgfh9lNI1EfDIEOqcc1PGBhX8c9hhSMJN9l5VFU=;
        b=D7KCo3XEDxUz4/qJbvAUqXZfy4bsb15FqTtB9AbNVHjMnlLwJPeDqaa/4M5EJROrYj
         JENa95AZQT0xGeoV/qseskw9xR/umvQ70KuKhuFdsN8fu4FmATMj0Dcm4Ezd9niZYrFi
         Hgw5uxZuvbKdADMrbTfL8hqOi2/AYoDLY0eSPl53hX2V6cW4QjwKZUdOWaeb6T/RVfEe
         2aI56kQqi/4h0O68LIsONYWz1X71JMEB3fySVVsfOFn9yifZRNKI3f+c10Y5pGtPPvFE
         rnRpWXC1QM7r5uk/bR5kGEnVmrzuDH6667r30mIILJ/1T8w3lQmnj7bfA1rU9Wue3Xdl
         i4ZQ==
X-Gm-Message-State: ALQs6tCwC71sG3Wvw/vQc0Dx4usF1VYFYqAVYudm6AYe/+hx9RXfuaLA
        ixyBXCK1RhSpSCjx9mguYGJAmZW09XePOlJmwYA=
X-Google-Smtp-Source: AIpwx4+Sfl7ObXyQYzdZtSigIxyk71HFELXi7IYlxuIWHLxIIildgUBWRvpH4cuqZyAAznn9FgThwCuS5owGUuGLrIQ=
X-Received: by 10.55.159.140 with SMTP id i134mr46260815qke.220.1523241104703;
 Sun, 08 Apr 2018 19:31:44 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.12.174.202 with HTTP; Sun, 8 Apr 2018 19:31:44 -0700 (PDT)
In-Reply-To: <xmqq7eph9wds.fsf@gitster-ct.c.googlers.com>
References: <20180408122832.65414-1-haraldnordgren@gmail.com>
 <20180402005248.52418-1-haraldnordgren@gmail.com> <20180408122832.65414-4-haraldnordgren@gmail.com>
 <xmqq7eph9wds.fsf@gitster-ct.c.googlers.com>
From:   Eric Sunshine <sunshine@sunshineco.com>
Date:   Sun, 8 Apr 2018 22:31:44 -0400
X-Google-Sender-Auth: qRiKPrsrlzlGwgu27mBe0CxOxk8
Message-ID: <CAPig+cR4kA+SHmOOOq20BJGzqQkqKvYrFEqPdDF6g6c=apjHtA@mail.gmail.com>
Subject: Re: [PATCH v12 4/4] ls-remote: create '--sort' option
To:     Junio C Hamano <gitster@pobox.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>,
        Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Sun, Apr 8, 2018 at 6:16 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Harald Nordgren <haraldnordgren@gmail.com> writes:
>> +--sort=<key>::
>> +     Sort based on the key given. [...]
>
> This is a tangent but I suspect that the description of --sort in
> git-for-each-ref documentation is wrong on the use of multiple
> options, or I am misreading parse_opt_ref_sorting(), which I think
> appends later keys to the end of the list, and compare_refs() which
> I think yields results when an earlier key in the last decides two
> are not equal and ignores the later keys.  The commit that added the
> description was c0f6dc9b ("git-for-each-ref.txt: minor
> improvements", 2008-06-05), and I think even back then the code in
> builtin-for-each-ref.c appended later keys at the end, and it seems
> nobody complained, so it is possible I am not reading the code right
> before fully adjusting to timezone change ;-)

I just re-read parse_opt_ref_sorting(), and I'm pretty sure that it is
_prepending_ keys to the list, despite the confusingly named variable
"sorting_tail", thus it agrees with the documentation that
--sort=<key> specified last becomes primary sort key.

For me, at least, that behavior (last --sort= becomes primary key)
feels counterintuitive, but it's too late to change it now.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 104BE1F404
	for <e@80x24.org>; Mon,  9 Apr 2018 03:57:49 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1753169AbeDID5r (ORCPT <rfc822;e@80x24.org>);
        Sun, 8 Apr 2018 23:57:47 -0400
Received: from cloud.peff.net ([104.130.231.41]:58210 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1752211AbeDID5q (ORCPT <rfc822;git@vger.kernel.org>);
        Sun, 8 Apr 2018 23:57:46 -0400
Received: (qmail 21928 invoked by uid 109); 9 Apr 2018 03:57:46 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Mon, 09 Apr 2018 03:57:46 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 12126 invoked by uid 111); 9 Apr 2018 03:57:45 -0000
Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Sun, 08 Apr 2018 23:57:45 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Sun, 08 Apr 2018 23:57:43 -0400
Date:   Sun, 8 Apr 2018 23:57:43 -0400
From:   Jeff King <peff@peff.net>
To:     Junio C Hamano <gitster@pobox.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>, git@vger.kernel.org,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH 3/3] ref-filter: factor ref_array pushing into its own
 function
Message-ID: <20180409035743.GA30063@sigill.intra.peff.net>
References: <20180406185801.GA921@sigill.intra.peff.net>
 <20180406185945.GC11108@sigill.intra.peff.net>
 <xmqqy3hx70dw.fsf@gitster-ct.c.googlers.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <xmqqy3hx70dw.fsf@gitster-ct.c.googlers.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Mon, Apr 09, 2018 at 08:18:35AM +0900, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > In preparation for callers constructing their own ref_array
> > structs, let's move our own internal push operation into its
> > own function.
> >
> > While we're at it, we can replace REALLOC_ARRAY() with
> > ALLOC_GROW(), which should give the growth operation
> > amortized linear complexity (as opposed to growing by one,
> > which is potentially quadratic, though in-place realloc
> > growth often makes this faster in practice).
> 
> Sorry, but I do not quite get the last part this paragraph.  Up to
> but not including ", though in-place..." I would understand as:
> 
>      - With ALLOC_GROW(), we are explicit in that we are amortizing
>        the allocation cost by growing in exponential batches.
> 
>      - With REALLOC_ARRAY(), we are telling the underlying
>        realloc(3) that it is OK to pretend that we grow by one, but
>        if that permission is literally followed, it could end up
>        quadratic.
> 
>     So if you have really a bad realloc(3) implementation, switching
>     to use ALLOC_GROW() is an improvement.

Yes, that's the gist of what I was saying. Though it is not even
necessarily "a bad realloc". At some point you may hit heap segmentation
and need to copy (though I guess if that happens repeatedly then maybe
your realloc really _is_ bad ;) ).

> But after that I am not sure what you are getting at.  Do you mean
> "In practice, a well-done realloc(3) does the amortizing internally
> anyway, which makes it faster than the grow-by-one quadratic, so
> this change may not make that much of a difference"?  Or do you mean
> "In practice, a well-done realloc(3) internally amortizes better
> than we do manually, so this change may hurt performance"?

The first. I couldn't measure any speedup on glibc, which makes me think
it's mostly doing in-place expansion.

> In either case, I think this splitting into a helper is obviously a
> good move, and using ALLOC_GROW() is conceptually cleaner, as we use
> it everywhere and tend to avoid realloc(3) just to add one item.
> 
> Other than that small confusion (not even a nit), three patches were
> pleasant read.  Thanks.

Thanks. Please feel free to expand or clarify the commit message if that
helps.

-Peff

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 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,RCVD_IN_DNSWL_HI
	shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id A9F731F404
	for <e@80x24.org>; Wed, 11 Apr 2018 17:57:59 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752270AbeDKR55 (ORCPT <rfc822;e@80x24.org>);
        Wed, 11 Apr 2018 13:57:57 -0400
Received: from mail-ot0-f195.google.com ([74.125.82.195]:44699 "EHLO
        mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751870AbeDKR54 (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 11 Apr 2018 13:57:56 -0400
Received: by mail-ot0-f195.google.com with SMTP id p33-v6so2972281otp.11
        for <git@vger.kernel.org>; Wed, 11 Apr 2018 10:57:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=TOFST5oiYlAtDeAxxbMdQxxAAVgtSF+uGEINNjdLJYw=;
        b=Y71tzG6ahZREjX5PuK4Ubc04j6j52uF857l4ms2R4vLz/qt5m8C9sC/zHTdXV4gX8d
         wkCzBuF8Sd2w3uorLMF6Wcvg/stM9ZwOqJTQVL+ybQLwq1YESborAqGQUVxR8uUkUSbD
         dOnq2RNuFdxKHS4gaAv5yV2BVc48ZJXuGicvorBFQi6xD3APFaMNoc4EQkqRN5/BYhFn
         co3YHl64CXtGXRrH9YwGKMYLZKNfTqgu/Fgys6f/IgfEWal1Vxla3ldBUHGvgKILxKR0
         /Rsov41TUrp4bBjLnDY4UQlTELwqYobkj42twsHg1NvyWUmWeUJJGLPBzOCYQW5Wi6nV
         P24A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=TOFST5oiYlAtDeAxxbMdQxxAAVgtSF+uGEINNjdLJYw=;
        b=eGr9M3VWC2CI88JaP/xlq3qciEQm/8klMm5FsA3IBEn967OSo/4C5tIq9t2QnjLnbK
         cC240W/ZCJF8nn8QpoL6ec5NJxzSct9lQyWJp6H2PLTDBHAmjci2f59z+itZ5bUJKlHR
         bpFROo8m//1GOky1I7HZ0gp+LH4kHR+GfXwTCmnDJ4ONRStY+7pfUeoC2QM6xUEc28h8
         POIpMJptd3T9wPrwZ+t8wJpvFFfoorYRfqQiB+tI0krPAMgaO3ur5rbJLzT7seSoX6+r
         vFKB7nDnsnxBtQobYRUvQF7AAwRxky93h1+z8Va9q/Oj1Awhi0xo8wqsacp5aW8iSpF+
         T9AQ==
X-Gm-Message-State: ALQs6tCSmwiApDVhEYYHzQ9BS+MoqQPRkZ9h3CcgXsfmp/zTCgB5KcTD
        l1VCoPc/xxv+/tzKkwIZ9dF6+lHrySFnZpuK/fA=
X-Google-Smtp-Source: AIpwx4/CUDKFH3dWYREbyESyZiLsrlb8GrB/OiYhcdAEXIluuIqMrwN5nMmVNTBRfhh7pTidaKO54DS7wYLGCebMXMI=
X-Received: by 2002:a9d:481a:: with SMTP id c26-v6mr3958755otf.393.1523469475981;
 Wed, 11 Apr 2018 10:57:55 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.201.68.194 with HTTP; Wed, 11 Apr 2018 10:57:15 -0700 (PDT)
In-Reply-To: <20180409014226.2647-2-haraldnordgren@gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180409014226.2647-1-haraldnordgren@gmail.com> <20180409014226.2647-2-haraldnordgren@gmail.com>
From:   Harald Nordgren <haraldnordgren@gmail.com>
Date:   Wed, 11 Apr 2018 19:57:15 +0200
Message-ID: <CAHwyqnURebvfW4rGz9RAbe7B9p6ZDy0jUueDFrYE30dmjCtMVA@mail.gmail.com>
Subject: Re: [PATCH v14 2/4] ref-filter: make ref_array_item allocation more consistent
To:     Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

There have been no new comments for the last few days. I know Jeff
King will be away for the next two weeks, but should we still move
forward with this? The initial reactions to the idea seemed positive.

Best regards
Harald

On Mon, Apr 9, 2018 at 3:42 AM, Harald Nordgren
<haraldnordgren@gmail.com> wrote:
> From: Jeff King <peff@peff.net>
>
> We have a helper function to allocate ref_array_item
> structs, but it only takes a subset of the possible fields
> in the struct as initializers. We could have it accept an
> argument for _every_ field, but that becomes a pain for the
> fields which some callers don't want to set initially.
>
> Instead, let's be explicit that it takes only the minimum
> required to create the ref, and that callers should then
> fill in the rest themselves.
>
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>  ref-filter.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index ade97a848..c1c3cc948 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -1824,15 +1824,18 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
>         return NULL;
>  }
>
> -/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
> +/*
> + * Allocate space for a new ref_array_item and copy the name and oid to it.
> + *
> + * Callers can then fill in other struct members at their leisure.
> + */
>  static struct ref_array_item *new_ref_array_item(const char *refname,
> -                                                const struct object_id *oid,
> -                                                int flag)
> +                                                const struct object_id *oid)
>  {
>         struct ref_array_item *ref;
> +
>         FLEX_ALLOC_STR(ref, refname, refname);
>         oidcpy(&ref->objectname, oid);
> -       ref->flag = flag;
>
>         return ref;
>  }
> @@ -1927,12 +1930,13 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
>          * to do its job and the resulting list may yet to be pruned
>          * by maxcount logic.
>          */
> -       ref = new_ref_array_item(refname, oid, flag);
> +       ref = new_ref_array_item(refname, oid);
>         ref->commit = commit;
> +       ref->flag = flag;
> +       ref->kind = kind;
>
>         REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
>         ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
> -       ref->kind = kind;
>         return 0;
>  }
>
> @@ -2169,7 +2173,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
>                       const struct ref_format *format)
>  {
>         struct ref_array_item *ref_item;
> -       ref_item = new_ref_array_item(name, oid, 0);
> +       ref_item = new_ref_array_item(name, oid);
>         ref_item->kind = ref_kind_from_refname(name);
>         show_ref_array_item(ref_item, format);
>         free_array_item(ref_item);
> --
> 2.14.3 (Apple Git-98)
>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	RCVD_IN_DNSWL_HI,T_DKIMWL_WL_MED shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 0996B1F404
	for <e@80x24.org>; Wed, 11 Apr 2018 18:08:02 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752512AbeDKSIA (ORCPT <rfc822;e@80x24.org>);
        Wed, 11 Apr 2018 14:08:00 -0400
Received: from mail-yw0-f177.google.com ([209.85.161.177]:38030 "EHLO
        mail-yw0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751777AbeDKSH7 (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 11 Apr 2018 14:07:59 -0400
Received: by mail-yw0-f177.google.com with SMTP id x20so858525ywg.5
        for <git@vger.kernel.org>; Wed, 11 Apr 2018 11:07:58 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=oc7BMQbtzNsjqQT5Iycz0IAeMpgkW3kupJjsBxdHQX4=;
        b=ceiAOt36TDfASUWtlzcfZWpzepIbbEzqzB2Hm8y9kGIGwXVMPdWxe/4yV3f4V/g7TU
         vGoeuQJWvGqqQWOo/aafkdIwYGe1qVAu+hEV2Ed55zeXTBOhbtEkh0l3Pv2N5e/ApDFi
         G3tyfvdKWiZE/RWioEQxNn42TvyQI6Zt6Cl5Tj/pX6MuqNk06JYT8bkiXq6TT0zGPMk0
         UMiYbZS2z6VbhjwqAYeDOKdOKMHzWx5ngbQYDco0TQkZS/2JBKcz0JCLi0UTWF91kwLz
         9+kS2hMWEhSfZPssjGc5yQoxOG2NQYQLsWkziqWEG02E+G8+FEAohKyCO5An3RsIjikj
         ZInQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=oc7BMQbtzNsjqQT5Iycz0IAeMpgkW3kupJjsBxdHQX4=;
        b=oEbYf1U/ULpDDGw4B0ms2bwQVfMu66d/clePl27gVjWie7DV3URFFRRvjRE/do+CCD
         zXMA/EBYOnIPrkdpS2DjxDKMPnWbOT/xpQmcZJ+p9HYzNcB4aKL+aVNmG+P2V1kmibmg
         CA6zjq9knu8igpzXOo9NwSEy/4sr9r4LuvkdWD4xg8pE7TqScII30zKVIanzu1tIWw8g
         MlAll9nwoUujp8BcDitX5EX5P6FzkRQHOr8uBVgKWyg1Vu+P5GsA9q39tGSf1feZmM7X
         TZcv/DETZp/ZZXuBPwbGtVtku8+g60elr5J//QQpkq84c+5/Xto8A0dBii3YPVpm2SeF
         aLXw==
X-Gm-Message-State: ALQs6tDOTIeue9o4rXZ/uTPFTVqvy7aiB35NhIEz0scgTqV7EIaIDqQz
        KkhcYjUa13Y8naMm9B8CGTyu+5NeHkocAmUZOqE+1A==
X-Google-Smtp-Source: AIpwx48Q8CP0mf/MIsHXctjgkKvqy6gFKREA4j6g9LBi25m9mYgPkjdeV35D5ojFJPb5GQXFcw2MZjZsVzu3EGMg9KY=
X-Received: by 10.129.86.5 with SMTP id k5mr2574812ywb.345.1523470077923; Wed,
 11 Apr 2018 11:07:57 -0700 (PDT)
MIME-Version: 1.0
Received: by 2002:a25:cf81:0:0:0:0:0 with HTTP; Wed, 11 Apr 2018 11:07:57
 -0700 (PDT)
In-Reply-To: <CAHwyqnURebvfW4rGz9RAbe7B9p6ZDy0jUueDFrYE30dmjCtMVA@mail.gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180409014226.2647-1-haraldnordgren@gmail.com> <20180409014226.2647-2-haraldnordgren@gmail.com>
 <CAHwyqnURebvfW4rGz9RAbe7B9p6ZDy0jUueDFrYE30dmjCtMVA@mail.gmail.com>
From:   Stefan Beller <sbeller@google.com>
Date:   Wed, 11 Apr 2018 11:07:57 -0700
Message-ID: <CAGZ79kYeM=CqKSWTL2tdDXWueMGoki4zAUmFy4wbhtagN7gEAA@mail.gmail.com>
Subject: Re: [PATCH v14 2/4] ref-filter: make ref_array_item allocation more consistent
To:     Harald Nordgren <haraldnordgren@gmail.com>
Cc:     Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Hi Harald,

On Wed, Apr 11, 2018 at 10:57 AM, Harald Nordgren
<haraldnordgren@gmail.com> wrote:
> There have been no new comments for the last few days. I know Jeff
> King will be away for the next two weeks, but should we still move
> forward with this? The initial reactions to the idea seemed positive.

Please see the "What's cooking?" email on the mailing list that is
sent out periodically by Junio.
the last one is
https://public-inbox.org/git/xmqqd0z865pk.fsf@gitster-ct.c.googlers.com/
which says:

> * jk/ref-array-push (2018-04-09) 3 commits
> - ref-filter: factor ref_array pushing into its own function
> - ref-filter: make ref_array_item allocation more consistent
> - ref-filter: use "struct object_id" consistently
> (this branch is used by hn/sort-ls-remote.)
>
> API clean-up aournd ref-filter code.
>
> Will merge to 'next'.

It will be merged to next and if no people speak up (due to bugs
observed or such)
then it will be merged to master eventually, later.

I am not able to find the documentation for the workflow right now,
though it is partially covered in Documentation/SubmittingPatches.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	RCVD_IN_DNSWL_HI shortcircuit=no autolearn=ham autolearn_force=no
	version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id BF00E1F404
	for <e@80x24.org>; Wed, 11 Apr 2018 18:30:42 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752804AbeDKSak (ORCPT <rfc822;e@80x24.org>);
        Wed, 11 Apr 2018 14:30:40 -0400
Received: from pb-smtp1.pobox.com ([64.147.108.70]:54589 "EHLO
        pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751777AbeDKSak (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 11 Apr 2018 14:30:40 -0400
Received: from pb-smtp1.pobox.com (unknown [127.0.0.1])
        by pb-smtp1.pobox.com (Postfix) with ESMTP id 91D35E2189;
        Wed, 11 Apr 2018 14:30:35 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to
        :cc:subject:message-id:references:mime-version:content-type
        :in-reply-to; s=sasl; bh=CtX6fHtO1wgcgizGyd6AIMc+fS0=; b=r4ngwVR
        NHf5DMJCI/6kDH3Y7yoWqtq9RW9hm7yYku8Tph2S2GHvqvqlBHw7JdTknToXJrti
        x9IBqUEKUsX0ctSCzKqz3uyhigHnxj1cc4e3uzx5O0o7UDUTF5yq4fN8X9EJp1jB
        K8e+7voyvDcjy7A3dFd2rExA4wCISw8YEPN0=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=date:from:to:cc
        :subject:message-id:references:mime-version:content-type
        :in-reply-to; q=dns; s=sasl; b=oQ2AWSf11DkUXes6yJMmBj7nmXxPaxq4R
        4I0Q5BMZ9m6SZ79Eap9qC7rqViI1VDNyNWd5+Nj4Q8FWxpnczfRDOIB9J3vRG9Zp
        6FDyFVcESbRXWmX5Tp1sPS4BOnDxhsjst40eHAr0DTNk4BdliqWMO6lmF3wAKsQD
        SngKeryO90=
Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1])
        by pb-smtp1.pobox.com (Postfix) with ESMTP id 88B8DE2188;
        Wed, 11 Apr 2018 14:30:35 -0400 (EDT)
Received: from zaya.teonanacatl.net (unknown [173.67.181.41])
        (using TLSv1.2 with cipher AES256-SHA (256/256 bits))
        (No client certificate requested)
        by pb-smtp1.pobox.com (Postfix) with ESMTPSA id DF9B2E2187;
        Wed, 11 Apr 2018 14:30:34 -0400 (EDT)
Date:   Wed, 11 Apr 2018 14:30:33 -0400
From:   Todd Zullinger <tmz@pobox.com>
To:     Stefan Beller <sbeller@google.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>,
        Git List <git@vger.kernel.org>,
        =?iso-8859-1?Q?=C6var_Arnfj=F6r=F0?= Bjarmason <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
        Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v14 2/4] ref-filter: make ref_array_item allocation more
 consistent
Message-ID: <20180411183033.GQ29680@zaya.teonanacatl.net>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180409014226.2647-1-haraldnordgren@gmail.com>
 <20180409014226.2647-2-haraldnordgren@gmail.com>
 <CAHwyqnURebvfW4rGz9RAbe7B9p6ZDy0jUueDFrYE30dmjCtMVA@mail.gmail.com>
 <CAGZ79kYeM=CqKSWTL2tdDXWueMGoki4zAUmFy4wbhtagN7gEAA@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAGZ79kYeM=CqKSWTL2tdDXWueMGoki4zAUmFy4wbhtagN7gEAA@mail.gmail.com>
User-Agent: Mutt/1.9.4 (2018-02-28)
X-Pobox-Relay-ID: 6C99DFD2-3DB6-11E8-BC5C-44CE1968708C-09356542!pb-smtp1.pobox.com
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Hi Stefan,

Stefan Beller wrote:
> Please see the "What's cooking?" email on the mailing list that is
> sent out periodically by Junio.
> the last one is
> https://public-inbox.org/git/xmqqd0z865pk.fsf@gitster-ct.c.googlers.com/
> which says:
> 
>> * jk/ref-array-push (2018-04-09) 3 commits
>> - ref-filter: factor ref_array pushing into its own function
>> - ref-filter: make ref_array_item allocation more consistent
>> - ref-filter: use "struct object_id" consistently
>> (this branch is used by hn/sort-ls-remote.)
>>
>> API clean-up aournd ref-filter code.
>>
>> Will merge to 'next'.
> 
> It will be merged to next and if no people speak up (due to bugs
> observed or such)
> then it will be merged to master eventually, later.
> 
> I am not able to find the documentation for the workflow right now,
> though it is partially covered in Documentation/SubmittingPatches.

Perhaps Documentation/howto/maintain-git.txt is the
documentation you're thinking of?

https://kernel.org/pub/software/scm/git/docs/howto/maintain-git.html

There's also MaintNotes in the todo branch:

https://raw.githubusercontent.com/git/git/todo/MaintNotes

-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Be who you are and say what you feel because those who mind don't
matter and those who matter don't mind.
    -- Dr Seuss, "Oh the Places You'll Go"


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.5 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id F22E51F404
	for <e@80x24.org>; Wed, 11 Apr 2018 20:01:34 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1756538AbeDKUBT (ORCPT <rfc822;e@80x24.org>);
        Wed, 11 Apr 2018 16:01:19 -0400
Received: from mail-qt0-f176.google.com ([209.85.216.176]:42416 "EHLO
        mail-qt0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S933873AbeDKS4W (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 11 Apr 2018 14:56:22 -0400
Received: by mail-qt0-f176.google.com with SMTP id j3so3149159qtn.9
        for <git@vger.kernel.org>; Wed, 11 Apr 2018 11:56:22 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:sender:in-reply-to:references:from:date:message-id
         :subject:to:cc;
        bh=kicJFQk1mJrD2u6rKGkyj3hYeaDbIVnA6iT57OXmeYc=;
        b=DXfI27qYhqoCSrZ8tZq6UqrbGRVAjSkZjnV0PHo5hJH2IJ5o6AUVXPW85FB71Wjf/f
         Lz1+cxN0SE3V4PM2eVz+zEq+8aXfbmP3tSSyXPzNoW/kTaQDVfkP80s4FudG9wZlWVRA
         gHjE7obUpTTkBgZWIdXitKI65M3qAGq2zLwisB7oebMZ5+bRZeYqfV7ibC96YQTAwcuc
         6W+QtuyNOmE5KOWPEJF2vzbbj/h+eCM5yyiO0peL4Xzxdqq0w2fA3ONWIrV45V0rv0Nq
         4VuIfZkJFJI+nrfpc1IRXLT0YHURWY7jy1J9Dw6v9awz5eVxNJ8Nd5tN8BUEg5ILBPAC
         UxIQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:cc;
        bh=kicJFQk1mJrD2u6rKGkyj3hYeaDbIVnA6iT57OXmeYc=;
        b=qFxEjxJ0TH8ah+lUPJkPAMLfyTFivV6VrHip85+wuX6YGp4ghoAhE/cQQL6uZGwsXs
         974MgG9xMgXVqL37Uieeovt6RqOdHnYD2JXVLJNsJ++VAAMvAipJojE/uJ45nWeHXzYu
         88yxXTA2tMe4LM2eSgGjQQhRFHqIeGbcGIJfuGg58a+VCwKEQHU6HH0WyD48Tk3Z5XnS
         KTJvU84VXX+RR7VzTFAFzXOuYPATOOgU6kR4yNWzZdM4vvcssJWPdM+Hgdu65slsq9oM
         umnWvZjplmfQAoXeNzmskPC8Ca56HkptcEjuZ+WAppmmjtrA1akN9AfSiiZJI6puYbhp
         7DkQ==
X-Gm-Message-State: ALQs6tDj1U/AVKig1GNZQWGCDy+/Hx2Mxr1sZhDjrU3FaMXeQXUWlFXG
        amwfX9xWzG0RKYhN6nby7ZekQQM/yL7vuyqFwmSRTA==
X-Google-Smtp-Source: AIpwx4+mI00MdZvu6J02Xy0+9x1DGte0b1YIZshZQdphT4EqBu2ALpkSmhKKb9MdhpX+BQrwhRI6FGq+9XpQI1nkB4A=
X-Received: by 10.237.33.231 with SMTP id m36mr2898221qtc.154.1523472981973;
 Wed, 11 Apr 2018 11:56:21 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.12.174.202 with HTTP; Wed, 11 Apr 2018 11:56:21 -0700 (PDT)
In-Reply-To: <CAGZ79kYeM=CqKSWTL2tdDXWueMGoki4zAUmFy4wbhtagN7gEAA@mail.gmail.com>
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
 <20180409014226.2647-1-haraldnordgren@gmail.com> <20180409014226.2647-2-haraldnordgren@gmail.com>
 <CAHwyqnURebvfW4rGz9RAbe7B9p6ZDy0jUueDFrYE30dmjCtMVA@mail.gmail.com> <CAGZ79kYeM=CqKSWTL2tdDXWueMGoki4zAUmFy4wbhtagN7gEAA@mail.gmail.com>
From:   Eric Sunshine <sunshine@sunshineco.com>
Date:   Wed, 11 Apr 2018 14:56:21 -0400
X-Google-Sender-Auth: FF17pDd7OXdq6K3AFrSy2BoRCjw
Message-ID: <CAPig+cQzWAbEVBJ8O0yKYHQ02EaGTx9CeUyF67xozeT2-FL0EA@mail.gmail.com>
Subject: Re: [PATCH v14 2/4] ref-filter: make ref_array_item allocation more consistent
To:     Stefan Beller <sbeller@google.com>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>,
        Git List <git@vger.kernel.org>,
        =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com>,
        Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Content-Type: text/plain; charset="UTF-8"
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Wed, Apr 11, 2018 at 2:07 PM, Stefan Beller <sbeller@google.com> wrote:
> On Wed, Apr 11, 2018 at 10:57 AM, Harald Nordgren
> <haraldnordgren@gmail.com> wrote:
>> There have been no new comments for the last few days. I know Jeff
>> King will be away for the next two weeks, but should we still move
>> forward with this? The initial reactions to the idea seemed positive.
>
> Please see the "What's cooking?" email on the mailing list that is
> sent out periodically by Junio.
>
>> * jk/ref-array-push (2018-04-09) 3 commits
>> - ref-filter: factor ref_array pushing into its own function
>> - ref-filter: make ref_array_item allocation more consistent
>> - ref-filter: use "struct object_id" consistently
>> (this branch is used by hn/sort-ls-remote.)
>>
>> API clean-up aournd ref-filter code.
>>
>> Will merge to 'next'.
>
> It will be merged to next and if no people speak up (due to bugs
> observed or such)

I would guess, however, that Harald is wondering more specifically
about the "--sort" patch he added atop Peff's patches. Disposition for
_that_ patch is not specified in the latest "What's cooking":

    * hn/sort-ls-remote (2018-04-09) 1 commit
     - ls-remote: create '--sort' option
     (this branch uses jk/ref-array-push.)

     "git ls-remote" learned an option to allow sorting its output based
     on the refnames being shown.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,
	T_DKIM_INVALID shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 6E32F1F404
	for <e@80x24.org>; Wed, 11 Apr 2018 23:25:42 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1752178AbeDKXZk (ORCPT <rfc822;e@80x24.org>);
        Wed, 11 Apr 2018 19:25:40 -0400
Received: from mail-wm0-f42.google.com ([74.125.82.42]:40776 "EHLO
        mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751942AbeDKXZj (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 11 Apr 2018 19:25:39 -0400
Received: by mail-wm0-f42.google.com with SMTP id x4so6540685wmh.5
        for <git@vger.kernel.org>; Wed, 11 Apr 2018 16:25:38 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
         :user-agent:mime-version;
        bh=RhKV1lRa0nPqA+OZJGFpSaLBgPvQPOVBM8ak2sL//JU=;
        b=EADnp4QFfzh4Sc12ixa22W1OjeHS+TqhgfkOlrixXL8fZRwMbyxbgPknu3HKw5aRJ3
         0VBODLQMwOtaqUzpOEfnT+DltJW3sbzmbLtLZKWtikvI6jUyaoanh+bUhowjdRoyICZa
         P5lZvTDro//q1mvrn/+xGhEGvJb4ZZ2fg35hKugU0V0Qq6+8LCBbKFCkYNwJLp0PQ2Td
         extMBP+espujX7+zpza7awZ6oVVwxjT22wEKHf6ATTOlW0TX3TsQlyLskqNGTC5rY6qC
         te4UQpRbSJ3ZC8eQFbEAfEEh7DLC/R21BTqC3XkiKTjQ6vMLIDiMKCH57ficRBoYq1XT
         RHbg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:sender:from:to:cc:subject:references:date
         :in-reply-to:message-id:user-agent:mime-version;
        bh=RhKV1lRa0nPqA+OZJGFpSaLBgPvQPOVBM8ak2sL//JU=;
        b=uEvL7eM/JAXh16I1dcvJeFF2bA0V6x9XGD4gzRmKfStuUw8PakVJOrGPEx4RlfhpkJ
         wqZCMwZWsd8booHCPzm69HgqtcwvBfVwZ7BbCQIHZjzqEqnk6WsFc0jkckP2OxEbZwJg
         PuuCPuhCW3avS4g62HMJIhbAkhJdq5ocqM9NexHaGjUi9ZzvwesOUsS9QyO+CyqXiifq
         a2S1ubhCPbSRGxbMguQ95Yr3DAKDXpMYXpfpTusBMU6QU1SjbKTfojw1c8oy60chIk9e
         j+hV0TLdAP1YVuk6hBR9GResJt/jSGZIsCKhWoWOkMSQP8UJyiGkeT0qK+mKKav5qMuz
         J2VA==
X-Gm-Message-State: ALQs6tA5YY0GqNyvrNvMdQHxt9u6tOr59h49reCasGeEbUEocP0vddJN
        9Ax1u4pvjb8elKtU7JEr+Yo=
X-Google-Smtp-Source: AIpwx49jcTTrZbAlO5hphHNofhSXh+r5KxCe0cqR9gRDAimRcAApxixPLogPCX1ewWB1ZJreAPhH4w==
X-Received: by 10.28.116.20 with SMTP id p20mr4009319wmc.24.1523489137918;
        Wed, 11 Apr 2018 16:25:37 -0700 (PDT)
Received: from localhost (112.68.155.104.bc.googleusercontent.com. [104.155.68.112])
        by smtp.gmail.com with ESMTPSA id e10sm4382811wri.23.2018.04.11.16.25.37
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Wed, 11 Apr 2018 16:25:37 -0700 (PDT)
From:   Junio C Hamano <gitster@pobox.com>
To:     Eric Sunshine <sunshine@sunshineco.com>
Cc:     Stefan Beller <sbeller@google.com>,
        Harald Nordgren <haraldnordgren@gmail.com>,
        Git List <git@vger.kernel.org>,
        =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>,
        Jeff King <peff@peff.net>
Subject: Re: [PATCH v14 2/4] ref-filter: make ref_array_item allocation more consistent
References: <20180402005248.52418-1-haraldnordgren@gmail.com>
        <20180409014226.2647-1-haraldnordgren@gmail.com>
        <20180409014226.2647-2-haraldnordgren@gmail.com>
        <CAHwyqnURebvfW4rGz9RAbe7B9p6ZDy0jUueDFrYE30dmjCtMVA@mail.gmail.com>
        <CAGZ79kYeM=CqKSWTL2tdDXWueMGoki4zAUmFy4wbhtagN7gEAA@mail.gmail.com>
        <CAPig+cQzWAbEVBJ8O0yKYHQ02EaGTx9CeUyF67xozeT2-FL0EA@mail.gmail.com>
Date:   Thu, 12 Apr 2018 08:25:36 +0900
In-Reply-To: <CAPig+cQzWAbEVBJ8O0yKYHQ02EaGTx9CeUyF67xozeT2-FL0EA@mail.gmail.com>
        (Eric Sunshine's message of "Wed, 11 Apr 2018 14:56:21 -0400")
Message-ID: <xmqq37014973.fsf@gitster-ct.c.googlers.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Wed, Apr 11, 2018 at 2:07 PM, Stefan Beller <sbeller@google.com> wrote:
>> On Wed, Apr 11, 2018 at 10:57 AM, Harald Nordgren
>> <haraldnordgren@gmail.com> wrote:
>>> There have been no new comments for the last few days. I know Jeff
>>> King will be away for the next two weeks, but should we still move
>>> forward with this? The initial reactions to the idea seemed positive.
>> ...
>> It will be merged to next and if no people speak up (due to bugs
>> observed or such)
>
> I would guess, however, that Harald is wondering more specifically
> about the "--sort" patch he added atop Peff's patches. Disposition for
> _that_ patch is not specified in the latest "What's cooking":
>
>     * hn/sort-ls-remote (2018-04-09) 1 commit
>      - ls-remote: create '--sort' option
>      (this branch uses jk/ref-array-push.)
>
>      "git ls-remote" learned an option to allow sorting its output based
>      on the refnames being shown.

Thanks all for summarizing.

I think the preliminary clean-up patches by Peff are all
independently good and can be advanced, even without him being
around.  I haven't formed a firm opinion on the doneness of the
latest round of the "--sort" thing.  I usually do not explicitly
write "I haven't formed an opinion" in "What's cooking" report,
so please read the lack of "disposition" as such.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00,
	FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI shortcircuit=no autolearn=ham
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id D69A31F42D
	for <e@80x24.org>; Sat, 12 May 2018 08:45:35 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1751048AbeELIpe (ORCPT <rfc822;e@80x24.org>);
        Sat, 12 May 2018 04:45:34 -0400
Received: from mout.web.de ([212.227.17.11]:60095 "EHLO mout.web.de"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1750908AbeELIpd (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 12 May 2018 04:45:33 -0400
Received: from [192.168.178.36] ([91.20.55.213]) by smtp.web.de (mrweb103
 [213.165.67.124]) with ESMTPSA (Nemesis) id 0McnqH-1f0AHl469R-00Hw5J; Sat, 12
 May 2018 10:45:25 +0200
Subject: Re: [PATCH v14 4/4] ls-remote: create '--sort' option
To:     Harald Nordgren <haraldnordgren@gmail.com>, peff@peff.net
References: <20180409014226.2647-1-haraldnordgren@gmail.com>
 <20180409014226.2647-4-haraldnordgren@gmail.com>
From:   =?UTF-8?Q?Ren=c3=a9_Scharfe?= <l.s.r@web.de>
Cc:     git@vger.kernel.org, avarab@gmail.com, gitster@pobox.com,
        sunshine@sunshineco.com
Message-ID: <b5555929-9f7c-1c4a-78e8-708ebdaaa9d2@web.de>
Date:   Sat, 12 May 2018 10:45:23 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
 Thunderbird/52.7.0
MIME-Version: 1.0
In-Reply-To: <20180409014226.2647-4-haraldnordgren@gmail.com>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Provags-ID: V03:K1:zBCnwKbm6YAlQxT6OoRP3wZ8DqxJ1S3VasRMiRV29UAm3SRyHy1
 /fUNp4GePPtsDSh403/h9w8AGOm7AahHsDw1aPK7K69Lzhx1UWuDxpSZyLUg0KUznaWXfns
 +mt+AUBtg4lUcUtORhwmGZNPH7oZzcKPO5kzsMArTpd9TB4FozdRMU+LTwlPECOBXWoZRkL
 MO3cu0WNh02utwTxN7nNQ==
X-UI-Out-Filterresults: notjunk:1;V01:K0:WRdeHWl2weQ=:dsW1ROUHKRM5bcdX/hTG2y
 APsY7bjEF9hfwXgSQ//UjYaSvNp462zkvtODQmLqmUwBqoMv36L2kFT5PRCQpo9Eb8MHBzE3b
 GZ5MrMES2+4fdfiDeLyxhAt4HjqU5ABn256SMqTcKclJgjtx40QFx0rEuoKBo30+cj8nvvhoS
 zZc8MIuzge4h7L7aFeWBcaTygveJsg8OEG8t6RNXdxx3fNOF9cvdxvYIaoHrKoMtFvfrxQyO2
 7UKG/jqngIQgy0bARiTouf0qaqnu8AUaHMzorsml4aGPCg+NtxqcS/Curaaulk6XFNZnbtOq7
 o6m0PBInVKKidjSRkjaup1F31bItIxbyL5cgXGI6B8FD7uRbQM5ejAhvUwtkME1vHI3yHqy+5
 w9LDIY3CAUlTTF4zFsimjcdEEMU+GiRyZqQiLKWcAcKpQBLTPE85Mzuu7a9YX/3rkSB9jzfzl
 U3YuA7/AHY19yRBpR8Ahb5IH+0MXHKanL3dzVo5AmwayUN3478wmW99tzSDwVR8NBkb9bqQO6
 EPzFmlqZiav5MH5vhMZthcypUNsLtsy8hT7/VpAAzAdoIlv/oC1cfK+7tc2/M9W87equhf+uU
 aDni/tPLDhH03aYsC/AwURdsSWzXead7aE/RlZMaqAfkPinHd7x+aX0pUacseiykMVlA4f9IM
 tulHjHM7EuXuDSKlZr/Zc+sDWqPX+kEahydOIIRd6af4KrZk5rxcbaGuWOOYiPRhVVKxfshAf
 6ANPF1EoHoRdL7AyNnY0gLueatAlBFMbniToQrq6+k1kmkDpE/unP/YMgRzOYkZAgwnaebZcI
 VxBHcAZ
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Am 09.04.2018 um 03:42 schrieb Harald Nordgren:
> diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
> index 02106c922..83cd35c39 100755
> --- a/t/t5512-ls-remote.sh
> +++ b/t/t5512-ls-remote.sh

> @@ -170,14 +206,18 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
>   	grep refs/tags/magic actual
>   '
>   
> +git fetch origin
>   test_expect_success 'ls-remote --symref' '
> -	cat >expect <<-\EOF &&
> +	cat >expect <<-EOF &&
>   	ref: refs/heads/master	HEAD
> -	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	HEAD
> -	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/heads/master
> -	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/HEAD
> -	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/remotes/origin/master
> -	1bd44cb9d13204b0fe1958db0082f5028a16eb3a	refs/tags/mark
> +	$(git rev-parse HEAD)	HEAD
> +	$(git rev-parse refs/heads/master)	refs/heads/master
> +	$(git rev-parse HEAD)	refs/remotes/origin/HEAD
> +	$(git rev-parse refs/remotes/origin/master)	refs/remotes/origin/master
> +	$(git rev-parse refs/tags/mark)	refs/tags/mark
> +	$(git rev-parse refs/tags/mark1.1)	refs/tags/mark1.1
> +	$(git rev-parse refs/tags/mark1.10)	refs/tags/mark1.10
> +	$(git rev-parse refs/tags/mark1.2)	refs/tags/mark1.2
>   	EOF
>   	git ls-remote --symref >actual &&
>   	test_cmp expect actual

Why is fetch called outside of the test?  Its output is shown among the
test messages, where it doesn't belong:

    ok 23 - overrides work between mixed transfer/upload-pack hideRefs
    From /home/lsr/src/git/t/trash directory.t5512-ls-remote/
     * [new branch]      master     -> origin/master
    ok 24 - ls-remote --symref

-- >8 --
Subject: [PATCH] t5512: run git fetch inside test

Do the preparatory fetch inside the test of ls-remote --symref to avoid
cluttering the test output and to be able to catch unexpected fetch
failures.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 t/t5512-ls-remote.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 83cd35c391..6a949484d0 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -206,8 +206,8 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
 	grep refs/tags/magic actual
 '
 
-git fetch origin
 test_expect_success 'ls-remote --symref' '
+	git fetch origin &&
 	cat >expect <<-EOF &&
 	ref: refs/heads/master	HEAD
 	$(git rev-parse HEAD)	HEAD
-- 
2.17.0

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI
	shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 796961F42D
	for <e@80x24.org>; Sat, 12 May 2018 09:55:28 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1750799AbeELJz0 (ORCPT <rfc822;e@80x24.org>);
        Sat, 12 May 2018 05:55:26 -0400
Received: from cloud.peff.net ([104.130.231.41]:37166 "HELO cloud.peff.net"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP
        id S1750735AbeELJzZ (ORCPT <rfc822;git@vger.kernel.org>);
        Sat, 12 May 2018 05:55:25 -0400
Received: (qmail 25803 invoked by uid 109); 12 May 2018 09:55:25 -0000
Received: from Unknown (HELO peff.net) (10.0.1.2)
 by cloud.peff.net (qpsmtpd/0.94) with SMTP; Sat, 12 May 2018 09:55:25 +0000
Authentication-Results: cloud.peff.net; auth=none
Received: (qmail 13894 invoked by uid 111); 12 May 2018 09:55:30 -0000
Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7)
 by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Sat, 12 May 2018 05:55:30 -0400
Authentication-Results: peff.net; auth=none
Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Sat, 12 May 2018 05:55:23 -0400
Date:   Sat, 12 May 2018 05:55:23 -0400
From:   Jeff King <peff@peff.net>
To:     =?utf-8?B?UmVuw6k=?= Scharfe <l.s.r@web.de>
Cc:     Harald Nordgren <haraldnordgren@gmail.com>, git@vger.kernel.org,
        avarab@gmail.com, gitster@pobox.com, sunshine@sunshineco.com
Subject: Re: [PATCH v14 4/4] ls-remote: create '--sort' option
Message-ID: <20180512095523.GA2234@sigill.intra.peff.net>
References: <20180409014226.2647-1-haraldnordgren@gmail.com>
 <20180409014226.2647-4-haraldnordgren@gmail.com>
 <b5555929-9f7c-1c4a-78e8-708ebdaaa9d2@web.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <b5555929-9f7c-1c4a-78e8-708ebdaaa9d2@web.de>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Sat, May 12, 2018 at 10:45:23AM +0200, René Scharfe wrote:

> Why is fetch called outside of the test?  Its output is shown among the
> test messages, where it doesn't belong:
> 
>     ok 23 - overrides work between mixed transfer/upload-pack hideRefs
>     From /home/lsr/src/git/t/trash directory.t5512-ls-remote/
>      * [new branch]      master     -> origin/master
>     ok 24 - ls-remote --symref

Heh, I just noticed this yesterday, too, but ran out of time before
writing up the patch.

> -- >8 --
> Subject: [PATCH] t5512: run git fetch inside test
> 
> Do the preparatory fetch inside the test of ls-remote --symref to avoid
> cluttering the test output and to be able to catch unexpected fetch
> failures.

Yep, this looks obviously correct.

-Peff

